diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-08-23 14:56:08 -0400 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-08-23 14:56:08 -0400 |
commit | 0664ab6ebfe794441a5d2f15507f449231384c85 (patch) | |
tree | 7df11c9a0d891c62cb284b62e1416b2742788ee2 /cpp/src/Freeze/TransactionI.cpp | |
parent | http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=2426 - logger date/time fo... (diff) | |
download | ice-0664ab6ebfe794441a5d2f15507f449231384c85.tar.bz2 ice-0664ab6ebfe794441a5d2f15507f449231384c85.tar.xz ice-0664ab6ebfe794441a5d2f15507f449231384c85.zip |
Fixed bug #2233
Diffstat (limited to 'cpp/src/Freeze/TransactionI.cpp')
-rw-r--r-- | cpp/src/Freeze/TransactionI.cpp | 129 |
1 files changed, 91 insertions, 38 deletions
diff --git a/cpp/src/Freeze/TransactionI.cpp b/cpp/src/Freeze/TransactionI.cpp index 7537818596e..e5b28a79132 100644 --- a/cpp/src/Freeze/TransactionI.cpp +++ b/cpp/src/Freeze/TransactionI.cpp @@ -82,58 +82,105 @@ Freeze::TransactionI::commit() void Freeze::TransactionI::rollback() { - assert(_txn != 0); - - long txnId = 0; - try + if(_txn != 0) { - _connection->closeAllIterators(); - - if(_txTrace >= 1) + long txnId = 0; + try { - txnId = (_txn->id() & 0x7FFFFFFF) + 0x80000000L; + _connection->closeAllIterators(); + + if(_txTrace >= 1) + { + txnId = (_txn->id() & 0x7FFFFFFF) + 0x80000000L; + } + + _txn->abort(); + + if(_txTrace >= 1) + { + Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); + out << "rolled back transaction " << hex << txnId << dec; + } } - - _txn->abort(); - - if(_txTrace >= 1) + catch(const ::DbDeadlockException& dx) { - Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); - out << "rolled back transaction " << hex << txnId << dec; + if(_txTrace >= 1) + { + Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); + out << "failed to rollback transaction " << hex << txnId << dec << ": " << dx.what(); + } + + postCompletion(false, true); + throw DeadlockException(__FILE__, __LINE__, dx.what()); } - } - catch(const ::DbDeadlockException& dx) - { - if(_txTrace >= 1) + catch(const ::DbException& dx) { - Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); - out << "failed to rollback transaction " << hex << txnId << dec << ": " << dx.what(); + if(_txTrace >= 1) + { + Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); + out << "failed to rollback transaction " << hex << txnId << dec << ": " << dx.what(); + } + + postCompletion(false, false); + throw DatabaseException(__FILE__, __LINE__, dx.what()); } + postCompletion(true, false); + } +} - postCompletion(false, true); - throw DeadlockException(__FILE__, __LINE__, dx.what()); +Freeze::ConnectionPtr +Freeze::TransactionI::getConnection() const +{ + if(_txn != 0) + { + return _connection; } - catch(const ::DbException& dx) + else { - if(_txTrace >= 1) - { - Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); - out << "failed to rollback transaction " << hex << txnId << dec << ": " << dx.what(); - } + return 0; + } +} - postCompletion(false, false); - throw DatabaseException(__FILE__, __LINE__, dx.what()); +// +// External refcount operations, from code holding a Transaction[I]Ptr +// +void +Freeze::TransactionI::__incRef() +{ + Shared::__incRef(); + if(_txn != 0) + { + _connection->__incRef(); } - postCompletion(true, false); } -Freeze::ConnectionPtr -Freeze::TransactionI::getConnection() const +void +Freeze::TransactionI::__decRef() +{ + if(_txn != 0) + { + _connection->__decRef(); + } + Shared::__decRef(); +} + +// +// The refcount on transaction held by the associated ConnectionI object +// +void +Freeze::TransactionI::internalIncRef() { - return _connection; + Shared::__incRef(); } void +Freeze::TransactionI::internalDecRef() +{ + Shared::__incRef(); +} + + +void Freeze::TransactionI::setPostCompletionCallback(const Freeze::PostCompletionCallbackPtr& cb) { _postCompletionCallback = cb; @@ -175,15 +222,21 @@ Freeze::TransactionI::~TransactionI() { if(_txn != 0) { - rollback(); + try + { + rollback(); + } + catch(const IceUtil::Exception& e) + { + Error error(_connection->communicator()->getLogger()); + error << "transaction rollback raised :" << e; + } } } void Freeze::TransactionI::postCompletion(bool committed, bool deadlock) { - ConnectionIPtr connection = _connection; - _connection = 0; _txn = 0; if(_postCompletionCallback != 0) @@ -191,5 +244,5 @@ Freeze::TransactionI::postCompletion(bool committed, bool deadlock) _postCompletionCallback->postCompletion(committed, deadlock); } - connection->clearTransaction(); + _connection->clearTransaction(); // will release the internal refcount } |