From 351a30500c528cffe740802cfef6471877dd8e5b Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Thu, 4 Jul 2024 11:19:42 +0800 Subject: [PATCH] Polishing `SimpleJpaRepository` 1. `TypedQuery.set*()` returns the same query instance 2. use `instanceof` instead of `isInstance()` --- .../jpa/repository/support/SimpleJpaRepository.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index a2aaf3478e..0e000faf7a 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -244,7 +244,7 @@ public void deleteAllByIdInBatch(Iterable ids) { * Some JPA providers require {@code ids} to be a {@link Collection} so we must convert if it's not already. */ - if (Collection.class.isInstance(ids)) { + if (ids instanceof Collection) { query.setParameter("ids", ids); } else { Collection idsCollection = StreamSupport.stream(ids.spliterator(), false) @@ -854,11 +854,13 @@ private TypedQuery applyRepositoryMethodMetadata(TypedQuery query) { } LockModeType type = metadata.getLockModeType(); - TypedQuery toReturn = type == null ? query : query.setLockMode(type); + if (type != null) { + query.setLockMode(type); + } - applyQueryHints(toReturn); + applyQueryHints(query); - return toReturn; + return query; } private void applyQueryHints(Query query) {