Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1965] Use regular CriteriaBuilder instead of PaginatedCriteriaBuild… #1966

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ For executing tests against a database on a dedicated host you might want to spe
## Testing with Jakarta Persistence provider

To build everything use `mvn -pl core/testsuite-jakarta-runner clean install -am -P "hibernate-6.2,jakarta,h2,spring-data-2.6.x,deltaspike-1.9" -DskipTests`
and to run tests use ` mvn -pl core/testsuite-jakarta-runner clean install -P "hibernate-6.2,jakarta,h2,spring-data-2.6.x,deltaspike-1.9" "-Dtest=com.blazebit.persistence.testsuite.SetOperationTest#testUnionAllOrderBySubqueryLimit"`.
and to run tests use `mvn -pl core/testsuite-jakarta-runner clean install -P "hibernate-6.2,jakarta,h2,spring-data-2.6.x,deltaspike-1.9" "-Dtest=com.blazebit.persistence.testsuite.SetOperationTest#testUnionAllOrderBySubqueryLimit"`.

## Switching JPA provider profiles in IntelliJ

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.springframework.data.jpa.repository.query.JpaEntityGraph;
import org.springframework.data.jpa.repository.query.JpaQueryExecution;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.data.repository.query.parser.PartTree;

Expand Down Expand Up @@ -59,9 +58,9 @@ protected ParameterMetadataProvider createParameterMetadataProvider(CriteriaBuil
@Override
protected JpaQueryExecution getExecution() {
if (getQueryMethod().isSliceQuery()) {
return new PartTreeBlazePersistenceQuery.SlicedExecution(getQueryMethod().getParameters());
return new PartTreeBlazePersistenceQuery.SlicedExecution();
} else if (getQueryMethod().isPageQuery()) {
return new PartTreeBlazePersistenceQuery.PagedExecution(getQueryMethod().getParameters());
return new PartTreeBlazePersistenceQuery.PagedExecution();
} else if (isDelete()) {
return new PartTreeBlazePersistenceQuery.DeleteExecution(getEntityManager());
} else if (isExists()) {
Expand Down Expand Up @@ -93,18 +92,12 @@ protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
*/
private static class SlicedExecution extends JpaQueryExecution {

private final Parameters<?, ?> parameters;

public SlicedExecution(Parameters<?, ?> parameters) {
this.parameters = parameters;
}

@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(values, false);
PagedList<Object> resultList = (PagedList<Object>) paginatedCriteriaBuilder.getResultList();
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
ParameterAccessor accessor = new ParametersParameterAccessor(repositoryQuery.getQueryMethod().getParameters(), values);
Pageable pageable = accessor.getPageable();

return new KeysetAwareSliceImpl<>(resultList, pageable);
Expand All @@ -119,20 +112,19 @@ protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
*/
private static class PagedExecution extends JpaQueryExecution {

private final Parameters<?, ?> parameters;

public PagedExecution(Parameters<?, ?> parameters) {
this.parameters = parameters;
}

@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
ParameterAccessor accessor = new ParametersParameterAccessor(repositoryQuery.getQueryMethod().getParameters(), values);
Pageable pageable = accessor.getPageable();
if (pageable == null) {
List<Object> unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(values).getResultList();
return new KeysetAwarePageImpl<>(unpagedResult);
}

Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(values, true);
PagedList<Object> resultList = (PagedList<Object>) paginatedCriteriaBuilder.getResultList();
Long total = resultList.getTotalSize();
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
Pageable pageable = accessor.getPageable();

if (total.equals(0L)) {
return new KeysetAwarePageImpl<>(Collections.emptyList(), total, null, pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.springframework.data.jpa.repository.query.JpaEntityGraph;
import org.springframework.data.jpa.repository.query.JpaQueryExecution;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.data.repository.query.parser.PartTree;

Expand Down Expand Up @@ -59,9 +58,9 @@ protected ParameterMetadataProvider createParameterMetadataProvider(CriteriaBuil
@Override
protected JpaQueryExecution getExecution() {
if (getQueryMethod().isSliceQuery()) {
return new PartTreeBlazePersistenceQuery.SlicedExecution(getQueryMethod().getParameters());
return new PartTreeBlazePersistenceQuery.SlicedExecution();
} else if (getQueryMethod().isPageQuery()) {
return new PartTreeBlazePersistenceQuery.PagedExecution(getQueryMethod().getParameters());
return new PartTreeBlazePersistenceQuery.PagedExecution();
} else if (isDelete()) {
return new PartTreeBlazePersistenceQuery.DeleteExecution(getEntityManager());
} else if (isExists()) {
Expand Down Expand Up @@ -93,18 +92,12 @@ protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
*/
private static class SlicedExecution extends JpaQueryExecution {

private final Parameters<?, ?> parameters;

public SlicedExecution(Parameters<?, ?> parameters) {
this.parameters = parameters;
}

@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(values, false);
PagedList<Object> resultList = (PagedList<Object>) paginatedCriteriaBuilder.getResultList();
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
ParameterAccessor accessor = new ParametersParameterAccessor(repositoryQuery.getQueryMethod().getParameters(), values);
Pageable pageable = accessor.getPageable();

return new KeysetAwareSliceImpl<>(resultList, pageable);
Expand All @@ -119,20 +112,19 @@ protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
*/
private static class PagedExecution extends JpaQueryExecution {

private final Parameters<?, ?> parameters;

public PagedExecution(Parameters<?, ?> parameters) {
this.parameters = parameters;
}

@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
ParameterAccessor accessor = new ParametersParameterAccessor(repositoryQuery.getQueryMethod().getParameters(), values);
Pageable pageable = accessor.getPageable();
if (pageable.isUnpaged()) {
List<Object> unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(values).getResultList();
return new KeysetAwarePageImpl<>(unpagedResult);
}

Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(values, true);
PagedList<Object> resultList = (PagedList<Object>) paginatedCriteriaBuilder.getResultList();
Long total = resultList.getTotalSize();
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
Pageable pageable = accessor.getPageable();

if (total.equals(0L)) {
return new KeysetAwarePageImpl<>(Collections.emptyList(), total, null, pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.springframework.data.jpa.repository.query.JpaEntityGraph;
import org.springframework.data.jpa.repository.query.JpaQueryExecution;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.data.repository.query.parser.PartTree;

Expand Down Expand Up @@ -60,9 +59,9 @@ protected ParameterMetadataProvider createParameterMetadataProvider(CriteriaBuil
@Override
protected JpaQueryExecution getExecution() {
if (getQueryMethod().isSliceQuery()) {
return new PartTreeBlazePersistenceQuery.SlicedExecution(getQueryMethod().getParameters());
return new PartTreeBlazePersistenceQuery.SlicedExecution();
} else if (getQueryMethod().isPageQuery()) {
return new PartTreeBlazePersistenceQuery.PagedExecution(getQueryMethod().getParameters());
return new PartTreeBlazePersistenceQuery.PagedExecution();
} else if (isDelete()) {
return new PartTreeBlazePersistenceQuery.DeleteExecution(getEntityManager());
} else if (isExists()) {
Expand Down Expand Up @@ -94,18 +93,12 @@ protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
*/
private static class SlicedExecution extends JpaQueryExecution {

private final Parameters<?, ?> parameters;

public SlicedExecution(Parameters<?, ?> parameters) {
this.parameters = parameters;
}

@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(values, false);
PagedList<Object> resultList = (PagedList<Object>) paginatedCriteriaBuilder.getResultList();
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
ParameterAccessor accessor = new ParametersParameterAccessor(repositoryQuery.getQueryMethod().getParameters(), values);
Pageable pageable = accessor.getPageable();

return new KeysetAwareSliceImpl<>(resultList, pageable);
Expand All @@ -120,20 +113,19 @@ protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
*/
private static class PagedExecution extends JpaQueryExecution {

private final Parameters<?, ?> parameters;

public PagedExecution(Parameters<?, ?> parameters) {
this.parameters = parameters;
}

@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractJpaQuery repositoryQuery, Object[] values) {
ParameterAccessor accessor = new ParametersParameterAccessor(repositoryQuery.getQueryMethod().getParameters(), values);
Pageable pageable = accessor.getPageable();
if (pageable.isUnpaged()) {
List<Object> unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(values).getResultList();
return new KeysetAwarePageImpl<>(unpagedResult);
}

Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(values, true);
PagedList<Object> resultList = (PagedList<Object>) paginatedCriteriaBuilder.getResultList();
Long total = resultList.getTotalSize();
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
Pageable pageable = accessor.getPageable();

if (total.equals(0L)) {
return new KeysetAwarePageImpl<>(Collections.emptyList(), total, null, pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.springframework.data.jpa.repository.query.JpaEntityGraph;
import org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor;
import org.springframework.data.jpa.repository.query.JpaQueryExecution;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.data.repository.query.parser.PartTree;

Expand Down Expand Up @@ -61,9 +59,9 @@ protected ParameterMetadataProvider createParameterMetadataProvider(CriteriaBuil
@Override
protected JpaQueryExecution getExecution() {
if (getQueryMethod().isSliceQuery()) {
return new PartTreeBlazePersistenceQuery.SlicedExecution(getQueryMethod().getParameters());
return new PartTreeBlazePersistenceQuery.SlicedExecution();
} else if (getQueryMethod().isPageQuery()) {
return new PartTreeBlazePersistenceQuery.PagedExecution(getQueryMethod().getParameters());
return new PartTreeBlazePersistenceQuery.PagedExecution();
} else if (isDelete()) {
return new PartTreeBlazePersistenceQuery.DeleteExecution(getEntityManager());
} else if (isExists()) {
Expand Down Expand Up @@ -95,19 +93,12 @@ protected Object doExecute(AbstractJpaQuery repositoryQuery, JpaParametersParame
*/
private static class SlicedExecution extends JpaQueryExecution {

private final Parameters<?, ?> parameters;

public SlicedExecution(Parameters<?, ?> parameters) {
this.parameters = parameters;
}

@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractJpaQuery repositoryQuery, JpaParametersParameterAccessor jpaParametersParameterAccessor) {
Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), false);
PagedList<Object> resultList = (PagedList<Object>) paginatedCriteriaBuilder.getResultList();
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues());
Pageable pageable = accessor.getPageable();
Pageable pageable = jpaParametersParameterAccessor.getPageable();

return new KeysetAwareSliceImpl<>(resultList, pageable);
}
Expand All @@ -121,20 +112,18 @@ protected Object doExecute(AbstractJpaQuery repositoryQuery, JpaParametersParame
*/
private static class PagedExecution extends JpaQueryExecution {

private final Parameters<?, ?> parameters;

public PagedExecution(Parameters<?, ?> parameters) {
this.parameters = parameters;
}

@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractJpaQuery repositoryQuery, JpaParametersParameterAccessor jpaParametersParameterAccessor) {
Pageable pageable = jpaParametersParameterAccessor.getPageable();
if (pageable.isUnpaged()) {
List<Object> unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(jpaParametersParameterAccessor).getResultList();
return new KeysetAwarePageImpl<>(unpagedResult);
}

Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), true);
PagedList<Object> resultList = (PagedList<Object>) paginatedCriteriaBuilder.getResultList();
Long total = resultList.getTotalSize();
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues());
Pageable pageable = accessor.getPageable();

if (total.equals(0L)) {
return new KeysetAwarePageImpl<>(Collections.emptyList(), total, null, pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.springframework.data.jpa.repository.query.JpaEntityGraph;
import org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor;
import org.springframework.data.jpa.repository.query.JpaQueryExecution;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.data.repository.query.parser.PartTree;

Expand Down Expand Up @@ -61,9 +59,9 @@ protected ParameterMetadataProvider createParameterMetadataProvider(CriteriaBuil
@Override
protected JpaQueryExecution getExecution() {
if (getQueryMethod().isSliceQuery()) {
return new PartTreeBlazePersistenceQuery.SlicedExecution(getQueryMethod().getParameters());
return new PartTreeBlazePersistenceQuery.SlicedExecution();
} else if (getQueryMethod().isPageQuery()) {
return new PartTreeBlazePersistenceQuery.PagedExecution(getQueryMethod().getParameters());
return new PartTreeBlazePersistenceQuery.PagedExecution();
} else if (isDelete()) {
return new PartTreeBlazePersistenceQuery.DeleteExecution(getEntityManager());
} else if (isExists()) {
Expand Down Expand Up @@ -95,19 +93,12 @@ protected Object doExecute(AbstractJpaQuery repositoryQuery, JpaParametersParame
*/
private static class SlicedExecution extends JpaQueryExecution {

private final Parameters<?, ?> parameters;

public SlicedExecution(Parameters<?, ?> parameters) {
this.parameters = parameters;
}

@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractJpaQuery repositoryQuery, JpaParametersParameterAccessor jpaParametersParameterAccessor) {
Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), false);
PagedList<Object> resultList = (PagedList<Object>) paginatedCriteriaBuilder.getResultList();
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues());
Pageable pageable = accessor.getPageable();
Pageable pageable = jpaParametersParameterAccessor.getPageable();

return new KeysetAwareSliceImpl<>(resultList, pageable);
}
Expand All @@ -121,20 +112,18 @@ protected Object doExecute(AbstractJpaQuery repositoryQuery, JpaParametersParame
*/
private static class PagedExecution extends JpaQueryExecution {

private final Parameters<?, ?> parameters;

public PagedExecution(Parameters<?, ?> parameters) {
this.parameters = parameters;
}

@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractJpaQuery repositoryQuery, JpaParametersParameterAccessor jpaParametersParameterAccessor) {
Pageable pageable = jpaParametersParameterAccessor.getPageable();
if (pageable.isUnpaged()) {
List<Object> unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(jpaParametersParameterAccessor).getResultList();
return new KeysetAwarePageImpl<>(unpagedResult);
}

Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), true);
PagedList<Object> resultList = (PagedList<Object>) paginatedCriteriaBuilder.getResultList();
Long total = resultList.getTotalSize();
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues());
Pageable pageable = accessor.getPageable();

if (total.equals(0L)) {
return new KeysetAwarePageImpl<>(Collections.emptyList(), total, null, pageable);
Expand Down
Loading
Loading