Class SimpleSearchCondition<T>
- java.lang.Object
-
- org.apache.cxf.jaxrs.ext.search.SimpleSearchCondition<T>
-
- Type Parameters:
T- type of search condition.
- All Implemented Interfaces:
SearchCondition<T>
public class SimpleSearchCondition<T> extends Object implements SearchCondition<T>
Simple search condition comparing primitive objects or complex object by its getters. For details seeisMet(Object)description.
-
-
Field Summary
Fields Modifier and Type Field Description protected static Set<ConditionType>SUPPORTED_TYPES
-
Constructor Summary
Constructors Constructor Description 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; seeisMet(Object)for details of comparison.SimpleSearchCondition(Map<String,ConditionType> getters2operators, T condition)SimpleSearchCondition(ConditionType cType, T condition)Creates search condition with same operator (equality, inequality) applied in all comparison; seeisMet(Object)for details of comparison.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(SearchConditionVisitor<T,?> visitor)Provides a visitor which will convert this SearchCondition into a custom expression, for example, into the SQL statement, etcList<T>findAll(Collection<T> pojos)Returns a list of pojos matching the conditionTgetCondition()Some SearchConditions may use instance of T to capture the actual search criteria thus making it simpler to implement isMet(T).ConditionTypegetConditionType()Returns the type of the condition this SearchCondition representsList<SearchCondition<T>>getSearchConditions()List of conditions this SearchCondition may represent.PrimitiveStatementgetStatement()Primitive statement such a > b, i < 5, etc this condition may represent.booleanisMet(T pojo)Compares given object against template condition object.StringtoSQL(String table, String... columns)
-
-
-
Field Detail
-
SUPPORTED_TYPES
protected static final Set<ConditionType> SUPPORTED_TYPES
-
-
Constructor Detail
-
SimpleSearchCondition
public SimpleSearchCondition(ConditionType cType, T condition)
Creates search condition with same operator (equality, inequality) applied in all comparison; seeisMet(Object)for details of comparison.- Parameters:
cType- shared condition typecondition- template object
-
SimpleSearchCondition
public 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; seeisMet(Object)for details of comparison. Cannot be used for primitive T type due to per-getter comparison strategy.- Parameters:
getters2operators- getters names and operators to be used with them during comparisonrealGetters-propertyTypeInfo-condition- template object
-
SimpleSearchCondition
public SimpleSearchCondition(Map<String,ConditionType> getters2operators, T condition)
-
-
Method Detail
-
getCondition
public T getCondition()
Description copied from interface:SearchConditionSome SearchConditions may use instance of T to capture the actual search criteria thus making it simpler to implement isMet(T). In some cases, the code which is given SearchCondition may find it more efficient to directly deal with the captured state for a more efficient lookup of matching data/records as opposed to calling SearchCondition.isMet for every instance of T it knows about.- Specified by:
getConditionin interfaceSearchCondition<T>- Returns:
- T the captured search criteria, can be null
-
getConditionType
public ConditionType getConditionType()
Returns the type of the condition this SearchCondition representsWhen constructor with map is used it returns null.
- Specified by:
getConditionTypein interfaceSearchCondition<T>- Returns:
- condition type
-
getSearchConditions
public List<SearchCondition<T>> getSearchConditions()
Description copied from interface:SearchConditionList of conditions this SearchCondition may represent. Composite SearchConditions will return a list of conditions they are composed from, primitive ones will return null- Specified by:
getSearchConditionsin interfaceSearchCondition<T>- Returns:
- list of conditions, can be null
-
isMet
public boolean isMet(T pojo)
Compares given object against template condition object.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.EQUALSrequires correct implementation ofObject.equals(Object), using inequalities requires type T implementingComparable.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 operatorwas used, then getters are compared using the same operator. Ifconstructor with map of operatorswas 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 forConditionType.EQUALSrequires correct implementation ofObject.equals(Object), using inequalities requires that getter type implementsComparable.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)- Specified by:
isMetin interfaceSearchCondition<T>- Parameters:
pojo- the object which will be checked- Returns:
- true if the pojo meets this search condition, false - otherwise
- Throws:
IllegalAccessException- when security manager disallows reflective call of getters.
-
findAll
public List<T> findAll(Collection<T> pojos)
Description copied from interface:SearchConditionReturns a list of pojos matching the condition- Specified by:
findAllin interfaceSearchCondition<T>- Parameters:
pojos- list of pojos- Returns:
- list of the matching pojos or null if none have been found
-
getStatement
public PrimitiveStatement getStatement()
Description copied from interface:SearchConditionPrimitive statement such a > b, i < 5, etc this condition may represent. Complex conditions will return null.- Specified by:
getStatementin interfaceSearchCondition<T>- Returns:
- primitive search statement, can be null
-
accept
public void accept(SearchConditionVisitor<T,?> visitor)
Description copied from interface:SearchConditionProvides a visitor which will convert this SearchCondition into a custom expression, for example, into the SQL statement, etc- Specified by:
acceptin interfaceSearchCondition<T>
-
-