summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/cursor
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2007-08-26 16:33:40 +0000
committerBrian S. O'Neill <bronee@gmail.com>2007-08-26 16:33:40 +0000
commit0bd39994718c15ec7b6690217219f12fd24aae42 (patch)
tree82224d7553bbecdfad2fbebdbc612400f1c7ae7b /src/main/java/com/amazon/carbonado/cursor
parentabb61b817c4c87dde9fa8f6899f0901b9d945142 (diff)
Yanked out support for filtering against one-to-many join properties. It needs to be redesigned.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/cursor')
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java87
1 files changed, 13 insertions, 74 deletions
diff --git a/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java b/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java
index 71aaf5b..7762885 100644
--- a/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java
+++ b/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java
@@ -38,7 +38,6 @@ import org.cojen.util.ClassInjector;
import org.cojen.util.WeakIdentityMap;
import com.amazon.carbonado.Cursor;
-import com.amazon.carbonado.Query;
import com.amazon.carbonado.Storable;
import com.amazon.carbonado.filter.AndFilter;
@@ -168,11 +167,7 @@ class FilteredCursorGenerator {
isAllowedBuilder.storeLocal(storableVar);
}
- CodeGen<S> cg = new CodeGen<S>(cf, ctorBuilder, isAllowedBuilder, storableVar);
- filter.accept(cg, null);
-
- // Finish static initializer. (if any)
- cg.finish();
+ filter.accept(new CodeGen<S>(cf, ctorBuilder, isAllowedBuilder, storableVar), null);
// Finish constructor.
ctorBuilder.returnVoid();
@@ -241,7 +236,6 @@ class FilteredCursorGenerator {
private static class CodeGen<S extends Storable> extends Visitor<S, Object, Object> {
private static String FIELD_PREFIX = "value$";
- private static String FILTER_FIELD_PREFIX = "filter$";
private final ClassFile mClassFile;
private final CodeBuilder mCtorBuilder;
@@ -252,8 +246,6 @@ class FilteredCursorGenerator {
private int mPropertyOrdinal;
- private CodeBuilder mInitBuilder;
-
CodeGen(ClassFile cf,
CodeBuilder ctorBuilder,
CodeBuilder isAllowedBuilder, LocalVariable storableVar) {
@@ -265,12 +257,6 @@ class FilteredCursorGenerator {
mScopeStack.push(new Scope(null, null));
}
- public void finish() {
- if (mInitBuilder != null) {
- mInitBuilder.returnVoid();
- }
- }
-
public Object visit(OrFilter<S> filter, Object param) {
Label failLocation = mIsAllowedBuilder.createLabel();
// Inherit success location to short-circuit if 'or' test succeeds.
@@ -316,72 +302,25 @@ class FilteredCursorGenerator {
b = mIsAllowedBuilder;
b.loadLocal(mStorableVar);
loadProperty(b, chained.getPrimeProperty());
+ for (int i=0; i<chained.getChainCount(); i++) {
+ // Check if last loaded property was null, and fail if so.
+ b.dup();
+ Label notNull = b.createLabel();
+ b.ifNullBranch(notNull, false);
+ b.pop();
+ getScope().fail(b);
+ notNull.setLocation();
- if (chained.getPrimeProperty().isQuery()) {
- Filter tail = Filter.getOpenFilter(chained.getPrimeProperty().getJoinedType())
- .and(chained.tail().toString(), filter.getOperator());
-
- String filterFieldName = addStaticFilterField(tail);
-
- TypeDesc filterType = TypeDesc.forClass(Filter.class);
- TypeDesc queryType = TypeDesc.forClass(Query.class);
-
- b.loadStaticField(filterFieldName, filterType);
- b.invokeInterface(queryType, "and", queryType, new TypeDesc[] {filterType});
- b.loadThis();
- b.loadField(fieldName, fieldType);
- TypeDesc withType = fieldType;
- if (!withType.isPrimitive()) {
- withType = TypeDesc.OBJECT;
- }
- b.invokeInterface(queryType, "with", queryType, new TypeDesc[] {withType});
- b.invokeInterface(queryType, "exists", TypeDesc.BOOLEAN, null);
-
- // Success if boolean value is true (non-zero).
- getScope().successIfZeroComparisonElseFail(b, RelOp.NE);
- } else {
- for (int i=0; i<chained.getChainCount(); i++) {
- // Check if last loaded property was null, and fail if so.
- b.dup();
- Label notNull = b.createLabel();
- b.ifNullBranch(notNull, false);
- b.pop();
- getScope().fail(b);
- notNull.setLocation();
-
- // Now load next property in chain.
- loadProperty(b, chained.getChainedProperty(i));
- }
-
- addPropertyFilter(b, type, filter.getOperator());
+ // Now load next property in chain.
+ loadProperty(b, chained.getChainedProperty(i));
}
+ addPropertyFilter(b, type, filter.getOperator());
+
mPropertyOrdinal++;
return null;
}
- private String addStaticFilterField(Filter filter) {
- String fieldName = FILTER_FIELD_PREFIX + mPropertyOrdinal;
-
- TypeDesc filterType = TypeDesc.forClass(Filter.class);
- TypeDesc classType = TypeDesc.forClass(Class.class);
-
- mClassFile.addField(Modifiers.PRIVATE.toStatic(true).toFinal(true),
- fieldName, filterType);
-
- if (mInitBuilder == null) {
- mInitBuilder = new CodeBuilder(mClassFile.addInitializer());
- }
-
- mInitBuilder.loadConstant(TypeDesc.forClass(filter.getStorableType()));
- mInitBuilder.loadConstant(filter.toString());
- mInitBuilder.invokeStatic(Filter.class.getName(), "filterFor", filterType,
- new TypeDesc[] {classType, TypeDesc.STRING});
- mInitBuilder.storeStaticField(fieldName, filterType);
-
- return fieldName;
- }
-
private Scope getScope() {
return mScopeStack.peek();
}