diff --git a/README.md b/README.md index 9fdd1c55dd..6785604ddd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/integration/spring-data/1.x/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java b/integration/spring-data/1.x/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java index 03f418f822..33c20208bf 100644 --- a/integration/spring-data/1.x/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java +++ b/integration/spring-data/1.x/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java @@ -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; @@ -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()) { @@ -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 resultList = (PagedList) 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); @@ -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 unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(values).getResultList(); + return new KeysetAwarePageImpl<>(unpagedResult); + } + Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(values, true); PagedList resultList = (PagedList) 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); diff --git a/integration/spring-data/2.0/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java b/integration/spring-data/2.0/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java index f52cc0021f..3eba93f2e7 100644 --- a/integration/spring-data/2.0/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java +++ b/integration/spring-data/2.0/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java @@ -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; @@ -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()) { @@ -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 resultList = (PagedList) 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); @@ -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 unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(values).getResultList(); + return new KeysetAwarePageImpl<>(unpagedResult); + } + Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(values, true); PagedList resultList = (PagedList) 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); diff --git a/integration/spring-data/2.1/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java b/integration/spring-data/2.1/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java index be1b14780f..8f791c0d84 100644 --- a/integration/spring-data/2.1/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java +++ b/integration/spring-data/2.1/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java @@ -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; @@ -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()) { @@ -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 resultList = (PagedList) 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); @@ -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 unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(values).getResultList(); + return new KeysetAwarePageImpl<>(unpagedResult); + } + Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(values, true); PagedList resultList = (PagedList) 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); diff --git a/integration/spring-data/2.2/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java b/integration/spring-data/2.2/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java index 8bf734fbe9..8bf325c026 100644 --- a/integration/spring-data/2.2/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java +++ b/integration/spring-data/2.2/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java @@ -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; @@ -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()) { @@ -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 resultList = (PagedList) paginatedCriteriaBuilder.getResultList(); - ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues()); - Pageable pageable = accessor.getPageable(); + Pageable pageable = jpaParametersParameterAccessor.getPageable(); return new KeysetAwareSliceImpl<>(resultList, pageable); } @@ -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 unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(jpaParametersParameterAccessor).getResultList(); + return new KeysetAwarePageImpl<>(unpagedResult); + } + Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), true); PagedList resultList = (PagedList) 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); diff --git a/integration/spring-data/2.3/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java b/integration/spring-data/2.3/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java index 8bf734fbe9..8bf325c026 100644 --- a/integration/spring-data/2.3/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java +++ b/integration/spring-data/2.3/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java @@ -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; @@ -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()) { @@ -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 resultList = (PagedList) paginatedCriteriaBuilder.getResultList(); - ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues()); - Pageable pageable = accessor.getPageable(); + Pageable pageable = jpaParametersParameterAccessor.getPageable(); return new KeysetAwareSliceImpl<>(resultList, pageable); } @@ -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 unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(jpaParametersParameterAccessor).getResultList(); + return new KeysetAwarePageImpl<>(unpagedResult); + } + Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), true); PagedList resultList = (PagedList) 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); diff --git a/integration/spring-data/2.4/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java b/integration/spring-data/2.4/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java index e8adbb21e0..e10b825d60 100644 --- a/integration/spring-data/2.4/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java +++ b/integration/spring-data/2.4/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java @@ -25,8 +25,6 @@ import org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor; import org.springframework.data.jpa.repository.query.JpaQueryExecution; import org.springframework.data.jpa.repository.support.QueryHints; -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; @@ -63,9 +61,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()) { @@ -97,19 +95,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 resultList = (PagedList) paginatedCriteriaBuilder.getResultList(); - ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues()); - Pageable pageable = accessor.getPageable(); + Pageable pageable = jpaParametersParameterAccessor.getPageable(); return new KeysetAwareSliceImpl<>(resultList, pageable); } @@ -123,20 +114,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 unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(jpaParametersParameterAccessor).getResultList(); + return new KeysetAwarePageImpl<>(unpagedResult); + } + Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), true); PagedList resultList = (PagedList) 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); diff --git a/integration/spring-data/2.5/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java b/integration/spring-data/2.5/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java index e8adbb21e0..e10b825d60 100644 --- a/integration/spring-data/2.5/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java +++ b/integration/spring-data/2.5/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java @@ -25,8 +25,6 @@ import org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor; import org.springframework.data.jpa.repository.query.JpaQueryExecution; import org.springframework.data.jpa.repository.support.QueryHints; -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; @@ -63,9 +61,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()) { @@ -97,19 +95,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 resultList = (PagedList) paginatedCriteriaBuilder.getResultList(); - ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues()); - Pageable pageable = accessor.getPageable(); + Pageable pageable = jpaParametersParameterAccessor.getPageable(); return new KeysetAwareSliceImpl<>(resultList, pageable); } @@ -123,20 +114,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 unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(jpaParametersParameterAccessor).getResultList(); + return new KeysetAwarePageImpl<>(unpagedResult); + } + Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), true); PagedList resultList = (PagedList) 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); diff --git a/integration/spring-data/2.6/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java b/integration/spring-data/2.6/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java index e8adbb21e0..e10b825d60 100644 --- a/integration/spring-data/2.6/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java +++ b/integration/spring-data/2.6/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java @@ -25,8 +25,6 @@ import org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor; import org.springframework.data.jpa.repository.query.JpaQueryExecution; import org.springframework.data.jpa.repository.support.QueryHints; -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; @@ -63,9 +61,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()) { @@ -97,19 +95,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 resultList = (PagedList) paginatedCriteriaBuilder.getResultList(); - ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues()); - Pageable pageable = accessor.getPageable(); + Pageable pageable = jpaParametersParameterAccessor.getPageable(); return new KeysetAwareSliceImpl<>(resultList, pageable); } @@ -123,20 +114,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 unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(jpaParametersParameterAccessor).getResultList(); + return new KeysetAwarePageImpl<>(unpagedResult); + } + Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), true); PagedList resultList = (PagedList) 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); diff --git a/integration/spring-data/2.7/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java b/integration/spring-data/2.7/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java index e8adbb21e0..e10b825d60 100644 --- a/integration/spring-data/2.7/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java +++ b/integration/spring-data/2.7/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java @@ -25,8 +25,6 @@ import org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor; import org.springframework.data.jpa.repository.query.JpaQueryExecution; import org.springframework.data.jpa.repository.support.QueryHints; -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; @@ -63,9 +61,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()) { @@ -97,19 +95,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 resultList = (PagedList) paginatedCriteriaBuilder.getResultList(); - ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues()); - Pageable pageable = accessor.getPageable(); + Pageable pageable = jpaParametersParameterAccessor.getPageable(); return new KeysetAwareSliceImpl<>(resultList, pageable); } @@ -123,20 +114,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 unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(jpaParametersParameterAccessor).getResultList(); + return new KeysetAwarePageImpl<>(unpagedResult); + } + Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), true); PagedList resultList = (PagedList) 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); diff --git a/integration/spring-data/3.1/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java b/integration/spring-data/3.1/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java index 18dbe0922a..5e8899946a 100644 --- a/integration/spring-data/3.1/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java +++ b/integration/spring-data/3.1/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java @@ -25,8 +25,6 @@ import org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor; import org.springframework.data.jpa.repository.query.JpaQueryExecution; import org.springframework.data.jpa.repository.support.QueryHints; -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; import jakarta.persistence.EntityManager; @@ -64,9 +62,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()) { @@ -98,19 +96,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 resultList = (PagedList) paginatedCriteriaBuilder.getResultList(); - ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues()); - Pageable pageable = accessor.getPageable(); + Pageable pageable = jpaParametersParameterAccessor.getPageable(); return new KeysetAwareSliceImpl<>(resultList, pageable); } @@ -124,20 +115,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 unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(jpaParametersParameterAccessor).getResultList(); + return new KeysetAwarePageImpl<>(unpagedResult); + } + Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), true); PagedList resultList = (PagedList) 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); diff --git a/integration/spring-data/3.3/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java b/integration/spring-data/3.3/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java index 18dbe0922a..5e8899946a 100644 --- a/integration/spring-data/3.3/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java +++ b/integration/spring-data/3.3/src/main/java/com/blazebit/persistence/spring/data/impl/query/PartTreeBlazePersistenceQuery.java @@ -25,8 +25,6 @@ import org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor; import org.springframework.data.jpa.repository.query.JpaQueryExecution; import org.springframework.data.jpa.repository.support.QueryHints; -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; import jakarta.persistence.EntityManager; @@ -64,9 +62,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()) { @@ -98,19 +96,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 resultList = (PagedList) paginatedCriteriaBuilder.getResultList(); - ParameterAccessor accessor = new ParametersParameterAccessor(parameters, jpaParametersParameterAccessor.getValues()); - Pageable pageable = accessor.getPageable(); + Pageable pageable = jpaParametersParameterAccessor.getPageable(); return new KeysetAwareSliceImpl<>(resultList, pageable); } @@ -124,20 +115,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 unpagedResult = ((PartTreeBlazePersistenceQuery) repositoryQuery).createQuery(jpaParametersParameterAccessor).getResultList(); + return new KeysetAwarePageImpl<>(unpagedResult); + } + Query paginatedCriteriaBuilder = ((PartTreeBlazePersistenceQuery) repositoryQuery).createPaginatedQuery(jpaParametersParameterAccessor.getValues(), true); PagedList resultList = (PagedList) 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); diff --git a/integration/spring-data/base-3.1/src/main/java/com/blazebit/persistence/spring/data/base/query/ParameterBinder.java b/integration/spring-data/base-3.1/src/main/java/com/blazebit/persistence/spring/data/base/query/ParameterBinder.java index 003f2c85f8..e39c3c0d8a 100644 --- a/integration/spring-data/base-3.1/src/main/java/com/blazebit/persistence/spring/data/base/query/ParameterBinder.java +++ b/integration/spring-data/base-3.1/src/main/java/com/blazebit/persistence/spring/data/base/query/ParameterBinder.java @@ -165,7 +165,7 @@ private Query bindAndPrepare(Query query, Parameters parameters) { Query result = bind(query); - if (!parameters.hasPageableParameter() || getPageable() == null) { + if (!parameters.hasPageableParameter() || getPageable().isUnpaged()) { return result; } diff --git a/integration/spring-data/base-3.1/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java b/integration/spring-data/base-3.1/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java index 9d7f67257f..d6f339dbde 100644 --- a/integration/spring-data/base-3.1/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java +++ b/integration/spring-data/base-3.1/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java @@ -76,18 +76,6 @@ public abstract class AbstractEntityViewAwareRepository Page findAll(Example example, Pageable pageable) { Class probeType = example.getProbeType(); TypedQuery query = getQuery(new ExampleSpecification<>(example, escapeCharacter), probeType, pageable); - return pageable == null || pageable == UNPAGED ? new KeysetAwarePageImpl<>(query.getResultList()) : new KeysetAwarePageImpl<>((PagedList) query.getResultList(), pageable); + return pageable.isUnpaged() ? new KeysetAwarePageImpl<>(query.getResultList()) : new KeysetAwarePageImpl<>((PagedList) query.getResultList(), pageable); } public List findAll(Sort sort) { @@ -351,7 +339,7 @@ public List findAll(Sort sort) { } public Page findAll(Pageable pageable) { - if (pageable == null || pageable == UNPAGED) { + if (pageable.isUnpaged()) { return (Page) new PageImpl<>(findAll()); } @@ -561,7 +549,7 @@ public List findAll(Specification spec) { public Page findAll(Specification spec, Pageable pageable) { TypedQuery query = getQuery(spec, pageable); - if (pageable == null || pageable == UNPAGED) { + if (pageable.isUnpaged()) { return new KeysetAwarePageImpl<>(query.getResultList()); } PagedList resultList = (PagedList) query.getResultList(); @@ -623,7 +611,7 @@ protected TypedQuery getQuery(Specification spec, Class d TypedQuery query; if (entityViewClass == null) { - if (pageable == null || pageable == UNPAGED) { + if (pageable.isUnpaged()) { query = (TypedQuery) cb.getQuery(); } else { PaginatedCriteriaBuilder paginatedCriteriaBuilder; @@ -644,7 +632,7 @@ protected TypedQuery getQuery(Specification spec, Class d query = (TypedQuery) paginatedCriteriaBuilder.getQuery(); } } else { - if (pageable == null || pageable == UNPAGED) { + if (pageable.isUnpaged()) { EntityViewSetting> setting = EntityViewSetting.create(entityViewClass); CriteriaBuilder fqb = evm.applySetting(setting, cb); if (sort != null) { diff --git a/integration/spring-data/base-3.3/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java b/integration/spring-data/base-3.3/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java index 9d7f67257f..d6f339dbde 100644 --- a/integration/spring-data/base-3.3/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java +++ b/integration/spring-data/base-3.3/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java @@ -76,18 +76,6 @@ public abstract class AbstractEntityViewAwareRepository Page findAll(Example example, Pageable pageable) { Class probeType = example.getProbeType(); TypedQuery query = getQuery(new ExampleSpecification<>(example, escapeCharacter), probeType, pageable); - return pageable == null || pageable == UNPAGED ? new KeysetAwarePageImpl<>(query.getResultList()) : new KeysetAwarePageImpl<>((PagedList) query.getResultList(), pageable); + return pageable.isUnpaged() ? new KeysetAwarePageImpl<>(query.getResultList()) : new KeysetAwarePageImpl<>((PagedList) query.getResultList(), pageable); } public List findAll(Sort sort) { @@ -351,7 +339,7 @@ public List findAll(Sort sort) { } public Page findAll(Pageable pageable) { - if (pageable == null || pageable == UNPAGED) { + if (pageable.isUnpaged()) { return (Page) new PageImpl<>(findAll()); } @@ -561,7 +549,7 @@ public List findAll(Specification spec) { public Page findAll(Specification spec, Pageable pageable) { TypedQuery query = getQuery(spec, pageable); - if (pageable == null || pageable == UNPAGED) { + if (pageable.isUnpaged()) { return new KeysetAwarePageImpl<>(query.getResultList()); } PagedList resultList = (PagedList) query.getResultList(); @@ -623,7 +611,7 @@ protected TypedQuery getQuery(Specification spec, Class d TypedQuery query; if (entityViewClass == null) { - if (pageable == null || pageable == UNPAGED) { + if (pageable.isUnpaged()) { query = (TypedQuery) cb.getQuery(); } else { PaginatedCriteriaBuilder paginatedCriteriaBuilder; @@ -644,7 +632,7 @@ protected TypedQuery getQuery(Specification spec, Class d query = (TypedQuery) paginatedCriteriaBuilder.getQuery(); } } else { - if (pageable == null || pageable == UNPAGED) { + if (pageable.isUnpaged()) { EntityViewSetting> setting = EntityViewSetting.create(entityViewClass); CriteriaBuilder fqb = evm.applySetting(setting, cb); if (sort != null) { diff --git a/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/PageableUtil.java b/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/PageableUtil.java new file mode 100644 index 0000000000..72dd40d60e --- /dev/null +++ b/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/PageableUtil.java @@ -0,0 +1,32 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Blazebit + */ + +package com.blazebit.persistence.spring.data.base; + +import java.lang.reflect.Method; +import org.springframework.data.domain.Pageable; + +public final class PageableUtil { + + private static final Pageable UNPAGED; + + static { + Pageable unpaged = null; + try { + Method unpagedMethod = Class.forName("org.springframework.data.domain.Pageable").getMethod("unpaged"); + unpaged = (Pageable) unpagedMethod.invoke(null); + } catch (Exception e) { + // ignore + } + UNPAGED = unpaged; + } + + private PageableUtil() { + } + + public static boolean isUnpaged(Pageable pageable) { + return pageable == null || pageable == UNPAGED; + } +} diff --git a/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/query/ParameterBinder.java b/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/query/ParameterBinder.java index 727a97747c..72cdc87430 100644 --- a/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/query/ParameterBinder.java +++ b/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/query/ParameterBinder.java @@ -15,6 +15,7 @@ */ package com.blazebit.persistence.spring.data.base.query; +import com.blazebit.persistence.spring.data.base.PageableUtil; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.query.AbstractJpaQuery; @@ -163,12 +164,13 @@ private Query bindAndPrepare(Query query, Parameters parameters) { Query result = bind(query); - if (!parameters.hasPageableParameter() || getPageable() == null) { + Pageable pageable; + if (!parameters.hasPageableParameter() || PageableUtil.isUnpaged(pageable = getPageable())) { return result; } result.setFirstResult(getOffset()); - result.setMaxResults(getPageable().getPageSize()); + result.setMaxResults(pageable.getPageSize()); return result; } diff --git a/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java b/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java index 6f2192de1b..8e6dfd6252 100644 --- a/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java +++ b/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java @@ -15,6 +15,7 @@ import com.blazebit.persistence.parser.EntityMetamodel; import com.blazebit.persistence.spi.ExtendedManagedType; import com.blazebit.persistence.spring.data.base.EntityViewSortUtil; +import com.blazebit.persistence.spring.data.base.PageableUtil; import com.blazebit.persistence.spring.data.base.query.KeysetAwarePageImpl; import com.blazebit.persistence.spring.data.repository.KeysetPageable; import com.blazebit.persistence.view.EntityViewManager; @@ -69,18 +70,6 @@ public abstract class AbstractEntityViewAwareRepository Page findAll(Example example, Pageable pageable) { Class probeType = example.getProbeType(); TypedQuery query = getQuery(new ExampleSpecification<>(example, escapeCharacter), probeType, pageable); - return pageable == null || pageable == UNPAGED ? new KeysetAwarePageImpl<>(query.getResultList()) : new KeysetAwarePageImpl<>((PagedList) query.getResultList(), pageable); + return PageableUtil.isUnpaged(pageable) ? new KeysetAwarePageImpl<>(query.getResultList()) : new KeysetAwarePageImpl<>((PagedList) query.getResultList(), pageable); } public List findAll(Sort sort) { @@ -339,7 +328,7 @@ public List findAll(Sort sort) { } public Page findAll(Pageable pageable) { - if (pageable == null || pageable == UNPAGED) { + if (PageableUtil.isUnpaged(pageable)) { return (Page) new PageImpl<>(findAll()); } @@ -502,7 +491,7 @@ public List findAll(Specification spec) { public Page findAll(Specification spec, Pageable pageable) { TypedQuery query = getQuery(spec, pageable); - if (pageable == null || pageable == UNPAGED) { + if (PageableUtil.isUnpaged(pageable)) { return new KeysetAwarePageImpl<>(query.getResultList()); } PagedList resultList = (PagedList) query.getResultList(); @@ -564,7 +553,7 @@ protected TypedQuery getQuery(Specification spec, Class d TypedQuery query; if (entityViewClass == null) { - if (pageable == null || pageable == UNPAGED) { + if (PageableUtil.isUnpaged(pageable)) { query = (TypedQuery) cb.getQuery(); } else { PaginatedCriteriaBuilder paginatedCriteriaBuilder; @@ -585,7 +574,7 @@ protected TypedQuery getQuery(Specification spec, Class d query = (TypedQuery) paginatedCriteriaBuilder.getQuery(); } } else { - if (pageable == null || pageable == UNPAGED) { + if (PageableUtil.isUnpaged(pageable)) { EntityViewSetting> setting = EntityViewSetting.create(entityViewClass); CriteriaBuilder fqb = evm.applySetting(setting, cb); if (sort != null) { diff --git a/integration/spring-data/testsuite/webmvc/src/main/java/com/blazebit/persistence/spring/data/testsuite/webmvc/entity/Document.java b/integration/spring-data/testsuite/webmvc/src/main/java/com/blazebit/persistence/spring/data/testsuite/webmvc/entity/Document.java index 32ab322e3b..949b3f9986 100644 --- a/integration/spring-data/testsuite/webmvc/src/main/java/com/blazebit/persistence/spring/data/testsuite/webmvc/entity/Document.java +++ b/integration/spring-data/testsuite/webmvc/src/main/java/com/blazebit/persistence/spring/data/testsuite/webmvc/entity/Document.java @@ -14,7 +14,6 @@ import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; -import java.io.Serializable; /** * @author Moritz Becker @@ -25,7 +24,7 @@ @NamedQuery(name = "findIdOfD1", query = "select d.id from Document d where d.name = 'D1'") }) @Entity -public class Document implements Serializable { +public class Document implements Identifiable { private Long id; private String name; @@ -43,6 +42,7 @@ public Document(String name) { @Id @GeneratedValue + @Override public Long getId() { return id; } diff --git a/integration/spring-data/testsuite/webmvc/src/main/java/com/blazebit/persistence/spring/data/testsuite/webmvc/entity/Identifiable.java b/integration/spring-data/testsuite/webmvc/src/main/java/com/blazebit/persistence/spring/data/testsuite/webmvc/entity/Identifiable.java new file mode 100644 index 0000000000..85db4bb352 --- /dev/null +++ b/integration/spring-data/testsuite/webmvc/src/main/java/com/blazebit/persistence/spring/data/testsuite/webmvc/entity/Identifiable.java @@ -0,0 +1,11 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Blazebit + */ + +package com.blazebit.persistence.spring.data.testsuite.webmvc.entity; + +public interface Identifiable { + + T getId(); +} diff --git a/integration/spring-data/testsuite/webmvc/src/main/java/com/blazebit/persistence/spring/data/testsuite/webmvc/entity/Person.java b/integration/spring-data/testsuite/webmvc/src/main/java/com/blazebit/persistence/spring/data/testsuite/webmvc/entity/Person.java index 7b9c174dc6..9d2d0128c4 100644 --- a/integration/spring-data/testsuite/webmvc/src/main/java/com/blazebit/persistence/spring/data/testsuite/webmvc/entity/Person.java +++ b/integration/spring-data/testsuite/webmvc/src/main/java/com/blazebit/persistence/spring/data/testsuite/webmvc/entity/Person.java @@ -9,7 +9,6 @@ import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; -import java.io.Serializable; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -20,7 +19,7 @@ * @since 1.5.0 */ @Entity -public class Person implements Serializable { +public class Person implements Identifiable { private static final long serialVersionUID = 1L; private String id; @@ -38,6 +37,7 @@ public Person(String name) { } @Id + @Override public String getId() { return id; } diff --git a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/ReadOnlyDocumentRepositoryTest.java b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/ReadOnlyDocumentRepositoryTest.java index 1db3f629d7..f538b98f98 100644 --- a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/ReadOnlyDocumentRepositoryTest.java +++ b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/ReadOnlyDocumentRepositoryTest.java @@ -15,6 +15,7 @@ import com.blazebit.persistence.spring.data.testsuite.webmvc.accessor.DocumentAccessors; import com.blazebit.persistence.spring.data.testsuite.webmvc.config.SystemPropertyBasedActiveProfilesResolver; import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Document; +import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Identifiable; import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.MyEnum; import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Person; import com.blazebit.persistence.spring.data.testsuite.webmvc.repository.ReadOnlyDocumentEntityRepository; @@ -36,6 +37,7 @@ import com.blazebit.persistence.view.EntityViewSetting; import com.blazebit.persistence.view.Sorters; +import java.util.stream.Collectors; import org.junit.Assert; import org.junit.Assume; import org.junit.Before; @@ -885,6 +887,41 @@ public void testSortByExpression() { } } + @Test + public void dynamicProjectionWithUnpagedPagination() { + // Given + final Document d1 = createDocument("A"); + final Document d2 = createDocument("A"); + createDocument("B"); + + // When + Class> projectionClass; + if (repositoryClass == ReadOnlyDocumentEntityRepository.class) { + projectionClass = Document.class; + } else { + projectionClass = DocumentView.class; + } + Page> d = readOnlyDocumentRepository.findByName( + "A", projectionClass, Pageable.unpaged()); + + // Then + assertEquals(2, d.getTotalElements()); + assertEquals(1, d.getTotalPages()); + assertEquals(0, d.getNumber()); + assertEquals(2, d.getSize()); + assertEquals(2, d.getNumberOfElements()); + assertFalse(d.hasNext()); + assertFalse(d.hasPrevious()); + assertTrue(d.hasContent()); + assertFalse(d.isEmpty()); + assertTrue(d.isFirst()); + assertTrue(d.isLast()); + assertEquals(2, d.getContent().size()); + List resultIds = d.getContent().stream().map(Identifiable::getId).collect(Collectors.toList()); + assertTrue(resultIds.contains(d1.getId())); + assertTrue(resultIds.contains(d2.getId())); + } + private Pageable unpaged() { try { Method unpaged = Class.forName("org.springframework.data.domain.Pageable").getMethod("unpaged"); diff --git a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/repository/ReadOnlyDocumentRepository.java b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/repository/ReadOnlyDocumentRepository.java index 6708c20da7..cee35f783f 100644 --- a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/repository/ReadOnlyDocumentRepository.java +++ b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/repository/ReadOnlyDocumentRepository.java @@ -99,4 +99,6 @@ public interface ReadOnlyDocumentRepository extends EntityViewRepository findAllByOrderByNameAsc(Sort sort, EntityViewSettingProcessor processor); int countDocumentsByStatus(MyEnum status); + + Page findByName(String name, Class type, Pageable pageable); } diff --git a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/DocumentUpdateView.java b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/DocumentUpdateView.java index 96733f5b3e..6639e37f8a 100644 --- a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/DocumentUpdateView.java +++ b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/DocumentUpdateView.java @@ -6,6 +6,7 @@ package com.blazebit.persistence.spring.data.testsuite.webmvc.view; import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Document; +import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Identifiable; import com.blazebit.persistence.view.EntityView; import com.blazebit.persistence.view.IdMapping; import com.blazebit.persistence.view.UpdatableEntityView; @@ -16,9 +17,10 @@ */ @UpdatableEntityView @EntityView(Document.class) -public interface DocumentUpdateView { +public interface DocumentUpdateView extends Identifiable { @IdMapping + @Override Long getId(); String getName(); diff --git a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/DocumentView.java b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/DocumentView.java index 4c2dbabf44..28ee90d6ab 100644 --- a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/DocumentView.java +++ b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/DocumentView.java @@ -6,6 +6,7 @@ package com.blazebit.persistence.spring.data.testsuite.webmvc.view; import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Document; +import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Identifiable; import com.blazebit.persistence.view.EntityView; import com.blazebit.persistence.view.IdMapping; import com.blazebit.persistence.view.Mapping; @@ -18,9 +19,10 @@ * @since 1.5.0 */ @EntityView(Document.class) -public interface DocumentView { +public interface DocumentView extends Identifiable { @IdMapping + @Override Long getId(); String getName(); diff --git a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/PersonUpdateView.java b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/PersonUpdateView.java index 86b9367cb1..f0a39f68d4 100644 --- a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/PersonUpdateView.java +++ b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/PersonUpdateView.java @@ -5,6 +5,7 @@ package com.blazebit.persistence.spring.data.testsuite.webmvc.view; +import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Identifiable; import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Person; import com.blazebit.persistence.view.EntityView; import com.blazebit.persistence.view.IdMapping; @@ -18,9 +19,10 @@ */ @UpdatableEntityView @EntityView(Person.class) -public interface PersonUpdateView { +public interface PersonUpdateView extends Identifiable { @IdMapping + @Override UUID getId(); String getName(); diff --git a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/PersonView.java b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/PersonView.java index e17ea69802..57cc8bce1c 100644 --- a/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/PersonView.java +++ b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/view/PersonView.java @@ -5,6 +5,7 @@ package com.blazebit.persistence.spring.data.testsuite.webmvc.view; +import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Identifiable; import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Person; import com.blazebit.persistence.view.EntityView; import com.blazebit.persistence.view.IdMapping; @@ -16,9 +17,10 @@ * @since 1.5.0 */ @EntityView(Person.class) -public interface PersonView { +public interface PersonView extends Identifiable { @IdMapping + @Override UUID getId(); String getName();