From bf29a6f862fae1de3c21a870229394b7c8cbe458 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 25 Mar 2008 06:05:59 +0000 Subject: Fix bug that allowed a transaction to be attached to multiple threads. Thanks FindBugs! --- src/main/java/com/amazon/carbonado/spi/TransactionManager.java | 4 ++-- src/main/java/com/amazon/carbonado/spi/TransactionScope.java | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/amazon/carbonado') diff --git a/src/main/java/com/amazon/carbonado/spi/TransactionManager.java b/src/main/java/com/amazon/carbonado/spi/TransactionManager.java index a2b1375..a63784a 100644 --- a/src/main/java/com/amazon/carbonado/spi/TransactionManager.java +++ b/src/main/java/com/amazon/carbonado/spi/TransactionManager.java @@ -96,9 +96,9 @@ public abstract class TransactionManager { } // Called by TransactionScope. - boolean setLocalScope(TransactionScope scope) { + boolean setLocalScope(TransactionScope scope, boolean detached) { TransactionScope existing = mLocalScope.get(); - if (existing == null || existing == scope) { + if ((existing == null && detached) || existing == scope) { mLocalScope.set(scope); return true; } diff --git a/src/main/java/com/amazon/carbonado/spi/TransactionScope.java b/src/main/java/com/amazon/carbonado/spi/TransactionScope.java index 82a20eb..60e5f84 100644 --- a/src/main/java/com/amazon/carbonado/spi/TransactionScope.java +++ b/src/main/java/com/amazon/carbonado/spi/TransactionScope.java @@ -219,8 +219,10 @@ public class TransactionScope { public void attach() { mLock.lock(); try { - if (mTxnMgr.setLocalScope(this)) { + if (mTxnMgr.setLocalScope(this, mDetached)) { mDetached = false; + } else if (!mDetached) { + throw new IllegalStateException("Transaction scope is not detached"); } else { throw new IllegalStateException ("Current thread has a different transaction already attached"); -- cgit v1.2.3