Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Defer user-class lookup.

See #3564
  • Loading branch information
mp911de committed Aug 13, 2024
1 parent 4f54291 commit 303c2db
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ public void delete(T entity) {
return;
}

Class<?> type = ProxyUtils.getUserClass(entity);

if (entityManager.contains(entity)) {
entityManager.remove(entity);
return;
}

Class<?> type = ProxyUtils.getUserClass(entity);

// if the entity to be deleted doesn't exist, delete is a NOOP
T existing = (T) entityManager.find(type, entityInformation.getId(entity));
if (existing != null) {
Expand Down Expand Up @@ -282,8 +282,7 @@ public void deleteAllInBatch(Iterable<T> entities) {
return;
}

applyAndBind(getQueryString(DELETE_ALL_QUERY_STRING, entityInformation.getEntityName()), entities,
entityManager)
applyAndBind(getQueryString(DELETE_ALL_QUERY_STRING, entityInformation.getEntityName()), entities, entityManager)
.executeUpdate();
}

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

return Optional.ofNullable(type == null ? entityManager.find(domainType, id, hints) : entityManager.find(domainType, id, type, hints));
return Optional.ofNullable(
type == null ? entityManager.find(domainType, id, hints) : entityManager.find(domainType, id, type, hints));
}

@Deprecated
Expand Down Expand Up @@ -486,7 +486,8 @@ public long delete(@Nullable Specification<T> spec) {
CriteriaDelete<T> delete = builder.createCriteriaDelete(getDomainClass());

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

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

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

SpecificationScrollDelegate<T> scrollDelegate = new SpecificationScrollDelegate<>(scrollFunction,
entityInformation);
FetchableFluentQueryBySpecification<?, T> fluentQuery = new FetchableFluentQueryBySpecification<>(spec, domainClass, finder,
scrollDelegate, this::count, this::exists, this.entityManager, getProjectionFactory());
FetchableFluentQueryBySpecification<?, T> fluentQuery = new FetchableFluentQueryBySpecification<>(spec, domainClass,
finder, scrollDelegate, this::count, this::exists, this.entityManager, getProjectionFactory());

return queryFunction.apply((FetchableFluentQuery<S>) fluentQuery);
}
Expand Down

0 comments on commit 303c2db

Please sign in to comment.