diff options
author | Bernard Normier <bernard@zeroc.com> | 2003-09-16 01:41:46 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2003-09-16 01:41:46 +0000 |
commit | 83cb29a8de333646c9b3e7ac6909accce72e6b5f (patch) | |
tree | cc1037886e0d1770d9c1ad412d79c81a5a1d21ad /cpp/src/Freeze/TransactionI.cpp | |
parent | flex fixes (diff) | |
download | ice-83cb29a8de333646c9b3e7ac6909accce72e6b5f.tar.bz2 ice-83cb29a8de333646c9b3e7ac6909accce72e6b5f.tar.xz ice-83cb29a8de333646c9b3e7ac6909accce72e6b5f.zip |
Added Freeze Connection and Transaction
Diffstat (limited to 'cpp/src/Freeze/TransactionI.cpp')
-rw-r--r-- | cpp/src/Freeze/TransactionI.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/cpp/src/Freeze/TransactionI.cpp b/cpp/src/Freeze/TransactionI.cpp new file mode 100644 index 00000000000..0e28f9c9acf --- /dev/null +++ b/cpp/src/Freeze/TransactionI.cpp @@ -0,0 +1,103 @@ +// ********************************************************************** +// +// Copyright (c) 2003 +// ZeroC, Inc. +// Billerica, MA, USA +// +// All Rights Reserved. +// +// Ice is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License version 2 as published by +// the Free Software Foundation. +// +// ********************************************************************** + +#include <Freeze/TransactionI.h> +#include <Freeze/ConnectionI.h> +#include <Freeze/DBException.h> + + +void +Freeze::TransactionI::commit() +{ + assert(_txn != 0); + try + { + _connection->closeAllIterators(); + _txn->commit(0); + } + catch(const ::DbDeadlockException& dx) + { + cleanup(); + DBDeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + catch(const ::DbException& dx) + { + cleanup(); + DBException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + cleanup(); +} + +void +Freeze::TransactionI::rollback() +{ + assert(_txn != 0); + + try + { + _connection->closeAllIterators(); + _txn->abort(); + } + catch(const ::DbDeadlockException& dx) + { + cleanup(); + DBDeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + catch(const ::DbException& dx) + { + cleanup(); + DBException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + cleanup(); +} + +Freeze::TransactionI::TransactionI(ConnectionI* connection) : + _connection(connection), + _txn(0) +{ + try + { + _connection->dbEnv()->txn_begin(0, &_txn, 0); + } + catch(const ::DbException& dx) + { + DBException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } +} + +Freeze::TransactionI::~TransactionI() +{ + if(_txn != 0) + { + rollback(); + } +} + +void +Freeze::TransactionI::cleanup() +{ + _connection->clearTransaction(); + _connection = 0; + _txn = 0; +} |