Interface UpdateSpecification<T>
- All Superinterfaces:
Serializable
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Specification in the sense of Domain Driven Design to handle Criteria Updates.
Specifications can be composed into higher order functions from other specifications using
and(UpdateSpecification), or(UpdateSpecification) or factory methods such as
allOf(Iterable). Composition considers whether one or more specifications contribute to the overall
predicate by returning a Predicate or null. Specifications returning null are
considered to not contribute to the overall predicate and their result is not considered in the final predicate.
- Since:
- 4.0
- Author:
- Mark Paluch
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceSimplified extension toUpdateSpecificationthat only considers theUPDATEpart without specifying a predicate. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> UpdateSpecification<T>allOf(Iterable<UpdateSpecification<T>> specifications) Applies an AND operation to all the givenUpdateSpecifications.static <T> UpdateSpecification<T>allOf(UpdateSpecification<T>... specifications) Applies an AND operation to all the givenUpdateSpecifications.default UpdateSpecification<T>and(PredicateSpecification<T> other) ANDs the givenUpdateSpecificationto the current one.default UpdateSpecification<T>and(UpdateSpecification<T> other) ANDs the givenUpdateSpecificationto the current one.static <T> UpdateSpecification<T>anyOf(Iterable<UpdateSpecification<T>> specifications) Applies an OR operation to all the givenUpdateSpecifications.static <T> UpdateSpecification<T>anyOf(UpdateSpecification<T>... specifications) Applies an OR operation to all the givenUpdateSpecifications.static <T> UpdateSpecification<T>not(UpdateSpecification<T> spec) Negates the givenUpdateSpecification.default UpdateSpecification<T>or(PredicateSpecification<T> other) ORs the given specification to the current one.default UpdateSpecification<T>or(UpdateSpecification<T> other) ORs the given specification to the current one.@Nullable jakarta.persistence.criteria.PredicatetoPredicate(jakarta.persistence.criteria.Root<T> root, jakarta.persistence.criteria.CriteriaUpdate<T> update, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder) Creates a WHERE clause for a query of the referenced entity in form of aPredicatefor the givenRootandCriteriaUpdate.static <T> UpdateSpecification<T>Simple static factory method to create a specification updating all objects.static <T> UpdateSpecification.UpdateOperation<T>Simple static factory method to add some syntactic sugar around a UpdateOperation.static <T> UpdateSpecification<T>where(PredicateSpecification<T> spec) Simple static factory method to add some syntactic sugar translatingPredicateSpecificationtoUpdateSpecification.static <T> UpdateSpecification<T>where(UpdateSpecification<T> spec) Simple static factory method to add some syntactic sugar around a UpdateSpecification.
-
Method Details
-
unrestricted
Simple static factory method to create a specification updating all objects.- Type Parameters:
T- the type of theRootthe resulting UpdateSpecification operates on.- Returns:
- guaranteed to be not null.
-
update
static <T> UpdateSpecification.UpdateOperation<T> update(UpdateSpecification.UpdateOperation<T> spec) Simple static factory method to add some syntactic sugar around a UpdateOperation. For example:UpdateSpecification<User> updateLastname = UpdateOperation .<User> update((root, update, criteriaBuilder) -> update.set("lastname", "Heisenberg")) .where(userHasFirstname("Walter").and(userHasLastname("White"))); repository.update(updateLastname);- Type Parameters:
T- the type of theRootthe resulting UpdateOperation operates on.- Parameters:
spec- must not be null.- Returns:
- guaranteed to be not null.
-
where
Simple static factory method to add some syntactic sugar around a UpdateSpecification.- Type Parameters:
T- the type of theRootthe resulting UpdateSpecification operates on.- Parameters:
spec- must not be null.- Returns:
- guaranteed to be not null.
-
where
Simple static factory method to add some syntactic sugar translatingPredicateSpecificationtoUpdateSpecification.- Type Parameters:
T- the type of theRootthe resulting UpdateSpecification operates on.- Parameters:
spec- thePredicateSpecificationto wrap.- Returns:
- guaranteed to be not null.
-
and
@Contract("_ -> new") @CheckReturnValue default UpdateSpecification<T> and(UpdateSpecification<T> other) ANDs the givenUpdateSpecificationto the current one.- Parameters:
other- the otherUpdateSpecification.- Returns:
- the conjunction of the specifications.
-
and
@Contract("_ -> new") @CheckReturnValue default UpdateSpecification<T> and(PredicateSpecification<T> other) ANDs the givenUpdateSpecificationto the current one.- Parameters:
other- the otherPredicateSpecification.- Returns:
- the conjunction of the specifications.
-
or
@Contract("_ -> new") @CheckReturnValue default UpdateSpecification<T> or(UpdateSpecification<T> other) ORs the given specification to the current one.- Parameters:
other- the otherUpdateSpecification.- Returns:
- the disjunction of the specifications.
-
or
@Contract("_ -> new") @CheckReturnValue default UpdateSpecification<T> or(PredicateSpecification<T> other) ORs the given specification to the current one.- Parameters:
other- the otherPredicateSpecification.- Returns:
- the disjunction of the specifications.
-
not
Negates the givenUpdateSpecification.- Type Parameters:
T- the type of theRootthe resulting UpdateSpecification operates on.- Parameters:
spec- can be null.- Returns:
- guaranteed to be not null.
-
allOf
Applies an AND operation to all the givenUpdateSpecifications. Ifspecificationsis empty, the resultingUpdateSpecificationwill be unrestricted applying to all objects.- Parameters:
specifications- theUpdateSpecifications to compose.- Returns:
- the conjunction of the specifications.
- See Also:
-
allOf
Applies an AND operation to all the givenUpdateSpecifications. Ifspecificationsis empty, the resultingUpdateSpecificationwill be unrestricted applying to all objects.- Parameters:
specifications- theUpdateSpecifications to compose.- Returns:
- the conjunction of the specifications.
- See Also:
-
anyOf
Applies an OR operation to all the givenUpdateSpecifications. Ifspecificationsis empty, the resultingUpdateSpecificationwill be unrestricted applying to all objects.- Parameters:
specifications- theUpdateSpecifications to compose.- Returns:
- the disjunction of the specifications.
- See Also:
-
anyOf
Applies an OR operation to all the givenUpdateSpecifications. Ifspecificationsis empty, the resultingUpdateSpecificationwill be unrestricted applying to all objects.- Parameters:
specifications- theUpdateSpecifications to compose.- Returns:
- the disjunction of the specifications.
- See Also:
-
toPredicate
@Nullable jakarta.persistence.criteria.Predicate toPredicate(jakarta.persistence.criteria.Root<T> root, jakarta.persistence.criteria.CriteriaUpdate<T> update, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder) Creates a WHERE clause for a query of the referenced entity in form of aPredicatefor the givenRootandCriteriaUpdate.- Parameters:
root- must not be null.update- the update criteria.criteriaBuilder- must not be null.- Returns:
- a
Predicate, may be null.
-