|
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.databind.ObjectMapper;
|
4 | 4 | import com.github.mhewedy.expressions.model.*;
|
| 5 | +import lombok.AllArgsConstructor; |
5 | 6 | import lombok.SneakyThrows;
|
| 7 | +import lombok.ToString; |
6 | 8 | import lombok.extern.slf4j.Slf4j;
|
7 | 9 | import org.junit.jupiter.api.AfterEach;
|
8 | 10 | import org.junit.jupiter.api.BeforeEach;
|
|
14 | 16 | import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
15 | 17 | import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
|
16 | 18 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
| 19 | +import org.springframework.data.domain.Example; |
17 | 20 | import org.springframework.data.domain.Page;
|
18 | 21 | import org.springframework.data.domain.PageRequest;
|
19 | 22 | import org.springframework.data.domain.Sort;
|
|
29 | 32 | import java.util.Arrays;
|
30 | 33 | import java.util.List;
|
31 | 34 | import java.util.UUID;
|
| 35 | +import java.util.stream.Collectors; |
32 | 36 |
|
33 | 37 | import static com.github.mhewedy.expressions.model.Status.ACTIVE;
|
34 | 38 | import static com.github.mhewedy.expressions.model.Status.NOT_ACTIVE;
|
@@ -588,6 +592,44 @@ public void testHijrahDate_InJava() {
|
588 | 592 | // where e.h_birth_date>=?
|
589 | 593 | }
|
590 | 594 |
|
| 595 | + @Test |
| 596 | + public void testFluentQueryInQBE() { |
| 597 | + @ToString |
| 598 | + @AllArgsConstructor |
| 599 | + class EmployeeProjectionDTO { |
| 600 | + public final String firstName; |
| 601 | + public final String lastName; |
| 602 | + } |
| 603 | + |
| 604 | + List<EmployeeProjectionDTO> list = employeeRepository.findBy(Example.of(new Employee()), |
| 605 | + query -> query.project("firstName", "lastName") |
| 606 | + .stream() |
| 607 | + .map(it -> new EmployeeProjectionDTO(it.firstName, it.lastName)) |
| 608 | + .collect(Collectors.toList()) |
| 609 | + ); |
| 610 | + System.out.println(list); |
| 611 | + |
| 612 | + // sql: |
| 613 | + /* |
| 614 | + SELECT employee0_.id AS id1_2_, |
| 615 | + employee0_.created_date AS created_2_2_, |
| 616 | + employee0_.active AS active3_2_, |
| 617 | + employee0_.age AS age4_2_, |
| 618 | + employee0_.birth_date AS birth_da5_2_, |
| 619 | + employee0_.department_id AS departm14_2_, |
| 620 | + employee0_.first_name AS first_na6_2_, |
| 621 | + employee0_.h_birth_date AS h_birth_7_2_, |
| 622 | + employee0_.hire_date AS hire_dat8_2_, |
| 623 | + employee0_.last_name AS last_nam9_2_, |
| 624 | + employee0_.employee_name_ar AS employe10_2_, |
| 625 | + employee0_.employee_name_en AS employe11_2_, |
| 626 | + employee0_.serial AS serial12_2_, |
| 627 | + employee0_.type AS type13_2_ |
| 628 | + FROM employee employee0_ |
| 629 | + WHERE ?= 1 |
| 630 | + */ |
| 631 | + } |
| 632 | + |
591 | 633 | @SneakyThrows
|
592 | 634 | private String loadResourceJsonFile(String name) {
|
593 | 635 | File file = ResourceUtils.getFile("classpath:" + name + ".json");
|
|
0 commit comments