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:
committed by
Mark Paluch
parent
e90be0c65b
commit
f98c7b9c93
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package example.springdata.cassandra.people;
|
||||
|
||||
import org.springframework.data.domain.Limit;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -36,6 +37,15 @@ public interface ReactivePersonRepository extends ReactiveCrudRepository<Person,
|
||||
*/
|
||||
Flux<Person> findByLastname(String lastname);
|
||||
|
||||
/**
|
||||
* Derived query selecting by {@code lastname} reducing the result size to a given {@link Limit}.
|
||||
*
|
||||
* @param lastname
|
||||
* @param maxResults the maximum number of results returned.
|
||||
* @return
|
||||
*/
|
||||
Flux<Person> findByLastname(String lastname, Limit maxResults);
|
||||
|
||||
/**
|
||||
* String query selecting one entity.
|
||||
*
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package example.springdata.cassandra.people;
|
||||
|
||||
import example.springdata.cassandra.util.CassandraKeyspace;
|
||||
import org.springframework.data.domain.Limit;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
@@ -89,6 +90,14 @@ class ReactivePersonRepositoryIntegrationTest {
|
||||
StepVerifier.create(repository.findByLastname("White")).expectNextCount(2).verifyComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data limiting result size.
|
||||
*/
|
||||
@Test
|
||||
void limitResultSize() {
|
||||
StepVerifier.create(repository.findByLastname("White", Limit.of(1))).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data using a string query.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user