From 33c8b712edde86572443a0200169262240d2d974 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 26 Apr 2012 16:45:23 +0200 Subject: Add database::reset() --- odb/transaction.cxx | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'odb/transaction.cxx') diff --git a/odb/transaction.cxx b/odb/transaction.cxx index 9099b57..6f92c41 100644 --- a/odb/transaction.cxx +++ b/odb/transaction.cxx @@ -18,35 +18,32 @@ namespace odb static ODB_TLS_POINTER (transaction) current_transaction; transaction:: - transaction (transaction_impl* impl, bool make_current) - : finalized_ (false), impl_ (impl) + ~transaction () + { + if (!finalized_) + try {rollback ();} catch (...) {} + } + + void transaction:: + reset (transaction_impl* impl, bool make_current) { + details::unique_ptr i (impl); + + if (!finalized_) + rollback (); + + impl_.reset (i.release ()); + if (make_current && tls_get (current_transaction) != 0) throw already_in_transaction (); impl_->start (); + finalized_ = false; if (make_current) tls_set (current_transaction, this); } - transaction:: - ~transaction () - { - if (!finalized_) - { - try - { - rollback (); - } - catch (...) - { - } - } - - delete impl_; - } - bool transaction:: has_current () { -- cgit v1.1