Skip to content

Commit

Permalink
Polishing SimpleJpaRepository
Browse files Browse the repository at this point in the history
1. `TypedQuery.set*()` returns the same query instance
2. remove `if (spec != null)` since `spec` must not be null
  • Loading branch information
quaff committed May 10, 2024
1 parent 6a2510d commit 5f46bdd
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public void deleteAllByIdInBatch(Iterable<ID> 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<ID> idsCollection = StreamSupport.stream(ids.spliterator(), false)
Expand Down Expand Up @@ -481,12 +481,10 @@ public long delete(Specification<T> spec) {
CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();
CriteriaDelete<T> delete = builder.createCriteriaDelete(getDomainClass());

if (spec != null) {
Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), null, builder);
Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), null, builder);

if (predicate != null) {
delete.where(predicate);
}
if (predicate != null) {
delete.where(predicate);
}

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

LockModeType type = metadata.getLockModeType();
TypedQuery<S> 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) {
Expand Down

0 comments on commit 5f46bdd

Please sign in to comment.