From 4db278970eec5165c04fa0bc1d9c2dd7aa7ce6b3 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 3 Sep 2007 03:15:01 +0000 Subject: Logged transaction context is per repository instead of global. --- .../amazon/carbonado/repo/logging/LoggingRepository.java | 9 ++++++--- .../amazon/carbonado/repo/logging/LoggingTransaction.java | 13 +++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java index e196993..4032313 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java @@ -45,6 +45,9 @@ class LoggingRepository implements Repository, LogAccessCapability { private final StoragePool mStoragePool; + private final ThreadLocal mActiveTxn = + new ThreadLocal(); + LoggingRepository(AtomicReference rootRef, Repository actual, Log log) { @@ -73,21 +76,21 @@ class LoggingRepository implements Repository, LogAccessCapability { public Transaction enterTransaction() { mLog.write("Repository.enterTransaction()"); - return new LoggingTransaction(mLog, mRepo.enterTransaction(), false); + return new LoggingTransaction(mActiveTxn, mLog, mRepo.enterTransaction(), false); } public Transaction enterTransaction(IsolationLevel level) { if (mLog.isEnabled()) { mLog.write("Repository.enterTransaction(" + level + ')'); } - return new LoggingTransaction(mLog, mRepo.enterTransaction(level), false); + return new LoggingTransaction(mActiveTxn, mLog, mRepo.enterTransaction(level), false); } public Transaction enterTopTransaction(IsolationLevel level) { if (mLog.isEnabled()) { mLog.write("Repository.enterTopTransaction(" + level + ')'); } - return new LoggingTransaction(mLog, mRepo.enterTopTransaction(level), true); + return new LoggingTransaction(mActiveTxn, mLog, mRepo.enterTopTransaction(level), true); } public IsolationLevel getTransactionIsolationLevel() { diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingTransaction.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingTransaction.java index 2fe9865..fd88f35 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingTransaction.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingTransaction.java @@ -31,24 +31,25 @@ import com.amazon.carbonado.Transaction; * @author Brian S O'Neill */ class LoggingTransaction implements Transaction { - private static final ThreadLocal mActiveTxn = - new ThreadLocal(); - private static final AtomicLong mNextID = new AtomicLong(); + private final ThreadLocal mActiveTxn; private final LoggingTransaction mParent; private final Log mLog; private final Transaction mTxn; private final long mID; private final boolean mTop; - LoggingTransaction(Log log, Transaction txn, boolean top) { - mParent = mActiveTxn.get(); + LoggingTransaction(ThreadLocal activeTxn, + Log log, Transaction txn, boolean top) + { + mActiveTxn = activeTxn; + mParent = activeTxn.get(); mLog = log; mTxn = txn; mID = mNextID.addAndGet(1); mTop = top; - mActiveTxn.set(this); + activeTxn.set(this); mLog.write("Entered transaction: " + idChain()); } -- cgit v1.2.3