T
- type of search condition.public class SimpleSearchCondition<T> extends Object implements SearchCondition<T>
isMet(Object)
description.Constructor and Description |
---|
SimpleSearchCondition(ConditionType cType,
T condition)
Creates search condition with same operator (equality, inequality) applied in all comparison; see
isMet(Object) for details of comparison. |
SimpleSearchCondition(Map<String,ConditionType> getters2operators,
Map<String,String> realGetters,
Map<String,Beanspector.TypeInfo> propertyTypeInfo,
T condition)
Creates search condition with different operators (equality, inequality etc) specified for each getter;
see
isMet(Object) for details of comparison. |
SimpleSearchCondition(Map<String,ConditionType> getters2operators,
T condition) |
Modifier and Type | Method and Description |
---|---|
void |
accept(SearchConditionVisitor<T,?> visitor)
Provides a visitor which will convert this SearchCondition into
a custom expression, for example, into the SQL statement, etc
|
List<T> |
findAll(Collection<T> pojos)
Returns a list of pojos matching the condition
|
T |
getCondition()
Some SearchConditions may use instance of T to capture the actual search criteria
thus making it simpler to implement isMet(T).
|
ConditionType |
getConditionType()
Returns the type of the condition this SearchCondition represents
|
List<SearchCondition<T>> |
getSearchConditions()
List of conditions this SearchCondition may represent.
|
PrimitiveStatement |
getStatement()
Primitive statement such a > b, i < 5, etc
this condition may represent.
|
boolean |
isMet(T pojo)
Compares given object against template condition object.
|
String |
toSQL(String table,
String... columns) |
public SimpleSearchCondition(ConditionType cType, T condition)
isMet(Object)
for details of comparison.cType
- shared condition typecondition
- template objectpublic SimpleSearchCondition(Map<String,ConditionType> getters2operators, Map<String,String> realGetters, Map<String,Beanspector.TypeInfo> propertyTypeInfo, T condition)
isMet(Object)
for details of comparison. Cannot be used for primitive T type due to
per-getter comparison strategy.getters2operators
- getters names and operators to be used with them during comparisoncondition
- template objectpublic SimpleSearchCondition(Map<String,ConditionType> getters2operators, T condition)
public T getCondition()
SearchCondition
getCondition
in interface SearchCondition<T>
public ConditionType getConditionType()
When constructor with map is used it returns null.
getConditionType
in interface SearchCondition<T>
public List<SearchCondition<T>> getSearchConditions()
SearchCondition
getSearchConditions
in interface SearchCondition<T>
public boolean isMet(T pojo)
For built-in type T like String, Number (precisely, from type T located in subpackage of "java.lang.*")
given object is directly compared with template object. Comparison for ConditionType.EQUALS
requires correct implementation of Object.equals(Object)
, using inequalities requires type T
implementing Comparable
.
For other types the comparison of given object against template object is done using its getters; Value returned by isMet(Object) operation is conjunction ('and' operator) of comparisons of each getter accessible in object of type T. Getters of template object that return null or throw exception are not used in comparison. Finally, if all getters return nulls (are excluded) it is interpreted as no filter (match every pojo).
If constructor with shared operator
was used,
then getters are compared using the same operator. If constructor with map of operators
was used then for every getter specified operator is used (getters
for missing mapping are ignored). The way that comparison per-getter is done depending on operator type
per getter - comparison for ConditionType.EQUALS
requires correct implementation of
Object.equals(Object)
, using inequalities requires that getter type implements
Comparable
.
For equality comparison and String type in template object (either being built-in or getter from client provided type) it is allowed to used asterisk at the beginning or at the end of text as wild card (zero or more of any characters) e.g. "foo*", "*foo" or "*foo*". Inner asterisks are not interpreted as wild cards.
Example:
SimpleSearchCondition<Integer> ssc = new SimpleSearchCondition<Integer>( ConditionType.GREATER_THAN, 10); ssc.isMet(20); // true since 20>10 class Entity { public String getName() {... public int getLevel() {... public String getMessage() {... } Entity template = new Entity("bbb", 10, null); ssc = new SimpleSearchCondition<Entity>( ConditionType.GREATER_THAN, template); ssc.isMet(new Entity("aaa", 20, "some mesage")); // false: is not met, expression '"aaa">"bbb" and 20>10' is not true // since "aaa" is not greater than "bbb"; not that message is null in template hence ingored ssc.isMet(new Entity("ccc", 30, "other message")); // true: is met, expression '"ccc">"bbb" and 30>10' is true Map<String,ConditionType> map; map.put("name", ConditionType.EQUALS); map.put("level", ConditionType.GREATER_THAN); ssc = new SimpleSearchCondition<Entity>( ConditionType.GREATER_THAN, template); ssc.isMet(new Entity("ccc", 30, "other message")); // false due to expression '"aaa"=="ccc" and 30>10"' (note different operators)
isMet
in interface SearchCondition<T>
pojo
- the object which will be checkedIllegalAccessException
- when security manager disallows reflective call of getters.public List<T> findAll(Collection<T> pojos)
SearchCondition
findAll
in interface SearchCondition<T>
pojos
- list of pojospublic PrimitiveStatement getStatement()
SearchCondition
getStatement
in interface SearchCondition<T>
public void accept(SearchConditionVisitor<T,?> visitor)
SearchCondition
accept
in interface SearchCondition<T>
Apache CXF