Skip to content

Polishing #3612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public String toString() {
builder.append(attribute.getName()).append(".");
}

return builder.length() == 0 ? "" : builder.substring(0, builder.lastIndexOf("."));
return builder.isEmpty() ? "" : builder.substring(0, builder.lastIndexOf("."));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)

// 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,21 @@ public Map<String, Object> getKeyset(Iterable<String> propertyPaths, T entity) {

Function<String, Object> getter = getPropertyValueFunction(entity);

Map<String, Object> keyset = new LinkedHashMap<>();
Map<String, Object> keySet = new LinkedHashMap<>();

if (hasCompositeId()) {
for (String idAttributeName : getIdAttributeNames()) {
keyset.put(idAttributeName, getter.apply(idAttributeName));
keySet.put(idAttributeName, getter.apply(idAttributeName));
}
} else {
keyset.put(getIdAttribute().getName(), getId(entity));
keySet.put(getIdAttribute().getName(), getId(entity));
}

for (String propertyPath : propertyPaths) {
keyset.put(propertyPath, getter.apply(propertyPath));
keySet.put(propertyPath, getter.apply(propertyPath));
}

return keyset;
return keySet;
}

private Function<String, Object> getPropertyValueFunction(Object entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,11 @@ public Querydsl(EntityManager em, PathBuilder<?> builder) {
*/
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);
};
}

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

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;
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ public <S extends T, R> R findBy(Predicate predicate, Function<FetchableFluentQu

Predicate predicateToUse = predicate;

if (scrollPosition instanceof KeysetScrollPosition keyset) {
if (scrollPosition instanceof KeysetScrollPosition keySet) {

KeysetScrollDelegate delegate = KeysetScrollDelegate.of(keyset.getDirection());
sort = KeysetScrollSpecification.createSort(keyset, sort, entityInformation);
BooleanExpression keysetPredicate = delegate.createPredicate(keyset, sort, scrollQueryAdapter);
KeysetScrollDelegate delegate = KeysetScrollDelegate.of(keySet.getDirection());
sort = KeysetScrollSpecification.createSort(keySet, sort, entityInformation);
BooleanExpression keySetPredicate = delegate.createPredicate(keySet, sort, scrollQueryAdapter);

if (keysetPredicate != null) {
predicateToUse = predicate instanceof BooleanExpression be ? be.and(keysetPredicate)
: keysetPredicate.and(predicate);
if (keySetPredicate != null) {
predicateToUse = predicate instanceof BooleanExpression be ? be.and(keySetPredicate)
: keySetPredicate.and(predicate);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
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;
Expand Down Expand Up @@ -212,7 +214,7 @@ public void delete(T entity) {
@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);
Expand All @@ -223,7 +225,7 @@ public void deleteAllById(Iterable<? extends ID> ids) {
@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;
Expand Down Expand Up @@ -258,7 +260,7 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
@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);
Expand All @@ -269,7 +271,7 @@ public void deleteAll(Iterable<? extends T> entities) {
@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;
Expand Down Expand Up @@ -390,7 +392,7 @@ public List<T> findAll() {
@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();
Expand Down Expand Up @@ -639,7 +641,7 @@ public <S extends T> S saveAndFlush(S entity) {
@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<>();

Expand Down