Skip to content

Commit 303c2db

Browse files
committed
Polishing.
Defer user-class lookup. See #3564
1 parent 4f54291 commit 303c2db

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

+10-9
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
@@ -486,7 +486,8 @@ public long delete(@Nullable Specification<T> spec) {
486486
CriteriaDelete<T> delete = builder.createCriteriaDelete(getDomainClass());
487487

488488
if (spec != null) {
489-
Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), builder.createQuery(getDomainClass()), builder);
489+
Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), builder.createQuery(getDomainClass()),
490+
builder);
490491

491492
if (predicate != null) {
492493
delete.where(predicate);
@@ -524,7 +525,7 @@ private <S extends T, R> R doFindBy(Specification<T> spec, Class<T> domainClass,
524525
TypedQuery<T> query = getQuery(specToUse, domainClass, sort);
525526

526527
if (scrollPosition instanceof OffsetScrollPosition offset) {
527-
if(!offset.isInitial()) {
528+
if (!offset.isInitial()) {
528529
query.setFirstResult(Math.toIntExact(offset.getOffset()) + 1);
529530
}
530531
}
@@ -536,8 +537,8 @@ private <S extends T, R> R doFindBy(Specification<T> spec, Class<T> domainClass,
536537

537538
SpecificationScrollDelegate<T> scrollDelegate = new SpecificationScrollDelegate<>(scrollFunction,
538539
entityInformation);
539-
FetchableFluentQueryBySpecification<?, T> fluentQuery = new FetchableFluentQueryBySpecification<>(spec, domainClass, finder,
540-
scrollDelegate, this::count, this::exists, this.entityManager, getProjectionFactory());
540+
FetchableFluentQueryBySpecification<?, T> fluentQuery = new FetchableFluentQueryBySpecification<>(spec, domainClass,
541+
finder, scrollDelegate, this::count, this::exists, this.entityManager, getProjectionFactory());
541542

542543
return queryFunction.apply((FetchableFluentQuery<S>) fluentQuery);
543544
}

0 commit comments

Comments
 (0)