From e1a76e83bd0fac08ae51edc183f6273f7eac1fad Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sat, 4 Aug 2007 20:01:50 +0000 Subject: Support query filters against one-to-many join properties. --- .../amazon/carbonado/cursor/FilteredCursor.java | 2 +- .../carbonado/cursor/FilteredCursorGenerator.java | 87 ++++++++++++++++++---- .../com/amazon/carbonado/filter/FilterParser.java | 2 +- 3 files changed, 76 insertions(+), 15 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java b/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java index 264f7a9..51d69e7 100644 --- a/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java @@ -104,7 +104,7 @@ public abstract class FilteredCursor extends AbstractCursor { /** * @return false if object should not be in results */ - protected abstract boolean isAllowed(S storable); + protected abstract boolean isAllowed(S storable) throws FetchException; public void close() throws FetchException { mCursor.close(); diff --git a/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java b/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java index 4514865..9b2a945 100644 --- a/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java +++ b/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java @@ -38,6 +38,7 @@ 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; @@ -154,7 +155,11 @@ class FilteredCursorGenerator { isAllowedBuilder.storeLocal(storableVar); } - filter.accept(new CodeGen(cf, ctorBuilder, isAllowedBuilder, storableVar), null); + CodeGen cg = new CodeGen(cf, ctorBuilder, isAllowedBuilder, storableVar); + filter.accept(cg, null); + + // Finish static initializer. (if any) + cg.finish(); // Finish constructor. ctorBuilder.returnVoid(); @@ -223,6 +228,7 @@ class FilteredCursorGenerator { private static class CodeGen extends Visitor { private static String FIELD_PREFIX = "value$"; + private static String FILTER_FIELD_PREFIX = "filter$"; private final ClassFile mClassFile; private final CodeBuilder mCtorBuilder; @@ -233,6 +239,8 @@ class FilteredCursorGenerator { private int mPropertyOrdinal; + private CodeBuilder mInitBuilder; + CodeGen(ClassFile cf, CodeBuilder ctorBuilder, CodeBuilder isAllowedBuilder, LocalVariable storableVar) { @@ -244,6 +252,12 @@ class FilteredCursorGenerator { mScopeStack.push(new Scope(null, null)); } + public void finish() { + if (mInitBuilder != null) { + mInitBuilder.returnVoid(); + } + } + public Object visit(OrFilter filter, Object param) { Label failLocation = mIsAllowedBuilder.createLabel(); // Inherit success location to short-circuit if 'or' test succeeds. @@ -289,25 +303,72 @@ class FilteredCursorGenerator { b = mIsAllowedBuilder; b.loadLocal(mStorableVar); loadProperty(b, chained.getPrimeProperty()); - for (int i=0; i { } List> chain = new ArrayList>(4); - Class type = prime.getType(); + Class type = prime.isJoin() ? prime.getJoinedType() : prime.getType(); while (true) { ident = parseIdentifier(); -- cgit v1.2.3