aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite/connection-factory.hxx
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.hxx
parent0db95154f2f063f6747d29c5c048bae933dcb7a1 (diff)
Add single_connection_factory
Diffstat (limited to 'odb/sqlite/connection-factory.hxx')
-rw-r--r--odb/sqlite/connection-factory.hxx60
1 files changed, 60 insertions, 0 deletions
diff --git a/odb/sqlite/connection-factory.hxx b/odb/sqlite/connection-factory.hxx
index 76bdc11..e687e27 100644
--- a/odb/sqlite/connection-factory.hxx
+++ b/odb/sqlite/connection-factory.hxx
@@ -40,6 +40,64 @@ namespace odb
~connection_factory ();
};
+ // Share a single connection.
+ //
+ class LIBODB_SQLITE_EXPORT single_connection_factory:
+ public connection_factory
+ {
+ public:
+ single_connection_factory (): db_ (0) {}
+
+ virtual details::shared_ptr<connection>
+ connect ();
+
+ virtual void
+ database (database_type&);
+
+ virtual
+ ~single_connection_factory ();
+
+ private:
+ single_connection_factory (const single_connection_factory&);
+ single_connection_factory& operator= (const single_connection_factory&);
+
+ private:
+ 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*);
+
+ private:
+ static bool
+ zero_counter (void*);
+
+ private:
+ friend class single_connection_factory;
+
+ shared_base::refcount_callback callback_;
+ single_connection_factory* factory_;
+ };
+
+ friend class single_connection;
+
+ private:
+ // Return true if the connection should be deleted, false otherwise.
+ //
+ bool
+ release (single_connection*);
+
+ private:
+ database_type* db_;
+ details::mutex mutex_;
+ details::shared_ptr<single_connection> connection_;
+ };
+
+ // Create a new connection every time one is requested.
+ //
class LIBODB_SQLITE_EXPORT new_connection_factory:
public connection_factory
{
@@ -61,6 +119,8 @@ namespace odb
int extra_flags_;
};
+ // Pool a number of connections.
+ //
class LIBODB_SQLITE_EXPORT connection_pool_factory:
public connection_factory
{