diff options
-rw-r--r-- | odb/connection.cxx | 6 | ||||
-rw-r--r-- | odb/connection.hxx | 19 | ||||
-rw-r--r-- | odb/connection.ixx | 6 | ||||
-rw-r--r-- | odb/database.cxx | 2 | ||||
-rw-r--r-- | odb/database.hxx | 19 | ||||
-rw-r--r-- | odb/database.ixx | 5 | ||||
-rw-r--r-- | odb/details/unique-ptr.hxx | 16 |
7 files changed, 59 insertions, 14 deletions
diff --git a/odb/connection.cxx b/odb/connection.cxx index 87f76d3..e3bc946 100644 --- a/odb/connection.cxx +++ b/odb/connection.cxx @@ -12,6 +12,8 @@ using namespace std; namespace odb { + // connection + // connection:: ~connection () { @@ -98,8 +100,8 @@ namespace odb { // Use a factory, if there is one. // - if (database_.call_query_factory (name, - const_cast<connection&> (*this))) + if (factory_.database ().call_query_factory ( + name, const_cast<connection&> (*this))) i = prepared_map_.find (name); } diff --git a/odb/connection.hxx b/odb/connection.hxx index 20cb285..f1f8c3b 100644 --- a/odb/connection.hxx +++ b/odb/connection.hxx @@ -26,6 +26,7 @@ namespace odb { class transaction_impl; + class connection_factory; class connection; typedef details::shared_ptr<connection> connection_ptr; @@ -130,7 +131,7 @@ namespace odb recycle (); protected: - connection (database_type&); + connection (connection_factory&); template <typename T, database_id DB, @@ -180,7 +181,7 @@ namespace odb clear_prepared_map (); protected: - database_type& database_; + connection_factory& factory_; tracer_type* tracer_; // Active query result list. @@ -203,6 +204,20 @@ namespace odb friend class transaction; tracer_type* transaction_tracer_; }; + + class LIBODB_EXPORT connection_factory + { + public: + typedef odb::database database_type; + + connection_factory (): db_ (0) {} + + database_type& + database () {return *db_;} + + protected: + database_type* db_; + }; } #include <odb/connection.ixx> diff --git a/odb/connection.ixx b/odb/connection.ixx index 573134d..e86f8d8 100644 --- a/odb/connection.ixx +++ b/odb/connection.ixx @@ -8,8 +8,8 @@ namespace odb { inline connection:: - connection (database_type& database) - : database_ (database), + connection (connection_factory& f) + : factory_ (f), tracer_ (0), results_ (0), prepared_queries_ (0), @@ -20,7 +20,7 @@ namespace odb inline connection::database_type& connection:: database () { - return database_; + return factory_.database (); } inline unsigned long long connection:: diff --git a/odb/database.cxx b/odb/database.cxx index 2ce15b2..7ea8313 100644 --- a/odb/database.cxx +++ b/odb/database.cxx @@ -27,7 +27,7 @@ namespace odb const database::schema_version_migration_type& database:: schema_version_migration (const string& name) const { - lock l (mutex_); // Prevents concurrent loading. + lock l (*mutex_); // Prevents concurrent loading. schema_version_map::const_iterator i (schema_version_map_.find (name)); return i != schema_version_map_.end () && i->second.version != 0 diff --git a/odb/database.hxx b/odb/database.hxx index 8ee5c55..510b28b 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -32,6 +32,7 @@ #include <odb/details/export.hxx> #include <odb/details/mutex.hxx> #include <odb/details/c-string.hxx> +#include <odb/details/unique-ptr.hxx> #include <odb/details/function-wrapper.hxx> #include <odb/details/meta/answer.hxx> @@ -45,6 +46,18 @@ namespace odb virtual ~database (); +#ifdef ODB_CXX11 + database (database&&) = default; +#endif + + private: + database (const database&); + database& operator= (const database&); + +#ifdef ODB_CXX11 + database& operator= (const database&&); +#endif + // Object persistence API. // public: @@ -504,10 +517,6 @@ namespace odb protected: database (database_id); - private: - database (const database&); - database& operator= (const database&); - protected: virtual connection_type* connection_ () = 0; @@ -621,7 +630,7 @@ namespace odb tracer_type* tracer_; query_factory_map query_factory_map_; - mutable details::mutex mutex_; + details::unique_ptr<details::mutex> mutex_; // Dynamic for move support. mutable schema_version_map schema_version_map_; std::string schema_version_table_; unsigned int schema_version_seq_; diff --git a/odb/database.ixx b/odb/database.ixx index 2fd54c0..1ea7949 100644 --- a/odb/database.ixx +++ b/odb/database.ixx @@ -73,7 +73,10 @@ namespace odb inline database:: database (database_id id) - : id_ (id), tracer_ (0), schema_version_seq_ (1) + : id_ (id), + tracer_ (0), + mutex_ (new details::mutex), + schema_version_seq_ (1) { } diff --git a/odb/details/unique-ptr.hxx b/odb/details/unique-ptr.hxx index 35f4d68..547dd3b 100644 --- a/odb/details/unique-ptr.hxx +++ b/odb/details/unique-ptr.hxx @@ -7,6 +7,8 @@ #include <odb/pre.hxx> +#include <odb/details/config.hxx> + namespace odb { namespace details @@ -20,6 +22,20 @@ namespace odb explicit unique_ptr (T* p = 0): p_ (p) {} ~unique_ptr () {delete p_;} +#ifdef ODB_CXX11 + unique_ptr (unique_ptr&& p): p_ (p.p_) {p.p_ = 0;} + unique_ptr& operator= (unique_ptr&& p) + { + if (this != &p) + { + delete p_; + p_ = p.p_; + p.p_ = 0; + } + return *this; + } +#endif + private: unique_ptr (const unique_ptr&); unique_ptr& operator= (const unique_ptr&); |