diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-08-28 16:53:54 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-08-28 16:53:54 +0200 |
commit | 44a26d189e186ac10c4a80c4dbb68d65927b12a9 (patch) | |
tree | 4bf37b4283c4b51c5a6568cfb540e176f6bfa520 /odb/pgsql/connection-factory.cxx | |
parent | b405fdd235a7dcb40423229af033abd4687c72b2 (diff) |
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.
Diffstat (limited to 'odb/pgsql/connection-factory.cxx')
-rw-r--r-- | odb/pgsql/connection-factory.cxx | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/odb/pgsql/connection-factory.cxx b/odb/pgsql/connection-factory.cxx index c9e758d..d725ef0 100644 --- a/odb/pgsql/connection-factory.cxx +++ b/odb/pgsql/connection-factory.cxx @@ -45,6 +45,12 @@ namespace odb // connection_pool_factory // + connection_pool_factory::pooled_connection_ptr connection_pool_factory:: + create () + { + return pooled_connection_ptr (new (shared) pooled_connection (*db_)); + } + connection_pool_factory:: ~connection_pool_factory () { @@ -83,8 +89,8 @@ namespace odb // if (max_ == 0 || in_use_ < max_) { - shared_ptr<pooled_connection> c ( - new (shared) pooled_connection (*db_, this)); + shared_ptr<pooled_connection> c (create ()); + c->pool_ = this; in_use_++; return c; } @@ -107,11 +113,7 @@ namespace odb connections_.reserve (min_); for (size_t i (0); i < min_; ++i) - { - connections_.push_back ( - shared_ptr<pooled_connection> ( - new (shared) pooled_connection (*db_, 0))); - } + connections_.push_back (create ()); } } @@ -131,8 +133,7 @@ namespace odb in_use_--; if (keep) - connections_.push_back ( - shared_ptr<pooled_connection> (inc_ref (c))); + connections_.push_back (pooled_connection_ptr (inc_ref (c))); if (waiters_ != 0) cond_.signal (); @@ -145,8 +146,17 @@ namespace odb // connection_pool_factory::pooled_connection:: - pooled_connection (database_type& db, connection_pool_factory* pool) - : connection (db), pool_ (pool) + pooled_connection (database_type& db) + : connection (db), pool_ (0) + { + callback_.arg = this; + callback_.zero_counter = &zero_counter; + shared_base::callback_ = &callback_; + } + + connection_pool_factory::pooled_connection:: + pooled_connection (database_type& db, PGconn* handle) + : connection (db, handle), pool_ (0) { callback_.arg = this; callback_.zero_counter = &zero_counter; |