diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2008-03-25 06:05:59 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2008-03-25 06:05:59 +0000 |
commit | bf29a6f862fae1de3c21a870229394b7c8cbe458 (patch) | |
tree | 1174cc1ec82e81e2a8b6279c67b251fd05e02c41 /src/main | |
parent | 3db26bff365de7d2d4e7fc45ad31b8104c78a0ae (diff) |
Fix bug that allowed a transaction to be attached to multiple threads. Thanks FindBugs!
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/amazon/carbonado/spi/TransactionManager.java | 4 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/spi/TransactionScope.java | 4 |
2 files changed, 5 insertions, 3 deletions
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<Txn> { }
// Called by TransactionScope.
- boolean setLocalScope(TransactionScope<Txn> scope) {
+ boolean setLocalScope(TransactionScope<Txn> scope, boolean detached) {
TransactionScope<Txn> 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<Txn> { 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");
|