- Type Parameters:
V- type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
- All Superinterfaces:
Constraint<V>
A constraint that imposes a maximum value.
A parameter-based repository method can impose a constraint on an
entity attribute by defining a method parameter that is of type
AtMost or is annotated @Is(AtMost.class) and is
of the same type or a subtype of the entity attribute. For example,
@Find
List<Car> withMaximumPrice(@By(_Car.PRICE) AtMost<Integer> maxPrice);
@Find
List<Car> pricedAtMost(@By(_Car.PRICE) @Is(AtMost.class) int maximum,
Order<Car> sorts);
...
found = cars.withMaximumPrice(AtMost.max(40000));
found = cars.pricedAtMost(36000,
Order.by(_Car.price.desc(),
_Car.vin.asc()));
Repository methods can also accept AtMost constraints at
run time in the form of a Restriction on a
ComparableExpression. For example,
@Find
List<Car> searchAll(Restriction<Car> restrict, Order<Car> sorts);
...
found = cars.searchAll(_Car.price.lessThanEqual(35000),
Order.by(_Car.price.desc(),
_Car.year.desc()));
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 TypeMethodDescriptionbound()An expression that evaluates to the maximum value allowed for the constraint target.static <V extends Comparable<?>>
AtMost<V> max(ComparableExpression<?, V> maximum) Requires that the constraint target evaluates to a value that is less than or equal the value to which the the givenmaximumexpression evaluates.static <V extends Comparable<?>>
AtMost<V> max(V maximum) Requires that the constraint target evaluates to a value that is less than or equal to the givenmaximum.Methods inherited from interface jakarta.data.constraint.Constraint
negate
-
Method Details
-
max
Requires that the constraint target evaluates to a value that is less than or equal to the given
maximum. For example,found = cars.withMaximumPrice(AtMost.max(33000));- Type Parameters:
V- type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.- Parameters:
maximum- the maximum value.- Returns:
- an
AtMostconstraint. - Throws:
NullPointerException- if the maximum isnull.
-
max
Requires that the constraint target evaluates to a value that is less than or equal the value to which the the given
maximumexpression evaluates. For example,found = cars.withMaxFirstYear(AtMost.max(_Car.year.minus(2)));- Type Parameters:
V- type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.- Parameters:
maximum- an expression that evaluates to the maximum value.- Returns:
- an
AtMostconstraint. - Throws:
NullPointerException- if the maximum isnull.
-
bound
ComparableExpression<?,V> bound()An expression that evaluates to the maximum value allowed for the constraint target.
- Returns:
- an expression representing the maximum value.
-