summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/spi
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2006-10-17 00:08:26 +0000
committerBrian S. O'Neill <bronee@gmail.com>2006-10-17 00:08:26 +0000
commit987e5b79304062308a5d304a57dabcce97654867 (patch)
tree25b7adfef1834d5ede463429b89eb4cfaf76f076 /src/main/java/com/amazon/carbonado/spi
parent75edf91be7467ee8cd10f6ad5c95dbd8007453ff (diff)
More work on automatic triggers.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/spi')
-rw-r--r--src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java25
-rw-r--r--src/main/java/com/amazon/carbonado/spi/TriggerManager.java26
-rw-r--r--src/main/java/com/amazon/carbonado/spi/WrappedStorage.java5
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());