From 047fa2bc38c114ca698357bbe31ff8f64f4b84ed Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 20 Feb 2025 13:23:29 +0100 Subject: [PATCH] Polishing. Simplify POM setup. Reformat code. See #3745 Original pull request: #3781 --- spring-data-jpa/pom.xml | 128 +----------------- .../data/jpa/domain/Specification.java | 6 +- .../jpa/domain/SpecificationComposition.java | 2 +- .../config/JpaRepositoryConfigExtension.java | 6 +- .../query/JSqlParserQueryEnhancer.java | 17 +-- .../query/JpqlCountQueryTransformer.java | 6 +- .../data/jpa/repository/query/JpqlUtils.java | 23 ++-- .../query/KeysetScrollSpecification.java | 19 +-- .../data/jpa/repository/query/QueryUtils.java | 6 +- .../support/EntityGraphFactory.java | 8 +- .../FetchableFluentQueryBySpecification.java | 4 +- .../support/JpaRepositoryFactory.java | 11 +- .../support/QuerydslJpaPredicateExecutor.java | 5 +- .../support/SimpleJpaRepository.java | 4 +- .../jpa/repository/UserRepositoryTests.java | 38 ------ 15 files changed, 62 insertions(+), 221 deletions(-) diff --git a/spring-data-jpa/pom.xml b/spring-data-jpa/pom.xml index 13f0b1117..b6470bdc8 100644 --- a/spring-data-jpa/pom.xml +++ b/spring-data-jpa/pom.xml @@ -343,7 +343,7 @@ org.apache.maven.plugins maven-compiler-plugin - + com.querydsl querydsl-apt @@ -424,130 +424,4 @@ - - - all-dbs - - - - org.apache.maven.plugins - maven-surefire-plugin - - - mysql-test - test - - test - - - - **/MySql*IntegrationTests.java - - - - - postgres-test - test - - test - - - - **/Postgres*IntegrationTests.java - - - - - - - - - - - - - - nullaway - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - com.querydsl - querydsl-apt - ${querydsl} - jakarta - - - org.hibernate.orm - hibernate-jpamodelgen - ${hibernate} - - - org.hibernate.orm - hibernate-core - ${hibernate} - - - org.openjdk.jmh - jmh-generator-annprocess - ${jmh} - - - jakarta.persistence - jakarta.persistence-api - ${jakarta-persistence-api} - - - com.google.errorprone - error_prone_core - ${errorprone} - - - com.uber.nullaway - nullaway - ${nullaway} - - - - - - default-compile - none - - - default-testCompile - none - - - java-compile - compile - - compile - - - - -XDcompilePolicy=simple - --should-stop=ifError=FLOW - -Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true -XepOpt:NullAway:TreatGeneratedAsUnannotated=true -XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract - - - - - java-test-compile - test-compile - - testCompile - - - - - - - - - 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 f0c782d7a..b9994b79a 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,9 +25,9 @@ import java.io.Serializable; import java.util.Arrays; import java.util.stream.StreamSupport; -import org.springframework.lang.CheckReturnValue; - import org.jspecify.annotations.Nullable; + +import org.springframework.lang.CheckReturnValue; import org.springframework.lang.Contract; import org.springframework.util.Assert; @@ -232,6 +232,6 @@ public interface Specification extends Serializable { * @return a {@link Predicate}, may be {@literal null}. */ @Nullable - Predicate toPredicate(Root root, @Nullable CriteriaQuery query, CriteriaBuilder criteriaBuilder); + Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder); } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/SpecificationComposition.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/SpecificationComposition.java index 5600b40f5..0c73627ba 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/SpecificationComposition.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/SpecificationComposition.java @@ -61,7 +61,7 @@ class SpecificationComposition { } private static @Nullable Predicate toPredicate(@Nullable Specification specification, Root root, - @Nullable CriteriaQuery query, CriteriaBuilder builder) { + CriteriaQuery query, CriteriaBuilder builder) { return specification == null ? null : specification.toPredicate(root, query, builder); } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigExtension.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigExtension.java index 6366a8d5d..32b867080 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigExtension.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigExtension.java @@ -33,9 +33,9 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import org.springframework.aot.generate.GenerationContext; - import org.jspecify.annotations.Nullable; + +import org.springframework.aot.generate.GenerationContext; import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -117,7 +117,7 @@ public class JpaRepositoryConfigExtension extends RepositoryConfigurationExtensi Optional transactionManagerRef = source.getAttribute("transactionManagerRef"); builder.addPropertyValue("transactionManager", transactionManagerRef.orElse(DEFAULT_TRANSACTION_MANAGER_BEAN_NAME)); - if(entityManagerRefs.containsKey(source)) { + if (entityManagerRefs.containsKey(source)) { builder.addPropertyReference("entityManager", entityManagerRefs.get(source)); } builder.addPropertyValue(ESCAPE_CHARACTER_PROPERTY, getEscapeCharacter(source).orElse('\\')); diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JSqlParserQueryEnhancer.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JSqlParserQueryEnhancer.java index 6e9b672f9..141d61b5f 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JSqlParserQueryEnhancer.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JSqlParserQueryEnhancer.java @@ -38,7 +38,6 @@ import net.sf.jsqlparser.statement.select.SelectItem; import net.sf.jsqlparser.statement.select.SetOperationList; import net.sf.jsqlparser.statement.select.Values; import net.sf.jsqlparser.statement.update.Update; -import org.jspecify.annotations.Nullable; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -52,6 +51,8 @@ import java.util.StringJoiner; import java.util.function.Predicate; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.data.domain.Sort; import org.springframework.data.util.Predicates; import org.springframework.util.Assert; @@ -81,7 +82,7 @@ public class JSqlParserQueryEnhancer implements QueryEnhancer { private final String projection; private final Set joinAliases; private final Set selectAliases; - private final byte @Nullable[] serialized; + private final byte @Nullable [] serialized; /** * @param query the query we want to enhance. Must not be {@literal null}. @@ -98,7 +99,7 @@ public class JSqlParserQueryEnhancer implements QueryEnhancer { this.selectAliases = Collections.unmodifiableSet(getSelectionAliases(this.statement)); this.joinAliases = Collections.unmodifiableSet(getJoinAliases(this.statement)); byte[] tmp = SerializationUtils.serialize(this.statement); -// this.serialized = tmp != null ? tmp : new byte[0]; + // this.serialized = tmp != null ? tmp : new byte[0]; this.serialized = SerializationUtils.serialize(this.statement); } @@ -374,7 +375,7 @@ public class JSqlParserQueryEnhancer implements QueryEnhancer { return applySortingToSetOperationList(setOperationList, sort); } - doWithPlainSelect(selectStatement, it -> { + doWithPlainSelect (selectStatement , it -> { List orderByElements = new ArrayList<>(16); for (Sort.Order order : sort) { @@ -572,8 +573,8 @@ public class JSqlParserQueryEnhancer implements QueryEnhancer { * @param bytes a serialized object * @return the result of deserializing the bytes */ - private static @Nullable Object deserialize(byte @Nullable[] bytes) { - if(ObjectUtils.isEmpty(bytes)) { + private static @Nullable Object deserialize(byte @Nullable [] bytes) { + if (ObjectUtils.isEmpty(bytes)) { return null; } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) { @@ -585,9 +586,9 @@ public class JSqlParserQueryEnhancer implements QueryEnhancer { } } - private static T deserializeRequired(byte @Nullable[] bytes, Class type) { + private static T deserializeRequired(byte @Nullable [] bytes, Class type) { Object deserialize = deserialize(bytes); - if(deserialize != null) { + if (deserialize != null) { return type.cast(deserialize); } throw new IllegalStateException("Failed to deserialize object type"); diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlCountQueryTransformer.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlCountQueryTransformer.java index 480ec3426..6318d8acf 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlCountQueryTransformer.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlCountQueryTransformer.java @@ -17,9 +17,9 @@ package org.springframework.data.jpa.repository.query; import static org.springframework.data.jpa.repository.query.QueryTokens.*; -import org.springframework.data.jpa.repository.query.QueryRenderer.QueryRendererBuilder; - import org.jspecify.annotations.Nullable; + +import org.springframework.data.jpa.repository.query.QueryRenderer.QueryRendererBuilder; import org.springframework.data.jpa.repository.query.QueryTransformers.CountSelectionTokenStream; import org.springframework.util.StringUtils; @@ -82,7 +82,7 @@ class JpqlCountQueryTransformer extends JpqlQueryRenderer { if (usesDistinct) { nested.append(QueryTokens.expression(ctx.DISTINCT())); nested.append(getDistinctCountSelection(QueryTokenStream.concat(ctx.select_item(), this::visit, TOKEN_COMMA))); - } else if(StringUtils.hasText(primaryFromAlias)) { + } else if (StringUtils.hasText(primaryFromAlias)) { nested.append(QueryTokens.token(primaryFromAlias)); } else { throw new IllegalStateException("No primary alias present"); diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlUtils.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlUtils.java index f3e20a1d6..298b09591 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlUtils.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlUtils.java @@ -25,23 +25,25 @@ import jakarta.persistence.metamodel.PluralAttribute; import java.util.Objects; -import org.springframework.data.mapping.PropertyPath; - import org.jspecify.annotations.Nullable; + +import org.springframework.data.mapping.PropertyPath; import org.springframework.util.StringUtils; /** + * Utilities to create JPQL expressions, derived from {@link QueryUtils}. + * * @author Mark Paluch */ class JpqlUtils { - static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel, JpqlQueryBuilder.Origin source, - Bindable from, PropertyPath property) { + static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel, + JpqlQueryBuilder.Origin source, Bindable from, PropertyPath property) { return toExpressionRecursively(metamodel, source, from, property, false); } - static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel, JpqlQueryBuilder.Origin source, - Bindable from, PropertyPath property, boolean isForSelection) { + static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel, + JpqlQueryBuilder.Origin source, Bindable from, PropertyPath property, boolean isForSelection) { return toExpressionRecursively(metamodel, source, from, property, isForSelection, false); } @@ -54,8 +56,9 @@ class JpqlUtils { * @param hasRequiredOuterJoin has a parent already required an outer join? * @return the expression */ - static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel, JpqlQueryBuilder.Origin source, - Bindable from, PropertyPath property, boolean isForSelection, boolean hasRequiredOuterJoin) { + static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel, + JpqlQueryBuilder.Origin source, Bindable from, PropertyPath property, boolean isForSelection, + boolean hasRequiredOuterJoin) { String segment = property.getSegment(); @@ -81,7 +84,7 @@ class JpqlUtils { ManagedType managedTypeForModel = QueryUtils.getManagedTypeForModel(from); Attribute nextAttribute = getModelForPath(metamodel, property, managedTypeForModel, from); - if(nextAttribute == null) { + if (nextAttribute == null) { throw new IllegalStateException("Binding property is null"); } @@ -144,7 +147,7 @@ class JpqlUtils { } } - if(metamodel != null) { + if (metamodel != null) { Class fallbackType = fallback.getBindableJavaType(); try { diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/KeysetScrollSpecification.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/KeysetScrollSpecification.java index f39505222..504658726 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/KeysetScrollSpecification.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/KeysetScrollSpecification.java @@ -26,9 +26,9 @@ import jakarta.persistence.metamodel.Metamodel; import java.util.List; -import org.springframework.data.domain.KeysetScrollPosition; - import org.jspecify.annotations.Nullable; + +import org.springframework.data.domain.KeysetScrollPosition; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Order; import org.springframework.data.jpa.domain.Specification; @@ -68,7 +68,8 @@ public record KeysetScrollSpecification(KeysetScrollPosition position, Sort s } @Override - public @Nullable Predicate toPredicate(Root root, @Nullable CriteriaQuery query, CriteriaBuilder criteriaBuilder) { + public @Nullable Predicate toPredicate(Root root, @Nullable CriteriaQuery query, + CriteriaBuilder criteriaBuilder) { return createPredicate(root, criteriaBuilder); } @@ -78,7 +79,6 @@ public record KeysetScrollSpecification(KeysetScrollPosition position, Sort s return delegate.createPredicate(position, sort, new CriteriaBuilderStrategy(root, criteriaBuilder)); } - public JpqlQueryBuilder.@Nullable Predicate createJpqlPredicate(Bindable from, JpqlQueryBuilder.Entity entity, ParameterFactory factory) { @@ -108,9 +108,9 @@ public record KeysetScrollSpecification(KeysetScrollPosition position, Sort s @Override public Predicate compare(Order order, Expression propertyExpression, @Nullable Object value) { - if(value instanceof Comparable compareValue) { + if (value instanceof Comparable compareValue) { return order.isAscending() ? cb.greaterThan(propertyExpression, compareValue) - : cb.lessThan(propertyExpression, compareValue); + : cb.lessThan(propertyExpression, compareValue); } return order.isAscending() ? cb.isNull(propertyExpression) : cb.isNotNull(propertyExpression); @@ -139,12 +139,13 @@ public record KeysetScrollSpecification(KeysetScrollPosition position, Sort s private final ParameterFactory factory; private final @Nullable Metamodel metamodel; - public JpqlStrategy(@Nullable Metamodel metamodel, Bindable from, JpqlQueryBuilder.Entity entity, ParameterFactory factory) { + public JpqlStrategy(@Nullable Metamodel metamodel, Bindable from, JpqlQueryBuilder.Entity entity, + ParameterFactory factory) { this.from = from; this.entity = entity; this.factory = factory; - this.metamodel = metamodel; + this.metamodel = metamodel; } @Override @@ -159,7 +160,7 @@ public record KeysetScrollSpecification(KeysetScrollPosition position, Sort s @Nullable Object value) { JpqlQueryBuilder.WhereStep where = JpqlQueryBuilder.where(propertyExpression); - if(value == null) { + if (value == null) { return order.isAscending() ? where.isNull() : where.isNotNull(); } return order.isAscending() ? where.gt(factory.capture(value)) : where.lt(factory.capture(value)); diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java index 9b931a34e..41c572731 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java @@ -46,9 +46,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.springframework.core.annotation.AnnotationUtils; - import org.jspecify.annotations.Nullable; + +import org.springframework.core.annotation.AnnotationUtils; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Order; @@ -875,7 +875,7 @@ public abstract class QueryUtils { } Annotation annotation = AnnotationUtils.getAnnotation(annotatedMember, associationAnnotation); - if(annotation == null) { + if (annotation == null) { return defaultValue; } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/EntityGraphFactory.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/EntityGraphFactory.java index 6a63a8260..266bd3e00 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/EntityGraphFactory.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/EntityGraphFactory.java @@ -62,11 +62,13 @@ abstract class EntityGraphFactory { if (path.hasNext()) { - if(current == null) { - current = existingSubgraphs.computeIfAbsent(currentFullPath, k -> entityGraph.addSubgraph(path.getSegment())); + if (current == null) { + current = existingSubgraphs.computeIfAbsent(currentFullPath, + k -> entityGraph.addSubgraph(path.getSegment())); } else { final Subgraph finalCurrent = current; - current = existingSubgraphs.computeIfAbsent(currentFullPath, k -> finalCurrent.addSubgraph(path.getSegment())); + current = existingSubgraphs.computeIfAbsent(currentFullPath, + k -> finalCurrent.addSubgraph(path.getSegment())); } continue; } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/FetchableFluentQueryBySpecification.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/FetchableFluentQueryBySpecification.java index ba882f244..0b21210ff 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/FetchableFluentQueryBySpecification.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/FetchableFluentQueryBySpecification.java @@ -29,8 +29,6 @@ import java.util.stream.Stream; import org.jspecify.annotations.Nullable; import org.springframework.dao.IncorrectResultSizeDataAccessException; - -import org.jspecify.annotations.Nullable; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -227,7 +225,7 @@ class FetchableFluentQueryBySpecification extends FluentQuerySupport private Slice readSlice(Pageable pageable) { - TypedQuery pagedQuery = createSortedAndProjectedQuery(); + TypedQuery pagedQuery = createSortedAndProjectedQuery(pageable.getSort()); if (pageable.isPaged()) { pagedQuery.setFirstResult(PageableUtils.getOffsetAsInteger(pageable)); diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java index 2d5a95a27..96d627701 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java @@ -226,13 +226,14 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport { } @Override - protected ProjectionFactory getProjectionFactory(@Nullable ClassLoader classLoader, @Nullable BeanFactory beanFactory) { + protected ProjectionFactory getProjectionFactory(@Nullable ClassLoader classLoader, + @Nullable BeanFactory beanFactory) { CollectionAwareProjectionFactory factory = new CollectionAwareProjectionFactory(); - if(classLoader != null) { + if (classLoader != null) { factory.setBeanClassLoader(classLoader); } - if(beanFactory != null) { + if (beanFactory != null) { factory.setBeanFactory(beanFactory); } @@ -243,11 +244,9 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport { protected Optional getQueryLookupStrategy(@Nullable Key key, ValueExpressionDelegate valueExpressionDelegate) { return Optional.of(JpaQueryLookupStrategy.create(entityManager, queryMethodFactory, key, - new CachingValueExpressionDelegate(valueExpressionDelegate), - queryRewriterProvider, escapeCharacter)); + new CachingValueExpressionDelegate(valueExpressionDelegate), queryRewriterProvider, escapeCharacter)); } - @Override @SuppressWarnings("unchecked") public JpaEntityInformation getEntityInformation(Class domainClass) { diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/QuerydslJpaPredicateExecutor.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/QuerydslJpaPredicateExecutor.java index c28660cb9..8881ab84c 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/QuerydslJpaPredicateExecutor.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/QuerydslJpaPredicateExecutor.java @@ -23,6 +23,8 @@ import java.util.Optional; import java.util.function.BiFunction; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.domain.KeysetScrollPosition; @@ -59,7 +61,6 @@ import com.querydsl.core.types.dsl.Expressions; import com.querydsl.core.types.dsl.PathBuilder; import com.querydsl.jpa.JPQLQuery; import com.querydsl.jpa.impl.AbstractJPAQuery; -import org.jspecify.annotations.Nullable; /** * Querydsl specific fragment for extending {@link SimpleJpaRepository} with an implementation of @@ -376,7 +377,7 @@ public class QuerydslJpaPredicateExecutor implements QuerydslPredicateExecuto @Override public BooleanExpression compare(Order order, Expression propertyExpression, @Nullable Object value) { - if(value == null) { + if (value == null) { return Expressions.booleanOperation(order.isAscending() ? Ops.IS_NULL : Ops.IS_NOT_NULL, propertyExpression); } 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 48632c09b..422689117 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 @@ -40,9 +40,9 @@ import java.util.Optional; import java.util.function.BiConsumer; import java.util.function.Function; -import org.springframework.dao.InvalidDataAccessApiUsageException; - import org.jspecify.annotations.Nullable; + +import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.domain.Example; import org.springframework.data.domain.KeysetScrollPosition; import org.springframework.data.domain.OffsetScrollPosition; diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java index c4f2485b8..0ebf72693 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java @@ -2801,44 +2801,6 @@ class UserRepositoryTests { assertThat(page0.getTotalElements()).isEqualTo(3L); } - @Test // GH-2274 - void findByFluentSpecificationSlice() { - - flushTestUsers(); - - Slice slice = repository.findBy(userHasFirstnameLike("v"), - q -> q.sortBy(Sort.by("firstname")).slice(PageRequest.of(0, 2))); - - assertThat(slice).isNotInstanceOf(Page.class); - assertThat(slice.getContent()).containsExactly(thirdUser, firstUser); - assertThat(slice.hasNext()).isTrue(); - - slice = repository.findBy(userHasFirstnameLike("v"), - q -> q.sortBy(Sort.by("firstname")).slice(PageRequest.of(0, 3))); - - assertThat(slice).isNotInstanceOf(Page.class); - assertThat(slice).hasSize(3); - assertThat(slice.hasNext()).isFalse(); - } - - @Test // GH-3727 - void findByFluentSpecificationPageCustomCountSpec() { - - flushTestUsers(); - - Page page0 = repository.findBy(userHasFirstnameLike("v"), - q -> q.sortBy(Sort.by("firstname")).page(PageRequest.of(0, 2), (root, query, criteriaBuilder) -> null)); - - assertThat(page0.getContent()).containsExactly(thirdUser, firstUser); - assertThat(page0.getTotalElements()).isEqualTo(4L); - - page0 = repository.findBy(userHasFirstnameLike("v"), - q -> q.sortBy(Sort.by("firstname")).page(PageRequest.of(0, 2))); - - assertThat(page0.getContent()).containsExactly(thirdUser, firstUser); - assertThat(page0.getTotalElements()).isEqualTo(3L); - } - @Test // GH-2274, GH-3716 void findByFluentSpecificationWithInterfaceBasedProjection() {