|
60 | 60 | import org.springframework.data.domain.ExampleMatcher.StringMatcher; |
61 | 61 | import org.springframework.data.domain.Sort.Direction; |
62 | 62 | import org.springframework.data.domain.Sort.Order; |
| 63 | +import org.springframework.data.domain.ExampleMatcher.*; |
63 | 64 | import org.springframework.data.jpa.domain.Specification; |
64 | 65 | import org.springframework.data.jpa.domain.sample.Address; |
65 | 66 | import org.springframework.data.jpa.domain.sample.QUser; |
@@ -1308,6 +1309,31 @@ void scrollByExampleKeysetBackward() { |
1308 | 1309 | assertThat(previousWindow.hasNext()).isTrue(); |
1309 | 1310 | } |
1310 | 1311 |
|
| 1312 | + @Test // GH-2999 |
| 1313 | + void scrollInitiallyByExampleKeysetBackward() { |
| 1314 | + |
| 1315 | + User jane1 = new User("Jane", "Doe", "jane@doe1.com"); |
| 1316 | + User jane2 = new User("Jane", "Doe", "jane@doe2.com"); |
| 1317 | + User john1 = new User("John", "Doe", "john@doe1.com"); |
| 1318 | + User john2 = new User("John", "Doe", "john@doe2.com"); |
| 1319 | + |
| 1320 | + repository.saveAllAndFlush(Arrays.asList(john1, john2, jane1, jane2)); |
| 1321 | + |
| 1322 | + Example<User> example = Example.of(new User("J", null, null), |
| 1323 | + matching().withMatcher("firstname", GenericPropertyMatcher::startsWith).withIgnorePaths("age", "createdAt", |
| 1324 | + "dateOfBirth")); |
| 1325 | + |
| 1326 | + Window<User> firstWindow = repository.findBy(example, |
| 1327 | + q -> q.limit(2).sortBy(Sort.by("firstname", "emailAddress")).scroll(ScrollPosition.keyset().backward())); |
| 1328 | + |
| 1329 | + assertThat(firstWindow).containsExactly(john1, john2); |
| 1330 | + |
| 1331 | + Window<User> previousWindow = repository.findBy(example, |
| 1332 | + q -> q.limit(2).sortBy(Sort.by("firstname", "emailAddress")).scroll(firstWindow.positionAt(0))); |
| 1333 | + |
| 1334 | + assertThat(previousWindow).containsExactly(jane1, jane2); |
| 1335 | + } |
| 1336 | + |
1311 | 1337 | @Test // GH-2878 |
1312 | 1338 | void scrollByPredicateOffset() { |
1313 | 1339 |
|
|
0 commit comments