diff options
Diffstat (limited to 'src/main/java/com/amazon/carbonado/spi')
3 files changed, 41 insertions, 15 deletions
diff --git a/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java index 6193e50..b73a9ce 100644 --- a/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import com.amazon.carbonado.ConfigurationException;
@@ -37,7 +38,7 @@ import com.amazon.carbonado.TriggerFactory; * @author Brian S O'Neill
*/
public abstract class AbstractRepositoryBuilder implements RepositoryBuilder {
- private final Collection<TriggerFactory> mTriggerFactories;
+ private final Set<TriggerFactory> mTriggerFactories;
protected AbstractRepositoryBuilder() {
mTriggerFactories = new LinkedHashSet<TriggerFactory>(2);
@@ -47,15 +48,25 @@ public abstract class AbstractRepositoryBuilder implements RepositoryBuilder { return build(new AtomicReference<Repository>());
}
- public void addTriggerFactory(TriggerFactory factory) {
- mTriggerFactories.add(factory);
+ public boolean addTriggerFactory(TriggerFactory factory) {
+ synchronized (mTriggerFactories) {
+ return mTriggerFactories.add(factory);
+ }
+ }
+
+ public boolean removeTriggerFactory(TriggerFactory factory) {
+ synchronized (mTriggerFactories) {
+ return mTriggerFactories.remove(factory);
+ }
}
public Iterable<TriggerFactory> getTriggerFactories() {
- if (mTriggerFactories == null || mTriggerFactories.size() == 0) {
- return Collections.emptyList();
- } else {
- return new ArrayList<TriggerFactory>(mTriggerFactories);
+ synchronized (mTriggerFactories) {
+ 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/TriggerManager.java b/src/main/java/com/amazon/carbonado/spi/TriggerManager.java index ea7ae4f..147d1ed 100644 --- a/src/main/java/com/amazon/carbonado/spi/TriggerManager.java +++ b/src/main/java/com/amazon/carbonado/spi/TriggerManager.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Arrays;
import com.amazon.carbonado.PersistException;
+import com.amazon.carbonado.RepositoryException;
import com.amazon.carbonado.Storable;
import com.amazon.carbonado.Trigger;
import com.amazon.carbonado.TriggerFactory;
@@ -94,18 +95,18 @@ public class TriggerManager<S extends Storable> { private volatile ForUpdate<S> mForUpdate;
private volatile ForDelete<S> mForDelete;
+ public TriggerManager() {
+ }
+
/**
* @param triggerFactories TriggerFactories which will be called upon to
* optionally return a trigger to initially register
*/
- public TriggerManager(Class<S> type, Iterable<TriggerFactory> triggerFactories) {
+ public TriggerManager(Class<S> type, Iterable<TriggerFactory> triggerFactories)
+ throws RepositoryException
+ {
if (triggerFactories != null) {
- for (TriggerFactory factory : triggerFactories) {
- Trigger<? super S> trigger = factory.triggerFor(type);
- if (trigger != null) {
- addTrigger(trigger);
- }
- }
+ addTriggers(type, triggerFactories);
}
}
@@ -211,6 +212,17 @@ public class TriggerManager<S extends Storable> { return retValue;
}
+ public void addTriggers(Class<S> type, Iterable<TriggerFactory> triggerFactories)
+ throws RepositoryException
+ {
+ for (TriggerFactory factory : triggerFactories) {
+ Trigger<? super S> trigger = factory.triggerFor(type);
+ if (trigger != null) {
+ addTrigger(trigger);
+ }
+ }
+ }
+
/**
* Determines which operations the given trigger overrides.
*/
diff --git a/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java b/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java index ebe0c19..17db288 100644 --- a/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java +++ b/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java @@ -22,6 +22,7 @@ import com.amazon.carbonado.FetchException; import com.amazon.carbonado.PersistException;
import com.amazon.carbonado.Query;
import com.amazon.carbonado.Repository;
+import com.amazon.carbonado.RepositoryException;
import com.amazon.carbonado.Storable;
import com.amazon.carbonado.Storage;
import com.amazon.carbonado.Trigger;
@@ -46,7 +47,9 @@ public abstract class WrappedStorage<S extends Storable> implements Storage<S> { /**
* @param storage storage to wrap
*/
- public WrappedStorage(Storage<S> storage, Iterable<TriggerFactory> triggerFactories) {
+ public WrappedStorage(Storage<S> storage, Iterable<TriggerFactory> triggerFactories)
+ throws RepositoryException
+ {
mStorage = storage;
Class<? extends S> wrappedClass = StorableGenerator
.getWrappedClass(storage.getStorableType());
|