From 0040cf72f1a878d5e19253036ae38b09a6a48567 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 20 Jan 2009 05:30:43 +0000 Subject: Ensure that exited transaction cleans up the local scope even when an exception is thrown. --- .../com/amazon/carbonado/txn/TransactionScope.java | 53 +++++++++++++++------- 1 file changed, 36 insertions(+), 17 deletions(-) (limited to 'src/main/java/com/amazon') diff --git a/src/main/java/com/amazon/carbonado/txn/TransactionScope.java b/src/main/java/com/amazon/carbonado/txn/TransactionScope.java index daf4992..1e294e4 100644 --- a/src/main/java/com/amazon/carbonado/txn/TransactionScope.java +++ b/src/main/java/com/amazon/carbonado/txn/TransactionScope.java @@ -359,29 +359,48 @@ public class TransactionScope { scope.mLock.lock(); try { if (!mExited) { - if (mChild != null) { - mChild.exit(); - } - - closeCursors(); + Exception exception = null; + try { + if (mChild != null) { + try { + mChild.exit(); + } catch (Exception e) { + if (exception == null) { + exception = e; + } + } + } - if (mTxn != null) { try { - if (mParent == null || mParent.mTxn != mTxn) { - try { - scope.mTxnMgr.abortTxn(mTxn); - } catch (Throwable e) { - throw ExceptionTransformer.getInstance().toPersistException(e); + closeCursors(); + } catch (Exception e) { + if (exception == null) { + exception = e; + } + } + + if (mTxn != null) { + try { + if (mParent == null || mParent.mTxn != mTxn) { + try { + scope.mTxnMgr.abortTxn(mTxn); + } catch (Exception e) { + if (exception == null) { + exception = e; + } + } } + } finally { + mTxn = null; } - } finally { - mTxn = null; + } + } finally { + scope.mActive = mParent; + mExited = true; + if (exception != null) { + throw ExceptionTransformer.getInstance().toPersistException(exception); } } - - scope.mActive = mParent; - - mExited = true; } } finally { scope.mLock.unlock(); -- cgit v1.2.3