- Type Parameters:
T- entity type.
- All Known Subinterfaces:
BasicRestriction<T,,V> CompositeRestriction<T>
A restriction imposes constraints on entity attribute values or expressions.
Basic restrictions that impose a single
constraint are obtained from Attribute
subtypes of the static metamodel.
Composite restrictions that impose multiple
constraints are obtained from the
Restrict.all(Restriction...) and
Restrict.any(Restriction...) methods.
A repository Find method can optionally accept a parameter of
type Restriction. For example,
@Repository
public interface Cars extends CrudRepository<Car, String> {
@Find
List<Car> search(@By(_Car.MAKE) String manufacturer,
@By(_Car.MODEL) String model,
Restriction<Car> restriction,
Order<Car>... sort);
}
Instances of restriction obtained from the static metamodel or the
Restrict class can be supplied as the parameter when invoking the
respository method. For example,
List<Car> withinPriceRange =
cars.search(make,
model,
_Car.price.between(20000, 30000),
Order.by(_Car.price.desc()));
List<Car> pricedUnder30kWhenDiscounted =
cars.search(make,
model,
_Car.price.minus(discount).lessThan(30000),
Order.by(_Car.price.desc()));
List<Car> atLeast2020AndPricedBelow30k =
cars.search(make,
model,
Restrict.all(_Car.year.greaterThanEqual(2020),
_Car.price.lessThan(30000)),
Order.by(_Car.price.desc()));
The example entity and static metamodel for the
above are provided in the Attribute Javadoc.
Restrictions are immutable and do not change after they are created.
- Since:
- 1.1
-
Method Summary
-
Method Details
-
negate
Restriction<T> negate()Returns the negation of this restriction.
For example, a basic restriction that represents an exclusive upper bound on a value is negated as an inclusive lower bound on the value.
A basic restriction that represents matching a pattern is negated as a restriction to not match the pattern.
A composite restriction that requires satisfying at least one restriction is negated as requiring that not any (in other words, none) of the restrictions are satisfied.
A composite restriction that requires satisfying all restrictions is negated as requiring that not all of the restrictions are satisfied (in other words, at least one is unsatisfed).
This method does not modify the restriction upon which it is invoked.
- Returns:
- the negated restriction.
-