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..7b32f2bab4 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 @@ -59,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()) { @@ -93,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); @@ -119,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 == 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..666021134c 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 @@ -63,9 +63,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 +97,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 +116,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/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/DynamicViewTypeDocumentRepositoryTest.java b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/DynamicViewTypeDocumentRepositoryTest.java new file mode 100644 index 0000000000..4a3038af09 --- /dev/null +++ b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/DynamicViewTypeDocumentRepositoryTest.java @@ -0,0 +1,103 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Blazebit + */ +package com.blazebit.persistence.spring.data.testsuite.webmvc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import com.blazebit.persistence.integration.view.spring.EnableEntityViews; +import com.blazebit.persistence.spring.data.repository.config.EnableBlazeRepositories; +import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Document; +import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Person; +import com.blazebit.persistence.spring.data.testsuite.webmvc.repository.DynamicViewTypeDocumentRepository; +import com.blazebit.persistence.spring.data.testsuite.webmvc.tx.TransactionalWorkService; +import com.blazebit.persistence.spring.data.testsuite.webmvc.tx.TxWork; +import com.blazebit.persistence.spring.data.testsuite.webmvc.view.DocumentView; +import com.blazebit.persistence.view.EntityViewManager; +import java.util.List; +import java.util.stream.Collectors; +import javax.persistence.EntityManager; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.ImportResource; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; + +@ContextConfiguration(classes = DynamicViewTypeDocumentRepositoryTest.TestConfig.class) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +public class DynamicViewTypeDocumentRepositoryTest extends AbstractSpringTest { + + @Autowired + private DynamicViewTypeDocumentRepository documentRepository; + @Autowired + private TransactionalWorkService transactionalWorkService; + + @Test + public void dynamicProjectionWithUnpagedPagination() { + // Given + final Document d1 = createDocument("A"); + final Document d2 = createDocument("A"); + createDocument("B"); + + // When + Page d = documentRepository.findByName( + "A", DocumentView.class, 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(DocumentView::getId).collect(Collectors.toList()); + assertTrue(resultIds.contains(d1.getId())); + assertTrue(resultIds.contains(d2.getId())); + } + + private Document createDocument(String name) { + return createDocument(name, null); + } + + private Document createDocument(final String name, final Person owner) { + return createDocument(name, null, 0L, owner); + } + + private Document createDocument(final String name, final String description, final long age, final Person owner) { + return transactionalWorkService.doTxWork((em, evm) -> { + Document d = new Document(name); + d.setDescription(description); + d.setAge(age); + em.persist(d); + if (owner != null) { + d.setOwner(em.getReference(Person.class, owner.getId())); + } + return d; + }); + } + + @Configuration + @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = ".*TestConfig")) + @ImportResource("classpath:/com/blazebit/persistence/spring/data/testsuite/webmvc/application-config.xml") + @EnableEntityViews(basePackages = "com.blazebit.persistence.spring.data.testsuite.webmvc.view") + @EnableBlazeRepositories( + basePackages = "com.blazebit.persistence.spring.data.testsuite.webmvc.repository", + entityManagerFactoryRef = "myEmf" + ) + static class TestConfig { + } +} 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/DynamicViewTypeDocumentRepository.java b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/repository/DynamicViewTypeDocumentRepository.java new file mode 100644 index 0000000000..8bd8cd8c04 --- /dev/null +++ b/integration/spring-data/testsuite/webmvc/src/test/java/com/blazebit/persistence/spring/data/testsuite/webmvc/repository/DynamicViewTypeDocumentRepository.java @@ -0,0 +1,18 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Blazebit + */ +package com.blazebit.persistence.spring.data.testsuite.webmvc.repository; + +import com.blazebit.persistence.spring.data.testsuite.webmvc.entity.Document; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +@Repository +@Transactional(readOnly = true) +public interface DynamicViewTypeDocumentRepository extends org.springframework.data.repository.Repository { + + 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/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();