From 81475fd493bcc3d5fe750b54ce8d8fa9fb812c9c Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 8 Oct 2006 01:26:37 +0000 Subject: Finished support for trigger factories --- .../carbonado/repo/logging/LoggingRepository.java | 8 ++++++- .../repo/logging/LoggingRepositoryBuilder.java | 7 +++++- .../carbonado/repo/logging/LoggingStorage.java | 2 +- .../carbonado/repo/logging/LoggingTransaction.java | 26 +++++++++++++++++++--- 4 files changed, 37 insertions(+), 6 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo/logging') 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 3f17d17..99c462c 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java @@ -30,6 +30,7 @@ import com.amazon.carbonado.Storable; import com.amazon.carbonado.Storage; import com.amazon.carbonado.SupportException; import com.amazon.carbonado.Transaction; +import com.amazon.carbonado.TriggerFactory; import com.amazon.carbonado.capability.Capability; @@ -40,14 +41,19 @@ import com.amazon.carbonado.capability.Capability; */ class LoggingRepository implements Repository, LogAccessCapability { private final AtomicReference mRootRef; + final Iterable mTriggerFactories; private final Repository mRepo; private final Log mLog; // Map of storages by storable class private final Map, LoggingStorage> mStorages; - LoggingRepository(AtomicReference rootRef, Repository actual, Log log) { + LoggingRepository(AtomicReference rootRef, + Iterable triggerFactories, + Repository actual, Log log) + { mRootRef = rootRef; + mTriggerFactories = triggerFactories; mRepo = actual; mLog = log; diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java index 956c947..98c1008 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java @@ -26,6 +26,7 @@ import com.amazon.carbonado.ConfigurationException; import com.amazon.carbonado.Repository; import com.amazon.carbonado.RepositoryBuilder; import com.amazon.carbonado.RepositoryException; +import com.amazon.carbonado.TriggerFactory; import com.amazon.carbonado.spi.AbstractRepositoryBuilder; @@ -83,6 +84,9 @@ public class LoggingRepositoryBuilder extends AbstractRepositoryBuilder { mRepoBuilder.setName("Logging " + mName); } mRepoBuilder.setMaster(master); + for (TriggerFactory factory : getTriggerFactories()) { + mRepoBuilder.addTriggerFactory(factory); + } actual = mRepoBuilder.build(rootRef); } finally { mRepoBuilder.setName(originalName); @@ -93,7 +97,8 @@ public class LoggingRepositoryBuilder extends AbstractRepositoryBuilder { return actual; } - Repository repo = new LoggingRepository(rootRef, actual, mLog); + Repository repo = new LoggingRepository + (rootRef, mRepoBuilder.getTriggerFactories(), actual, mLog); rootRef.set(repo); return repo; } diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java index 93b5a33..47d6bb1 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java @@ -36,7 +36,7 @@ class LoggingStorage extends WrappedStorage { final LoggingRepository mRepo; LoggingStorage(LoggingRepository repo, Storage storage) { - super(storage); + super(storage, repo.mTriggerFactories); mRepo = repo; } 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 7deac92..b9782c8 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingTransaction.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingTransaction.java @@ -19,6 +19,7 @@ package com.amazon.carbonado.repo.logging; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; import com.amazon.carbonado.IsolationLevel; import com.amazon.carbonado.PersistException; @@ -30,27 +31,39 @@ 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 LoggingTransaction mParent; private final Log mLog; private final Transaction mTxn; + private final long mID; LoggingTransaction(Log log, Transaction txn) { + mParent = mActiveTxn.get(); mLog = log; mTxn = txn; + mID = mNextID.addAndGet(1); + mActiveTxn.set(this); + mLog.write("Entered transaction: " + idChain()); } public void commit() throws PersistException { - mLog.write("Transaction.commit()"); + mLog.write("Transaction.commit() on " + idChain()); mTxn.commit(); } public void exit() throws PersistException { - mLog.write("Transaction.exit()"); + mLog.write("Transaction.exit() on " + idChain()); mTxn.exit(); + mActiveTxn.set(mParent); } public void setForUpdate(boolean forUpdate) { if (mLog.isEnabled()) { - mLog.write("Transaction.setForUpdate(" + forUpdate + ')'); + mLog.write("Transaction.setForUpdate(" + forUpdate + ") on " + idChain()); } mTxn.setForUpdate(forUpdate); } @@ -66,4 +79,11 @@ class LoggingTransaction implements Transaction { public IsolationLevel getIsolationLevel() { return mTxn.getIsolationLevel(); } + + private String idChain() { + if (mParent == null) { + return String.valueOf(mID); + } + return mParent.idChain() + " > " + mID; + } } -- cgit v1.2.3