public abstract class Filter<S extends Storable> extends java.lang.Object implements java.io.Serializable, Appender
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 ")"
Modifier and Type | Class and Description |
---|---|
class |
Filter.NotJoined
Result from calling
notJoinedFrom(java.lang.String) . |
Modifier and Type | Method and Description |
---|---|
abstract <R,P> R |
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(java.lang.String expression)
Returns a combined filter instance that accepts records which are only
accepted by this filter and the one given.
|
Filter<S> |
and(java.lang.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(java.lang.String propertyName,
RelOp operator,
java.lang.Object constantValue)
Returns a combined filter instance that accepts records which are only
accepted by this filter and the one given.
|
Filter<S> |
andExists(java.lang.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(java.lang.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(java.lang.Appendable app)
Appends the string value of this filter into the given Appendable.
|
abstract void |
appendTo(java.lang.Appendable app,
FilterValues<S> values)
Appends the string value of this filter into the given Appendable.
|
<T extends Storable> |
asJoinedFrom(ChainedProperty<T> joinProperty)
Prepends a join property to all properties of this filter.
|
<T extends Storable> |
asJoinedFrom(java.lang.Class<T> type,
java.lang.String joinProperty)
Prepends a join property to all properties of this filter.
|
abstract <T extends Storable> |
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.
|
java.util.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.
|
java.util.List<Filter<S>> |
disjunctiveNormalFormSplit()
Splits the filter from its disjunctive normal form.
|
abstract boolean |
equals(java.lang.Object obj) |
static <S extends Storable> |
filterFor(java.lang.Class<S> type,
java.lang.String expression)
Returns a cached filter instance that operates on the given type and
filter expression.
|
static <S extends Storable> |
getClosedFilter(java.lang.Class<S> type)
Returns a cached filter instance that operates on the given type, which
prevents any results from passing through.
|
static <S extends Storable> |
getOpenFilter(java.lang.Class<S> type)
Returns a cached filter instance that operates on the given type, which
allows all results to pass through.
|
java.lang.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(java.lang.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(java.lang.String expression)
Returns a combined filter instance that accepts records which are
accepted either by this filter or the one given.
|
Filter<S> |
or(java.lang.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(java.lang.String propertyName,
RelOp operator,
java.lang.Object constantValue)
Returns a combined filter instance that accepts records which are
accepted either by this filter or the one given.
|
Filter<S> |
orExists(java.lang.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(java.lang.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.
|
java.lang.String |
toString()
Returns the string value of this filter, which is also parsable.
|
abstract Filter<S> |
unbind()
Undoes the effect of a bind operation.
|
public static <S extends Storable> Filter<S> filterFor(java.lang.Class<S> type, java.lang.String expression)
type
- type of Storable that query is made againstexpression
- query filter expression to parsejava.lang.IllegalArgumentException
- if type or filter expression is nullMalformedFilterException
- if filter expression is malformedpublic static <S extends Storable> OpenFilter<S> getOpenFilter(java.lang.Class<S> type)
type
- type of Storable that query is made againstOpenFilter
public static <S extends Storable> ClosedFilter<S> getClosedFilter(java.lang.Class<S> type)
type
- type of Storable that query is made againstClosedFilter
public java.lang.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(java.lang.String expression)
expression
- query filter expression to parsejava.lang.IllegalArgumentException
- if filter is nullpublic Filter<S> and(Filter<S> filter)
java.lang.IllegalArgumentException
- if filter is nullpublic final Filter<S> and(java.lang.String propertyName, RelOp operator)
propertyName
- property name to match on, which may be a chained propertyoperator
- relational operatorjava.lang.IllegalArgumentException
- if property is not foundpublic final Filter<S> and(java.lang.String propertyName, RelOp operator, java.lang.Object constantValue)
propertyName
- property name to match on, which may be a chained propertyoperator
- relational operatorconstantValue
- constant value to matchjava.lang.IllegalArgumentException
- if property is not foundpublic final Filter<S> andExists(java.lang.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 existingjava.lang.IllegalArgumentException
- if property is not foundpublic final Filter<S> andNotExists(java.lang.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 existingjava.lang.IllegalArgumentException
- if property is not foundpublic final Filter<S> or(java.lang.String expression)
expression
- query filter expression to parsejava.lang.IllegalArgumentException
- if filter is nullpublic Filter<S> or(Filter<S> filter)
java.lang.IllegalArgumentException
- if filter is nullpublic final Filter<S> or(java.lang.String propertyName, RelOp operator)
propertyName
- property name to match on, which may be a chained propertyoperator
- relational operatorjava.lang.IllegalArgumentException
- if property is not foundpublic final Filter<S> or(java.lang.String propertyName, RelOp operator, java.lang.Object constantValue)
propertyName
- property name to match on, which may be a chained propertyoperator
- relational operatorconstantValue
- constant value to matchjava.lang.IllegalArgumentException
- if property is not foundpublic final Filter<S> orExists(java.lang.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 existingjava.lang.IllegalArgumentException
- if property is not foundpublic final Filter<S> orNotExists(java.lang.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 existingjava.lang.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 java.util.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 java.util.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 methodspublic 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(java.lang.Class<T> type, java.lang.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 typejava.lang.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 typejava.lang.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(java.lang.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 fromjava.lang.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 fromjava.lang.IllegalArgumentException
- if property does not refer to a Storablepublic boolean isOpen()
public boolean isClosed()
public final int hashCode()
hashCode
in class java.lang.Object
public abstract boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public void appendTo(java.lang.Appendable app) throws java.io.IOException
public abstract void appendTo(java.lang.Appendable app, FilterValues<S> values) throws java.io.IOException
values
- optionally supply filter valuesjava.io.IOException
Copyright © 2006-2013 Amazon Technologies, Inc.. All Rights Reserved.