From 79923b66dc67f49a294a68eeab82a76b5dfaddc1 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Tue, 6 Apr 2021 14:08:51 +0200 Subject: [PATCH] Polishing. Tried to clarify the two step process of `JdbcQueryExecution` construction in `PartTreeJdbcQuery` by comments and renaming. Original pull request #952 --- .../repository/query/PartTreeJdbcQuery.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQuery.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQuery.java index 1107214b..ea361f53 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQuery.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQuery.java @@ -54,8 +54,8 @@ public class PartTreeJdbcQuery extends AbstractJdbcQuery { private final Dialect dialect; private final JdbcConverter converter; private final PartTree tree; - private final JdbcQueryExecution execution; - private final RowMapper rowMapper; + /** The execution for obtaining the bulk of the data. The execution may be decorated with further processing for handling sliced or paged queries */ + private final JdbcQueryExecution coreExecution; /** * Creates a new {@link PartTreeJdbcQuery}. @@ -87,9 +87,8 @@ public class PartTreeJdbcQuery extends AbstractJdbcQuery { ResultSetExtractor extractor = tree.isExistsProjection() ? (ResultSet::next) : null; - this.execution = queryMethod.isPageQuery() || queryMethod.isSliceQuery() ? collectionQuery(rowMapper) + this.coreExecution = queryMethod.isPageQuery() || queryMethod.isSliceQuery() ? collectionQuery(rowMapper) : getQueryExecution(queryMethod, extractor, rowMapper); - this.rowMapper = rowMapper; } private Sort getDynamicSort(RelationalParameterAccessor accessor) { @@ -106,20 +105,23 @@ public class PartTreeJdbcQuery extends AbstractJdbcQuery { RelationalParametersParameterAccessor accessor = new RelationalParametersParameterAccessor(getQueryMethod(), values); ParametrizedQuery query = createQuery(accessor); - JdbcQueryExecution execution = getQueryExecution(accessor); + JdbcQueryExecution execution = getDecoratedExecution(accessor); return execution.execute(query.getQuery(), query.getParameterSource()); } - private JdbcQueryExecution getQueryExecution(RelationalParametersParameterAccessor accessor) { + /** + * The decorated execution is the {@link #coreExecution} decorated with further processing for handling sliced or paged queries. + */ + private JdbcQueryExecution getDecoratedExecution(RelationalParametersParameterAccessor accessor) { if (getQueryMethod().isSliceQuery()) { - return new SliceQueryExecution<>((JdbcQueryExecution>) this.execution, accessor.getPageable()); + return new SliceQueryExecution<>((JdbcQueryExecution>) this.coreExecution, accessor.getPageable()); } if (getQueryMethod().isPageQuery()) { - return new PageQueryExecution<>((JdbcQueryExecution>) this.execution, accessor.getPageable(), + return new PageQueryExecution<>((JdbcQueryExecution>) this.coreExecution, accessor.getPageable(), () -> { RelationalEntityMetadata entityMetadata = getQueryMethod().getEntityInformation(); @@ -135,7 +137,7 @@ public class PartTreeJdbcQuery extends AbstractJdbcQuery { }); } - return this.execution; + return this.coreExecution; } protected ParametrizedQuery createQuery(RelationalParametersParameterAccessor accessor) { @@ -192,8 +194,8 @@ public class PartTreeJdbcQuery extends AbstractJdbcQuery { private final Pageable pageable; private final LongSupplier countSupplier; - public PageQueryExecution(JdbcQueryExecution> delegate, Pageable pageable, - LongSupplier countSupplier) { + PageQueryExecution(JdbcQueryExecution> delegate, Pageable pageable, + LongSupplier countSupplier) { this.delegate = delegate; this.pageable = pageable; this.countSupplier = countSupplier;