From 5e1d1b2919786c63c3c32206372f873350f51f2a Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 2 Apr 2020 14:20:45 +0200 Subject: [PATCH] #335 - Consider Pageable in derived queries. We now consider Pageable arguments in derived queries. Previously only limiting queries (findFirst10) were considered. --- .../repository/query/R2dbcQueryCreator.java | 11 +++- ...stractR2dbcRepositoryIntegrationTests.java | 54 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryCreator.java b/src/main/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryCreator.java index 291df57..1e55918 100644 --- a/src/main/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryCreator.java +++ b/src/main/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryCreator.java @@ -18,6 +18,7 @@ package org.springframework.data.r2dbc.repository.query; import java.util.List; import java.util.stream.Collectors; +import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.r2dbc.core.PreparedOperation; import org.springframework.data.r2dbc.core.ReactiveDataAccessStrategy; @@ -43,6 +44,7 @@ import org.springframework.util.Assert; public class R2dbcQueryCreator extends RelationalQueryCreator> { private final PartTree tree; + private final RelationalParameterAccessor accessor; private final ReactiveDataAccessStrategy dataAccessStrategy; private final RelationalEntityMetadata entityMetadata; @@ -58,11 +60,13 @@ public class R2dbcQueryCreator extends RelationalQueryCreator entityMetadata, RelationalParameterAccessor accessor) { super(tree, accessor); - this.tree = tree; Assert.notNull(dataAccessStrategy, "Data access strategy must not be null"); Assert.notNull(entityMetadata, "Relational entity metadata must not be null"); + this.tree = tree; + this.accessor = accessor; + this.dataAccessStrategy = dataAccessStrategy; this.entityMetadata = entityMetadata; } @@ -87,6 +91,11 @@ public class R2dbcQueryCreator extends RelationalQueryCreator sets = Flux.fromStream(IntStream.range(0, 100).mapToObj(value -> { + return new LegoSet(null, "Set " + value, value); + })); + + repository.saveAll(sets) // + .as(StepVerifier::create) // + .expectNextCount(100) // + .verifyComplete(); + + repository.findAllByOrderByManual(PageRequest.of(0, 10)) // + .collectList() // + .as(StepVerifier::create) // + .consumeNextWith(actual -> { + + assertThat(actual).hasSize(10).extracting(LegoSet::getManual).containsSequence(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); + }).verifyComplete(); + + repository.findAllByOrderByManual(PageRequest.of(19, 5)) // + .collectList() // + .as(StepVerifier::create) // + .consumeNextWith(actual -> { + + assertThat(actual).hasSize(5).extracting(LegoSet::getManual).containsSequence(95, 96, 97, 98, 99); + }).verifyComplete(); + } + + @Test // gh-335 + public void shouldFindTop10() { + + Flux sets = Flux.fromStream(IntStream.range(0, 100).mapToObj(value -> { + return new LegoSet(null, "Set " + value, value); + })); + + repository.saveAll(sets) // + .as(StepVerifier::create) // + .expectNextCount(100) // + .verifyComplete(); + + repository.findFirst10By() // + .as(StepVerifier::create) // + .expectNextCount(10) // + .verifyComplete(); + } + @Test public void shouldInsertItemsTransactional() { @@ -212,6 +262,10 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg Flux findByNameContains(String name); + Flux findFirst10By(); + + Flux findAllByOrderByManual(Pageable pageable); + Flux findAsProjection(); Mono findByManual(int manual);