summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2007-08-26 02:44:46 +0000
committerBrian S. O'Neill <bronee@gmail.com>2007-08-26 02:44:46 +0000
commitabb61b817c4c87dde9fa8f6899f0901b9d945142 (patch)
tree40bfb8490a3d5525ba8444f1ba4900aab84e1ebd /src/main
parent6d231091ddf24f5c05e51b8c48e455b09dab47c8 (diff)
Removed vestigial support for wrapping Storables.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/amazon/carbonado/gen/CommonMethodNames.java6
-rw-r--r--src/main/java/com/amazon/carbonado/gen/StorableGenerator.java616
-rw-r--r--src/main/java/com/amazon/carbonado/gen/WrappedSupport.java77
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java196
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java3
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java3
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java153
-rw-r--r--src/main/java/com/amazon/carbonado/spi/WrappedQuery.java257
-rw-r--r--src/main/java/com/amazon/carbonado/spi/WrappedStorage.java254
9 files changed, 340 insertions, 1225 deletions
diff --git a/src/main/java/com/amazon/carbonado/gen/CommonMethodNames.java b/src/main/java/com/amazon/carbonado/gen/CommonMethodNames.java
index 7187f38..2ed5c8d 100644
--- a/src/main/java/com/amazon/carbonado/gen/CommonMethodNames.java
+++ b/src/main/java/com/amazon/carbonado/gen/CommonMethodNames.java
@@ -84,10 +84,4 @@ public class CommonMethodNames {
SET_FOR_UPDATE_METHOD_NAME = "setForUpdate",
COMMIT_METHOD_NAME = "commit",
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/gen/StorableGenerator.java b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
index a753015..b4ed7c2 100644
--- a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
+++ b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
@@ -69,10 +69,10 @@ import com.amazon.carbonado.info.StorablePropertyConstraint;
import static com.amazon.carbonado.gen.CommonMethodNames.*;
/**
- * Generates and caches abstract and wrapped implementations of {@link
- * Storable} types. This greatly simplifies the process of defining new kinds
- * of {@link Repository Repositories}, since most of the mundane code
- * generation is taken care of.
+ * Generates and caches abstract implementations of {@link Storable}
+ * types. This greatly simplifies the process of defining new kinds of {@link
+ * Repository Repositories}, since most of the mundane code generation is taken
+ * care of.
*
* @author Brian S O'Neill
* @author Don Schneider
@@ -151,7 +151,7 @@ public final class StorableGenerator<S extends Storable> {
/** Constraint field names are propertyName + "$constraint$" + ordinal */
public static final String CONSTRAINT_FIELD_ELEMENT = "$constraint$";
- /** Reference to TriggerSupport or WrappedSupport instance */
+ /** Reference to TriggerSupport instance */
public static final String SUPPORT_FIELD_NAME = "support$";
/** Property state indicating that property has never been set, loaded, or saved */
@@ -172,12 +172,9 @@ public final class StorableGenerator<S extends Storable> {
// Cache of generated abstract classes.
private static Map<Class, Reference<Class<? extends Storable>>> cAbstractCache;
- // Cache of generated wrapped classes.
- private static Map<Class, Reference<Class<? extends Storable>>> cWrappedCache;
static {
cAbstractCache = new WeakIdentityMap();
- cWrappedCache = new WeakIdentityMap();
}
// There are three flavors of equals methods, used by addEqualsMethod.
@@ -185,12 +182,6 @@ public final class StorableGenerator<S extends Storable> {
private static final int EQUAL_PROPERTIES = 1;
private static final int EQUAL_FULL = 2;
- // Operation mode for generating Storable.
- private static final int GEN_ABSTRACT = 1;
- private static final int GEN_WRAPPED = 2;
-
- private static final String WRAPPED_STORABLE_FIELD_NAME = "wrappedStorable$";
-
private static final String UNCAUGHT_METHOD_NAME = "uncaught$";
private static final String INSERT_OP = "Insert";
@@ -306,93 +297,13 @@ public final class StorableGenerator<S extends Storable> {
return abstractClass;
}
}
- abstractClass = new StorableGenerator<S>(type, GEN_ABSTRACT).generateAndInjectClass();
+ abstractClass = new StorableGenerator<S>(type).generateAndInjectClass();
cAbstractCache.put(type, new SoftReference<Class<? extends Storable>>(abstractClass));
return abstractClass;
}
}
- /**
- * Returns a concrete Storable implementation of the given type which wraps
- * another Storable. The Storable type itself may be an interface or a
- * class. If it is a class, then it must not be final, and it must have a
- * public, no-arg constructor. The constructor signature for the returned
- * class is defined as follows:
- *
- * <pre>
- * /**
- * * @param support Custom implementation for Storable CRUD operations
- * * @param storable Storable being wrapped
- * *&#047;
- * public &lt;init&gt;(WrappedSupport support, Storable storable);
- * </pre>
- *
- * <p>Instances of the wrapped Storable delegate to the WrappedSupport for
- * all CRUD operations:
- *
- * <ul>
- * <li>load and tryLoad
- * <li>insert and tryInsert
- * <li>update and tryUpdate
- * <li>delete and tryDelete
- * </ul>
- *
- * <p>Methods which delegate to wrapped Storable:
- *
- * <ul>
- * <li>all ordinary user-defined properties
- * <li>copyAllProperties
- * <li>copyPrimaryKeyProperties
- * <li>copyVersionProperty
- * <li>copyUnequalProperties
- * <li>copyDirtyProperties
- * <li>hasDirtyProperties
- * <li>markPropertiesClean
- * <li>markAllPropertiesClean
- * <li>markPropertiesDirty
- * <li>markAllPropertiesDirty
- * <li>hashCode
- * <li>equalPrimaryKeys
- * <li>equalProperties
- * <li>toString
- * <li>toStringKeyOnly
- * </ul>
- *
- * <p>Methods with special implementation:
- *
- * <ul>
- * <li>all user-defined join properties (join properties query using wrapper's Storage)
- * <li>storage (returns Storage used by wrapper)
- * <li>storableType (returns literal class)
- * <li>copy (delegates to wrapped storable, but bridge methods must be defined as well)
- * <li>equals (compares Storage instance and properties)
- * </ul>
- *
- * @throws com.amazon.carbonado.MalformedTypeException if Storable type is not well-formed
- * @throws IllegalArgumentException if type is null
- * @deprecated no replacement
- */
- @SuppressWarnings("unchecked")
- public static <S extends Storable> Class<? extends S> getWrappedClass(Class<S> type)
- throws IllegalArgumentException
- {
- synchronized (cWrappedCache) {
- Class<? extends S> wrappedClass;
- Reference<Class<? extends Storable>> ref = cWrappedCache.get(type);
- if (ref != null) {
- wrappedClass = (Class<? extends S>) ref.get();
- if (wrappedClass != null) {
- return wrappedClass;
- }
- }
- wrappedClass = new StorableGenerator<S>(type, GEN_WRAPPED).generateAndInjectClass();
- cWrappedCache.put(type, new SoftReference<Class<? extends Storable>>(wrappedClass));
- return wrappedClass;
- }
- }
-
private final Class<S> mStorableType;
- private final int mGenMode;
private final TypeDesc mSupportType;
private final StorableInfo<S> mInfo;
private final Map<String, ? extends StorableProperty<S>> mAllProperties;
@@ -401,14 +312,9 @@ public final class StorableGenerator<S extends Storable> {
private final ClassInjector mClassInjector;
private final ClassFile mClassFile;
- private StorableGenerator(Class<S> storableType, int genMode) {
+ private StorableGenerator(Class<S> storableType) {
mStorableType = storableType;
- mGenMode = genMode;
- if (genMode == GEN_WRAPPED) {
- mSupportType = TypeDesc.forClass(WrappedSupport.class);
- } else {
- mSupportType = TypeDesc.forClass(TriggerSupport.class);
- }
+ mSupportType = TypeDesc.forClass(TriggerSupport.class);
mInfo = StorableIntrospector.examine(storableType);
mAllProperties = mInfo.getAllProperties();
@@ -424,7 +330,7 @@ public final class StorableGenerator<S extends Storable> {
mClassInjector = ClassInjector.create
(storableType.getName(), storableType.getClassLoader());
mClassFile = CodeBuilderUtil.createStorableClassFile
- (mClassInjector, storableType, genMode == GEN_ABSTRACT,
+ (mClassInjector, storableType, true,
StorableGenerator.class.getName());
}
@@ -439,24 +345,11 @@ public final class StorableGenerator<S extends Storable> {
defineUncaughtExceptionHandler();
// private final TriggerSupport support;
- // Field is not final for GEN_WRAPPED, so that copy method can
- // change WrappedSupport after calling clone.
- mClassFile.addField(Modifiers.PROTECTED.toFinal(mGenMode == GEN_ABSTRACT),
+ mClassFile.addField(Modifiers.PROTECTED.toFinal(true),
SUPPORT_FIELD_NAME,
mSupportType);
- if (mGenMode == GEN_WRAPPED) {
- // Add a few more fields to hold arguments passed from constructor.
-
- // private final <user storable> wrappedStorable;
- // Field is not final for GEN_WRAPPED, so that copy method can
- // change wrapped Storable after calling clone.
- mClassFile.addField(Modifiers.PRIVATE.toFinal(false),
- WRAPPED_STORABLE_FIELD_NAME,
- TypeDesc.forClass(mStorableType));
- }
-
- if (mGenMode == GEN_ABSTRACT) {
+ {
// Add protected constructor.
TypeDesc[] params = {mSupportType};
@@ -472,36 +365,11 @@ public final class StorableGenerator<S extends Storable> {
b.storeField(SUPPORT_FIELD_NAME, mSupportType);
b.returnVoid();
- } else if (mGenMode == GEN_WRAPPED) {
- // Add public constructor.
- TypeDesc[] params = {mSupportType, TypeDesc.forClass(Storable.class)};
-
- final int wrappedSupportParam = 0;
- final int wrappedStorableParam = 1;
- MethodInfo mi = mClassFile.addConstructor(Modifiers.PUBLIC, params);
- CodeBuilder b = new CodeBuilder(mi);
- b.loadThis();
- b.invokeSuperConstructor(null);
-
- //// this.wrappedSupport = wrappedSupport
- b.loadThis();
- b.loadLocal(b.getParameter(wrappedSupportParam));
- b.storeField(SUPPORT_FIELD_NAME, mSupportType);
-
- //// this.wrappedStorable = wrappedStorable
- b.loadThis();
- b.loadLocal(b.getParameter(wrappedStorableParam));
- b.checkCast(TypeDesc.forClass(mStorableType));
- b.storeField(WRAPPED_STORABLE_FIELD_NAME, TypeDesc.forClass(mStorableType));
-
- // FIXME: call loadCompleted
-
- b.returnVoid();
}
// Add static fields for adapters and constraints, and create static
// initializer to populate fields.
- if (mGenMode == GEN_ABSTRACT) {
+ {
// CodeBuilder for static initializer, defined only if there's
// something to put in it.
CodeBuilder clinit = null;
@@ -598,20 +466,13 @@ public final class StorableGenerator<S extends Storable> {
if (!property.isDerived()) {
if (property.isJoin()) {
- // If generating wrapper, property access is not guarded by
- // synchronization. Mark as volatile instead. Also mark as
- // transient since join properties can be reconstructed from
- // the other fields.
- mClassFile.addField(Modifiers.PRIVATE
- .toVolatile(mGenMode == GEN_WRAPPED)
- .toTransient(true),
- name, type);
+ // Mark as transient since join properties can be
+ // reconstructed from the other fields.
+ mClassFile.addField(Modifiers.PRIVATE.toTransient(true), name, type);
requireStateField = true;
- } else if (mGenMode == GEN_ABSTRACT) {
- // Only define regular property fields if abstract
- // class. Wrapped class doesn't reference them. Double
- // words are volatile to prevent word tearing without
- // explicit synchronization.
+ } else {
+ // Double words are volatile to prevent word tearing
+ // without explicit synchronization.
mClassFile.addField(Modifiers.PROTECTED.toVolatile(type.isDoubleWord()),
name, type);
requireStateField = true;
@@ -621,11 +482,8 @@ public final class StorableGenerator<S extends Storable> {
final String stateFieldName = PROPERTY_STATE_FIELD_NAME + (ordinal >> 4);
if (ordinal == maxOrdinal || ((ordinal & 0xf) == 0xf)) {
if (requireStateField) {
- // If generating wrapper, property state access is not guarded by
- // synchronization. Mark as volatile instead.
mClassFile.addField
- (Modifiers.PROTECTED.toVolatile(mGenMode == GEN_WRAPPED),
- stateFieldName, TypeDesc.INT);
+ (Modifiers.PROTECTED, stateFieldName, TypeDesc.INT);
}
requireStateField = false;
}
@@ -647,7 +505,7 @@ public final class StorableGenerator<S extends Storable> {
}
}
- if (mGenMode == GEN_ABSTRACT && property.isJoin()) {
+ if (property.isJoin()) {
// Synchronization is required for join property
// accessors, as they may alter bit masks.
mi.setModifiers(mi.getModifiers().toSynchronized(true));
@@ -694,16 +552,9 @@ public final class StorableGenerator<S extends Storable> {
StorableProperty internal = property.getInternalJoinElement(i);
StorableProperty external = property.getExternalJoinElement(i);
if (internal.isNullable() && !external.isNullable()) {
- if (mGenMode == GEN_ABSTRACT) {
- b.loadThis();
- b.loadField(internal.getName(),
- TypeDesc.forClass(internal.getType()));
- } else {
- b.loadThis();
- b.loadField(WRAPPED_STORABLE_FIELD_NAME,
- TypeDesc.forClass(mStorableType));
- b.invoke(internal.getReadMethod());
- }
+ b.loadThis();
+ b.loadField(internal.getName(),
+ TypeDesc.forClass(internal.getType()));
Label notNull = b.createLabel();
b.ifNullBranch(notNull, false);
@@ -755,16 +606,9 @@ public final class StorableGenerator<S extends Storable> {
b.loadLocal(join);
StorableProperty internal = property.getInternalJoinElement(i);
StorableProperty external = property.getExternalJoinElement(i);
- if (mGenMode == GEN_ABSTRACT) {
- b.loadThis();
- b.loadField(internal.getName(),
- TypeDesc.forClass(internal.getType()));
- } else {
- b.loadThis();
- b.loadField(WRAPPED_STORABLE_FIELD_NAME,
- TypeDesc.forClass(mStorableType));
- b.invoke(internal.getReadMethod());
- }
+ b.loadThis();
+ b.loadField(internal.getName(),
+ TypeDesc.forClass(internal.getType()));
CodeBuilderUtil.convertValue
(b, internal.getType(), external.getType());
b.invoke(external.getWriteMethod());
@@ -810,16 +654,9 @@ public final class StorableGenerator<S extends Storable> {
// Now fill in the parameters of the query.
for (int i=0; i<count; i++) {
StorableProperty<S> internal = property.getInternalJoinElement(i);
- if (mGenMode == GEN_ABSTRACT) {
- b.loadThis();
- b.loadField(internal.getName(),
- TypeDesc.forClass(internal.getType()));
- } else {
- b.loadThis();
- b.loadField(WRAPPED_STORABLE_FIELD_NAME,
- TypeDesc.forClass(mStorableType));
- b.invoke(internal.getReadMethod());
- }
+ b.loadThis();
+ b.loadField(internal.getName(),
+ TypeDesc.forClass(internal.getType()));
TypeDesc bindType =
CodeBuilderUtil.bindQueryParam(internal.getType());
CodeBuilderUtil.convertValue
@@ -862,15 +699,8 @@ public final class StorableGenerator<S extends Storable> {
// Load property value and return it.
- if (mGenMode == GEN_ABSTRACT || property.isJoin()) {
- b.loadThis();
- b.loadField(property.getName(), type);
- } else {
- b.loadThis();
- b.loadField(WRAPPED_STORABLE_FIELD_NAME, TypeDesc.forClass(mStorableType));
- b.invoke(readMethod);
- }
-
+ b.loadThis();
+ b.loadField(property.getName(), type);
b.returnValue(type);
}
@@ -889,13 +719,11 @@ public final class StorableGenerator<S extends Storable> {
mi.markSynthetic();
}
- if (mGenMode == GEN_ABSTRACT) {
- mi.setModifiers(mi.getModifiers().toSynchronized(true));
- }
+ mi.setModifiers(mi.getModifiers().toSynchronized(true));
CodeBuilder b = new CodeBuilder(mi);
// Primary keys cannot be altered if state is "clean".
- if (mGenMode == GEN_ABSTRACT && property.isPrimaryKeyMember()) {
+ if (property.isPrimaryKeyMember()) {
b.loadThis();
b.loadField(stateFieldName, TypeDesc.INT);
b.loadConstant(PROPERTY_STATE_MASK << ((ordinal & 0xf) * 2));
@@ -914,7 +742,7 @@ public final class StorableGenerator<S extends Storable> {
!property.getType().isPrimitive() &&
!property.isJoin() && !property.isNullable();
- if (mGenMode == GEN_ABSTRACT && (nullNotAllowed || spcCount > 0)) {
+ if (nullNotAllowed || spcCount > 0) {
// Add constraint checks.
Label skipConstraints = b.createLabel();
@@ -960,26 +788,24 @@ public final class StorableGenerator<S extends Storable> {
if (!property.isJoin() || Lob.class.isAssignableFrom(property.getType())) {
Label markDirty = b.createLabel();
- if (mGenMode == GEN_ABSTRACT) {
- if (Lob.class.isAssignableFrom(property.getType())) {
- // Contrary to how standard properties are managed,
- // only mark dirty if value changed. Exception is made
- // for null -- always mark dirty. This allows LOB property
- // to be updated to null without having to load it.
- b.loadLocal(b.getParameter(0));
- b.ifNullBranch(markDirty, true);
+ if (Lob.class.isAssignableFrom(property.getType())) {
+ // Contrary to how standard properties are managed,
+ // only mark dirty if value changed. Exception is made
+ // for null -- always mark dirty. This allows LOB property
+ // to be updated to null without having to load it.
+ b.loadLocal(b.getParameter(0));
+ b.ifNullBranch(markDirty, true);
- b.loadThis();
- b.loadField(property.getName(), type);
- LocalVariable tempProp = b.createLocalVariable(null, type);
- b.storeLocal(tempProp);
- b.loadLocal(tempProp);
- b.ifNullBranch(markDirty, true);
+ b.loadThis();
+ b.loadField(property.getName(), type);
+ LocalVariable tempProp = b.createLocalVariable(null, type);
+ b.storeLocal(tempProp);
+ b.loadLocal(tempProp);
+ b.ifNullBranch(markDirty, true);
- b.loadLocal(tempProp);
- b.loadLocal(b.getParameter(0));
- CodeBuilderUtil.addValuesEqualCall(b, type, false, setValue, true);
- }
+ b.loadLocal(tempProp);
+ b.loadLocal(b.getParameter(0));
+ CodeBuilderUtil.addValuesEqualCall(b, type, false, setValue, true);
}
markDirty.setLocation();
@@ -1023,26 +849,15 @@ public final class StorableGenerator<S extends Storable> {
Label setInternalProp = b.createLabel();
- if (mGenMode == GEN_ABSTRACT) {
- // Access state of internal property directly.
- int ord = findPropertyOrdinal(internal);
- b.loadThis();
- b.loadField(PROPERTY_STATE_FIELD_NAME + (ord >> 4), TypeDesc.INT);
- b.loadConstant(PROPERTY_STATE_MASK << ((ord & 0xf) * 2));
- b.math(Opcode.IAND);
- b.loadConstant(PROPERTY_STATE_CLEAN << ((ord & 0xf) * 2));
- // If not clean, skip equal check.
- b.ifComparisonBranch(setInternalProp, "!=");
- } else {
- // Call the public isPropertyClean method since
- // the raw state bits are hidden.
- b.loadThis();
- b.loadConstant(internal.getName());
- b.invokeVirtual(IS_PROPERTY_CLEAN, TypeDesc.BOOLEAN,
- new TypeDesc[] {TypeDesc.STRING});
- // If not clean, skip equal check.
- b.ifZeroComparisonBranch(setInternalProp, "==");
- }
+ // Access state of internal property directly.
+ int ord = findPropertyOrdinal(internal);
+ b.loadThis();
+ b.loadField(PROPERTY_STATE_FIELD_NAME + (ord >> 4), TypeDesc.INT);
+ b.loadConstant(PROPERTY_STATE_MASK << ((ord & 0xf) * 2));
+ b.math(Opcode.IAND);
+ b.loadConstant(PROPERTY_STATE_CLEAN << ((ord & 0xf) * 2));
+ // If not clean, skip equal check.
+ b.ifComparisonBranch(setInternalProp, "!=");
// If new internal property value is equal to
// existing value, skip setting it.
@@ -1078,22 +893,15 @@ public final class StorableGenerator<S extends Storable> {
setValue.setLocation();
- if (mGenMode == GEN_ABSTRACT || property.isJoin()) {
- b.loadThis();
- b.loadLocal(b.getParameter(0));
- b.storeField(property.getName(), type);
- } else {
- b.loadThis();
- b.loadField(WRAPPED_STORABLE_FIELD_NAME, TypeDesc.forClass(mStorableType));
- b.loadLocal(b.getParameter(0));
- b.invoke(writeMethod);
- }
+ b.loadThis();
+ b.loadLocal(b.getParameter(0));
+ b.storeField(property.getName(), type);
b.returnVoid();
}
// Add optional protected adapted read methods.
- if (mGenMode == GEN_ABSTRACT && property.getAdapter() != null) {
+ if (property.getAdapter() != null) {
// End name with '$' to prevent any possible collisions.
String readName = property.getReadMethodName() + '$';
@@ -1129,7 +937,7 @@ public final class StorableGenerator<S extends Storable> {
// Note: Calling these methods does not affect any state bits.
// They are only intended to be used by subclasses during loading.
- if (mGenMode == GEN_ABSTRACT && property.getAdapter() != null) {
+ if (property.getAdapter() != null) {
// End name with '$' to prevent any possible collisions.
String writeName = property.getWriteMethodName() + '$';
@@ -1169,7 +977,7 @@ public final class StorableGenerator<S extends Storable> {
addTryLoad: {
// Define the tryLoad method.
MethodInfo mi = addMethodIfNotFinal
- (Modifiers.PUBLIC.toSynchronized(mGenMode == GEN_ABSTRACT),
+ (Modifiers.PUBLIC.toSynchronized(true),
TRY_LOAD_METHOD_NAME, TypeDesc.BOOLEAN, null);
if (mi == null) {
@@ -1178,11 +986,6 @@ public final class StorableGenerator<S extends Storable> {
mi.addException(TypeDesc.forClass(FetchException.class));
- if (mGenMode == GEN_WRAPPED) {
- callWrappedSupport(mi, null, false, null);
- break addTryLoad;
- }
-
CodeBuilder b = new CodeBuilder(mi);
// Check that primary key is initialized.
@@ -1327,20 +1130,18 @@ public final class StorableGenerator<S extends Storable> {
b.loadConstant(false);
b.returnValue(TypeDesc.BOOLEAN);
- if (mGenMode == GEN_ABSTRACT) {
- // Define the abstract method.
- mi = mClassFile.addMethod
- (Modifiers.PROTECTED.toAbstract(true),
- DO_TRY_LOAD_METHOD_NAME, TypeDesc.BOOLEAN, null);
- mi.addException(TypeDesc.forClass(FetchException.class));
- }
+ // Define the abstract method.
+ mi = mClassFile.addMethod
+ (Modifiers.PROTECTED.toAbstract(true),
+ DO_TRY_LOAD_METHOD_NAME, TypeDesc.BOOLEAN, null);
+ mi.addException(TypeDesc.forClass(FetchException.class));
}
// Add load method which calls tryLoad.
addLoad: {
// Define the load method.
MethodInfo mi = addMethodIfNotFinal
- (Modifiers.PUBLIC.toSynchronized(mGenMode == GEN_ABSTRACT),
+ (Modifiers.PUBLIC.toSynchronized(true),
LOAD_METHOD_NAME, null, null);
if (mi == null) {
@@ -1349,11 +1150,6 @@ public final class StorableGenerator<S extends Storable> {
mi.addException(TypeDesc.forClass(FetchException.class));
- if (mGenMode == GEN_WRAPPED) {
- callWrappedSupport(mi, null, false, FetchNoneException.class);
- break addLoad;
- }
-
CodeBuilder b = new CodeBuilder(mi);
// Call tryLoad and throw an exception if false returned.
@@ -1379,7 +1175,7 @@ public final class StorableGenerator<S extends Storable> {
final TypeDesc transactionType = TypeDesc.forClass(Transaction.class);
// Add insert(boolean forTry) method which delegates to abstract doTryInsert method.
- if (mGenMode == GEN_ABSTRACT) {
+ {
MethodInfo mi = mClassFile.addMethod
(Modifiers.PRIVATE.toSynchronized(true),
PRIVATE_INSERT_METHOD_NAME, TypeDesc.BOOLEAN, new TypeDesc[] {TypeDesc.BOOLEAN});
@@ -1454,11 +1250,6 @@ public final class StorableGenerator<S extends Storable> {
mi.addException(TypeDesc.forClass(PersistException.class));
- if (mGenMode == GEN_WRAPPED) {
- callWrappedSupport(mi, INSERT_OP, false, UniqueConstraintException.class);
- break addInsert;
- }
-
CodeBuilder b = new CodeBuilder(mi);
b.loadThis();
@@ -1480,11 +1271,6 @@ public final class StorableGenerator<S extends Storable> {
mi.addException(TypeDesc.forClass(PersistException.class));
- if (mGenMode == GEN_WRAPPED) {
- callWrappedSupport(mi, INSERT_OP, true, null);
- break addTryInsert;
- }
-
CodeBuilder b = new CodeBuilder(mi);
b.loadThis();
@@ -1495,7 +1281,7 @@ public final class StorableGenerator<S extends Storable> {
}
// Add update(boolean forTry) method which delegates to abstract doTryUpdate method.
- if (mGenMode == GEN_ABSTRACT) {
+ {
MethodInfo mi = mClassFile.addMethod
(Modifiers.PRIVATE.toSynchronized(true),
PRIVATE_UPDATE_METHOD_NAME, TypeDesc.BOOLEAN, new TypeDesc[] {TypeDesc.BOOLEAN});
@@ -1628,11 +1414,6 @@ public final class StorableGenerator<S extends Storable> {
mi.addException(TypeDesc.forClass(PersistException.class));
- if (mGenMode == GEN_WRAPPED) {
- callWrappedSupport(mi, UPDATE_OP, false, PersistNoneException.class);
- break addUpdate;
- }
-
CodeBuilder b = new CodeBuilder(mi);
b.loadThis();
@@ -1654,11 +1435,6 @@ public final class StorableGenerator<S extends Storable> {
mi.addException(TypeDesc.forClass(PersistException.class));
- if (mGenMode == GEN_WRAPPED) {
- callWrappedSupport(mi, UPDATE_OP, true, null);
- break addTryUpdate;
- }
-
CodeBuilder b = new CodeBuilder(mi);
b.loadThis();
@@ -1669,7 +1445,7 @@ public final class StorableGenerator<S extends Storable> {
}
// Add delete(boolean forTry) method which delegates to abstract doTryDelete method.
- if (mGenMode == GEN_ABSTRACT) {
+ {
MethodInfo mi = mClassFile.addMethod
(Modifiers.PRIVATE.toSynchronized(true),
PRIVATE_DELETE_METHOD_NAME, TypeDesc.BOOLEAN, new TypeDesc[] {TypeDesc.BOOLEAN});
@@ -1746,11 +1522,6 @@ public final class StorableGenerator<S extends Storable> {
mi.addException(TypeDesc.forClass(PersistException.class));
- if (mGenMode == GEN_WRAPPED) {
- callWrappedSupport(mi, DELETE_OP, false, PersistNoneException.class);
- break addDelete;
- }
-
CodeBuilder b = new CodeBuilder(mi);
b.loadThis();
@@ -1773,11 +1544,6 @@ public final class StorableGenerator<S extends Storable> {
mi.addException(TypeDesc.forClass(PersistException.class));
- if (mGenMode == GEN_WRAPPED) {
- callWrappedSupport(mi, DELETE_OP, true, null);
- break addTryDelete;
- }
-
CodeBuilder b = new CodeBuilder(mi);
b.loadThis();
@@ -1809,7 +1575,7 @@ public final class StorableGenerator<S extends Storable> {
// Add copy method.
MethodInfo mi = addMethodIfNotFinal
- (Modifiers.PUBLIC.toSynchronized(mGenMode == GEN_ABSTRACT),
+ (Modifiers.PUBLIC.toSynchronized(true),
COPY_METHOD_NAME, mClassFile.getType(), null);
if (mi == null) {
@@ -1821,38 +1587,6 @@ public final class StorableGenerator<S extends Storable> {
b.invokeVirtual(CLONE_METHOD_NAME, TypeDesc.OBJECT, null);
b.checkCast(mClassFile.getType());
- if (mGenMode == GEN_WRAPPED) {
- // Need to do a deeper copy.
-
- LocalVariable copiedVar = b.createLocalVariable(null, mClassFile.getType());
- b.storeLocal(copiedVar);
-
- // First copy the wrapped Storable.
- b.loadLocal(copiedVar); // storeField later
- b.loadThis();
- b.loadField(WRAPPED_STORABLE_FIELD_NAME, TypeDesc.forClass(mStorableType));
- b.invoke(lookupMethod(mStorableType, COPY_METHOD_NAME));
- b.checkCast(TypeDesc.forClass(mStorableType));
- b.storeField(WRAPPED_STORABLE_FIELD_NAME, TypeDesc.forClass(mStorableType));
-
- // Replace the WrappedSupport, passing in copy of wrapped Storable.
- b.loadLocal(copiedVar); // storeField later
- b.loadThis();
- b.loadField(SUPPORT_FIELD_NAME, mSupportType);
- b.loadLocal(copiedVar);
- b.loadField(WRAPPED_STORABLE_FIELD_NAME, TypeDesc.forClass(mStorableType));
-
- b.invokeInterface(WrappedSupport.class.getName(),
- CREATE_WRAPPED_SUPPORT_METHOD_NAME,
- mSupportType,
- new TypeDesc[] {TypeDesc.forClass(Storable.class)});
-
- // Store new WrappedSupport in copy.
- b.storeField(SUPPORT_FIELD_NAME, mSupportType);
-
- b.loadLocal(copiedVar);
- }
-
b.returnValue(type);
}
@@ -1882,11 +1616,6 @@ public final class StorableGenerator<S extends Storable> {
break addHasDirtyProps;
}
- if (mGenMode == GEN_WRAPPED) {
- callWrappedStorable(mi);
- break addHasDirtyProps;
- }
-
CodeBuilder b = new CodeBuilder(mi);
Label isDirty = b.createLabel();
branchIfDirty(b, false, isDirty);
@@ -1948,10 +1677,8 @@ public final class StorableGenerator<S extends Storable> {
CodeBuilder b = new CodeBuilder(mi);
- if (mGenMode == GEN_ABSTRACT) {
- b.loadThis();
- b.invokeVirtual(MARK_ALL_PROPERTIES_CLEAN, null, null);
- }
+ b.loadThis();
+ b.invokeVirtual(MARK_ALL_PROPERTIES_CLEAN, null, null);
// Now invoke trigger.
b.loadThis();
@@ -1975,7 +1702,7 @@ public final class StorableGenerator<S extends Storable> {
b.returnVoid();
}
- if (mGenMode == GEN_ABSTRACT) {
+ {
// Define protected isPkInitialized method.
addIsInitializedMethod
(IS_PK_INITIALIZED_METHOD_NAME, mInfo.getPrimaryKeyProperties());
@@ -2037,115 +1764,6 @@ public final class StorableGenerator<S extends Storable> {
}
}
- /**
- * If GEN_WRAPPED, generates a method implementation which delgates to the
- * WrappedSupport. Also clears join property state if called method
- * returns normally.
- *
- * @param opType optional, is one of INSERT_OP, UPDATE_OP, or DELETE_OP for trigger support
- * @param forTry used for INSERT_OP, UPDATE_OP, or DELETE_OP
- * @param exceptionType optional - if called method throws this exception,
- * join property state is still cleared.
- */
- // FIXME: support LOAD_OP? Just chuck all support for wrapped storables. It
- // is no longer needed.
- private void callWrappedSupport(MethodInfo mi,
- String opType,
- boolean forTry,
- Class exceptionType)
- {
- if (mGenMode == GEN_ABSTRACT || !mHasJoins) {
- // Don't need to clear state bits.
- exceptionType = null;
- }
-
- CodeBuilder b = new CodeBuilder(mi);
-
- final TypeDesc triggerType = TypeDesc.forClass(Trigger.class);
- final TypeDesc transactionType = TypeDesc.forClass(Transaction.class);
-
- LocalVariable triggerVar = b.createLocalVariable(null, triggerType);
- LocalVariable txnVar = b.createLocalVariable(null, transactionType);
- LocalVariable stateVar = b.createLocalVariable(null, TypeDesc.OBJECT);
-
- Label tryStart;
- if (opType == null) {
- tryStart = b.createLabel().setLocation();
- } else {
- tryStart = addGetTriggerAndEnterTxn
- (b, opType, null, forTry, triggerVar, txnVar, stateVar);
- }
-
- b.loadThis();
- b.loadField(SUPPORT_FIELD_NAME, mSupportType);
- Method method = lookupMethod(WrappedSupport.class, mi);
- b.invoke(method);
-
- Label tryEnd = b.createLabel().setLocation();
-
- clearState(b);
-
- if (method.getReturnType() == void.class) {
- if (opType != null) {
- addTriggerAfterAndExitTxn(b, opType, null, forTry, triggerVar, txnVar, stateVar);
- }
- b.returnVoid();
- } else {
- if (opType != null) {
- Label notDone = b.createLabel();
- b.ifZeroComparisonBranch(notDone, "==");
- addTriggerAfterAndExitTxn(b, opType, null, forTry, triggerVar, txnVar, stateVar);
- b.loadConstant(true);
- b.returnValue(TypeDesc.BOOLEAN);
- notDone.setLocation();
- addTriggerFailedAndExitTxn(b, opType, triggerVar, txnVar, stateVar);
- b.loadConstant(false);
- }
- b.returnValue(TypeDesc.forClass(method.getReturnType()));
- }
-
- if (opType != null) {
- addTriggerFailedAndExitTxn
- (b, opType, null, forTry, triggerVar, txnVar, stateVar, tryStart);
- }
-
- if (exceptionType != null) {
- b.exceptionHandler(tryStart, tryEnd, exceptionType.getName());
- clearState(b);
- b.throwObject();
- }
- }
-
- /**
- * If GEN_WRAPPED, generates a method implementation which delgates to the
- * wrapped Storable.
- */
- private void callWrappedStorable(MethodInfo mi) {
- callWrappedStorable(mi, new CodeBuilder(mi));
- }
-
- /**
- * If GEN_WRAPPED, generates a method implementation which delgates to the
- * wrapped Storable.
- */
- private void callWrappedStorable(MethodInfo mi, CodeBuilder b) {
- b.loadThis();
- b.loadField(WRAPPED_STORABLE_FIELD_NAME, TypeDesc.forClass(mStorableType));
-
- int count = mi.getMethodDescriptor().getParameterCount();
- for (int j=0; j<count; j++) {
- b.loadLocal(b.getParameter(j));
- }
-
- Method method = lookupMethod(mStorableType, mi);
- b.invoke(method);
- if (method.getReturnType() == void.class) {
- b.returnVoid();
- } else {
- b.returnValue(TypeDesc.forClass(method.getReturnType()));
- }
- }
-
private static Method lookupMethod(Class type, MethodInfo mi) {
MethodDesc desc = mi.getMethodDescriptor();
TypeDesc[] params = desc.getParameterTypes();
@@ -2196,20 +1814,12 @@ public final class StorableGenerator<S extends Storable> {
TypeDesc storableTypeDesc = TypeDesc.forClass(mStorableType);
MethodInfo mi= addMethodIfNotFinal
- (Modifiers.PUBLIC.toSynchronized(mGenMode == GEN_ABSTRACT),
- methodName,
- null,
- param);
+ (Modifiers.PUBLIC.toSynchronized(true), methodName, null, param);
if (mi == null) {
return;
}
- if (mGenMode == GEN_WRAPPED) {
- callWrappedStorable(mi);
- return;
- }
-
CodeBuilder b = new CodeBuilder(mi);
LocalVariable target = CodeBuilderUtil.uneraseGenericParameter(b, storableTypeDesc, 0);
@@ -2453,9 +2063,7 @@ public final class StorableGenerator<S extends Storable> {
ordinal++;
if (!property.isDerived()) {
- if (property.isJoin() || mGenMode == GEN_ABSTRACT) {
- requireStateField = true;
- }
+ requireStateField = true;
if (ordinal == maxOrdinal || ((ordinal & 0xf) == 0xf)) {
if (requireStateField) {
@@ -2481,12 +2089,6 @@ public final class StorableGenerator<S extends Storable> {
CodeBuilder b = new CodeBuilder(mi);
- if (mGenMode == GEN_WRAPPED) {
- clearState(b);
- callWrappedStorable(mi, b);
- return;
- }
-
final int count = mAllProperties.size();
int ordinal = 0;
int andMask = 0;
@@ -2544,12 +2146,6 @@ public final class StorableGenerator<S extends Storable> {
CodeBuilder b = new CodeBuilder(mi);
- if (mGenMode == GEN_WRAPPED) {
- clearState(b);
- callWrappedStorable(mi, b);
- return;
- }
-
final int count = mAllProperties.size();
int ordinal = 0;
int andMask = 0;
@@ -2631,10 +2227,7 @@ public final class StorableGenerator<S extends Storable> {
for (StorableProperty property : mAllProperties.values()) {
if (!property.isDerived()) {
if (property == ordinaryProperty) {
- if (mGenMode == GEN_ABSTRACT) {
- // Only GEN_ABSTRACT mode uses these state bits.
- orMask |= PROPERTY_STATE_DIRTY << ((ordinal & 0xf) * 2);
- }
+ orMask |= PROPERTY_STATE_DIRTY << ((ordinal & 0xf) * 2);
} else if (property.isJoin()) {
// Check to see if ordinary is an internal member of join property.
for (int i=property.getJoinElementCount(); --i>=0; ) {
@@ -2828,10 +2421,6 @@ public final class StorableGenerator<S extends Storable> {
* PROPERTY_STATE_CLEAN.
*/
private void addPropertyStateExtractMethod() {
- if (mGenMode == GEN_WRAPPED) {
- return;
- }
-
MethodInfo mi = mClassFile.addMethod(Modifiers.PRIVATE, PROPERTY_STATE_EXTRACT_METHOD_NAME,
TypeDesc.INT, new TypeDesc[] {TypeDesc.STRING});
@@ -3112,11 +2701,6 @@ public final class StorableGenerator<S extends Storable> {
CodeBuilder b = new CodeBuilder(mi);
- if (mGenMode == GEN_WRAPPED) {
- callWrappedStorable(mi, b);
- return;
- }
-
// Call private method to extract state and compare.
b.loadThis();
b.loadLocal(b.getParameter(0));
@@ -3146,11 +2730,6 @@ public final class StorableGenerator<S extends Storable> {
CodeBuilder b = new CodeBuilder(mi);
- if (mGenMode == GEN_WRAPPED) {
- callWrappedStorable(mi, b);
- return;
- }
-
addPropertySwitch(b, SWITCH_FOR_GET);
}
@@ -3164,11 +2743,6 @@ public final class StorableGenerator<S extends Storable> {
CodeBuilder b = new CodeBuilder(mi);
- if (mGenMode == GEN_WRAPPED) {
- callWrappedStorable(mi, b);
- return;
- }
-
addPropertySwitch(b, SWITCH_FOR_SET);
}
@@ -3176,18 +2750,13 @@ public final class StorableGenerator<S extends Storable> {
* Defines a hashCode method.
*/
private void addHashCodeMethod() {
- Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(mGenMode == GEN_ABSTRACT);
+ Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(true);
MethodInfo mi = addMethodIfNotFinal(modifiers, "hashCode", TypeDesc.INT, null);
if (mi == null) {
return;
}
- if (mGenMode == GEN_WRAPPED) {
- callWrappedStorable(mi);
- return;
- }
-
CodeBuilder b = new CodeBuilder(mi);
boolean mixIn = false;
@@ -3323,7 +2892,7 @@ public final class StorableGenerator<S extends Storable> {
equalsMethodName = EQUALS_METHOD_NAME;
}
- Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(mGenMode == GEN_ABSTRACT);
+ Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(true);
MethodInfo mi = addMethodIfNotFinal
(modifiers, equalsMethodName, TypeDesc.BOOLEAN, objectParam);
@@ -3331,11 +2900,6 @@ public final class StorableGenerator<S extends Storable> {
return;
}
- if (mGenMode == GEN_WRAPPED && equalityType != EQUAL_FULL) {
- callWrappedStorable(mi);
- return;
- }
-
CodeBuilder b = new CodeBuilder(mi);
// if (this == target) return true;
@@ -3377,12 +2941,7 @@ public final class StorableGenerator<S extends Storable> {
TypeDesc fieldType = TypeDesc.forClass(property.getType());
b.loadThis();
- if (mGenMode == GEN_ABSTRACT) {
- b.loadField(property.getName(), fieldType);
- } else {
- b.loadField(WRAPPED_STORABLE_FIELD_NAME, TypeDesc.forClass(mStorableType));
- b.invoke(property.getReadMethod());
- }
+ b.loadField(property.getName(), fieldType);
b.loadLocal(other);
b.invoke(property.getReadMethod());
@@ -3410,7 +2969,7 @@ public final class StorableGenerator<S extends Storable> {
TypeDesc[] stringParam = {TypeDesc.STRING};
TypeDesc[] charParam = {TypeDesc.CHAR};
- Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(mGenMode == GEN_ABSTRACT);
+ Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(true);
MethodInfo mi = addMethodIfNotFinal(modifiers,
keyOnly ?
TO_STRING_KEY_ONLY_METHOD_NAME :
@@ -3421,11 +2980,6 @@ public final class StorableGenerator<S extends Storable> {
return;
}
- if (mGenMode == GEN_WRAPPED) {
- callWrappedStorable(mi);
- return;
- }
-
CodeBuilder b = new CodeBuilder(mi);
b.newObject(stringBuilder);
b.dup();
diff --git a/src/main/java/com/amazon/carbonado/gen/WrappedSupport.java b/src/main/java/com/amazon/carbonado/gen/WrappedSupport.java
deleted file mode 100644
index 255bce2..0000000
--- a/src/main/java/com/amazon/carbonado/gen/WrappedSupport.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.gen;
-
-import com.amazon.carbonado.FetchException;
-import com.amazon.carbonado.PersistException;
-import com.amazon.carbonado.Storable;
-
-/**
- * Provides runtime support for Storable classes generated by {@link StorableGenerator}.
- *
- * @author Brian S O'Neill
- * @since 1.2
- * @deprecated
- */
-public interface WrappedSupport<S extends Storable> extends TriggerSupport<S> {
- /**
- * @see Storable#load
- */
- void load() throws FetchException;
-
- /**
- * @see Storable#tryLoad
- */
- boolean tryLoad() throws FetchException;
-
- /**
- * @see Storable#insert
- */
- void insert() throws PersistException;
-
- /**
- * @see Storable#tryInsert
- */
- boolean tryInsert() throws PersistException;
-
- /**
- * @see Storable#update
- */
- void update() throws PersistException;
-
- /**
- * @see Storable#tryUpdate
- */
- boolean tryUpdate() throws PersistException;
-
- /**
- * @see Storable#delete
- */
- void delete() throws PersistException;
-
- /**
- * @see Storable#tryDelete
- */
- boolean tryDelete() throws PersistException;
-
- /**
- * Return another Support instance for the given Storable.
- */
- WrappedSupport<S> createSupport(S storable);
-}
diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java
index ecf54a0..d1f21ce 100644
--- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java
+++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java
@@ -18,79 +18,239 @@
package com.amazon.carbonado.repo.logging;
+import java.io.IOException;
+
import com.amazon.carbonado.Cursor;
import com.amazon.carbonado.FetchException;
import com.amazon.carbonado.PersistException;
import com.amazon.carbonado.Query;
import com.amazon.carbonado.Storable;
-import com.amazon.carbonado.spi.WrappedQuery;
+
+import com.amazon.carbonado.filter.Filter;
+import com.amazon.carbonado.filter.FilterValues;
/**
*
*
* @author Brian S O'Neill
*/
-class LoggingQuery<S extends Storable> extends WrappedQuery<S> {
+class LoggingQuery<S extends Storable> implements Query<S> {
private final LoggingStorage<S> mStorage;
+ private final Query<S> mQuery;
LoggingQuery(LoggingStorage<S> storage, Query<S> query) {
- super(query);
mStorage = storage;
+ mQuery = query;
+ }
+
+ public Class<S> getStorableType() {
+ return mQuery.getStorableType();
+ }
+
+ public Filter<S> getFilter() {
+ return mQuery.getFilter();
+ }
+
+ public FilterValues<S> getFilterValues() {
+ return mQuery.getFilterValues();
+ }
+
+ public int getBlankParameterCount() {
+ return mQuery.getBlankParameterCount();
+ }
+
+ public Query<S> with(int value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(long value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(float value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(double value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(boolean value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(char value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(byte value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(short value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(Object value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> withValues(Object... objects) {
+ return newInstance(mQuery.withValues(objects));
+ }
+
+ public Query<S> and(String filter) throws FetchException {
+ return newInstance(mQuery.and(filter));
+ }
+
+ public Query<S> and(Filter<S> filter) throws FetchException {
+ return newInstance(mQuery.and(filter));
+ }
+
+ public Query<S> or(String filter) throws FetchException {
+ return newInstance(mQuery.or(filter));
+ }
+
+ public Query<S> or(Filter<S> filter) throws FetchException {
+ return newInstance(mQuery.or(filter));
+ }
+
+ public Query<S> not() throws FetchException {
+ return newInstance(mQuery.not());
+ }
+
+ public Query<S> orderBy(String property) throws FetchException, UnsupportedOperationException {
+ return newInstance(mQuery.orderBy(property));
+ }
+
+ public Query<S> orderBy(String... strings)
+ throws FetchException, UnsupportedOperationException
+ {
+ return newInstance(mQuery.orderBy(strings));
}
public Cursor<S> fetch() throws FetchException {
- Log log = mStorage.mRepo.getLog();
+ Log log = mStorage.mLog;
if (log.isEnabled()) {
log.write("Query.fetch() on " + this);
}
- return super.fetch();
+ return mQuery.fetch();
+ }
+
+ public Cursor<S> fetchAfter(S start) throws FetchException {
+ Log log = mStorage.mLog;
+ if (log.isEnabled()) {
+ log.write("Query.fetchAfter(start) on " + this + ", start: " + start);
+ }
+ return mQuery.fetchAfter(start);
}
public S loadOne() throws FetchException {
- Log log = mStorage.mRepo.getLog();
+ Log log = mStorage.mLog;
if (log.isEnabled()) {
log.write("Query.loadOne() on " + this);
}
- return super.loadOne();
+ return mQuery.loadOne();
}
public S tryLoadOne() throws FetchException {
- Log log = mStorage.mRepo.getLog();
+ Log log = mStorage.mLog;
if (log.isEnabled()) {
log.write("Query.tryLoadOne() on " + this);
}
- return super.tryLoadOne();
+ return mQuery.tryLoadOne();
}
public void deleteOne() throws PersistException {
- Log log = mStorage.mRepo.getLog();
+ Log log = mStorage.mLog;
if (log.isEnabled()) {
log.write("Query.deleteOne() on " + this);
}
- super.deleteOne();
+ mQuery.deleteOne();
}
public boolean tryDeleteOne() throws PersistException {
- Log log = mStorage.mRepo.getLog();
+ Log log = mStorage.mLog;
if (log.isEnabled()) {
log.write("Query.tryDeleteOne() on " + this);
}
- return super.tryDeleteOne();
+ return mQuery.tryDeleteOne();
}
public void deleteAll() throws PersistException {
- Log log = mStorage.mRepo.getLog();
+ Log log = mStorage.mLog;
if (log.isEnabled()) {
log.write("Query.deleteAll() on " + this);
}
- super.deleteAll();
+ mQuery.deleteAll();
+ }
+
+ public long count() throws FetchException {
+ Log log = mStorage.mLog;
+ if (log.isEnabled()) {
+ log.write("Query.count() on " + this);
+ }
+ return mQuery.count();
+ }
+
+ public boolean exists() throws FetchException {
+ Log log = mStorage.mLog;
+ if (log.isEnabled()) {
+ log.write("Query.exists() on " + this);
+ }
+ return mQuery.exists();
+ }
+
+ public boolean printNative() {
+ return mQuery.printNative();
+ }
+
+ public boolean printNative(Appendable app) throws IOException {
+ return mQuery.printNative(app);
+ }
+
+ public boolean printNative(Appendable app, int indentLevel) throws IOException {
+ return mQuery.printNative(app, indentLevel);
}
- protected S wrap(S storable) {
- return mStorage.wrap(storable);
+ public boolean printPlan() {
+ return mQuery.printPlan();
+ }
+
+ public boolean printPlan(Appendable app) throws IOException {
+ return mQuery.printPlan(app);
+ }
+
+ public boolean printPlan(Appendable app, int indentLevel) throws IOException {
+ return mQuery.printPlan(app, indentLevel);
+ }
+
+ public void appendTo(Appendable appendable) throws IOException {
+ appendable.append(mQuery.toString());
+ }
+
+ public String toString() {
+ return mQuery.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return mQuery.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof LoggingQuery) {
+ LoggingQuery<?> other = (LoggingQuery<?>) obj;
+ return mQuery.equals(other.mQuery);
+ }
+ return false;
}
- protected WrappedQuery<S> newInstance(Query<S> query) {
+ private LoggingQuery<S> newInstance(Query<S> query) {
return new LoggingQuery<S>(mStorage, query);
}
}
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 89e6e21..e196993 100644
--- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java
+++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java
@@ -40,18 +40,15 @@ import com.amazon.carbonado.spi.StoragePool;
*/
class LoggingRepository implements Repository, LogAccessCapability {
private final AtomicReference<Repository> mRootRef;
- final Iterable<TriggerFactory> mTriggerFactories;
private final Repository mRepo;
private final Log mLog;
private final StoragePool mStoragePool;
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 3909eb1..b8c2892 100644
--- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java
+++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java
@@ -97,8 +97,7 @@ public class LoggingRepositoryBuilder extends AbstractRepositoryBuilder {
return actual;
}
- Repository repo = new LoggingRepository
- (rootRef, mRepoBuilder.getTriggerFactories(), actual, mLog);
+ Repository repo = new LoggingRepository(rootRef, 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 a6a56a1..5aed8a7 100644
--- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java
+++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java
@@ -21,130 +21,129 @@ package com.amazon.carbonado.repo.logging;
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;
-import com.amazon.carbonado.spi.WrappedStorage;
+import com.amazon.carbonado.filter.Filter;
/**
*
*
* @author Brian S O'Neill
*/
-class LoggingStorage<S extends Storable> extends WrappedStorage<S> {
- final LoggingRepository mRepo;
+class LoggingStorage<S extends Storable> implements Storage<S> {
+ private final Storage<S> mStorage;
+ final Log mLog;
+
+ LoggingStorage(LoggingRepository repo, Storage<S> storage) {
+ mStorage = storage;
+ mLog = repo.getLog();
+ storage.addTrigger(new LoggingTrigger<S>(mLog));
+ }
+
+ public Class<S> getStorableType() {
+ return mStorage.getStorableType();
+ }
- LoggingStorage(LoggingRepository repo, Storage<S> storage) throws RepositoryException {
- super(storage, repo.mTriggerFactories);
- mRepo = repo;
+ public S prepare() {
+ return mStorage.prepare();
+ }
+
+ public Query<S> query() throws FetchException {
+ return new LoggingQuery<S>(this, mStorage.query());
+ }
+
+ public Query<S> query(String filter) throws FetchException {
+ return new LoggingQuery<S>(this, mStorage.query(filter));
+ }
+
+ public Query<S> query(Filter<S> filter) throws FetchException {
+ return new LoggingQuery<S>(this, mStorage.query(filter));
}
/**
* @since 1.2
*/
public void truncate() throws PersistException {
- Log log = mRepo.getLog();
- if (log.isEnabled()) {
- log.write("Storage.truncate() on " + getStorableType().getClass());
+ if (mLog.isEnabled()) {
+ mLog.write("Storage.truncate() on " + getStorableType().getClass());
}
- super.truncate();
+ mStorage.truncate();
}
- protected S wrap(S storable) {
- return super.wrap(storable);
+ public boolean addTrigger(Trigger<? super S> trigger) {
+ return mStorage.addTrigger(trigger);
}
- protected Query<S> wrap(Query<S> query) {
- return new LoggingQuery<S>(this, query);
+ public boolean removeTrigger(Trigger<? super S> trigger) {
+ return mStorage.removeTrigger(trigger);
}
- protected Support createSupport(S storable) {
- return new Handler(storable);
+ protected Query<S> wrap(Query<S> query) {
+ return new LoggingQuery<S>(this, query);
}
- private class Handler extends Support {
- private final S mStorable;
-
- Handler(S storable) {
- mStorable = storable;
- }
-
- public Repository getRootRepository() {
- return mRepo.getRootRepository();
- }
+ private static class LoggingTrigger<S extends Storable> extends Trigger<S> {
+ private final Log mLog;
- public boolean isPropertySupported(String propertyName) {
- return mStorable.isPropertySupported(propertyName);
+ LoggingTrigger(Log log) {
+ mLog = log;
}
- public void load() throws FetchException {
- Log log = mRepo.getLog();
- if (log.isEnabled()) {
- log.write("Storable.load() on " + mStorable.toStringKeyOnly());
+ @Override
+ public Object beforeInsert(S storable) {
+ if (mLog.isEnabled()) {
+ mLog.write("Storable.insert() on " + storable.toString());
}
- mStorable.load();
+ return null;
}
- public boolean tryLoad() throws FetchException {
- Log log = mRepo.getLog();
- if (log.isEnabled()) {
- log.write("Storable.tryLoad() on " + mStorable.toStringKeyOnly());
+ @Override
+ public Object beforeTryInsert(S storable) {
+ if (mLog.isEnabled()) {
+ mLog.write("Storable.tryInsert() on " + storable.toString());
}
- return mStorable.tryLoad();
+ return null;
}
- public void insert() throws PersistException {
- Log log = mRepo.getLog();
- if (log.isEnabled()) {
- log.write("Storable.insert() on " + mStorable.toString());
+ @Override
+ public Object beforeUpdate(S storable) {
+ if (mLog.isEnabled()) {
+ mLog.write("Storable.update() on " + storable.toString());
}
- mStorable.insert();
+ return null;
}
- public boolean tryInsert() throws PersistException {
- Log log = mRepo.getLog();
- if (log.isEnabled()) {
- log.write("Storable.tryInsert() on " + mStorable.toString());
+ @Override
+ public Object beforeTryUpdate(S storable) {
+ if (mLog.isEnabled()) {
+ mLog.write("Storable.tryUpdate() on " + storable.toString());
}
- return mStorable.tryInsert();
+ return null;
}
- public void update() throws PersistException {
- Log log = mRepo.getLog();
- if (log.isEnabled()) {
- log.write("Storable.update() on " + mStorable.toString());
+ @Override
+ public Object beforeDelete(S storable) {
+ if (mLog.isEnabled()) {
+ mLog.write("Storable.delete() on " + storable.toString());
}
- mStorable.update();
+ return null;
}
- public boolean tryUpdate() throws PersistException {
- Log log = mRepo.getLog();
- if (log.isEnabled()) {
- log.write("Storable.tryUpdate() on " + mStorable.toString());
+ @Override
+ public Object beforeTryDelete(S storable) {
+ if (mLog.isEnabled()) {
+ mLog.write("Storable.tryDelete() on " + storable.toString());
}
- return mStorable.tryUpdate();
+ return null;
}
- public void delete() throws PersistException {
- Log log = mRepo.getLog();
- if (log.isEnabled()) {
- log.write("Storable.delete() on " + mStorable.toStringKeyOnly());
+ @Override
+ public void afterLoad(S storable) {
+ if (mLog.isEnabled()) {
+ mLog.write("Loaded " + storable.toString());
}
- mStorable.delete();
- }
-
- public boolean tryDelete() throws PersistException {
- Log log = mRepo.getLog();
- if (log.isEnabled()) {
- log.write("Storable.tryDelete() on " + mStorable.toStringKeyOnly());
- }
- return mStorable.tryDelete();
- }
-
- public Support createSupport(S storable) {
- return new Handler(storable);
}
}
}
diff --git a/src/main/java/com/amazon/carbonado/spi/WrappedQuery.java b/src/main/java/com/amazon/carbonado/spi/WrappedQuery.java
deleted file mode 100644
index bee05f0..0000000
--- a/src/main/java/com/amazon/carbonado/spi/WrappedQuery.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * 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.spi;
-
-import java.io.IOException;
-
-import com.amazon.carbonado.Cursor;
-import com.amazon.carbonado.FetchException;
-import com.amazon.carbonado.PersistException;
-import com.amazon.carbonado.Query;
-import com.amazon.carbonado.Storable;
-
-import com.amazon.carbonado.cursor.AbstractCursor;
-
-import com.amazon.carbonado.filter.Filter;
-import com.amazon.carbonado.filter.FilterValues;
-
-/**
- * Abstract query that wraps all returned Storables into another Storable.
- *
- * @author Don Schneider
- * @author Brian S O'Neill
- */
-public abstract class WrappedQuery<S extends Storable> implements Query<S> {
-
- // The query to which this query will delegate
- private final Query<S> mQuery;
-
- /**
- * @param query query to wrap
- */
- public WrappedQuery(Query<S> query) {
- mQuery = query;
- }
-
- public Class<S> getStorableType() {
- return mQuery.getStorableType();
- }
-
- public Filter<S> getFilter() {
- return mQuery.getFilter();
- }
-
- public FilterValues<S> getFilterValues() {
- return mQuery.getFilterValues();
- }
-
- public int getBlankParameterCount() {
- return mQuery.getBlankParameterCount();
- }
-
- public Query<S> with(int value) {
- return newInstance(mQuery.with(value));
- }
-
- public Query<S> with(long value) {
- return newInstance(mQuery.with(value));
- }
-
- public Query<S> with(float value) {
- return newInstance(mQuery.with(value));
- }
-
- public Query<S> with(double value) {
- return newInstance(mQuery.with(value));
- }
-
- public Query<S> with(boolean value) {
- return newInstance(mQuery.with(value));
- }
-
- public Query<S> with(char value) {
- return newInstance(mQuery.with(value));
- }
-
- public Query<S> with(byte value) {
- return newInstance(mQuery.with(value));
- }
-
- public Query<S> with(short value) {
- return newInstance(mQuery.with(value));
- }
-
- public Query<S> with(Object value) {
- return newInstance(mQuery.with(value));
- }
-
- public Query<S> withValues(Object... objects) {
- return newInstance(mQuery.withValues(objects));
- }
-
- public Query<S> and(String filter) throws FetchException {
- return newInstance(mQuery.and(filter));
- }
-
- public Query<S> and(Filter<S> filter) throws FetchException {
- return newInstance(mQuery.and(filter));
- }
-
- public Query<S> or(String filter) throws FetchException {
- return newInstance(mQuery.or(filter));
- }
-
- public Query<S> or(Filter<S> filter) throws FetchException {
- return newInstance(mQuery.or(filter));
- }
-
- public Query<S> not() throws FetchException {
- return newInstance(mQuery.not());
- }
-
- public Query<S> orderBy(String property) throws FetchException, UnsupportedOperationException {
- return newInstance(mQuery.orderBy(property));
- }
-
- public Query<S> orderBy(String... strings)
- throws FetchException, UnsupportedOperationException
- {
- return newInstance(mQuery.orderBy(strings));
- }
-
- public Cursor<S> fetch() throws FetchException {
- return new WrappedCursor(mQuery.fetch());
- }
-
- public Cursor<S> fetchAfter(S start) throws FetchException {
- return new WrappedCursor(mQuery.fetchAfter(start));
- }
-
- public S loadOne() throws FetchException {
- return wrap(mQuery.loadOne());
- }
-
- public S tryLoadOne() throws FetchException {
- S one = mQuery.tryLoadOne();
- return one == null ? null : wrap(one);
- }
-
- public void deleteOne() throws PersistException {
- mQuery.tryDeleteOne();
- }
-
- public boolean tryDeleteOne() throws PersistException {
- return mQuery.tryDeleteOne();
- }
-
- public void deleteAll() throws PersistException {
- mQuery.deleteAll();
- }
-
- public long count() throws FetchException {
- return mQuery.count();
- }
-
- public boolean exists() throws FetchException {
- return mQuery.exists();
- }
-
- public boolean printNative() {
- return mQuery.printNative();
- }
-
- public boolean printNative(Appendable app) throws IOException {
- return mQuery.printNative(app);
- }
-
- public boolean printNative(Appendable app, int indentLevel) throws IOException {
- return mQuery.printNative(app, indentLevel);
- }
-
- public boolean printPlan() {
- return mQuery.printPlan();
- }
-
- public boolean printPlan(Appendable app) throws IOException {
- return mQuery.printPlan(app);
- }
-
- public boolean printPlan(Appendable app, int indentLevel) throws IOException {
- return mQuery.printPlan(app, indentLevel);
- }
-
- public void appendTo(Appendable appendable) throws IOException {
- appendable.append(mQuery.toString());
- }
-
- public String toString() {
- return mQuery.toString();
- }
-
- @Override
- public int hashCode() {
- return mQuery.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof WrappedQuery) {
- WrappedQuery<?> other = (WrappedQuery<?>) obj;
- return mQuery.equals(other.mQuery);
- }
- return false;
- }
-
- protected Query<S> getWrappedQuery() {
- return mQuery;
- }
-
- /**
- * Called to wrap the given Storable.
- */
- protected abstract S wrap(S storable);
-
- protected abstract WrappedQuery<S> newInstance(Query<S> query);
-
- private class WrappedCursor extends AbstractCursor<S> {
- private Cursor<S> mCursor;
-
- public WrappedCursor(Cursor<S> cursor) {
- mCursor = cursor;
- }
-
- public void close() throws FetchException {
- mCursor.close();
- }
-
- public boolean hasNext() throws FetchException {
- return mCursor.hasNext();
- }
-
- public S next() throws FetchException {
- return wrap(mCursor.next());
- }
-
- public int skipNext(int amount) throws FetchException {
- return mCursor.skipNext(amount);
- }
- }
-}
diff --git a/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java b/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java
deleted file mode 100644
index cdae0e3..0000000
--- a/src/main/java/com/amazon/carbonado/spi/WrappedStorage.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * 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.spi;
-
-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;
-import com.amazon.carbonado.TriggerFactory;
-
-import com.amazon.carbonado.filter.Filter;
-import com.amazon.carbonado.util.QuickConstructorGenerator;
-
-import com.amazon.carbonado.gen.StorableGenerator;
-import com.amazon.carbonado.gen.WrappedSupport;
-
-/**
- * Abstract storage that wraps all returned Storables and Queries, including
- * those returned from joins. Property access methods (get and set) are
- * delegated directly to the wrapped storable. Other operations are delegated
- * to a special {@link WrappedStorage.Support handler}.
- *
- * @author Brian S O'Neill
- */
-public abstract class WrappedStorage<S extends Storable> implements Storage<S> {
- private final Storage<S> mStorage;
- private final WrappedStorableFactory<S> mFactory;
- final TriggerManager<S> mTriggerManager;
-
- /**
- * @param storage storage to wrap
- */
- public WrappedStorage(Storage<S> storage, Iterable<TriggerFactory> triggerFactories)
- throws RepositoryException
- {
- mStorage = storage;
- Class<? extends S> wrappedClass = StorableGenerator
- .getWrappedClass(storage.getStorableType());
- mFactory = QuickConstructorGenerator
- .getInstance(wrappedClass, WrappedStorableFactory.class);
- mTriggerManager = new TriggerManager<S>(storage.getStorableType(), triggerFactories);
- }
-
- public Class<S> getStorableType() {
- return mStorage.getStorableType();
- }
-
- public S prepare() {
- return wrap(mStorage.prepare());
- }
-
- public Query<S> query() throws FetchException {
- return wrap(mStorage.query());
- }
-
- public Query<S> query(String filter) throws FetchException {
- return wrap(mStorage.query(filter));
- }
-
- public Query<S> query(Filter<S> filter) throws FetchException {
- return wrap(mStorage.query(filter));
- }
-
- /**
- * @since 1.2
- */
- public void truncate() throws PersistException {
- mStorage.truncate();
- }
-
- public boolean addTrigger(Trigger<? super S> trigger) {
- return mTriggerManager.addTrigger(trigger);
- }
-
- public boolean removeTrigger(Trigger<? super S> trigger) {
- return mTriggerManager.removeTrigger(trigger);
- }
-
- /**
- * Wraps the storable into one which delegates some operations to the
- * storable handler.
- *
- * @param storable storable being wrapped
- * @see #createSupport
- * @deprecated
- */
- protected S wrap(S storable) {
- if (storable == null) {
- throw new IllegalArgumentException("Storable to wrap is null");
- }
- return mFactory.newWrappedStorable(createSupport(storable), storable);
- }
-
- /**
- * Wraps the query such that all storables returned by it are wrapped as
- * well.
- *
- * @param query query being wrapped
- * @see WrappedQuery
- */
- protected Query<S> wrap(Query<S> query) {
- return new QueryWrapper(query);
- }
-
- /**
- * Create a handler used by wrapped storables.
- *
- * @param storable storable being wrapped
- * @deprecated
- */
- protected abstract Support createSupport(S storable);
-
- protected Storage<S> getWrappedStorage() {
- return mStorage;
- }
-
- /**
- * Support for use with {@link WrappedStorage}. Most of the methods defined
- * here are a subset of those defined in Storable.
- *
- * @author Brian S O'Neill
- */
- public abstract class Support implements WrappedSupport<S> {
- public Trigger<? super S> getInsertTrigger() {
- return mTriggerManager.getInsertTrigger();
- }
-
- public Trigger<? super S> getUpdateTrigger() {
- return mTriggerManager.getUpdateTrigger();
- }
-
- public Trigger<? super S> getDeleteTrigger() {
- return mTriggerManager.getDeleteTrigger();
- }
-
- public Trigger<? super S> getLoadTrigger() {
- return mTriggerManager.getLoadTrigger();
- }
-
- public void locallyDisableLoadTrigger() {
- mTriggerManager.locallyDisableLoad();
- }
-
- public void locallyEnableLoadTrigger() {
- mTriggerManager.locallyEnableLoad();
- }
- }
-
- /**
- * Support implementation which delegates all calls to a Storable.
- */
- public class BasicSupport extends Support {
- private final Repository mRepository;
- private final S mStorable;
-
- public BasicSupport(Repository repo, S storable) {
- mRepository = repo;
- mStorable = storable;
- }
-
- public Support createSupport(S storable) {
- return new BasicSupport(mRepository, storable);
- }
-
- public Repository getRootRepository() {
- return mRepository;
- }
-
- public boolean isPropertySupported(String propertyName) {
- return mStorable.isPropertySupported(propertyName);
- }
-
- public void load() throws FetchException {
- mStorable.load();
- }
-
- public boolean tryLoad() throws FetchException {
- return mStorable.tryLoad();
- }
-
- public void insert() throws PersistException {
- mStorable.insert();
- }
-
- public boolean tryInsert() throws PersistException {
- return mStorable.tryInsert();
- }
-
- public void update() throws PersistException {
- mStorable.update();
- }
-
- public boolean tryUpdate() throws PersistException {
- return mStorable.tryUpdate();
- }
-
- public void delete() throws PersistException {
- mStorable.delete();
- }
-
- public boolean tryDelete() throws PersistException {
- return mStorable.tryDelete();
- }
-
- protected S getWrappedStorable() {
- return mStorable;
- }
- }
-
- private class QueryWrapper extends WrappedQuery<S> {
- QueryWrapper(Query<S> query) {
- super(query);
- }
-
- protected S wrap(S storable) {
- return WrappedStorage.this.wrap(storable);
- }
-
- protected WrappedQuery<S> newInstance(Query<S> query) {
- return new QueryWrapper(query);
- }
- }
-
- /**
- * Used with QuickConstructorGenerator.
- */
- public static interface WrappedStorableFactory<S extends Storable> {
- /**
- * @param storable storable being wrapped
- * @param support handler for persistence methods
- */
- S newWrappedStorable(WrappedSupport<S> support, S storable);
- }
-}