From f5d79a0cd5dc12a430d17bbdca7ec5aacb45996c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 24 Aug 2011 13:42:04 +0200 Subject: 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. --- odb/transaction.cxx | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'odb/transaction.cxx') diff --git a/odb/transaction.cxx b/odb/transaction.cxx index e1fed91..70abd0c 100644 --- a/odb/transaction.cxx +++ b/odb/transaction.cxx @@ -19,10 +19,16 @@ namespace odb static ODB_TLS_POINTER (transaction) current_transaction; transaction:: - transaction (transaction_impl* impl) + transaction (transaction_impl* impl, bool make_current) : finalized_ (false), impl_ (impl) { - tls_set (current_transaction, this); + if (make_current && tls_get (current_transaction) != 0) + throw already_in_transaction (); + + impl_->start (); + + if (make_current) + tls_set (current_transaction, this); } transaction:: @@ -60,14 +66,32 @@ namespace odb } void transaction:: + current (transaction& t) + { + tls_set (current_transaction, &t); + } + + void transaction:: + reset_current () + { + transaction* t (0); + tls_set (current_transaction, t); + } + + void transaction:: commit () { if (finalized_) throw transaction_already_finalized (); finalized_ = true; - transaction* t (0); - tls_set (current_transaction, t); + + if (tls_get (current_transaction) == this) + { + transaction* t (0); + tls_set (current_transaction, t); + } + impl_->commit (); } @@ -78,8 +102,13 @@ namespace odb throw transaction_already_finalized (); finalized_ = true; - transaction* t (0); - tls_set (current_transaction, t); + + if (tls_get (current_transaction) == this) + { + transaction* t (0); + tls_set (current_transaction, t); + } + impl_->rollback (); } -- cgit v1.1