Skip to content

Commit

Permalink
Remove OpenJPA leftovers.
Browse files Browse the repository at this point in the history
Remove unused tests, simplify findAllById(Iterable) implementation.

Closes #3741
  • Loading branch information
mp911de committed Jan 14, 2025
1 parent 7804874 commit 265209a
Show file tree
Hide file tree
Showing 22 changed files with 14 additions and 596 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@
</includes>
<excludes>
<exclude>**/*UnitTests.java</exclude>
<exclude>**/OpenJpa*</exclude>
<exclude>**/EclipseLink*</exclude>
<exclude>**/MySql*</exclude>
<exclude>**/Postgres*</exclude>
Expand Down
1 change: 0 additions & 1 deletion spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@
</includes>
<excludes>
<exclude>**/*UnitTests.java</exclude>
<exclude>**/OpenJpa*</exclude>
<exclude>**/EclipseLink*</exclude>
<exclude>**/MySql*</exclude>
<exclude>**/Postgres*</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@

import jakarta.persistence.EntityManager;
import jakarta.persistence.LockModeType;
import jakarta.persistence.Parameter;
import jakarta.persistence.Query;
import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaUpdate;
import jakarta.persistence.criteria.ParameterExpression;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.criteria.Selection;

import java.io.Serial;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -260,7 +257,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.
*/
Collection<ID> idCollection = toCollection(ids);
Collection<ID> idCollection = toCollection(ids);
query.setParameter("ids", idCollection);

applyQueryHints(query);
Expand Down Expand Up @@ -424,10 +421,14 @@ public List<T> findAllById(Iterable<ID> ids) {

Collection<ID> idCollection = toCollection(ids);

ByIdsSpecification<T> specification = new ByIdsSpecification<>(entityInformation);
TypedQuery<T> query = getQuery(specification, Sort.unsorted());
TypedQuery<T> query = getQuery((root, q, criteriaBuilder) -> {

return query.setParameter(specification.parameter, idCollection).getResultList();
Path<?> path = root.get(entityInformation.getIdAttribute());
return path.in(idCollection);

}, Sort.unsorted());

return query.getResultList();
}

@Override
Expand Down Expand Up @@ -1062,37 +1063,6 @@ private static long executeCountQuery(TypedQuery<Long> query) {
return total;
}

/**
* Specification that gives access to the {@link Parameter} instance used to bind the ids for
* {@link SimpleJpaRepository#findAllById(Iterable)}. Workaround for OpenJPA not binding collections to in-clauses
* correctly when using by-name binding.
*
* @author Oliver Gierke
* @see <a href="https://issues.apache.org/jira/browse/OPENJPA-2018?focusedCommentId=13924055">OPENJPA-2018</a>
*/
@SuppressWarnings("rawtypes")
private static final class ByIdsSpecification<T> implements Specification<T> {

private static final @Serial long serialVersionUID = 1L;

private final JpaEntityInformation<T, ?> entityInformation;

@Nullable ParameterExpression<Collection<?>> parameter;

ByIdsSpecification(JpaEntityInformation<T, ?> entityInformation) {
this.entityInformation = entityInformation;
}

@Override
@SuppressWarnings("unchecked")
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {

Path<?> path = root.get(entityInformation.getIdAttribute());
parameter = (ParameterExpression<Collection<?>>) (ParameterExpression) cb.parameter(Collection.class);
return path.in(parameter);
}
}

/**
* {@link Specification} that gives access to the {@link Predicate} instance representing the values contained in the
* {@link Example}.
Expand All @@ -1101,26 +1071,20 @@ public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuild
* @author Christoph Strobl
* @since 1.10
*/
private static class ExampleSpecification<T> implements Specification<T> {

private static final @Serial long serialVersionUID = 1L;

private final Example<T> example;
private final EscapeCharacter escapeCharacter;
private record ExampleSpecification<T>(Example<T> example,
EscapeCharacter escapeCharacter) implements Specification<T> {

/**
* Creates new {@link ExampleSpecification}.
*
* @param example the example to base the specification of. Must not be {@literal null}.
* @param escapeCharacter the escape character to use for like expressions. Must not be {@literal null}.
*/
ExampleSpecification(Example<T> example, EscapeCharacter escapeCharacter) {
private ExampleSpecification {

Assert.notNull(example, EXAMPLE_MUST_NOT_BE_NULL);
Assert.notNull(escapeCharacter, "EscapeCharacter must not be null");

this.example = example;
this.escapeCharacter = escapeCharacter;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.springframework.test.context.ContextConfiguration;

/**
* Metamodel tests using OpenJPA.
* Metamodel tests using Eclipselink.
*
* @author Oliver Gierke
*/
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 265209a

Please sign in to comment.