summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/amazon/carbonado/RepositoryBuilder.java5
-rw-r--r--src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepositoryBuilder.java4
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java8
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java7
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java2
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingTransaction.java26
-rw-r--r--src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepositoryBuilder.java4
-rw-r--r--src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java24
-rw-r--r--src/main/java/com/amazon/carbonado/spi/CommonMethodNames.java1
-rw-r--r--src/main/java/com/amazon/carbonado/spi/StorableGenerator.java1
-rw-r--r--src/main/java/com/amazon/carbonado/spi/WrappedQuery.java1
-rw-r--r--src/main/java/com/amazon/carbonado/spi/WrappedStorage.java7
-rw-r--r--src/main/java/com/amazon/carbonado/spi/WrappedSupport.java1
13 files changed, 64 insertions, 27 deletions
diff --git a/src/main/java/com/amazon/carbonado/RepositoryBuilder.java b/src/main/java/com/amazon/carbonado/RepositoryBuilder.java
index 368ed9a..8c64483 100644
--- a/src/main/java/com/amazon/carbonado/RepositoryBuilder.java
+++ b/src/main/java/com/amazon/carbonado/RepositoryBuilder.java
@@ -107,4 +107,9 @@ public interface RepositoryBuilder {
* opportunity to register custom persistence code for each Storable.
*/
void addTriggerFactory(TriggerFactory factory);
+
+ /**
+ * Returns all the TriggerFactories which were added.
+ */
+ Iterable<TriggerFactory> getTriggerFactories();
}
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepositoryBuilder.java
index a1aa45e..2010230 100644
--- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepositoryBuilder.java
+++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepositoryBuilder.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;
@@ -58,6 +59,9 @@ public class IndexedRepositoryBuilder extends AbstractRepositoryBuilder {
boolean originalOption = mRepoBuilder.isMaster();
try {
mRepoBuilder.setMaster(mIsMaster);
+ for (TriggerFactory factory : getTriggerFactories()) {
+ mRepoBuilder.addTriggerFactory(factory);
+ }
wrapped = mRepoBuilder.build(rootRef);
} finally {
mRepoBuilder.setMaster(originalOption);
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<Repository> mRootRef;
+ final Iterable<TriggerFactory> mTriggerFactories;
private final Repository mRepo;
private final Log mLog;
// Map of storages by storable class
private final Map<Class<?>, LoggingStorage<?>> mStorages;
- LoggingRepository(AtomicReference<Repository> rootRef, Repository actual, Log log) {
+ LoggingRepository(AtomicReference<Repository> rootRef,
+ Iterable<TriggerFactory> 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<S extends Storable> extends WrappedStorage<S> {
final LoggingRepository mRepo;
LoggingStorage(LoggingRepository repo, Storage<S> 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<LoggingTransaction> mActiveTxn =
+ new ThreadLocal<LoggingTransaction>();
+
+ 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;
+ }
}
diff --git a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepositoryBuilder.java
index 2a09c19..3ab2146 100644
--- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepositoryBuilder.java
+++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicatedRepositoryBuilder.java
@@ -28,6 +28,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;
import com.amazon.carbonado.spi.BelatedRepositoryCreator;
@@ -64,6 +65,9 @@ public class ReplicatedRepositoryBuilder extends AbstractRepositoryBuilder {
boolean originalOption = mReplicaRepositoryBuilder.isMaster();
try {
mReplicaRepositoryBuilder.setMaster(false);
+ for (TriggerFactory factory : getTriggerFactories()) {
+ mReplicaRepositoryBuilder.addTriggerFactory(factory);
+ }
replica = mReplicaRepositoryBuilder.build(rootRef);
} finally {
mReplicaRepositoryBuilder.setMaster(originalOption);
diff --git a/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java
index d74c70a..ed4eaf3 100644
--- a/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java
+++ b/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java
@@ -21,6 +21,7 @@ package com.amazon.carbonado.spi;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
@@ -39,10 +40,10 @@ import com.amazon.carbonado.TriggerFactory;
* @author Brian S O'Neill
*/
public abstract class AbstractRepositoryBuilder implements RepositoryBuilder {
- private final List<TriggerFactory> mTriggerFactories;
+ private final Collection<TriggerFactory> mTriggerFactories;
protected AbstractRepositoryBuilder() {
- mTriggerFactories = new ArrayList<TriggerFactory>(2);
+ mTriggerFactories = new LinkedHashSet<TriggerFactory>(2);
}
public Repository build() throws ConfigurationException, RepositoryException {
@@ -53,6 +54,14 @@ public abstract class AbstractRepositoryBuilder implements RepositoryBuilder {
mTriggerFactories.add(factory);
}
+ public Iterable<TriggerFactory> getTriggerFactories() {
+ if (mTriggerFactories == null || mTriggerFactories.size() == 0) {
+ return Collections.emptyList();
+ } else {
+ return new ArrayList<TriggerFactory>(mTriggerFactories);
+ }
+ }
+
/**
* Throw a configuration exception if the configuration is not filled out
* sufficiently and correctly such that a repository could be instantiated
@@ -91,15 +100,4 @@ public abstract class AbstractRepositoryBuilder implements RepositoryBuilder {
messages.add("name missing");
}
}
-
- /**
- * Returns all the TriggerFactories which were added.
- */
- protected Iterable<TriggerFactory> getTriggerFactories() {
- if (mTriggerFactories == null || mTriggerFactories.size() == 0) {
- return Collections.emptyList();
- } else {
- return new ArrayList<TriggerFactory>(mTriggerFactories);
- }
- }
}
diff --git a/src/main/java/com/amazon/carbonado/spi/CommonMethodNames.java b/src/main/java/com/amazon/carbonado/spi/CommonMethodNames.java
index c79e502..8a011c9 100644
--- a/src/main/java/com/amazon/carbonado/spi/CommonMethodNames.java
+++ b/src/main/java/com/amazon/carbonado/spi/CommonMethodNames.java
@@ -83,6 +83,5 @@ public class CommonMethodNames {
EXIT_METHOD_NAME = "exit";
/** WrappedStorage.Support API method name */
- @Deprecated
public static final String CREATE_WRAPPED_SUPPORT_METHOD_NAME = "createSupport";
}
diff --git a/src/main/java/com/amazon/carbonado/spi/StorableGenerator.java b/src/main/java/com/amazon/carbonado/spi/StorableGenerator.java
index f69d4dd..ecd344d 100644
--- a/src/main/java/com/amazon/carbonado/spi/StorableGenerator.java
+++ b/src/main/java/com/amazon/carbonado/spi/StorableGenerator.java
@@ -357,7 +357,6 @@ public final class StorableGenerator<S extends Storable> {
* @throws IllegalArgumentException if type is null
*/
@SuppressWarnings("unchecked")
- @Deprecated
public static <S extends Storable> Class<? extends S> getWrappedClass(Class<S> type)
throws IllegalArgumentException
{
diff --git a/src/main/java/com/amazon/carbonado/spi/WrappedQuery.java b/src/main/java/com/amazon/carbonado/spi/WrappedQuery.java
index 531f38f..ec3ae34 100644
--- a/src/main/java/com/amazon/carbonado/spi/WrappedQuery.java
+++ b/src/main/java/com/amazon/carbonado/spi/WrappedQuery.java
@@ -36,7 +36,6 @@ import com.amazon.carbonado.filter.FilterValues;
* @author Don Schneider
* @author Brian S O'Neill
*/
-@Deprecated
public abstract class WrappedQuery<S extends Storable> implements Query<S> {
// The query to which this query will delegate
diff --git a/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java b/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java
index 629cb53..1cefc73 100644
--- a/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java
+++ b/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java
@@ -25,6 +25,7 @@ import com.amazon.carbonado.Repository;
import com.amazon.carbonado.Storable;
import com.amazon.carbonado.Storage;
import com.amazon.carbonado.Trigger;
+import com.amazon.carbonado.TriggerFactory;
import com.amazon.carbonado.filter.Filter;
import com.amazon.carbonado.filter.FilterValues;
@@ -39,7 +40,6 @@ import com.amazon.carbonado.util.QuickConstructorGenerator;
*
* @author Brian S O'Neill
*/
-@Deprecated
public abstract class WrappedStorage<S extends Storable> implements Storage<S> {
private final Storage<S> mStorage;
private final WrappedStorableFactory<S> mFactory;
@@ -48,14 +48,13 @@ public abstract class WrappedStorage<S extends Storable> implements Storage<S> {
/**
* @param storage storage to wrap
*/
- public WrappedStorage(Storage<S> storage) {
+ public WrappedStorage(Storage<S> storage, Iterable<TriggerFactory> triggerFactories) {
mStorage = storage;
Class<? extends S> wrappedClass = StorableGenerator
.getWrappedClass(storage.getStorableType());
mFactory = QuickConstructorGenerator
.getInstance(wrappedClass, WrappedStorableFactory.class);
- // FIXME: wrong, just deprecate this class
- mTriggerManager = new TriggerManager<S>(null, null);
+ mTriggerManager = new TriggerManager<S>(storage.getStorableType(), triggerFactories);
}
public Class<S> getStorableType() {
diff --git a/src/main/java/com/amazon/carbonado/spi/WrappedSupport.java b/src/main/java/com/amazon/carbonado/spi/WrappedSupport.java
index fa57c60..24e2c02 100644
--- a/src/main/java/com/amazon/carbonado/spi/WrappedSupport.java
+++ b/src/main/java/com/amazon/carbonado/spi/WrappedSupport.java
@@ -27,7 +27,6 @@ import com.amazon.carbonado.Storable;
*
* @author Brian S O'Neill
*/
-@Deprecated
public interface WrappedSupport<S extends Storable> extends TriggerSupport<S> {
/**
* @see Storable#load