Class Criteria<T>
- java.lang.Object
-
- org.omnifaces.persistence.criteria.Criteria<T>
-
- Type Parameters:
T- The generic criteria value type.
- Direct Known Subclasses:
Between,Bool,Enumerated,IgnoreCase,Like,Not,Numeric,Order
public abstract class Criteria<T> extends Object
This is used by
PageandBaseEntityService.getPage(Page, boolean). It defines a set of criteria which could be supplied as value of "required criteria" and "optional criteria" maps.There are so far the following criteria:
Not- to negate the valueLike- to search a string valueOrder- to perform "less than" or "greater than" searchesBetween- to perform "between" searchesEnumerated- to parse value as enumNumeric- to parse value as numberBool- to parse value as booleanIgnoreCase- to perform "ignore case" searches
You can create your own ones if you want to have more fine grained control over how criteria values are parsed and turned into a predicate.
An elaborate use case can be found in OptimusFaces project.
- Author:
- Bauke Scholtz
- See Also:
Page,BaseEntityService
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceCriteria.ParameterBuilderThis is used inbuild(Expression, CriteriaBuilder, ParameterBuilder).
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanapplies(Object modelValue)Returns whether this criteria value would apply to the given model value.abstract Predicatebuild(Expression<?> path, CriteriaBuilder criteriaBuilder, Criteria.ParameterBuilder parameterBuilder)Returns a predicate for the criteria value.booleanequals(Object object)TgetValue()Returns the criteria value.inthashCode()StringtoString()static Objectunwrap(Object possibleCriteria)Unwraps the criteria value from given object which could possibly represent aCriteria.
-
-
-
Constructor Detail
-
Criteria
protected Criteria(T value)
Create criteria based on given value.- Parameters:
value- The criteria value.- Throws:
IllegalArgumentException- When given criteria value cannot be reasonably parsed.
-
-
Method Detail
-
build
public abstract Predicate build(Expression<?> path, CriteriaBuilder criteriaBuilder, Criteria.ParameterBuilder parameterBuilder)
Returns a predicate for the criteria value. Below is an example implementation:return criteriaBuilder.equal(path, parameterBuilder.create(getValue()));
- Parameters:
path- Entity property path. You can use this to inspect the target entity property.criteriaBuilder- So you can build a predicate with aParameterExpression.parameterBuilder- You must use this to create aParameterExpressionfor the criteria value.- Returns:
- A predicate for the criteria value.
-
applies
public boolean applies(Object modelValue)
Returns whether this criteria value would apply to the given model value. This must basically represent the "plain Java" equivalent of the SQL behavior as achieved bybuild(Expression, CriteriaBuilder, ParameterBuilder).- Parameters:
modelValue- The model value to test this criteria on.- Returns:
- Whether this criteria value would apply to the given model value.
- Throws:
IllegalArgumentException- When given model value cannot be reasonably parsed.UnsupportedOperationException- When this method is not implemented yet.
-
getValue
public T getValue()
Returns the criteria value.- Returns:
- The criteria value.
-
unwrap
public static Object unwrap(Object possibleCriteria)
Unwraps the criteria value from given object which could possibly represent aCriteria.
-
-