Skip to content

Commit 5f46bdd

Browse files
committed
Polishing SimpleJpaRepository
1. `TypedQuery.set*()` returns the same query instance 2. remove `if (spec != null)` since `spec` must not be null
1 parent 6a2510d commit 5f46bdd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
244244
* Some JPA providers require {@code ids} to be a {@link Collection} so we must convert if it's not already.
245245
*/
246246

247-
if (Collection.class.isInstance(ids)) {
247+
if (ids instanceof Collection) {
248248
query.setParameter("ids", ids);
249249
} else {
250250
Collection<ID> idsCollection = StreamSupport.stream(ids.spliterator(), false)
@@ -481,12 +481,10 @@ public long delete(Specification<T> spec) {
481481
CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();
482482
CriteriaDelete<T> delete = builder.createCriteriaDelete(getDomainClass());
483483

484-
if (spec != null) {
485-
Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), null, builder);
484+
Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), null, builder);
486485

487-
if (predicate != null) {
488-
delete.where(predicate);
489-
}
486+
if (predicate != null) {
487+
delete.where(predicate);
490488
}
491489

492490
return this.entityManager.createQuery(delete).executeUpdate();
@@ -853,11 +851,13 @@ private <S> TypedQuery<S> applyRepositoryMethodMetadata(TypedQuery<S> query) {
853851
}
854852

855853
LockModeType type = metadata.getLockModeType();
856-
TypedQuery<S> toReturn = type == null ? query : query.setLockMode(type);
854+
if (type == null) {
855+
query.setLockMode(type);
856+
}
857857

858-
applyQueryHints(toReturn);
858+
applyQueryHints(query);
859859

860-
return toReturn;
860+
return query;
861861
}
862862

863863
private void applyQueryHints(Query query) {

0 commit comments

Comments
 (0)