Skip to content

Commit 79923b6

Browse files
committed
Polishing.
Tried to clarify the two step process of `JdbcQueryExecution` construction in `PartTreeJdbcQuery` by comments and renaming. Original pull request #952
1 parent d191938 commit 79923b6

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQuery.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public class PartTreeJdbcQuery extends AbstractJdbcQuery {
5454
private final Dialect dialect;
5555
private final JdbcConverter converter;
5656
private final PartTree tree;
57-
private final JdbcQueryExecution<?> execution;
58-
private final RowMapper<Object> rowMapper;
57+
/** The execution for obtaining the bulk of the data. The execution may be decorated with further processing for handling sliced or paged queries */
58+
private final JdbcQueryExecution<?> coreExecution;
5959

6060
/**
6161
* Creates a new {@link PartTreeJdbcQuery}.
@@ -87,9 +87,8 @@ public PartTreeJdbcQuery(RelationalMappingContext context, JdbcQueryMethod query
8787

8888
ResultSetExtractor<Boolean> extractor = tree.isExistsProjection() ? (ResultSet::next) : null;
8989

90-
this.execution = queryMethod.isPageQuery() || queryMethod.isSliceQuery() ? collectionQuery(rowMapper)
90+
this.coreExecution = queryMethod.isPageQuery() || queryMethod.isSliceQuery() ? collectionQuery(rowMapper)
9191
: getQueryExecution(queryMethod, extractor, rowMapper);
92-
this.rowMapper = rowMapper;
9392
}
9493

9594
private Sort getDynamicSort(RelationalParameterAccessor accessor) {
@@ -106,20 +105,23 @@ public Object execute(Object[] values) {
106105
RelationalParametersParameterAccessor accessor = new RelationalParametersParameterAccessor(getQueryMethod(),
107106
values);
108107
ParametrizedQuery query = createQuery(accessor);
109-
JdbcQueryExecution<?> execution = getQueryExecution(accessor);
108+
JdbcQueryExecution<?> execution = getDecoratedExecution(accessor);
110109

111110
return execution.execute(query.getQuery(), query.getParameterSource());
112111
}
113112

114-
private JdbcQueryExecution<?> getQueryExecution(RelationalParametersParameterAccessor accessor) {
113+
/**
114+
* The decorated execution is the {@link #coreExecution} decorated with further processing for handling sliced or paged queries.
115+
*/
116+
private JdbcQueryExecution<?> getDecoratedExecution(RelationalParametersParameterAccessor accessor) {
115117

116118
if (getQueryMethod().isSliceQuery()) {
117-
return new SliceQueryExecution<>((JdbcQueryExecution<Collection<Object>>) this.execution, accessor.getPageable());
119+
return new SliceQueryExecution<>((JdbcQueryExecution<Collection<Object>>) this.coreExecution, accessor.getPageable());
118120
}
119121

120122
if (getQueryMethod().isPageQuery()) {
121123

122-
return new PageQueryExecution<>((JdbcQueryExecution<Collection<Object>>) this.execution, accessor.getPageable(),
124+
return new PageQueryExecution<>((JdbcQueryExecution<Collection<Object>>) this.coreExecution, accessor.getPageable(),
123125
() -> {
124126

125127
RelationalEntityMetadata<?> entityMetadata = getQueryMethod().getEntityInformation();
@@ -135,7 +137,7 @@ private JdbcQueryExecution<?> getQueryExecution(RelationalParametersParameterAcc
135137
});
136138
}
137139

138-
return this.execution;
140+
return this.coreExecution;
139141
}
140142

141143
protected ParametrizedQuery createQuery(RelationalParametersParameterAccessor accessor) {
@@ -192,8 +194,8 @@ static class PageQueryExecution<T> implements JdbcQueryExecution<Slice<T>> {
192194
private final Pageable pageable;
193195
private final LongSupplier countSupplier;
194196

195-
public PageQueryExecution(JdbcQueryExecution<? extends Collection<T>> delegate, Pageable pageable,
196-
LongSupplier countSupplier) {
197+
PageQueryExecution(JdbcQueryExecution<? extends Collection<T>> delegate, Pageable pageable,
198+
LongSupplier countSupplier) {
197199
this.delegate = delegate;
198200
this.pageable = pageable;
199201
this.countSupplier = countSupplier;

0 commit comments

Comments
 (0)