diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/DeleteSpecification.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/DeleteSpecification.java index 738ad212ce..310ed0c6da 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/DeleteSpecification.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/DeleteSpecification.java @@ -24,6 +24,8 @@ import java.util.Arrays; import java.util.stream.StreamSupport; +import org.springframework.lang.CheckReturnValue; +import org.springframework.lang.Contract; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -31,7 +33,7 @@ * Specification in the sense of Domain Driven Design to handle Criteria Deletes. * * @author Mark Paluch - * @since xxx + * @since 4.0 */ @FunctionalInterface public interface DeleteSpecification extends Serializable { @@ -81,6 +83,8 @@ static DeleteSpecification where(PredicateSpecification spec) { * @param other the other {@link DeleteSpecification}. * @return the conjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default DeleteSpecification and(DeleteSpecification other) { Assert.notNull(other, "Other specification must not be null"); @@ -94,6 +98,8 @@ default DeleteSpecification and(DeleteSpecification other) { * @param other the other {@link PredicateSpecification}. * @return the conjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default DeleteSpecification and(PredicateSpecification other) { Assert.notNull(other, "Other specification must not be null"); @@ -107,6 +113,8 @@ default DeleteSpecification and(PredicateSpecification other) { * @param other the other {@link DeleteSpecification}. * @return the disjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default DeleteSpecification or(DeleteSpecification other) { Assert.notNull(other, "Other specification must not be null"); @@ -120,6 +128,8 @@ default DeleteSpecification or(DeleteSpecification other) { * @param other the other {@link PredicateSpecification}. * @return the disjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default DeleteSpecification or(PredicateSpecification other) { Assert.notNull(other, "Other specification must not be null"); diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/PredicateSpecification.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/PredicateSpecification.java index 49ff92c5ba..f237715bc0 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/PredicateSpecification.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/PredicateSpecification.java @@ -23,6 +23,8 @@ import java.util.Arrays; import java.util.stream.StreamSupport; +import org.springframework.lang.CheckReturnValue; +import org.springframework.lang.Contract; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -30,7 +32,7 @@ * Specification in the sense of Domain Driven Design. * * @author Mark Paluch - * @since xxx + * @since 4.0 */ public interface PredicateSpecification extends Serializable { @@ -54,7 +56,7 @@ static PredicateSpecification all() { */ static PredicateSpecification where(PredicateSpecification spec) { - Assert.notNull(spec, "DeleteSpecification must not be null"); + Assert.notNull(spec, "PredicateSpecification must not be null"); return spec; } @@ -65,6 +67,8 @@ static PredicateSpecification where(PredicateSpecification spec) { * @param other the other {@link PredicateSpecification}. * @return the conjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default PredicateSpecification and(PredicateSpecification other) { Assert.notNull(other, "Other specification must not be null"); @@ -78,6 +82,8 @@ default PredicateSpecification and(PredicateSpecification other) { * @param other the other {@link PredicateSpecification}. * @return the disjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default PredicateSpecification or(PredicateSpecification other) { Assert.notNull(other, "Other specification must not be null"); diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/Specification.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/Specification.java index 73e45e308f..975d52d6ec 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/Specification.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/Specification.java @@ -25,6 +25,8 @@ import java.util.Arrays; import java.util.stream.StreamSupport; +import org.springframework.lang.CheckReturnValue; +import org.springframework.lang.Contract; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -75,6 +77,8 @@ static Specification where(PredicateSpecification spec) { * @return the conjunction of the specifications. * @since 2.0 */ + @Contract("_ -> new") + @CheckReturnValue default Specification and(Specification other) { Assert.notNull(other, "Other specification must not be null"); @@ -89,6 +93,8 @@ default Specification and(Specification other) { * @return the conjunction of the specifications. * @since 2.0 */ + @Contract("_ -> new") + @CheckReturnValue default Specification and(PredicateSpecification other) { Assert.notNull(other, "Other specification must not be null"); @@ -103,6 +109,8 @@ default Specification and(PredicateSpecification other) { * @return the disjunction of the specifications * @since 2.0 */ + @Contract("_ -> new") + @CheckReturnValue default Specification or(Specification other) { Assert.notNull(other, "Other specification must not be null"); @@ -117,6 +125,8 @@ default Specification or(Specification other) { * @return the disjunction of the specifications * @since 2.0 */ + @Contract("_ -> new") + @CheckReturnValue default Specification or(PredicateSpecification other) { Assert.notNull(other, "Other specification must not be null"); diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/UpdateSpecification.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/UpdateSpecification.java index 2872b0ab0f..7667faa9c4 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/UpdateSpecification.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/UpdateSpecification.java @@ -24,6 +24,8 @@ import java.util.Arrays; import java.util.stream.StreamSupport; +import org.springframework.lang.CheckReturnValue; +import org.springframework.lang.Contract; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -31,7 +33,7 @@ * Specification in the sense of Domain Driven Design to handle Criteria Updates. * * @author Mark Paluch - * @since xxx + * @since 4.0 */ @FunctionalInterface public interface UpdateSpecification extends Serializable { @@ -103,6 +105,8 @@ static UpdateSpecification where(PredicateSpecification spec) { * @param other the other {@link UpdateSpecification}. * @return the conjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default UpdateSpecification and(UpdateSpecification other) { Assert.notNull(other, "Other specification must not be null"); @@ -116,6 +120,8 @@ default UpdateSpecification and(UpdateSpecification other) { * @param other the other {@link PredicateSpecification}. * @return the conjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default UpdateSpecification and(PredicateSpecification other) { Assert.notNull(other, "Other specification must not be null"); @@ -129,6 +135,8 @@ default UpdateSpecification and(PredicateSpecification other) { * @param other the other {@link UpdateSpecification}. * @return the disjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default UpdateSpecification or(UpdateSpecification other) { Assert.notNull(other, "Other specification must not be null"); @@ -142,6 +150,8 @@ default UpdateSpecification or(UpdateSpecification other) { * @param other the other {@link PredicateSpecification}. * @return the disjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default UpdateSpecification or(PredicateSpecification other) { Assert.notNull(other, "Other specification must not be null"); @@ -256,6 +266,8 @@ interface UpdateOperation { * @param other the other {@link UpdateOperation}. * @return the conjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default UpdateOperation and(UpdateOperation other) { Assert.notNull(other, "Other UpdateOperation must not be null"); @@ -272,6 +284,8 @@ default UpdateOperation and(UpdateOperation other) { * @param specification the {@link PredicateSpecification}. * @return the conjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default UpdateSpecification where(PredicateSpecification specification) { Assert.notNull(specification, "PredicateSpecification must not be null"); @@ -288,6 +302,8 @@ default UpdateSpecification where(PredicateSpecification specification) { * @param specification the {@link UpdateSpecification}. * @return the conjunction of the specifications. */ + @Contract("_ -> new") + @CheckReturnValue default UpdateSpecification where(UpdateSpecification specification) { Assert.notNull(specification, "UpdateSpecification must not be null"); @@ -306,6 +322,7 @@ default UpdateSpecification where(UpdateSpecification specification) { * @param criteriaBuilder must not be {@literal null}. */ void apply(Root root, CriteriaUpdate update, CriteriaBuilder criteriaBuilder); + } } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 7f1d9ce651..c0f7cffd6e 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -260,7 +260,7 @@ public void deleteAllByIdInBatch(Iterable ids) { /* * Some JPA providers require {@code ids} to be a {@link Collection} so we must convert if it's not already. */ - Collection idCollection = toCollection(ids); + Collection idCollection = toCollection(ids); query.setParameter("ids", idCollection); applyQueryHints(query); @@ -732,8 +732,7 @@ protected TypedQuery getQuery(Specification spec, Pageable pageable) { * @param domainClass must not be {@literal null}. * @param pageable must not be {@literal null}. */ - protected TypedQuery getQuery(Specification spec, Class domainClass, - Pageable pageable) { + protected TypedQuery getQuery(Specification spec, Class domainClass, Pageable pageable) { return getQuery(spec, domainClass, pageable.getSort()); } @@ -1074,7 +1073,7 @@ private static long executeCountQuery(TypedQuery query) { @SuppressWarnings("rawtypes") private static final class ByIdsSpecification implements Specification { - @Serial private static final long serialVersionUID = 1L; + @Serial private static final @Serial long serialVersionUID = 1L; private final JpaEntityInformation entityInformation; @@ -1085,6 +1084,7 @@ private static final class ByIdsSpecification implements Specification { } @Override + @SuppressWarnings("unchecked") public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder cb) { Path path = root.get(entityInformation.getIdAttribute()); @@ -1103,7 +1103,7 @@ public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuild */ private static class ExampleSpecification implements Specification { - @Serial private static final long serialVersionUID = 1L; + @Serial private static final @Serial long serialVersionUID = 1L; private final Example example; private final EscapeCharacter escapeCharacter;