diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2007-09-03 03:15:01 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2007-09-03 03:15:01 +0000 |
commit | 4db278970eec5165c04fa0bc1d9c2dd7aa7ce6b3 (patch) | |
tree | 0cec80a6eccc8f9236f8e4d02c57e943e2e68b6e /src/main/java/com/amazon/carbonado/repo/logging | |
parent | 077804624eb7dc69899d1c7f045931f794501925 (diff) |
Logged transaction context is per repository instead of global.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/logging')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java | 9 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/logging/LoggingTransaction.java | 13 |
2 files changed, 13 insertions, 9 deletions
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<LoggingTransaction> mActiveTxn =
+ new ThreadLocal<LoggingTransaction>();
+
LoggingRepository(AtomicReference<Repository> 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<LoggingTransaction> mActiveTxn =
- new ThreadLocal<LoggingTransaction>();
-
private static final AtomicLong mNextID = new AtomicLong();
+ private final ThreadLocal<LoggingTransaction> 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<LoggingTransaction> 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());
}
|