diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-05-30 13:18:35 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-05-30 13:18:35 +0000 |
commit | cd8abbb04a79b0d93f34742c49b06607e4e989f7 (patch) | |
tree | fabe04903dac6bd3ecf2ac6f3248ab5c22300fa7 /cpp/src/Freeze/TransactionI.cpp | |
parent | fix problem with possible use of uninitialized local variable (diff) | |
download | ice-cd8abbb04a79b0d93f34742c49b06607e4e989f7.tar.bz2 ice-cd8abbb04a79b0d93f34742c49b06607e4e989f7.tar.xz ice-cd8abbb04a79b0d93f34742c49b06607e4e989f7.zip |
Removed transactional evictor context
Diffstat (limited to 'cpp/src/Freeze/TransactionI.cpp')
-rw-r--r-- | cpp/src/Freeze/TransactionI.cpp | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/cpp/src/Freeze/TransactionI.cpp b/cpp/src/Freeze/TransactionI.cpp index c9920c7bfc0..94c56dc134b 100644 --- a/cpp/src/Freeze/TransactionI.cpp +++ b/cpp/src/Freeze/TransactionI.cpp @@ -25,9 +25,13 @@ Freeze::getTxn(const Freeze::TransactionPtr& tx) void Freeze::TransactionI::commit() { - assert(_txn != 0); - + if(_txn == 0) + { + throw DatabaseException(__FILE__, __LINE__, "inactive transaction"); + } + long txnId = 0; + try { _connection->closeAllIterators(); @@ -41,19 +45,20 @@ Freeze::TransactionI::commit() if(_txTrace >= 1) { - Trace out(_connection->communicator()->getLogger(), "Freeze.Map"); + Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); out << "committed transaction " << hex << txnId << dec; } } catch(const ::DbDeadlockException& dx) { + if(_txTrace >= 1) { - Trace out(_connection->communicator()->getLogger(), "Freeze.Map"); + Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); out << "failed to commit transaction " << hex << txnId << dec << ": " << dx.what(); } - cleanup(); + postCompletion(false, true); DeadlockException ex(__FILE__, __LINE__); ex.message = dx.what(); throw ex; @@ -62,16 +67,16 @@ Freeze::TransactionI::commit() { if(_txTrace >= 1) { - Trace out(_connection->communicator()->getLogger(), "Freeze.Map"); + Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); out << "failed to commit transaction " << hex << txnId << dec << ": " << dx.what(); } - cleanup(); + postCompletion(false, false); DatabaseException ex(__FILE__, __LINE__); ex.message = dx.what(); throw ex; } - cleanup(); + postCompletion(true, false); } void @@ -93,7 +98,7 @@ Freeze::TransactionI::rollback() if(_txTrace >= 1) { - Trace out(_connection->communicator()->getLogger(), "Freeze.Map"); + Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); out << "rolled back transaction " << hex << txnId << dec; } } @@ -101,30 +106,39 @@ Freeze::TransactionI::rollback() { if(_txTrace >= 1) { - Trace out(_connection->communicator()->getLogger(), "Freeze.Map"); + Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); out << "failed to rollback transaction " << hex << txnId << dec << ": " << dx.what(); } - cleanup(); - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + postCompletion(false, true); + throw DeadlockException(__FILE__, __LINE__, dx.what()); } catch(const ::DbException& dx) { if(_txTrace >= 1) { - Trace out(_connection->communicator()->getLogger(), "Freeze.Map"); + Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); out << "failed to rollback transaction " << hex << txnId << dec << ": " << dx.what(); } - cleanup(); - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + postCompletion(false, false); + throw DatabaseException(__FILE__, __LINE__, dx.what()); } - cleanup(); + postCompletion(true, false); +} + +Freeze::ConnectionPtr +Freeze::TransactionI::getConnection() const +{ + return _connection; } + +void +Freeze::TransactionI::setPostCompletionCallback(const Freeze::PostCompletionCallbackPtr& cb) +{ + _postCompletionCallback = cb; +} + Freeze::TransactionI::TransactionI(ConnectionI* connection) : _connection(connection), @@ -138,7 +152,7 @@ Freeze::TransactionI::TransactionI(ConnectionI* connection) : if(_txTrace >= 1) { long txnId = (_txn->id() & 0x7FFFFFFF) + 0x80000000L; - Trace out(_connection->communicator()->getLogger(), "Freeze.Map"); + Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); out << "started transaction " << hex << txnId << dec; } } @@ -146,7 +160,7 @@ Freeze::TransactionI::TransactionI(ConnectionI* connection) : { if(_txTrace >= 1) { - Trace out(_connection->communicator()->getLogger(), "Freeze.Map"); + Trace out(_connection->communicator()->getLogger(), "Freeze.Transaction"); out << "failed to start transaction: " << dx.what(); } @@ -165,9 +179,14 @@ Freeze::TransactionI::~TransactionI() } void -Freeze::TransactionI::cleanup() +Freeze::TransactionI::postCompletion(bool committed, bool deadlock) { _connection->clearTransaction(); _connection = 0; _txn = 0; + + if(_postCompletionCallback != 0) + { + _postCompletionCallback->postCompletion(committed, deadlock); + } } |