diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2006-10-07 22:27:25 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2006-10-07 22:27:25 +0000 |
commit | 6dd20a4b23592c0a9a6be23a2123fef410981a2e (patch) | |
tree | 2af894f5335c26115d2f92cdf26d01614dfdc1b6 /src/main/java | |
parent | ebc282a22ddc2cb97bc1af4fe3fa0fedc290fe1b (diff) |
Added TriggerFactory.
Deprecated wrapped storage and query.
Diffstat (limited to 'src/main/java')
12 files changed, 97 insertions, 4 deletions
diff --git a/src/main/java/com/amazon/carbonado/RepositoryBuilder.java b/src/main/java/com/amazon/carbonado/RepositoryBuilder.java index 179d902..368ed9a 100644 --- a/src/main/java/com/amazon/carbonado/RepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/RepositoryBuilder.java @@ -99,4 +99,12 @@ public interface RepositoryBuilder { * @see com.amazon.carbonado.repo.replicated.ReplicatedRepositoryBuilder
*/
void setMaster(boolean b);
+
+ /**
+ * Optionally add a TriggerFactory which will be called upon to create an
+ * initial trigger for each Storable type that the Repository supports. The
+ * primary purpose of this method is to allow decorator repositories the
+ * opportunity to register custom persistence code for each Storable.
+ */
+ void addTriggerFactory(TriggerFactory factory);
}
diff --git a/src/main/java/com/amazon/carbonado/TriggerFactory.java b/src/main/java/com/amazon/carbonado/TriggerFactory.java new file mode 100644 index 0000000..5193267 --- /dev/null +++ b/src/main/java/com/amazon/carbonado/TriggerFactory.java @@ -0,0 +1,38 @@ +/*
+ * Copyright 2006 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.amazon.carbonado;
+
+/**
+ * Can be used with {@link RepositoryBuilder} to automatically register
+ * triggers as Storable types become available.
+ *
+ * @author Brian S O'Neill
+ */
+public interface TriggerFactory {
+ /**
+ * Return an appropriate trigger for the given type, or null if none. This
+ * method is expected to be called at most once per Storable type. As an
+ * extra safeguard, trigger implementations are encouraged to implement the
+ * equals method.
+ *
+ * @param type Storable type requesting an automatic trigger
+ * @return trigger instance or null if not applicable
+ */
+ <S> Trigger<? super S> triggerFor(Class<S> type);
+}
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java index bcdd0c4..6e7bf2f 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java @@ -43,6 +43,7 @@ import com.amazon.carbonado.PersistException; import com.amazon.carbonado.Repository;
import com.amazon.carbonado.RepositoryException;
import com.amazon.carbonado.Transaction;
+import com.amazon.carbonado.TriggerFactory;
import com.amazon.carbonado.UnsupportedTypeException;
import com.amazon.carbonado.capability.Capability;
@@ -135,6 +136,7 @@ public class JDBCRepository private final String mName;
final boolean mIsMaster;
+ final Iterable<TriggerFactory> mTriggerFactories;
private final AtomicReference<Repository> mRootRef;
private final String mDatabaseProductName;
private final DataSource mDataSource;
@@ -179,6 +181,7 @@ public class JDBCRepository @SuppressWarnings("unchecked")
JDBCRepository(AtomicReference<Repository> rootRef,
String name, boolean isMaster,
+ Iterable<TriggerFactory> triggerFactories,
DataSource dataSource, String catalog, String schema)
throws RepositoryException
{
@@ -187,6 +190,7 @@ public class JDBCRepository }
mName = name;
mIsMaster = isMaster;
+ mTriggerFactories = triggerFactories;
mRootRef = rootRef;
mDataSource = dataSource;
mCatalog = catalog;
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java index 3a797e8..5b59852 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java @@ -72,7 +72,8 @@ public class JDBCRepositoryBuilder extends AbstractRepositoryBuilder { public JDBCRepository build(AtomicReference<Repository> rootRef) throws RepositoryException {
assertReady();
JDBCRepository repo = new JDBCRepository
- (rootRef, getName(), isMaster(), getDataSource(), mCatalog, mSchema);
+ (rootRef, getName(), isMaster(), getTriggerFactories(),
+ getDataSource(), mCatalog, mSchema);
rootRef.set(repo);
return repo;
}
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java index 5d4a4a2..08cdb46 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java @@ -110,7 +110,8 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S> mExecutorFactory = new QueryExecutorCache<S>(new ExecutorFactory());
- mTriggerManager = new TriggerManager<S>();
+ mTriggerManager = new TriggerManager<S>
+ (info.getStorableType(), repository.mTriggerFactories);
}
public Class<S> getStorableType() {
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<TriggerFactory> mTriggerFactories;
+
protected AbstractRepositoryBuilder() {
+ mTriggerFactories = new ArrayList<TriggerFactory>(2);
}
public Repository build() throws ConfigurationException, RepositoryException {
return build(new AtomicReference<Repository>());
}
+ 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<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 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<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/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<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) {
+ if (triggerFactories != null) {
+ for (TriggerFactory factory : triggerFactories) {
+ Trigger<? super S> 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<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 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<S extends Storable> implements Storage<S> {
private final Storage<S> mStorage;
private final WrappedStorableFactory<S> mFactory;
@@ -53,7 +54,8 @@ public abstract class WrappedStorage<S extends Storable> implements Storage<S> { .getWrappedClass(storage.getStorableType());
mFactory = QuickConstructorGenerator
.getInstance(wrappedClass, WrappedStorableFactory.class);
- mTriggerManager = new TriggerManager<S>();
+ // FIXME: wrong, just deprecate this class
+ mTriggerManager = new TriggerManager<S>(null, null);
}
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 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<S extends Storable> extends TriggerSupport<S> {
/**
* @see Storable#load
|