diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/JpaSort.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/JpaSort.java index e1fa00338..a28bf8a39 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/JpaSort.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/JpaSort.java @@ -303,7 +303,7 @@ public class JpaSort extends Sort { builder.append(attribute.getName()).append("."); } - return builder.length() == 0 ? "" : builder.substring(0, builder.lastIndexOf(".")); + return builder.isEmpty() ? "" : builder.substring(0, builder.lastIndexOf(".")); } } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/JpaRuntimeHints.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/JpaRuntimeHints.java index 955401af7..a2dcece1f 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/JpaRuntimeHints.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/JpaRuntimeHints.java @@ -88,9 +88,8 @@ class JpaRuntimeHints implements RuntimeHintsRegistrar { // streaming results requires reflective access to jakarta.persistence.Query#getResultAsStream hints.reflection().registerType(jakarta.persistence.Query.class, MemberCategory.INTROSPECT_PUBLIC_METHODS); - hints.reflection().registerType(jakarta.persistence.Query.class, hint -> { - hint.withMethod("getResultStream", Collections.emptyList(), ExecutableMode.INVOKE); - }); + hints.reflection().registerType(jakarta.persistence.Query.class, hint -> + hint.withMethod("getResultStream", Collections.emptyList(), ExecutableMode.INVOKE)); hints.reflection().registerType(NamedEntityGraph.class, hint -> hint.onReachableType(EntityGraph.class).withMembers(MemberCategory.INVOKE_PUBLIC_METHODS)); diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java index eaadddb2a..0ade24f13 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java @@ -77,15 +77,11 @@ public class Querydsl { */ public AbstractJPAQuery> createQuery() { - switch (provider) { - case ECLIPSELINK: - return new JPAQuery<>(em, EclipseLinkTemplates.DEFAULT); - case HIBERNATE: - return new JPAQuery<>(em, HQLTemplates.DEFAULT); - case GENERIC_JPA: - default: - return new JPAQuery<>(em); - } + return switch (provider) { + case ECLIPSELINK -> new JPAQuery<>(em, EclipseLinkTemplates.DEFAULT); + case HIBERNATE -> new JPAQuery<>(em, HQLTemplates.DEFAULT); + default -> new JPAQuery<>(em); + }; } /** @@ -202,18 +198,11 @@ public class Querydsl { Assert.notNull(nullHandling, "NullHandling must not be null"); - switch (nullHandling) { - - case NULLS_FIRST: - return NullHandling.NullsFirst; - - case NULLS_LAST: - return NullHandling.NullsLast; - - case NATIVE: - default: - return NullHandling.Default; - } + return switch (nullHandling) { + case NULLS_FIRST -> NullHandling.NullsFirst; + case NULLS_LAST -> NullHandling.NullsLast; + default -> NullHandling.Default; + }; } /** 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 bda460e3c..bf2faea2f 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 @@ -99,6 +99,8 @@ import org.springframework.util.Assert; public class SimpleJpaRepository implements JpaRepositoryImplementation { private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null"; + private static final String IDS_MUST_NOT_BE_NULL = "Ids must not be null"; + private static final String ENTITIES_MUST_NOT_BE_NULL = "Entities must not be null"; private final JpaEntityInformation entityInformation; private final EntityManager entityManager; @@ -212,7 +214,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation ids) { - Assert.notNull(ids, "Ids must not be null"); + Assert.notNull(ids, IDS_MUST_NOT_BE_NULL); for (ID id : ids) { deleteById(id); @@ -223,7 +225,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation ids) { - Assert.notNull(ids, "Ids must not be null"); + Assert.notNull(ids, IDS_MUST_NOT_BE_NULL); if (!ids.iterator().hasNext()) { return; @@ -258,7 +260,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation entities) { - Assert.notNull(entities, "Entities must not be null"); + Assert.notNull(entities, ENTITIES_MUST_NOT_BE_NULL); for (T entity : entities) { delete(entity); @@ -269,7 +271,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation entities) { - Assert.notNull(entities, "Entities must not be null"); + Assert.notNull(entities, ENTITIES_MUST_NOT_BE_NULL); if (!entities.iterator().hasNext()) { return; @@ -390,7 +392,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation findAllById(Iterable ids) { - Assert.notNull(ids, "Ids must not be null"); + Assert.notNull(ids, IDS_MUST_NOT_BE_NULL); if (!ids.iterator().hasNext()) { return Collections.emptyList(); @@ -639,7 +641,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation List saveAll(Iterable entities) { - Assert.notNull(entities, "Entities must not be null"); + Assert.notNull(entities, ENTITIES_MUST_NOT_BE_NULL); List result = new ArrayList<>();