Skip to content

Commit 3c4fbb4

Browse files
author
Artemiy Degtyarev
committed
add: limit support
Signed-off-by: Artemiy Degtyarev <[email protected]>
1 parent b176483 commit 3c4fbb4

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ private JdbcQueryExecution<?> getQueryExecution(ResultProcessor processor,
191191

192192
if (getQueryMethod().isScrollQuery()) {
193193
//noinspection unchecked
194-
return new ScrollQueryExecution<>((JdbcQueryExecution<Collection<Object>>) queryExecution, accessor.getScrollPosition(), this.tree.getMaxResults(), tree.getSort());
194+
return new ScrollQueryExecution<>((JdbcQueryExecution<Collection<Object>>) queryExecution, accessor.getScrollPosition(), this.tree.getMaxResults(), tree.getSort(), tree.getResultLimit());
195195
}
196196

197197
if (getQueryMethod().isSliceQuery()) {
@@ -260,15 +260,17 @@ private JdbcQueryExecution<?> getJdbcQueryExecution(@Nullable ResultSetExtractor
260260

261261
static class ScrollQueryExecution<T> implements JdbcQueryExecution<Window<T>> {
262262
private final JdbcQueryExecution<? extends Collection<T>> delegate;
263-
private final ScrollPosition position;
263+
private final @Nullable ScrollPosition position;
264264
private final @Nullable Integer maxResults;
265265
private final Sort sort;
266+
private final Limit limit;
266267

267-
ScrollQueryExecution(JdbcQueryExecution<? extends Collection<T>> delegate, ScrollPosition position, @Nullable Integer maxResults, Sort sort) {
268+
ScrollQueryExecution(JdbcQueryExecution<? extends Collection<T>> delegate, @Nullable ScrollPosition position, @Nullable Integer maxResults, Sort sort, Limit limit) {
268269
this.delegate = delegate;
269270
this.position = position;
270271
this.maxResults = maxResults;
271272
this.sort = sort;
273+
this.limit = limit;
272274
}
273275

274276
@Override
@@ -293,7 +295,16 @@ static class ScrollQueryExecution<T> implements JdbcQueryExecution<Window<T>> {
293295
positionFunction = (ignoredI) -> ScrollPosition.of(finalKeys, ((KeysetScrollPosition) position).getDirection()) ;
294296
}
295297

296-
boolean hasNext = resultList.size() >= maxResults;
298+
if (positionFunction == null)
299+
throw new UnsupportedOperationException("Not supported scroll type.");
300+
301+
boolean hasNext;
302+
if (maxResults != null)
303+
hasNext = resultList.size() >= maxResults;
304+
else if (limit.isLimited())
305+
hasNext = resultList.size() >= limit.max();
306+
else
307+
hasNext = !resultList.isEmpty();
297308

298309
return Window.from(resultList, positionFunction, hasNext);
299310
}

0 commit comments

Comments
 (0)