Skip to content

Commit ea0bd8c

Browse files
arefbehboudischauder
authored andcommitted
Polishing.
Original pull request #3612
1 parent 87cc57b commit ea0bd8c

File tree

4 files changed

+21
-31
lines changed

4 files changed

+21
-31
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/JpaSort.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public String toString() {
303303
builder.append(attribute.getName()).append(".");
304304
}
305305

306-
return builder.length() == 0 ? "" : builder.substring(0, builder.lastIndexOf("."));
306+
return builder.isEmpty() ? "" : builder.substring(0, builder.lastIndexOf("."));
307307
}
308308
}
309309

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/JpaRuntimeHints.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
8888

8989
// streaming results requires reflective access to jakarta.persistence.Query#getResultAsStream
9090
hints.reflection().registerType(jakarta.persistence.Query.class, MemberCategory.INTROSPECT_PUBLIC_METHODS);
91-
hints.reflection().registerType(jakarta.persistence.Query.class, hint -> {
92-
hint.withMethod("getResultStream", Collections.emptyList(), ExecutableMode.INVOKE);
93-
});
91+
hints.reflection().registerType(jakarta.persistence.Query.class, hint ->
92+
hint.withMethod("getResultStream", Collections.emptyList(), ExecutableMode.INVOKE));
9493

9594
hints.reflection().registerType(NamedEntityGraph.class,
9695
hint -> hint.onReachableType(EntityGraph.class).withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java

+10-21
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,11 @@ public Querydsl(EntityManager em, PathBuilder<?> builder) {
7777
*/
7878
public <T> AbstractJPAQuery<T, JPAQuery<T>> createQuery() {
7979

80-
switch (provider) {
81-
case ECLIPSELINK:
82-
return new JPAQuery<>(em, EclipseLinkTemplates.DEFAULT);
83-
case HIBERNATE:
84-
return new JPAQuery<>(em, HQLTemplates.DEFAULT);
85-
case GENERIC_JPA:
86-
default:
87-
return new JPAQuery<>(em);
88-
}
80+
return switch (provider) {
81+
case ECLIPSELINK -> new JPAQuery<>(em, EclipseLinkTemplates.DEFAULT);
82+
case HIBERNATE -> new JPAQuery<>(em, HQLTemplates.DEFAULT);
83+
default -> new JPAQuery<>(em);
84+
};
8985
}
9086

9187
/**
@@ -202,18 +198,11 @@ private NullHandling toQueryDslNullHandling(org.springframework.data.domain.Sort
202198

203199
Assert.notNull(nullHandling, "NullHandling must not be null");
204200

205-
switch (nullHandling) {
206-
207-
case NULLS_FIRST:
208-
return NullHandling.NullsFirst;
209-
210-
case NULLS_LAST:
211-
return NullHandling.NullsLast;
212-
213-
case NATIVE:
214-
default:
215-
return NullHandling.Default;
216-
}
201+
return switch (nullHandling) {
202+
case NULLS_FIRST -> NullHandling.NullsFirst;
203+
case NULLS_LAST -> NullHandling.NullsLast;
204+
default -> NullHandling.Default;
205+
};
217206
}
218207

219208
/**

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T, ID> {
100100

101101
private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null";
102+
private static final String IDS_MUST_NOT_BE_NULL = "Ids must not be null";
103+
private static final String ENTITIES_MUST_NOT_BE_NULL = "Entities must not be null";
102104

103105
private final JpaEntityInformation<T, ?> entityInformation;
104106
private final EntityManager entityManager;
@@ -212,7 +214,7 @@ public void delete(T entity) {
212214
@Transactional
213215
public void deleteAllById(Iterable<? extends ID> ids) {
214216

215-
Assert.notNull(ids, "Ids must not be null");
217+
Assert.notNull(ids, IDS_MUST_NOT_BE_NULL);
216218

217219
for (ID id : ids) {
218220
deleteById(id);
@@ -223,7 +225,7 @@ public void deleteAllById(Iterable<? extends ID> ids) {
223225
@Transactional
224226
public void deleteAllByIdInBatch(Iterable<ID> ids) {
225227

226-
Assert.notNull(ids, "Ids must not be null");
228+
Assert.notNull(ids, IDS_MUST_NOT_BE_NULL);
227229

228230
if (!ids.iterator().hasNext()) {
229231
return;
@@ -258,7 +260,7 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
258260
@Transactional
259261
public void deleteAll(Iterable<? extends T> entities) {
260262

261-
Assert.notNull(entities, "Entities must not be null");
263+
Assert.notNull(entities, ENTITIES_MUST_NOT_BE_NULL);
262264

263265
for (T entity : entities) {
264266
delete(entity);
@@ -269,7 +271,7 @@ public void deleteAll(Iterable<? extends T> entities) {
269271
@Transactional
270272
public void deleteAllInBatch(Iterable<T> entities) {
271273

272-
Assert.notNull(entities, "Entities must not be null");
274+
Assert.notNull(entities, ENTITIES_MUST_NOT_BE_NULL);
273275

274276
if (!entities.iterator().hasNext()) {
275277
return;
@@ -390,7 +392,7 @@ public List<T> findAll() {
390392
@Override
391393
public List<T> findAllById(Iterable<ID> ids) {
392394

393-
Assert.notNull(ids, "Ids must not be null");
395+
Assert.notNull(ids, IDS_MUST_NOT_BE_NULL);
394396

395397
if (!ids.iterator().hasNext()) {
396398
return Collections.emptyList();
@@ -639,7 +641,7 @@ public <S extends T> S saveAndFlush(S entity) {
639641
@Transactional
640642
public <S extends T> List<S> saveAll(Iterable<S> entities) {
641643

642-
Assert.notNull(entities, "Entities must not be null");
644+
Assert.notNull(entities, ENTITIES_MUST_NOT_BE_NULL);
643645

644646
List<S> result = new ArrayList<>();
645647

0 commit comments

Comments
 (0)