Show how to use Limit with repository queries.

Add methods taking a Limit parameter to various samples.

Original pull request: #672
Closes #671
This commit is contained in:
Christoph Strobl
2023-11-02 08:49:24 +01:00
committed by Mark Paluch
parent e90be0c65b
commit f98c7b9c93
13 changed files with 167 additions and 0 deletions

View File

@@ -15,6 +15,7 @@
*/
package example.springdata.r2dbc.basics;
import org.springframework.data.domain.Limit;
import reactor.core.publisher.Flux;
import org.springframework.data.r2dbc.repository.Query;
@@ -28,4 +29,6 @@ interface CustomerRepository extends ReactiveCrudRepository<Customer, Long> {
@Query("select id, firstname, lastname from customer c where c.lastname = :lastname")
Flux<Customer> findByLastname(String lastname);
Flux<Customer> findByLastname(String lastname, Limit limit);
}

View File

@@ -15,6 +15,7 @@
*/
package example.springdata.r2dbc.basics;
import org.springframework.data.domain.Limit;
import reactor.core.publisher.Hooks;
import reactor.test.StepVerifier;
@@ -72,6 +73,25 @@ class TransactionalServiceIntegrationTests {
.verifyComplete();
}
@Test
void limitResultSize() {
service.save(new Customer(null, "Carter", "Matthews")) //
.as(StepVerifier::create) //
.expectNextMatches(Customer::hasId) //
.verifyComplete();
service.save(new Customer(null, "Evad", "Matthews")) //
.as(StepVerifier::create) //
.expectNextMatches(Customer::hasId) //
.verifyComplete();
repository.findByLastname("Matthews", Limit.of(1)) //
.as(StepVerifier::create) //
.expectNextCount(1)
.verifyComplete();
}
@Test // #500
void insertsDataTransactionally() {