|
6 | 6 | import java.util.List;
|
7 | 7 | import java.util.Optional;
|
8 | 8 | import java.util.Set;
|
| 9 | +import java.util.stream.Collectors; |
9 | 10 |
|
10 | 11 | import org.bson.Document;
|
11 | 12 | import org.springframework.beans.factory.annotation.Autowired;
|
@@ -61,18 +62,12 @@ public void run(String... args) {
|
61 | 62 | runQueryByExample(product1);
|
62 | 63 | runInTransaction(product1);
|
63 | 64 |
|
64 |
| - personRepository.save(new Person("first-1", "last-1")); |
65 |
| - personRepository.save(new Person("first-2", "last-2")); |
66 |
| - personRepository.save(new Person("first-3", "last-3")); |
67 |
| - |
68 |
| - for (Person person : this.personRepository.findAll()) { |
69 |
| - System.out.printf("findAll(): %s%n", person); |
70 |
| - } |
71 |
| - |
72 |
| - for (Person person : this.personRepository.findByLastname("last-3")) { |
73 |
| - System.out.printf("findByLastname(): %s%n", person); |
74 |
| - } |
| 65 | + Person person1 = new Person("first-1", "last-1"); |
| 66 | + Person person2 = new Person("first-2", "last-2"); |
| 67 | + Person person3 = new Person("first-3", "last-3"); |
75 | 68 |
|
| 69 | + runDerivedFinder(person1, person2, person3); |
| 70 | + runQueriesWithDefaultSort(person1, person2, person3); |
76 | 71 | }
|
77 | 72 |
|
78 | 73 | // Prepare Collections to avoid timeouts on slow ci/docker/...
|
@@ -324,6 +319,39 @@ private void runInTransaction(LineItem product1) {
|
324 | 319 | log("-----------------\n\n\n");
|
325 | 320 | }
|
326 | 321 |
|
| 322 | + private void runDerivedFinder(Person person1, Person person2, Person person3) { |
| 323 | + |
| 324 | + log("---- DERIVED FINDER ----"); |
| 325 | + personRepository.deleteAll(); |
| 326 | + personRepository.saveAll(List.of(person1, person2, person3)); |
| 327 | + |
| 328 | + for (Person person : this.personRepository.findAll()) { |
| 329 | + System.out.printf("findAll(): %s%n", person); |
| 330 | + } |
| 331 | + |
| 332 | + for (Person person : this.personRepository.findByLastname("last-3")) { |
| 333 | + System.out.printf("findByLastname(): %s%n", person); |
| 334 | + } |
| 335 | + log("-----------------\n\n\n"); |
| 336 | + } |
| 337 | + |
| 338 | + private void runQueriesWithDefaultSort(Person person1, Person person2, Person person3) { |
| 339 | + |
| 340 | + log("---- DEFAULT SORT ----"); |
| 341 | + personRepository.deleteAll(); |
| 342 | + personRepository.saveAll(List.of(person1, person2, person3)); |
| 343 | + |
| 344 | + List<Person> annotatedQueryResult = this.personRepository.findAndSortPersonsDescByLastnameViaAnnotation("last"); |
| 345 | + System.out.printf("annotated-query-default-sort(): %s", |
| 346 | + annotatedQueryResult.stream().map(Person::getLastname).collect(Collectors.toList())); |
| 347 | + |
| 348 | + List<Person> derivedQueryResult = this.personRepository.findWithDefaultSortByLastnameStartingWith("last"); |
| 349 | + System.out.printf("derived-query-default-sort(): %s", |
| 350 | + derivedQueryResult.stream().map(Person::getLastname).collect(Collectors.toList())); |
| 351 | + |
| 352 | + log("-----------------\n\n\n"); |
| 353 | + } |
| 354 | + |
327 | 355 | private Order newOrder(String customerId, LineItem... items) {
|
328 | 356 | return newOrder(customerId, new Date(), items);
|
329 | 357 | }
|
|
0 commit comments