T
- The generic criteria value type.public abstract class Criteria<T> extends Object
This is used by Page
and BaseEntityService.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 value
Like
- to search a string value
Order
- to perform "less than" or "greater than" searches
Between
- to perform "between" searches
Enumerated
- to parse value as enum
Numeric
- to parse value as number
Bool
- to parse value as boolean
IgnoreCase
- 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.
Page
,
BaseEntityService
Modifier and Type | Class and Description |
---|---|
static interface |
Criteria.ParameterBuilder
This is used in
build(Expression, CriteriaBuilder, ParameterBuilder) . |
Modifier | Constructor and Description |
---|---|
protected |
Criteria(T value)
Create criteria based on given value.
|
Modifier and Type | Method and Description |
---|---|
boolean |
applies(Object modelValue)
Returns whether this criteria value would apply to the given model value.
|
abstract Predicate |
build(Expression<?> path,
CriteriaBuilder criteriaBuilder,
Criteria.ParameterBuilder parameterBuilder)
Returns a predicate for the criteria value.
|
boolean |
equals(Object object) |
T |
getValue()
Returns the criteria value.
|
int |
hashCode() |
String |
toString() |
static Object |
unwrap(Object possibleCriteria)
Unwraps the criteria value from given object which could possibly represent a
Criteria . |
protected Criteria(T value)
value
- The criteria value.IllegalArgumentException
- When given criteria value cannot be reasonably parsed.public abstract Predicate build(Expression<?> path, CriteriaBuilder criteriaBuilder, Criteria.ParameterBuilder parameterBuilder)
return criteriaBuilder.equal(path, parameterBuilder.create(getValue()));
path
- Entity property path. You can use this to inspect the target entity property.criteriaBuilder
- So you can build a predicate with a ParameterExpression
.parameterBuilder
- You must use this to create a ParameterExpression
for the criteria value.public boolean applies(Object modelValue)
build(Expression, CriteriaBuilder, ParameterBuilder)
.modelValue
- The model value to test this criteria on.IllegalArgumentException
- When given model value cannot be reasonably parsed.UnsupportedOperationException
- When this method is not implemented yet.public T getValue()
public static Object unwrap(Object possibleCriteria)
Criteria
.Copyright © 2015–2021 OmniFaces. All rights reserved.