Skip to content

Commit 41a7f9b

Browse files
arefbehboudischauder
authored andcommitted
Polishing.
Original pull request #3612
1 parent 7ed8f4a commit 41a7f9b

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public String toString() {
309309
builder.append(attribute.getName()).append(".");
310310
}
311311

312-
return builder.length() == 0 ? "" : builder.substring(0, builder.lastIndexOf("."));
312+
return builder.isEmpty() ? "" : builder.substring(0, builder.lastIndexOf("."));
313313
}
314314
}
315315

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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 10 additions & 21 deletions
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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T, ID> {
9999

100100
private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null";
101+
private static final String IDS_MUST_NOT_BE_NULL = "Ids must not be null";
102+
private static final String ENTITIES_MUST_NOT_BE_NULL = "Entities must not be null";
101103

102104
private final JpaEntityInformation<T, ?> entityInformation;
103105
private final EntityManager entityManager;
@@ -203,7 +205,7 @@ public void delete(T entity) {
203205
@Transactional
204206
public void deleteAllById(Iterable<? extends ID> ids) {
205207

206-
Assert.notNull(ids, "Ids must not be null");
208+
Assert.notNull(ids, IDS_MUST_NOT_BE_NULL);
207209

208210
for (ID id : ids) {
209211
deleteById(id);
@@ -214,7 +216,7 @@ public void deleteAllById(Iterable<? extends ID> ids) {
214216
@Transactional
215217
public void deleteAllByIdInBatch(Iterable<ID> ids) {
216218

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

219221
if (!ids.iterator().hasNext()) {
220222
return;
@@ -255,7 +257,7 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
255257
@Transactional
256258
public void deleteAll(Iterable<? extends T> entities) {
257259

258-
Assert.notNull(entities, "Entities must not be null");
260+
Assert.notNull(entities, ENTITIES_MUST_NOT_BE_NULL);
259261

260262
for (T entity : entities) {
261263
delete(entity);
@@ -266,7 +268,7 @@ public void deleteAll(Iterable<? extends T> entities) {
266268
@Transactional
267269
public void deleteAllInBatch(Iterable<T> entities) {
268270

269-
Assert.notNull(entities, "Entities must not be null");
271+
Assert.notNull(entities, ENTITIES_MUST_NOT_BE_NULL);
270272

271273
if (!entities.iterator().hasNext()) {
272274
return;
@@ -387,7 +389,7 @@ public List<T> findAll() {
387389
@Override
388390
public List<T> findAllById(Iterable<ID> ids) {
389391

390-
Assert.notNull(ids, "Ids must not be null");
392+
Assert.notNull(ids, IDS_MUST_NOT_BE_NULL);
391393

392394
if (!ids.iterator().hasNext()) {
393395
return Collections.emptyList();
@@ -638,7 +640,7 @@ public <S extends T> S saveAndFlush(S entity) {
638640
@Transactional
639641
public <S extends T> List<S> saveAll(Iterable<S> entities) {
640642

641-
Assert.notNull(entities, "Entities must not be null");
643+
Assert.notNull(entities, ENTITIES_MUST_NOT_BE_NULL);
642644

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

0 commit comments

Comments
 (0)