diff options
| author | Brian S. O'Neill <bronee@gmail.com> | 2009-01-20 05:30:43 +0000 | 
|---|---|---|
| committer | Brian S. O'Neill <bronee@gmail.com> | 2009-01-20 05:30:43 +0000 | 
| commit | 0040cf72f1a878d5e19253036ae38b09a6a48567 (patch) | |
| tree | c88818b634ce5658c1ed92e4716df46b30ad035a /src/main | |
| parent | d3893bcee8df9db78538e5eee23a608fa41cd77c (diff) | |
Ensure that exited transaction cleans up the local scope even when an exception is thrown.
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/com/amazon/carbonado/txn/TransactionScope.java | 53 | 
1 files changed, 36 insertions, 17 deletions
| 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<Txn> {              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();
 | 
