aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite/connection-factory.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-03-29 17:53:00 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-03-29 17:53:00 +0200
commit163bb9d59de08b02074395fbb2a9fde5f8cc14d9 (patch)
tree891972c2612ff6b4c4ddd787f5952591f6c9fbd9 /odb/sqlite/connection-factory.cxx
parent0db95154f2f063f6747d29c5c048bae933dcb7a1 (diff)
Add single_connection_factory
Diffstat (limited to 'odb/sqlite/connection-factory.cxx')
-rw-r--r--odb/sqlite/connection-factory.cxx61
1 files changed, 61 insertions, 0 deletions
diff --git a/odb/sqlite/connection-factory.cxx b/odb/sqlite/connection-factory.cxx
index 11184bc..fc9fefc 100644
--- a/odb/sqlite/connection-factory.cxx
+++ b/odb/sqlite/connection-factory.cxx
@@ -26,6 +26,67 @@ namespace odb
}
//
+ // single_connection_factory
+ //
+
+ single_connection_factory::
+ ~single_connection_factory ()
+ {
+ // If the connection is currently in use, wait for it to return to
+ // the factory.
+ //
+ lock l (mutex_);
+ }
+
+ shared_ptr<connection> single_connection_factory::
+ connect ()
+ {
+ mutex_.lock ();
+ connection_->factory_ = this;
+ shared_ptr<connection> r (connection_);
+ connection_.reset ();
+ return r;
+ }
+
+ void single_connection_factory::
+ database (database_type& db)
+ {
+ db_ = &db;
+ connection_.reset (new (shared) single_connection (*db_, 0, 0));
+ }
+
+ bool single_connection_factory::
+ release (single_connection* c)
+ {
+ c->factory_ = 0;
+ connection_.reset (inc_ref (c));
+ mutex_.unlock ();
+ return false;
+ }
+
+ //
+ // single_connection_factory::single_connection
+ //
+
+ single_connection_factory::single_connection::
+ single_connection (database_type& db,
+ int extra_flags,
+ single_connection_factory* factory)
+ : connection (db, extra_flags), factory_ (factory)
+ {
+ callback_.arg = this;
+ callback_.zero_counter = &zero_counter;
+ shared_base::callback_ = &callback_;
+ }
+
+ bool single_connection_factory::single_connection::
+ zero_counter (void* arg)
+ {
+ single_connection* c (static_cast<single_connection*> (arg));
+ return c->factory_ ? c->factory_->release (c) : true;
+ }
+
+ //
// new_connection_factory
//