summaryrefslogtreecommitdiff
path: root/cpp/src/Freeze/TransactionI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Freeze/TransactionI.cpp')
-rw-r--r--cpp/src/Freeze/TransactionI.cpp103
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;
+}