public interface ModelCriteriaBuilder<M>
CriteriaBuilder
,
however it is much simpler version as it is tailored to very specific needs
of future Keycloak store.
Implementations are expected to be immutable. The expected use is like this:
cb = storage.getCriteriaBuilder(); storage.read( cb.or( cb.compare(FIELD1, EQ, 1).compare(FIELD2, EQ, 2), cb.compare(FIELD1, EQ, 3).compare(FIELD2, EQ, 4) ) );The above code should read items where
(FIELD1 == 1 && FIELD2 == 2) || (FIELD1 == 3 && FIELD2 == 4)
.
It is equivalent to this:
cb = storage.getCriteriaBuilder(); storage.read( cb.or( cb.and(cb.compare(FIELD1, EQ, 1), cb.compare(FIELD2, EQ, 2)), cb.and(cb.compare(FIELD1, EQ, 3), cb.compare(FIELD2, EQ, 4)) ) );
Modifier and Type | Interface and Description |
---|---|
static class |
ModelCriteriaBuilder.Operator
The operators are very basic ones for this use case.
|
Modifier and Type | Method and Description |
---|---|
ModelCriteriaBuilder<M> |
and(ModelCriteriaBuilder<M>... builders)
Creates and returns a new instance of
ModelCriteriaBuilder that
combines the given builders with the Boolean AND operator. |
ModelCriteriaBuilder<M> |
compare(SearchableModelField<M> modelField,
ModelCriteriaBuilder.Operator op,
Object... value)
Adds a constraint for the given model field to this criteria builder
and returns a criteria builder that is combined with the the new constraint.
|
ModelCriteriaBuilder<M> |
not(ModelCriteriaBuilder<M> builder)
Creates and returns a new instance of
ModelCriteriaBuilder that
negates the given builder. |
ModelCriteriaBuilder<M> |
or(ModelCriteriaBuilder<M>... builders)
Creates and returns a new instance of
ModelCriteriaBuilder that
combines the given builders with the Boolean OR operator. |
default <T extends ModelCriteriaBuilder> |
unwrap(Class<T> clazz)
Returns this object cast to the given class, or
null if the class cannot be cast to that clazz . |
ModelCriteriaBuilder<M> compare(SearchableModelField<M> modelField, ModelCriteriaBuilder.Operator op, Object... value)
ModelCriteriaBuilder
and the given operator.modelField
- Field on the logical model to be constrainedop
- Operatorvalue
- Additional operands of the operator.CriterionNotSupported
- If the operator is not supported for the given field.ModelCriteriaBuilder<M> and(ModelCriteriaBuilder<M>... builders)
ModelCriteriaBuilder
that
combines the given builders with the Boolean AND operator.
Predicate coming out of and
on an empty array of builders
(i.e. empty conjunction) is always true
.
cb = storage.getCriteriaBuilder(); storage.read(cb.or( cb.and(cb.compare(FIELD1, EQ, 1), cb.compare(FIELD2, EQ, 2)), cb.and(cb.compare(FIELD1, EQ, 3), cb.compare(FIELD2, EQ, 4)) );
CriterionNotSupported
- If the operator is not supported for the given field.ModelCriteriaBuilder<M> or(ModelCriteriaBuilder<M>... builders)
ModelCriteriaBuilder
that
combines the given builders with the Boolean OR operator.
Predicate coming out of or
on an empty array of builders
(i.e. empty disjunction) is always false
.
cb = storage.getCriteriaBuilder(); storage.read(cb.or( cb.compare(FIELD1, EQ, 1).compare(FIELD2, EQ, 2), cb.compare(FIELD1, EQ, 3).compare(FIELD2, EQ, 4) );
CriterionNotSupported
- If the operator is not supported for the given field.ModelCriteriaBuilder<M> not(ModelCriteriaBuilder<M> builder)
ModelCriteriaBuilder
that
negates the given builder.
Note that if the builder
has no condition yet, there is nothing
to negate: empty negation is always true
.
builder
- CriterionNotSupported
- If the operator is not supported for the given field.default <T extends ModelCriteriaBuilder> T unwrap(Class<T> clazz)
null
if the class cannot be cast to that clazz
.T
- clazz
- Copyright © 2021 JBoss by Red Hat. All rights reserved.