|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.amazon.carbonado.filter.Filter<S>
public abstract class Filter<S extends Storable>
An immutable tree structure representing a query result filter. Filters can be created using a builder pattern, by expression parsing, or by a combination of techniques. Filter instances are canonical, which means that equivalent instances can be compared for equality using the '==' operator.
Any method that accepts a filter expression parses against the following syntax:
Filter = OrFilter
OrFilter = AndFilter { "|" AndFilter }
AndFilter = NotFilter { "&" NotFilter }
NotFilter = [ "!" ] EntityFilter
EntityFilter = PropertyFilter
= ChainedFilter
| "(" Filter ")"
PropertyFilter = ChainedProperty RelOp "?"
RelOp = "=" | "!=" | "<" | ">=" | ">" | "<="
ChainedFilter = ChainedProperty "(" [ Filter ] ")"
ChainedProperty = Identifier
| InnerJoin "." ChainedProperty
| OuterJoin "." ChainedProperty
InnerJoin = Identifier
OuterJoin = "(" Identifier ")"
| Nested Class Summary | |
|---|---|
class |
Filter.NotJoined
Result from calling notJoinedFrom(java.lang.String). |
| Method Summary | ||
|---|---|---|
abstract
|
accept(Visitor<S,R,P> visitor,
P param)
Accept the given visitor subclass to traverse the filter tree. |
|
Filter<S> |
and(Filter<S> filter)
Returns a combined filter instance that accepts records which are only accepted by this filter and the one given. |
|
Filter<S> |
and(String expression)
Returns a combined filter instance that accepts records which are only accepted by this filter and the one given. |
|
Filter<S> |
and(String propertyName,
RelOp operator)
Returns a combined filter instance that accepts records which are only accepted by this filter and the one given. |
|
Filter<S> |
and(String propertyName,
RelOp operator,
Object constantValue)
Returns a combined filter instance that accepts records which are only accepted by this filter and the one given. |
|
Filter<S> |
andExists(String propertyName,
Filter<?> subFilter)
Returns a combined filter instance that accepts records which are only accepted by this filter and the "exists" test applied to a join. |
|
Filter<S> |
andNotExists(String propertyName,
Filter<?> subFilter)
Returns a combined filter instance that accepts records which are only accepted by this filter and the "not exists" test applied to a join. |
|
void |
appendTo(Appendable app)
Appends the string value of this filter into the given Appendable. |
|
abstract void |
appendTo(Appendable app,
FilterValues<S> values)
Appends the string value of this filter into the given Appendable. |
|
|
asJoinedFrom(ChainedProperty<T> joinProperty)
Prepends a join property to all properties of this filter. |
|
|
asJoinedFrom(Class<T> type,
String joinProperty)
Prepends a join property to all properties of this filter. |
|
abstract
|
asJoinedFromAny(ChainedProperty<T> joinProperty)
Allows join from any property type, including one-to-many joins. |
|
abstract Filter<S> |
bind()
Walks through each property filter, assigning a bind ID to it. |
|
Filter<S> |
conjunctiveNormalForm()
Returns an equivalent filter that is in conjunctive normal form. |
|
List<Filter<S>> |
conjunctiveNormalFormSplit()
Splits the filter from its conjunctive normal form. |
|
Filter<S> |
disjunctiveNormalForm()
Returns an equivalent filter that is in disjunctive normal form. |
|
List<Filter<S>> |
disjunctiveNormalFormSplit()
Splits the filter from its disjunctive normal form. |
|
abstract boolean |
equals(Object obj)
|
|
static
|
filterFor(Class<S> type,
String expression)
Returns a cached filter instance that operates on the given type and filter expression. |
|
static
|
getClosedFilter(Class<S> type)
Returns a cached filter instance that operates on the given type, which prevents any results from passing through. |
|
static
|
getOpenFilter(Class<S> type)
Returns a cached filter instance that operates on the given type, which allows all results to pass through. |
|
Class<S> |
getStorableType()
Returns the storable type that this filter operates on. |
|
int |
hashCode()
|
|
FilterValues<S> |
initialFilterValues()
Returns a FilterValues instance for assigning values to a Filter. |
|
abstract boolean |
isBound()
Returns true if all property filters are known to be properly bound. |
|
boolean |
isClosed()
Returns true if filter prevents any results from passing through. |
|
boolean |
isOpen()
Returns true if filter allows all results to pass through. |
|
abstract Filter<S> |
not()
Returns the logical negation of this filter. |
|
Filter.NotJoined |
notJoinedFrom(ChainedProperty<S> joinProperty)
Removes a join property prefix from all applicable properties of this filter. |
|
Filter.NotJoined |
notJoinedFrom(String joinProperty)
Removes a join property prefix from all applicable properties of this filter. |
|
Filter<S> |
or(Filter<S> filter)
Returns a combined filter instance that accepts records which are accepted either by this filter or the one given. |
|
Filter<S> |
or(String expression)
Returns a combined filter instance that accepts records which are accepted either by this filter or the one given. |
|
Filter<S> |
or(String propertyName,
RelOp operator)
Returns a combined filter instance that accepts records which are accepted either by this filter or the one given. |
|
Filter<S> |
or(String propertyName,
RelOp operator,
Object constantValue)
Returns a combined filter instance that accepts records which are accepted either by this filter or the one given. |
|
Filter<S> |
orExists(String propertyName,
Filter<?> subFilter)
Returns a combined filter instance that accepts records which are accepted either by this filter or the "exists" test applied to a join. |
|
Filter<S> |
orNotExists(String propertyName,
Filter<?> subFilter)
Returns a combined filter instance that accepts records which are accepted either by this filter or the "not exists" test applied to a join. |
|
Filter<S> |
reduce()
Returns an equivalent filter with redundant terms eliminated. |
|
String |
toString()
Returns the string value of this filter, which is also parsable. |
|
abstract Filter<S> |
unbind()
Undoes the effect of a bind operation. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public static <S extends Storable> Filter<S> filterFor(Class<S> type,
String expression)
type - type of Storable that query is made againstexpression - query filter expression to parse
IllegalArgumentException - if type or filter expression is null
MalformedFilterException - if filter expression is malformedpublic static <S extends Storable> OpenFilter<S> getOpenFilter(Class<S> type)
type - type of Storable that query is made against
OpenFilterpublic static <S extends Storable> ClosedFilter<S> getClosedFilter(Class<S> type)
type - type of Storable that query is made against
ClosedFilterpublic Class<S> getStorableType()
public FilterValues<S> initialFilterValues()
Note: The returned FilterValues instance may reference a different
filter instance than this one. Call getFilter to retrieve it. The
difference is caused by the filter property values being bound.
public final Filter<S> and(String expression)
expression - query filter expression to parse
IllegalArgumentException - if filter is nullpublic Filter<S> and(Filter<S> filter)
IllegalArgumentException - if filter is null
public final Filter<S> and(String propertyName,
RelOp operator)
propertyName - property name to match on, which may be a chained propertyoperator - relational operator
IllegalArgumentException - if property is not found
public final Filter<S> and(String propertyName,
RelOp operator,
Object constantValue)
propertyName - property name to match on, which may be a chained propertyoperator - relational operatorconstantValue - constant value to match
IllegalArgumentException - if property is not found
public final Filter<S> andExists(String propertyName,
Filter<?> subFilter)
propertyName - join property name, which may be a chained propertysubFilter - sub-filter to apply to join, which may be null to test
for any existing
IllegalArgumentException - if property is not found
public final Filter<S> andNotExists(String propertyName,
Filter<?> subFilter)
propertyName - join property name, which may be a chained propertysubFilter - sub-filter to apply to join, which may be null to test
for any not existing
IllegalArgumentException - if property is not foundpublic final Filter<S> or(String expression)
expression - query filter expression to parse
IllegalArgumentException - if filter is nullpublic Filter<S> or(Filter<S> filter)
IllegalArgumentException - if filter is null
public final Filter<S> or(String propertyName,
RelOp operator)
propertyName - property name to match on, which may be a chained propertyoperator - relational operator
IllegalArgumentException - if property is not found
public final Filter<S> or(String propertyName,
RelOp operator,
Object constantValue)
propertyName - property name to match on, which may be a chained propertyoperator - relational operatorconstantValue - constant value to match
IllegalArgumentException - if property is not found
public final Filter<S> orExists(String propertyName,
Filter<?> subFilter)
propertyName - one-to-many join property name, which may be a chained propertysubFilter - sub-filter to apply to join, which may be null to test
for any existing
IllegalArgumentException - if property is not found
public final Filter<S> orNotExists(String propertyName,
Filter<?> subFilter)
propertyName - one-to-many join property name, which may be a chained propertysubFilter - sub-filter to apply to join, which may be null to test
for any not existing
IllegalArgumentException - if property is not foundpublic abstract Filter<S> not()
public final Filter<S> disjunctiveNormalForm()
The tree is also normalized such that all terms in a common logical
operation are ordered left to right. For example, expressions of the
form "(a = ? & b = ?) & (c = ? & d = ?)" are converted to
"(((a = ?) & (b = ?)) & c = ?) & d = ?".
Although the disjunctive normal filter may have more terms, it can be used to extract values from a FilterValues instance created from this filter. This works because the disjunctive normal filter is composed of the same set of PropertyFilter instances.
public List<Filter<S>> disjunctiveNormalFormSplit()
public final Filter<S> conjunctiveNormalForm()
The tree is also normalized such that all terms in a common logical
operation are ordered left to right. For example, expressions of the
form "(a = ? | b = ?) | (c = ? | d = ?)" are converted to
"(((a = ?) | (b = ?)) | c = ?) | d = ?".
Although the conjunctive normal filter may have more terms, it can be used to extract values from a FilterValues instance created from this filter. This works because the conjunctive normal filter is composed of the same set of PropertyFilter instances.
public List<Filter<S>> conjunctiveNormalFormSplit()
public abstract <R,P> R accept(Visitor<S,R,P> visitor,
P param)
visitor - visitor to traverse through the treeparam - generic input parameter passed to visit methods
public abstract Filter<S> bind()
public abstract Filter<S> unbind()
public abstract boolean isBound()
bind(), initialFilterValues(), disjunctiveNormalForm() or conjunctiveNormalForm().
public final Filter<S> reduce()
"(a = ? & b = ?) & (c = ? & d = ?)" are converted to
"(((a = ?) & (b = ?)) & c = ?) & d = ?".
public final <T extends Storable> Filter<T> asJoinedFrom(Class<T> type,
String joinProperty)
Filter<Address> addressFilter = Filter.filterFor(Address.class, "city = ?"); Filter<Person> personFilter = addressFilter.asJoinedFrom(Person.class, "homeAddress"); // Equivalent filter: Filter<Person> personFilter2 = Filter.filterFor(Person.class, "homeAddress.city = ?");
type - type of T which contains join propertyjoinProperty - property of T which joins to this Filter's Storable type
IllegalArgumentException - if property does not exist or is not a
join to type Spublic final <T extends Storable> Filter<T> asJoinedFrom(ChainedProperty<T> joinProperty)
joinProperty - property of T which joins to this Filter's Storable type
IllegalArgumentException - if property is not a join to type Spublic abstract <T extends Storable> Filter<T> asJoinedFromAny(ChainedProperty<T> joinProperty)
public final Filter.NotJoined notJoinedFrom(String joinProperty)
The resulting remainder filter (if any) is always logically and'd to
the not joined filter. In order to achieve this, the original filter is
first converted to conjunctive normal form. And as a side affect, both
the remainder and not joined filters are bound.
joinProperty - property to not join from
IllegalArgumentException - if property does not exist or if
property does not refer to a Storablepublic final Filter.NotJoined notJoinedFrom(ChainedProperty<S> joinProperty)
The resulting remainder filter (if any) is always logically and'd to
the not joined filter. In order to achieve this, the original filter is
first converted to conjunctive normal form. And as a side affect, both
the remainder and not joined filters are bound.
joinProperty - property to not join from
IllegalArgumentException - if property does not refer to a Storablepublic boolean isOpen()
public boolean isClosed()
public final int hashCode()
hashCode in class Objectpublic abstract boolean equals(Object obj)
equals in class Objectpublic String toString()
toString in class Object
public void appendTo(Appendable app)
throws IOException
appendTo in interface Appenderapp - Appendable object to receive string representation
IOException - if thrown from given Appendable
public abstract void appendTo(Appendable app,
FilterValues<S> values)
throws IOException
values - optionally supply filter values
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||