From 6dd20a4b23592c0a9a6be23a2123fef410981a2e Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sat, 7 Oct 2006 22:27:25 +0000 Subject: Added TriggerFactory. Deprecated wrapped storage and query. --- .../carbonado/spi/AbstractRepositoryBuilder.java | 22 ++++++++++++++++++++++ .../amazon/carbonado/spi/CommonMethodNames.java | 1 + .../amazon/carbonado/spi/StorableGenerator.java | 1 + .../com/amazon/carbonado/spi/TriggerManager.java | 15 ++++++++++++++- .../com/amazon/carbonado/spi/WrappedQuery.java | 1 + .../com/amazon/carbonado/spi/WrappedStorage.java | 4 +++- .../com/amazon/carbonado/spi/WrappedSupport.java | 1 + 7 files changed, 43 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/spi') diff --git a/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java index a8f0169..d74c70a 100644 --- a/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java @@ -20,6 +20,8 @@ package com.amazon.carbonado.spi; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicReference; @@ -27,6 +29,8 @@ import com.amazon.carbonado.ConfigurationException; import com.amazon.carbonado.Repository; import com.amazon.carbonado.RepositoryBuilder; import com.amazon.carbonado.RepositoryException; +import com.amazon.carbonado.Trigger; +import com.amazon.carbonado.TriggerFactory; /** * Abstract builder class for opening repositories. @@ -35,13 +39,20 @@ import com.amazon.carbonado.RepositoryException; * @author Brian S O'Neill */ public abstract class AbstractRepositoryBuilder implements RepositoryBuilder { + private final List mTriggerFactories; + protected AbstractRepositoryBuilder() { + mTriggerFactories = new ArrayList(2); } public Repository build() throws ConfigurationException, RepositoryException { return build(new AtomicReference()); } + public void addTriggerFactory(TriggerFactory factory) { + mTriggerFactories.add(factory); + } + /** * Throw a configuration exception if the configuration is not filled out * sufficiently and correctly such that a repository could be instantiated @@ -80,4 +91,15 @@ public abstract class AbstractRepositoryBuilder implements RepositoryBuilder { messages.add("name missing"); } } + + /** + * Returns all the TriggerFactories which were added. + */ + protected Iterable getTriggerFactories() { + if (mTriggerFactories == null || mTriggerFactories.size() == 0) { + return Collections.emptyList(); + } else { + return new ArrayList(mTriggerFactories); + } + } } diff --git a/src/main/java/com/amazon/carbonado/spi/CommonMethodNames.java b/src/main/java/com/amazon/carbonado/spi/CommonMethodNames.java index 8a011c9..c79e502 100644 --- a/src/main/java/com/amazon/carbonado/spi/CommonMethodNames.java +++ b/src/main/java/com/amazon/carbonado/spi/CommonMethodNames.java @@ -83,5 +83,6 @@ 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 ecd344d..f69d4dd 100644 --- a/src/main/java/com/amazon/carbonado/spi/StorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/spi/StorableGenerator.java @@ -357,6 +357,7 @@ public final class StorableGenerator { * @throws IllegalArgumentException if type is null */ @SuppressWarnings("unchecked") + @Deprecated public static Class getWrappedClass(Class type) throws IllegalArgumentException { diff --git a/src/main/java/com/amazon/carbonado/spi/TriggerManager.java b/src/main/java/com/amazon/carbonado/spi/TriggerManager.java index cabf526..60661d1 100644 --- a/src/main/java/com/amazon/carbonado/spi/TriggerManager.java +++ b/src/main/java/com/amazon/carbonado/spi/TriggerManager.java @@ -26,6 +26,7 @@ import java.util.Arrays; import com.amazon.carbonado.PersistException; import com.amazon.carbonado.Storable; import com.amazon.carbonado.Trigger; +import com.amazon.carbonado.TriggerFactory; /** * Used by Storage implementations to manage triggers and consolidate them into @@ -93,7 +94,19 @@ public class TriggerManager { private volatile ForUpdate mForUpdate; private volatile ForDelete mForDelete; - public TriggerManager() { + /** + * @param triggerFactories TriggerFactories which will be called upon to + * optionally return a trigger to initially register + */ + public TriggerManager(Class type, Iterable triggerFactories) { + if (triggerFactories != null) { + for (TriggerFactory factory : triggerFactories) { + Trigger trigger = factory.triggerFor(type); + if (trigger != null) { + addTrigger(trigger); + } + } + } } /** diff --git a/src/main/java/com/amazon/carbonado/spi/WrappedQuery.java b/src/main/java/com/amazon/carbonado/spi/WrappedQuery.java index ec3ae34..531f38f 100644 --- a/src/main/java/com/amazon/carbonado/spi/WrappedQuery.java +++ b/src/main/java/com/amazon/carbonado/spi/WrappedQuery.java @@ -36,6 +36,7 @@ import com.amazon.carbonado.filter.FilterValues; * @author Don Schneider * @author Brian S O'Neill */ +@Deprecated public abstract class WrappedQuery implements Query { // 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 598e889..629cb53 100644 --- a/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java +++ b/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java @@ -39,6 +39,7 @@ import com.amazon.carbonado.util.QuickConstructorGenerator; * * @author Brian S O'Neill */ +@Deprecated public abstract class WrappedStorage implements Storage { private final Storage mStorage; private final WrappedStorableFactory mFactory; @@ -53,7 +54,8 @@ public abstract class WrappedStorage implements Storage { .getWrappedClass(storage.getStorableType()); mFactory = QuickConstructorGenerator .getInstance(wrappedClass, WrappedStorableFactory.class); - mTriggerManager = new TriggerManager(); + // FIXME: wrong, just deprecate this class + mTriggerManager = new TriggerManager(null, null); } public Class getStorableType() { diff --git a/src/main/java/com/amazon/carbonado/spi/WrappedSupport.java b/src/main/java/com/amazon/carbonado/spi/WrappedSupport.java index 24e2c02..fa57c60 100644 --- a/src/main/java/com/amazon/carbonado/spi/WrappedSupport.java +++ b/src/main/java/com/amazon/carbonado/spi/WrappedSupport.java @@ -27,6 +27,7 @@ import com.amazon.carbonado.Storable; * * @author Brian S O'Neill */ +@Deprecated public interface WrappedSupport extends TriggerSupport { /** * @see Storable#load -- cgit v1.2.3