summaryrefslogtreecommitdiff
path: root/cpp/src/Freeze/TransactionHolder.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2003-09-16 01:41:46 +0000
committerBernard Normier <bernard@zeroc.com>2003-09-16 01:41:46 +0000
commit83cb29a8de333646c9b3e7ac6909accce72e6b5f (patch)
treecc1037886e0d1770d9c1ad412d79c81a5a1d21ad /cpp/src/Freeze/TransactionHolder.cpp
parentflex fixes (diff)
downloadice-83cb29a8de333646c9b3e7ac6909accce72e6b5f.tar.bz2
ice-83cb29a8de333646c9b3e7ac6909accce72e6b5f.tar.xz
ice-83cb29a8de333646c9b3e7ac6909accce72e6b5f.zip
Added Freeze Connection and Transaction
Diffstat (limited to 'cpp/src/Freeze/TransactionHolder.cpp')
-rw-r--r--cpp/src/Freeze/TransactionHolder.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/cpp/src/Freeze/TransactionHolder.cpp b/cpp/src/Freeze/TransactionHolder.cpp
new file mode 100644
index 00000000000..8b758624467
--- /dev/null
+++ b/cpp/src/Freeze/TransactionHolder.cpp
@@ -0,0 +1,76 @@
+// **********************************************************************
+//
+// 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/TransactionHolder.h>
+
+using namespace Freeze;
+
+Freeze::TransactionHolder::TransactionHolder(const ConnectionPtr& connection)
+ : _transaction(0)
+{
+ if(connection->currentTransaction() == 0)
+ {
+ _transaction = connection->beginTransaction();
+ }
+}
+
+Freeze::TransactionHolder::~TransactionHolder()
+{
+ try
+ {
+ rollback();
+ }
+ catch(...)
+ {
+ //
+ // Ignored to avoid crash during stack unwinding
+ //
+ }
+}
+
+void
+Freeze::TransactionHolder::commit()
+{
+ if(_transaction != 0)
+ {
+ try
+ {
+ _transaction->commit();
+ _transaction = 0;
+ }
+ catch(...)
+ {
+ _transaction = 0;
+ throw;
+ }
+ }
+}
+
+void
+Freeze::TransactionHolder::rollback()
+{
+ if(_transaction != 0)
+ {
+ try
+ {
+ _transaction->rollback();
+ _transaction = 0;
+ }
+ catch(...)
+ {
+ _transaction = 0;
+ throw;
+ }
+ }
+}