Skip to content

Commit 3483e16

Browse files
committed
Polishing.
Defer user-class lookup. See #3564
1 parent 58fe95f commit 3483e16

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ public void delete(T entity) {
195195
return;
196196
}
197197

198-
Class<?> type = ProxyUtils.getUserClass(entity);
199-
200198
if (entityManager.contains(entity)) {
201199
entityManager.remove(entity);
202200
return;
203201
}
204202

203+
Class<?> type = ProxyUtils.getUserClass(entity);
204+
205205
// if the entity to be deleted doesn't exist, delete is a NOOP
206206
T existing = (T) entityManager.find(type, entityInformation.getId(entity));
207207
if (existing != null) {
@@ -282,8 +282,7 @@ public void deleteAllInBatch(Iterable<T> entities) {
282282
return;
283283
}
284284

285-
applyAndBind(getQueryString(DELETE_ALL_QUERY_STRING, entityInformation.getEntityName()), entities,
286-
entityManager)
285+
applyAndBind(getQueryString(DELETE_ALL_QUERY_STRING, entityInformation.getEntityName()), entities, entityManager)
287286
.executeUpdate();
288287
}
289288

@@ -321,7 +320,8 @@ public Optional<T> findById(ID id) {
321320
LockModeType type = metadata.getLockModeType();
322321
Map<String, Object> hints = getHints();
323322

324-
return Optional.ofNullable(type == null ? entityManager.find(domainType, id, hints) : entityManager.find(domainType, id, type, hints));
323+
return Optional.ofNullable(
324+
type == null ? entityManager.find(domainType, id, hints) : entityManager.find(domainType, id, type, hints));
325325
}
326326

327327
@Deprecated
@@ -481,7 +481,8 @@ public long delete(@Nullable Specification<T> spec) {
481481
CriteriaDelete<T> delete = builder.createCriteriaDelete(getDomainClass());
482482

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

486487
if (predicate != null) {
487488
delete.where(predicate);
@@ -519,7 +520,7 @@ private <S extends T, R> R doFindBy(Specification<T> spec, Class<T> domainClass,
519520
TypedQuery<T> query = getQuery(specToUse, domainClass, sort);
520521

521522
if (scrollPosition instanceof OffsetScrollPosition offset) {
522-
if(!offset.isInitial()) {
523+
if (!offset.isInitial()) {
523524
query.setFirstResult(Math.toIntExact(offset.getOffset()) + 1);
524525
}
525526
}
@@ -531,8 +532,8 @@ private <S extends T, R> R doFindBy(Specification<T> spec, Class<T> domainClass,
531532

532533
SpecificationScrollDelegate<T> scrollDelegate = new SpecificationScrollDelegate<>(scrollFunction,
533534
entityInformation);
534-
FetchableFluentQueryBySpecification<?, T> fluentQuery = new FetchableFluentQueryBySpecification<>(spec, domainClass, finder,
535-
scrollDelegate, this::count, this::exists, this.entityManager, getProjectionFactory());
535+
FetchableFluentQueryBySpecification<?, T> fluentQuery = new FetchableFluentQueryBySpecification<>(spec, domainClass,
536+
finder, scrollDelegate, this::count, this::exists, this.entityManager, getProjectionFactory());
536537

537538
return queryFunction.apply((FetchableFluentQuery<S>) fluentQuery);
538539
}

0 commit comments

Comments
 (0)