Polishing.

Original pull request #3612
This commit is contained in:
arefbehboudi
2024-09-17 14:27:10 +03:30
committed by Jens Schauder
parent 87cc57b0b5
commit ea0bd8c5e9
4 changed files with 21 additions and 31 deletions

View File

@@ -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("."));
}
}

View File

@@ -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));

View File

@@ -77,15 +77,11 @@ public class Querydsl {
*/
public <T> AbstractJPAQuery<T, JPAQuery<T>> 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;
};
}
/**

View File

@@ -99,6 +99,8 @@ import org.springframework.util.Assert;
public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T, ID> {
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<T, ?> entityInformation;
private final EntityManager entityManager;
@@ -212,7 +214,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
@Transactional
public void deleteAllById(Iterable<? extends ID> 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<T, ID> implements JpaRepositoryImplementation<T
@Transactional
public void deleteAllByIdInBatch(Iterable<ID> 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<T, ID> implements JpaRepositoryImplementation<T
@Transactional
public void deleteAll(Iterable<? extends T> 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<T, ID> implements JpaRepositoryImplementation<T
@Transactional
public void deleteAllInBatch(Iterable<T> 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<T, ID> implements JpaRepositoryImplementation<T
@Override
public List<T> findAllById(Iterable<ID> 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<T, ID> implements JpaRepositoryImplementation<T
@Transactional
public <S extends T> List<S> saveAll(Iterable<S> entities) {
Assert.notNull(entities, "Entities must not be null");
Assert.notNull(entities, ENTITIES_MUST_NOT_BE_NULL);
List<S> result = new ArrayList<>();