diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-08-24 13:42:04 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-08-24 13:42:04 +0200 |
commit | 1d42e7cc891403b5f20eb67bc08f23a667019402 (patch) | |
tree | 8cad3b525097d47b933e5f10c11ed83c6d661895 | |
parent | 148e68c83c45bb374785306476351181e00f0a09 (diff) |
Add support for transaction multiplexing
Also delay getting a connection until after we do all the sanity
checks (e.g., that there is no active transaction). Otherwise we
are running risk of getting blocked rather than throwing an
exception.
-rw-r--r-- | odb/tracer/connection.cxx | 6 | ||||
-rw-r--r-- | odb/tracer/database.cxx | 4 | ||||
-rw-r--r-- | odb/tracer/database.hxx | 2 | ||||
-rw-r--r-- | odb/tracer/transaction-impl.cxx | 21 | ||||
-rw-r--r-- | odb/tracer/transaction-impl.hxx | 9 | ||||
-rw-r--r-- | odb/tracer/transaction.hxx | 5 | ||||
-rw-r--r-- | odb/tracer/transaction.ixx | 6 |
7 files changed, 40 insertions, 13 deletions
diff --git a/odb/tracer/connection.cxx b/odb/tracer/connection.cxx index 516e36a..54c233c 100644 --- a/odb/tracer/connection.cxx +++ b/odb/tracer/connection.cxx @@ -27,11 +27,7 @@ namespace odb transaction_impl* connection:: begin () { - if (odb::transaction::has_current ()) - throw already_in_transaction (); - - return new transaction_impl ( - connection_ptr (inc_ref (this))); + return new transaction_impl (connection_ptr (inc_ref (this))); } } } diff --git a/odb/tracer/database.cxx b/odb/tracer/database.cxx index 90cfdfd..5e032ee 100644 --- a/odb/tracer/database.cxx +++ b/odb/tracer/database.cxx @@ -18,10 +18,10 @@ namespace odb transaction_impl* database:: begin () { - return connection ()->begin (); + return new transaction_impl (*this); } - inline connection_ptr database:: + connection_ptr database:: connection () { // Go through the virtual connection_() function instead of diff --git a/odb/tracer/database.hxx b/odb/tracer/database.hxx index 2468583..acdad8a 100644 --- a/odb/tracer/database.hxx +++ b/odb/tracer/database.hxx @@ -26,7 +26,7 @@ namespace odb virtual ~database (); - transaction_impl* + virtual transaction_impl* begin (); connection_ptr diff --git a/odb/tracer/transaction-impl.cxx b/odb/tracer/transaction-impl.cxx index 2069568..bf272b3 100644 --- a/odb/tracer/transaction-impl.cxx +++ b/odb/tracer/transaction-impl.cxx @@ -17,12 +17,17 @@ namespace odb namespace tracer { transaction_impl:: + transaction_impl (database_type& db) + : odb::transaction_impl (db), finalized_ (false) + { + } + + transaction_impl:: transaction_impl (connection_ptr c) : odb::transaction_impl (c->database (), *c), finalized_ (false), connection_ (c) { - cout << "begin transaction" << endl; } transaction_impl:: @@ -33,6 +38,20 @@ namespace odb } void transaction_impl:: + start () + { + // Grab a connection if we don't already have one. + // + if (connection_ == 0) + { + connection_ = static_cast<database_type&> (database_).connection (); + odb::transaction_impl::connection_ = connection_.get (); + } + + cout << "begin transaction" << endl; + } + + void transaction_impl:: commit () { cout << "commit transaction" << endl; diff --git a/odb/tracer/transaction-impl.hxx b/odb/tracer/transaction-impl.hxx index f926183..b92797b 100644 --- a/odb/tracer/transaction-impl.hxx +++ b/odb/tracer/transaction-impl.hxx @@ -20,18 +20,19 @@ namespace odb { class LIBODB_TRACER_EXPORT transaction_impl: public odb::transaction_impl { - protected: - friend class connection; - friend class transaction; - + public: typedef tracer::database database_type; + transaction_impl (database_type&); transaction_impl (connection_ptr); virtual ~transaction_impl (); virtual void + start (); + + virtual void commit (); virtual void diff --git a/odb/tracer/transaction.hxx b/odb/tracer/transaction.hxx index 0dbc366..b65903d 100644 --- a/odb/tracer/transaction.hxx +++ b/odb/tracer/transaction.hxx @@ -38,6 +38,11 @@ namespace odb static transaction& current (); + // Set the current thread's transaction. + // + static void + current (transaction&); + public: transaction_impl& implementation (); diff --git a/odb/tracer/transaction.ixx b/odb/tracer/transaction.ixx index a36c426..d936e8d 100644 --- a/odb/tracer/transaction.ixx +++ b/odb/tracer/transaction.ixx @@ -31,5 +31,11 @@ namespace odb return static_cast<transaction_impl&> ( odb::transaction::implementation ()); } + + inline void transaction:: + current (transaction& t) + { + odb::transaction::current (t); + } } } |