From 79cb2f05559e1ed9e724efd4f5dbceca794e7162 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 29 Apr 2021 12:37:09 +0200 Subject: Add serial_connection_factory This factory can be used when the database access is guaranteed to be serial. --- odb/sqlite/connection-factory.cxx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'odb/sqlite/connection-factory.cxx') diff --git a/odb/sqlite/connection-factory.cxx b/odb/sqlite/connection-factory.cxx index 1269db3..1a1f85a 100644 --- a/odb/sqlite/connection-factory.cxx +++ b/odb/sqlite/connection-factory.cxx @@ -17,6 +17,40 @@ namespace odb namespace sqlite { // + // serial_connection_factory + // + + serial_connection_factory:: + ~serial_connection_factory () + { + // We should hold the last reference to the connection. + // + if (connection_ != 0) + assert (connection_.count () == 1); + } + + connection_ptr serial_connection_factory:: + create () + { + return connection_ptr (new (shared) connection (*this)); + } + + connection_ptr serial_connection_factory:: + connect () + { + return connection_; + } + + void serial_connection_factory:: + database (database_type& db) + { + connection_factory::database (db); + + if (!connection_) + connection_ = create (); + } + + // // single_connection_factory // -- cgit v1.1