aboutsummaryrefslogtreecommitdiff
path: root/odb/transaction.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-24 13:42:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-24 13:42:04 +0200
commitf5d79a0cd5dc12a430d17bbdca7ec5aacb45996c (patch)
tree10518f3819b50b78470d3612a36a14580ca1ad11 /odb/transaction.cxx
parent27e362857cf748a54c62b157113cd4abf7eff570 (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.
Diffstat (limited to 'odb/transaction.cxx')
-rw-r--r--odb/transaction.cxx41
1 files changed, 35 insertions, 6 deletions
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 ();
}