From 0bd39994718c15ec7b6690217219f12fd24aae42 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 26 Aug 2007 16:33:40 +0000 Subject: Yanked out support for filtering against one-to-many join properties. It needs to be redesigned. --- .../carbonado/cursor/FilteredCursorGenerator.java | 87 ++++------------------ .../com/amazon/carbonado/filter/AndFilter.java | 19 ++--- .../java/com/amazon/carbonado/filter/Filter.java | 52 +++++-------- .../com/amazon/carbonado/filter/FilterParser.java | 2 +- .../java/com/amazon/carbonado/filter/OrFilter.java | 21 ++---- .../amazon/carbonado/filter/PropertyFilter.java | 13 ++-- 6 files changed, 52 insertions(+), 142 deletions(-) (limited to 'src/main/java/com') 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 cg = new CodeGen(cf, ctorBuilder, isAllowedBuilder, storableVar); - filter.accept(cg, null); - - // Finish static initializer. (if any) - cg.finish(); + filter.accept(new CodeGen(cf, ctorBuilder, isAllowedBuilder, storableVar), null); // Finish constructor. ctorBuilder.returnVoid(); @@ -241,7 +236,6 @@ 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; @@ -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 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 extends BinaryOpFilter { } @Override - NotJoined notJoinedFromCNF(ChainedProperty joinProperty) { - NotJoined left = mLeft.notJoinedFromCNF(joinProperty); - NotJoined right = mRight.notJoinedFromCNF(joinProperty); + NotJoined notJoinedFrom(ChainedProperty joinProperty, + Class joinPropertyType) + { + NotJoined left = mLeft.notJoinedFrom(joinProperty, joinPropertyType); + NotJoined right = mRight.notJoinedFrom(joinProperty, joinPropertyType); // Remove wildcards to shut the compiler up. Filter leftNotJoined = left.getNotJoinedFilter(); Filter rightNotJoined = right.getNotJoinedFilter(); - Filter notJoined; - if (leftNotJoined == null) { - notJoined = rightNotJoined; - } else if (rightNotJoined == null) { - notJoined = leftNotJoined; - } else { - notJoined = leftNotJoined.and(rightNotJoined); - } - - return new NotJoined(notJoined, + return new NotJoined(leftNotJoined.and(rightNotJoined), left.getRemainderFilter().and(right.getRemainderFilter())); } diff --git a/src/main/java/com/amazon/carbonado/filter/Filter.java b/src/main/java/com/amazon/carbonado/filter/Filter.java index 79f0435..cbc37dc 100644 --- a/src/main/java/com/amazon/carbonado/filter/Filter.java +++ b/src/main/java/com/amazon/carbonado/filter/Filter.java @@ -574,18 +574,19 @@ public abstract class Filter implements Appender { * * @param joinProperty property to not join from * @return not join result - * @throws IllegalArgumentException if property is not a join + * @throws IllegalArgumentException if property does not refer to a Storable */ public final NotJoined notJoinedFrom(ChainedProperty joinProperty) { - Class type = joinProperty.getLastProperty().getJoinedType(); - if (type == null) { - throw new IllegalArgumentException("Not a join property: " + joinProperty); + Class type = joinProperty.getType(); + if (!Storable.class.isAssignableFrom(type)) { + throw new IllegalArgumentException + ("Join property type is not a Storable: " + joinProperty); } Filter cnf = conjunctiveNormalForm(); - NotJoined nj = cnf.notJoinedFromCNF(joinProperty); + NotJoined nj = cnf.notJoinedFrom(joinProperty, (Class) type); - if (nj.getNotJoinedFilter() == null) { + if (nj.getNotJoinedFilter() instanceof OpenFilter) { // Remainder filter should be same as original, but it might have // expanded with conjunctive normal form. If so, restore to // original, but still bind it to ensure consistent side-effects. @@ -599,17 +600,11 @@ public abstract class Filter implements Appender { // conversion from disjunctive normal form to conjunctive normal // form may make major changes. If original was dnf, restore the // result filters to dnf. - - boolean isNotJoinedDNF = nj.getNotJoinedFilter() == null - || nj.getNotJoinedFilter().isDisjunctiveNormalForm(); - - boolean isRemainerDNF = nj.getRemainderFilter().isDisjunctiveNormalForm(); - - if (!isNotJoinedDNF || !isRemainerDNF) { - Filter notJoinedDNF = nj.getNotJoinedFilter() == null ? null - : nj.getNotJoinedFilter().disjunctiveNormalForm(); - - nj = new NotJoined(notJoinedDNF, + + if (!(nj.getNotJoinedFilter().isDisjunctiveNormalForm()) || + !(nj.getRemainderFilter().isDisjunctiveNormalForm())) + { + nj = new NotJoined(nj.getNotJoinedFilter().disjunctiveNormalForm(), nj.getRemainderFilter().disjunctiveNormalForm()); } } @@ -620,8 +615,10 @@ public abstract class Filter implements Appender { /** * Should only be called on a filter in conjunctive normal form. */ - NotJoined notJoinedFromCNF(ChainedProperty joinProperty) { - return new NotJoined(null, this); + NotJoined notJoinedFrom(ChainedProperty joinProperty, + Class joinPropertyType) + { + return new NotJoined(getOpenFilter(joinPropertyType), this); } abstract Filter buildDisjunctiveNormalForm(); @@ -692,11 +689,8 @@ public abstract class Filter implements Appender { /** * Returns the filter which is no longer as from a join. * - * @return not joined filter or null if none + * @return not joined filter or open filter if none */ - // Design note: Return value might be null since not all join - // properties have an open filter representation. For example, some - // joins return Query objects. public Filter getNotJoinedFilter() { return mNotJoined; } @@ -704,18 +698,14 @@ public abstract class Filter implements Appender { /** * Returns the filter which could not be separated. * - * @return remainder filter or open filter if none + * @return remainder filter or open filter if none */ public Filter getRemainderFilter() { return mRemainder; } public int hashCode() { - if (mNotJoined == null) { - return mRemainder.hashCode(); - } else { - return mNotJoined.hashCode() * 31 + mRemainder.hashCode(); - } + return mNotJoined.hashCode() * 31 + mRemainder.hashCode(); } public boolean equals(Object obj) { @@ -724,9 +714,7 @@ public abstract class Filter implements Appender { } if (obj instanceof Filter.NotJoined) { NotJoined other = (NotJoined) obj; - return (mNotJoined == null ? other.mNotJoined == null - : mNotJoined.equals(other.mNotJoined)) - && mRemainder.equals(other.mRemainder); + return mNotJoined.equals(other.mNotJoined) && mRemainder.equals(other.mRemainder); } return false; } diff --git a/src/main/java/com/amazon/carbonado/filter/FilterParser.java b/src/main/java/com/amazon/carbonado/filter/FilterParser.java index aa01ba9..a0a178d 100644 --- a/src/main/java/com/amazon/carbonado/filter/FilterParser.java +++ b/src/main/java/com/amazon/carbonado/filter/FilterParser.java @@ -220,7 +220,7 @@ class FilterParser { } List> chain = new ArrayList>(4); - Class type = prime.isJoin() ? prime.getJoinedType() : prime.getType(); + Class type = prime.getType(); while (true) { ident = parseIdentifier(); diff --git a/src/main/java/com/amazon/carbonado/filter/OrFilter.java b/src/main/java/com/amazon/carbonado/filter/OrFilter.java index 67da5ba..d5748aa 100644 --- a/src/main/java/com/amazon/carbonado/filter/OrFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/OrFilter.java @@ -67,9 +67,11 @@ public class OrFilter extends BinaryOpFilter { } @Override - NotJoined notJoinedFromCNF(ChainedProperty joinProperty) { - NotJoined left = mLeft.notJoinedFromCNF(joinProperty); - NotJoined right = mRight.notJoinedFromCNF(joinProperty); + NotJoined notJoinedFrom(ChainedProperty joinProperty, + Class joinPropertyType) + { + NotJoined left = mLeft.notJoinedFrom(joinProperty, joinPropertyType); + NotJoined right = mRight.notJoinedFrom(joinProperty, joinPropertyType); // Assert that our child nodes are only OrFilter or PropertyFilter. if (!isConjunctiveNormalForm()) { @@ -86,23 +88,14 @@ public class OrFilter extends BinaryOpFilter { if (!(left.getRemainderFilter() instanceof OpenFilter) || !(right.getRemainderFilter() instanceof OpenFilter)) { - return super.notJoinedFromCNF(joinProperty); + return super.notJoinedFrom(joinProperty, joinPropertyType); } // Remove wildcards to shut the compiler up. Filter leftNotJoined = left.getNotJoinedFilter(); Filter rightNotJoined = right.getNotJoinedFilter(); - Filter notJoined; - if (leftNotJoined == null) { - notJoined = rightNotJoined; - } else if (rightNotJoined == null) { - notJoined = leftNotJoined; - } else { - notJoined = leftNotJoined.or(rightNotJoined); - } - - return new NotJoined(notJoined, getOpenFilter(getStorableType())); + return new NotJoined(leftNotJoined.or(rightNotJoined), getOpenFilter(getStorableType())); } Filter buildDisjunctiveNormalForm() { diff --git a/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java b/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java index deb1f21..9f12095 100644 --- a/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java @@ -189,12 +189,7 @@ public class PropertyFilter extends Filter { } public PropertyFilter asJoinedFrom(ChainedProperty joinProperty) { - Class type = joinProperty.getLastProperty().getJoinedType(); - if (type == null) { - type = joinProperty.getType(); - } - - if (type != getStorableType()) { + if (joinProperty.getType() != getStorableType()) { throw new IllegalArgumentException ("Property is not of type \"" + getStorableType().getName() + "\": " + joinProperty); @@ -210,7 +205,9 @@ public class PropertyFilter extends Filter { } @Override - NotJoined notJoinedFromCNF(ChainedProperty joinProperty) { + NotJoined notJoinedFrom(ChainedProperty joinProperty, + Class joinPropertyType) + { ChainedProperty notJoinedProp = getChainedProperty(); ChainedProperty jp = joinProperty; @@ -224,7 +221,7 @@ public class PropertyFilter extends Filter { } if (jp != null || notJoinedProp.equals(getChainedProperty())) { - return super.notJoinedFromCNF(joinProperty); + return super.notJoinedFrom(joinProperty, joinPropertyType); } PropertyFilter notJoinedFilter; -- cgit v1.2.3