From 282cdfe67cc9f9763868abf9aeb0d97e52c06d63 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 28 Aug 2011 16:53:54 +0200 Subject: Add create() hook to connection factories This will allow the user to either establish the connection themselves (using the handle c-tor) and/or configure the connection post-creation. --- odb/sqlite/connection-factory.hxx | 52 +++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'odb/sqlite/connection-factory.hxx') diff --git a/odb/sqlite/connection-factory.hxx b/odb/sqlite/connection-factory.hxx index 8166fc4..04f91bf 100644 --- a/odb/sqlite/connection-factory.hxx +++ b/odb/sqlite/connection-factory.hxx @@ -61,15 +61,12 @@ namespace odb single_connection_factory (const single_connection_factory&); single_connection_factory& operator= (const single_connection_factory&); - private: + protected: class single_connection: public connection { public: - // NULL factory value indicates that the connection is not in use. - // - single_connection (database_type&, - int extra_flags, - single_connection_factory*); + single_connection (database_type&, int extra_flags); + single_connection (database_type&, sqlite3*); private: static bool @@ -79,21 +76,32 @@ namespace odb friend class single_connection_factory; shared_base::refcount_callback callback_; + + // NULL factory value indicates that the connection is not in use. + // single_connection_factory* factory_; }; friend class single_connection; - private: + typedef details::shared_ptr single_connection_ptr; + + // This function is called when the factory needs to create the + // connection. + // + virtual single_connection_ptr + create (); + + protected: // Return true if the connection should be deleted, false otherwise. // bool release (single_connection*); - private: + protected: database_type* db_; details::mutex mutex_; - details::shared_ptr connection_; + single_connection_ptr connection_; }; // Create a new connection every time one is requested. @@ -167,15 +175,12 @@ namespace odb connection_pool_factory (const connection_pool_factory&); connection_pool_factory& operator= (const connection_pool_factory&); - private: + protected: class pooled_connection: public connection { public: - // NULL pool value indicates that the connection is not in use. - // - pooled_connection (database_type&, - int extra_flags, - connection_pool_factory*); + pooled_connection (database_type&, int extra_flags); + pooled_connection (database_type&, sqlite3*); private: static bool @@ -185,19 +190,30 @@ namespace odb friend class connection_pool_factory; shared_base::refcount_callback callback_; + + // NULL pool value indicates that the connection is not in use. + // connection_pool_factory* pool_; }; friend class pooled_connection; - typedef std::vector > connections; - private: + typedef details::shared_ptr pooled_connection_ptr; + typedef std::vector connections; + + // This function is called whenever the pool needs to create a new + // connection. + // + virtual pooled_connection_ptr + create (); + + protected: // Return true if the connection should be deleted, false otherwise. // bool release (pooled_connection*); - private: + protected: const std::size_t max_; const std::size_t min_; int extra_flags_; -- cgit v1.1