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
@@ -27,6 +27,7 @@ import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -36,6 +37,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.domain.Limit;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
@@ -83,6 +85,22 @@ class SimpleUserRepositoryTests {
|
||||
assertThat(repository.findByLastname("lastname")).contains(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
void findLimitedNumberOfUsersViaDerivedQuery() {
|
||||
|
||||
IntStream.range(0, 10).forEach($ -> repository.save(new User(user.getFirstname(), user.getLastname())));
|
||||
|
||||
assertThat(repository.findByLastname("lastname", Limit.of(5))).hasSize(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void findLimitedNumberOfUsersViaAnnotatedQuery() {
|
||||
|
||||
IntStream.range(0, 10).forEach($ -> repository.save(new User(user.getFirstname(), user.getLastname())));
|
||||
|
||||
assertThat(repository.findByFirstname(user.getFirstname(), Limit.of(5))).hasSize(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void findByFirstnameOrLastname() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user