aboutsummaryrefslogtreecommitdiff
path: root/odb/pgsql/connection-factory.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/pgsql/connection-factory.cxx')
-rw-r--r--odb/pgsql/connection-factory.cxx56
1 files changed, 20 insertions, 36 deletions
diff --git a/odb/pgsql/connection-factory.cxx b/odb/pgsql/connection-factory.cxx
index f35b2c8..a57fc41 100644
--- a/odb/pgsql/connection-factory.cxx
+++ b/odb/pgsql/connection-factory.cxx
@@ -15,39 +15,20 @@ namespace odb
namespace pgsql
{
- //
- // connection_factory
- //
-
- connection_factory::
- ~connection_factory ()
- {
- }
-
- //
// new_connection_factory
//
-
connection_ptr new_connection_factory::
connect ()
{
- return connection_ptr (new (shared) connection (*db_));
+ return connection_ptr (new (shared) connection (*this));
}
- void new_connection_factory::
- database (database_type& db)
- {
- db_ = &db;
- }
-
- //
// connection_pool_factory
//
-
connection_pool_factory::pooled_connection_ptr connection_pool_factory::
create ()
{
- return pooled_connection_ptr (new (shared) pooled_connection (*db_));
+ return pooled_connection_ptr (new (shared) pooled_connection (*this));
}
connection_pool_factory::
@@ -79,7 +60,7 @@ namespace odb
shared_ptr<pooled_connection> c (connections_.back ());
connections_.pop_back ();
- c->pool_ = this;
+ c->callback_ = &c->cb_;
in_use_++;
return c;
}
@@ -89,7 +70,7 @@ namespace odb
if (max_ == 0 || in_use_ < max_)
{
shared_ptr<pooled_connection> c (create ());
- c->pool_ = this;
+ c->callback_ = &c->cb_;
in_use_++;
return c;
}
@@ -105,7 +86,12 @@ namespace odb
void connection_pool_factory::
database (database_type& db)
{
- db_ = &db;
+ bool first (db_ == 0);
+
+ connection_factory::database (db);
+
+ if (!first)
+ return;
if (min_ > 0)
{
@@ -119,7 +105,7 @@ namespace odb
bool connection_pool_factory::
release (pooled_connection* c)
{
- c->pool_ = 0;
+ c->callback_ = 0;
lock l (mutex_);
@@ -149,28 +135,26 @@ namespace odb
//
connection_pool_factory::pooled_connection::
- pooled_connection (database_type& db)
- : connection (db), pool_ (0)
+ pooled_connection (connection_pool_factory& f)
+ : connection (f)
{
- callback_.arg = this;
- callback_.zero_counter = &zero_counter;
- shared_base::callback_ = &callback_;
+ cb_.arg = this;
+ cb_.zero_counter = &zero_counter;
}
connection_pool_factory::pooled_connection::
- pooled_connection (database_type& db, PGconn* handle)
- : connection (db, handle), pool_ (0)
+ pooled_connection (connection_pool_factory& f, PGconn* handle)
+ : connection (f, handle)
{
- callback_.arg = this;
- callback_.zero_counter = &zero_counter;
- shared_base::callback_ = &callback_;
+ cb_.arg = this;
+ cb_.zero_counter = &zero_counter;
}
bool connection_pool_factory::pooled_connection::
zero_counter (void* arg)
{
pooled_connection* c (static_cast<pooled_connection*> (arg));
- return c->pool_ ? c->pool_->release (c) : true;
+ return static_cast<connection_pool_factory&> (c->factory_).release (c);
}
}
}