- Type Parameters:
V- type of the entity attribute.
- All Known Subinterfaces:
AtLeast<V>,AtMost<V>,Between<V>,EqualTo<V>,GreaterThan<V>,In<V>,LessThan<V>,Like,NotBetween<V>,NotEqualTo<V>,NotIn<V>,NotLike,NotNull<V>,Null<V>
Supertype of interfaces that define constraints on entity attributes.
Constraints are used on parameter-based Find and
Delete methods. Constraint parameters must be positioned before
special parameters (such as Restriction and Order) in the
method signature.
Method parameter
Constraint parameters can be of type C<T> or C<? super T>
where C is Constraint or any subtype of Constraint,
such as Like or LessThan, and T is the entity
attribute type. For example,
@Find
List<Car> withinYears(@By(_Car.YEAR) Between<Integer> year,
@By(_Car.MAKE) Like makePattern,
@By(_Car.MODEL) Like modelPattern,
Order<Car> sorts);
...
found = cars.withinYears(Between.bounds(2021, 2025),
Like.prefix(makePrefix),
Like.contains(modelSubstring),
Order.by(_Car.year.desc(),
_Car.price.desc(),
_Car.vin.asc()));
Annotation value
Constraint parameters of repository methods can be annotated with the
@Is annotation to indicate the subtype of Constraint.
The type of the method parameter must be the entity attribute type.
For example,
@Find
List<Car> pricedAtMost(@By(_Car.PRICE) @Is(AtMost.class) int maxPrice,
@By(_Car.MAKE) @Is(Like.class) String makePattern,
@By(_Car.MODEL) @Is(Like.class) Sting modelPattern,
Order<Car> sorts);
...
found = cars.pricedAtMost(35000, "Chev%", "% SUV",
Order.by(_Car.price.desc(),
_Car.vin.asc()));
The entity and static metamodel for the code
examples within this class are shown in the Attribute Javadoc.
- Since:
- 1.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V extends Comparable<?>>
Between<V> between(V minimum, V maximum) Requires that the constraint target evaluates to a value that is greater than or equal to the givenminimumand less than or equal to the givenmaximum.static <V> EqualTo<V> equalTo(V value) Requires that the constraint target evaluates to a value that is equal to the givenvalue.static <V extends Comparable<?>>
GreaterThan<V> greaterThan(V bound) Requires that the constraint target evaluates to a value that is greater than the givenbound.static <V extends Comparable<?>>
AtLeast<V> greaterThanEqual(V minimum) Requires that the constraint target evaluates to a value that is greater than or equal to the givenminimum.static <V> In<V> Requires that the constraint target evaluates to a value that is equal to one of the givenvalues.static <V> In<V> in(V... values) Requires that the constraint target evaluates to a value that is equal to one of the givenvalues.static <V> Null<V> isNull()Requires that the constraint target evaluates tonull.static <V extends Comparable<?>>
LessThan<V> lessThan(V bound) Requires that the constraint target evaluates to a value that is less than the givenbound.static <V extends Comparable<?>>
AtMost<V> lessThanEqual(V maximum) Requires that the constraint target evaluates to a value that is less than or equal to the givenmaximum.static LikeRequires that the constraint target match the givenpattern, in which_and%represent wildcards.static LikeRequires that the constraint target match the givenpattern, in which the given characters represent wildcards.static LikeRequires that the constraint target match the givenpattern, in which the given characters represent wildcards and escape.negate()Obtains the negation of theConstraint.static <V extends Comparable<?>>
NotBetween<V> notBetween(V lowerBound, V upperBound) Requires that the constraint target evaluates to a value that is less than the givenlowerBoundor greater than the givenupperBound.static <V> NotEqualTo<V> notEqualTo(V value) Requires that the constraint target evaluates to a value that is not equal to the givenvalue.static <V> NotIn<V> Requires that the constraint target evaluates to a value that is not equal to any of the givenvalues.static <V> NotIn<V> notIn(V... values) Requires that the constraint target evaluates to a value that is not equal to any of the givenvalues.static NotLikeRequires that the constraint target does not match the givenpattern, in which_and%represent wildcards.static NotLikeRequires that the constraint target does not match the givenpattern, in which the given characters represent wildcards.static NotLikeRequires that the constraint target does not match the givenpattern, in which the given characters represent wildcards and escape.static <V> NotNull<V> notNull()Requires that the constraint target does not evaluate tonull.
-
Method Details
-
negate
Constraint<V> negate()Obtains the negation of the
Constraint. For example, the negation ofLikeisNotLike, the negation ofNullisNotNull, and the negation ofAtLeastisLessThan. A value satisfies the negation of a constraint if and only if it does not satisfy the constraint.- Returns:
- the opposite
Constraintsubtype.
-
equalTo
Requires that the constraint target evaluates to a value that is equal to the given
value.- Type Parameters:
V- type of the entity attribute.- Parameters:
value- a value.- Returns:
- an
EqualToconstraint. - Throws:
NullPointerException- if the value isnull.- See Also:
-
notEqualTo
Requires that the constraint target evaluates to a value that is not equal to the given
value.- Type Parameters:
V- type of the entity attribute.- Parameters:
value- a value.- Returns:
- a
NotEqualToconstraint. - Throws:
NullPointerException- if the value isnull.- See Also:
-
in
Requires that the constraint target evaluates to a value that is equal to one of the given
values.- Type Parameters:
V- type of the entity attribute.- Parameters:
values- one or more values.- Returns:
- an
Inconstraint. - Throws:
IllegalArgumentException- if the array of values is empty.NullPointerException- if the array of values or any element of the array isnull.- See Also:
-
in
Requires that the constraint target evaluates to a value that is equal to one of the given
values.- Type Parameters:
V- type of the entity attribute.- Parameters:
values- one or more values.- Returns:
- an
Inconstraint. - Throws:
IllegalArgumentException- if the collection of values is empty.NullPointerException- if the collection of values or any value within the collection isnull.- See Also:
-
notIn
Requires that the constraint target evaluates to a value that is not equal to any of the given
values.- Type Parameters:
V- type of the entity attribute.- Parameters:
values- one or more values.- Returns:
- a
NotInconstraint. - Throws:
IllegalArgumentException- if the array of values is empty.NullPointerException- if the array of values or any element of the array isnull.- See Also:
-
notIn
Requires that the constraint target evaluates to a value that is not equal to any of the given
values.- Type Parameters:
V- type of the entity attribute.- Parameters:
values- one or more values.- Returns:
- a
NotInconstraint. - Throws:
IllegalArgumentException- if the collection of values is empty.NullPointerException- if the collection of values or any value within the collection isnull.- See Also:
-
like
Requires that the constraint target match the given
pattern, in which_and%represent wildcards. The supplied pattern has no escape character.- Parameters:
pattern- a pattern in which_matches a single character and%matches 0 or more characters.- Returns:
- a
Likeconstraint. - Throws:
NullPointerException- if the pattern isnull.- See Also:
-
like
Requires that the constraint target match the given
pattern, in which the given characters represent wildcards. The supplied pattern has no escape character.- Parameters:
pattern- a pattern that can include the given wildcard characters.charWildcard- wildcard that represents any single character.stringWildcard- wildcard that represents 0 or more characters.- Returns:
- a
Likeconstraint. - Throws:
NullPointerException- if the pattern isnull.- See Also:
-
like
Requires that the constraint target match the given
pattern, in which the given characters represent wildcards and escape.- Parameters:
pattern- a pattern that can include the given wildcard characters and escape character.charWildcard- wildcard that represents any single character.stringWildcard- wildcard that represents 0 or more characters.escape- escape character.- Returns:
- a
Likeconstraint. - Throws:
NullPointerException- if the pattern isnull.- See Also:
-
notLike
Requires that the constraint target does not match the given
pattern, in which_and%represent wildcards. The supplied pattern has no escape character.- Parameters:
pattern- a pattern in which_matches a single character and%matches 0 or more characters.- Returns:
- a
NotLikeconstraint. - Throws:
NullPointerException- if the pattern isnull.- See Also:
-
notLike
Requires that the constraint target does not match the given
pattern, in which the given characters represent wildcards. The supplied pattern has no escape character.- Parameters:
pattern- a pattern that can include the given wildcard characters.charWildcard- wildcard that represents any single character.stringWildcard- wildcard that represents 0 or more characters.- Returns:
- a
NotLikeconstraint. - Throws:
NullPointerException- if the pattern isnull.- See Also:
-
notLike
Requires that the constraint target does not match the given
pattern, in which the given characters represent wildcards and escape.- Parameters:
pattern- a pattern that can include the given wildcard characters and escape character.charWildcard- wildcard that represents any single character.stringWildcard- wildcard that represents 0 or more characters.escape- escape character.- Returns:
- a
NotLikeconstraint. - Throws:
NullPointerException- if the pattern isnull.- See Also:
-
isNull
Requires that the constraint target evaluates to
null.- Type Parameters:
V- type of the entity attribute.- Returns:
- a
Nullconstraint. - See Also:
-
notNull
Requires that the constraint target does not evaluate to
null.- Type Parameters:
V- type of the entity attribute.- Returns:
- a
NotNullconstraint. - See Also:
-
greaterThan
Requires that the constraint target evaluates to a value that is greater than the given
bound.- Type Parameters:
V- type of the entity attribute.- Parameters:
bound- an exclusive minimum value.- Returns:
- a
GreaterThanconstraint. - Throws:
NullPointerException- if the bound isnull.- See Also:
-
lessThan
Requires that the constraint target evaluates to a value that is less than the given
bound.- Type Parameters:
V- type of the entity attribute.- Parameters:
bound- an exclusive maximum value.- Returns:
- a
LessThanconstraint. - Throws:
NullPointerException- if the bound isnull.- See Also:
-
greaterThanEqual
Requires that the constraint target evaluates to a value that is greater than or equal to the given
minimum.- Type Parameters:
V- type of the entity attribute.- Parameters:
minimum- the minimum value.- Returns:
- an
AtLeastconstraint. - Throws:
NullPointerException- if the minimum isnull.- See Also:
-
lessThanEqual
Requires that the constraint target evaluates to a value that is less than or equal to the given
maximum.- Type Parameters:
V- type of the entity attribute.- Parameters:
maximum- the maximum value.- Returns:
- an
AtMostconstraint. - Throws:
NullPointerException- if the maximum isnull.- See Also:
-
between
Requires that the constraint target evaluates to a value that is greater than or equal to the given
minimumand less than or equal to the givenmaximum.- Type Parameters:
V- type of the entity attribute.- Parameters:
minimum- the minimum value.maximum- the maximum value.- Returns:
- a
Betweenconstraint. - Throws:
NullPointerException- if the minimum or maximum isnull.- See Also:
-
notBetween
Requires that the constraint target evaluates to a value that is less than the given
lowerBoundor greater than the givenupperBound.- Type Parameters:
V- type of the entity attribute.- Parameters:
lowerBound- a lower bound.upperBound- an upper bound.- Returns:
- a
NotBetweenconstraint. - Throws:
NullPointerException- if the lower bound or upper bound isnull.- See Also:
-