|
22 | 22 | import org.assertj.core.api.SoftAssertions;
|
23 | 23 | import org.junit.jupiter.api.Test;
|
24 | 24 | import org.springframework.dao.InvalidDataAccessApiUsageException;
|
| 25 | +import org.springframework.data.domain.PageRequest; |
25 | 26 | import org.springframework.data.domain.Sort;
|
26 | 27 | import org.springframework.data.jpa.domain.JpaSort;
|
27 | 28 | import org.springframework.lang.Nullable;
|
@@ -823,11 +824,27 @@ void sortShouldWorkWhenAliasingFunctions() {
|
823 | 824 | LEFT JOIN bundle bundle ON event.id = bundle.event_id
|
824 | 825 | GROUP BY event.id
|
825 | 826 | """, Sort.by(Sort.Direction.ASC, "cheapestBundlePrice") //
|
826 |
| - .and(Sort.by( |
827 |
| - Sort.Direction.ASC, "earliestBundleStart")) // |
828 |
| - .and(Sort.by(Sort.Direction.ASC, |
829 |
| - "name")))) |
830 |
| - .endsWith(" order by cheapestBundlePrice asc, earliestBundleStart asc, name asc"); |
| 827 | + .and(Sort.by(Sort.Direction.ASC, "earliestBundleStart")) // |
| 828 | + .and(Sort.by(Sort.Direction.ASC, "name")))) |
| 829 | + .endsWith(" order by cheapestBundlePrice asc, earliestBundleStart asc, name asc"); |
| 830 | + } |
| 831 | + |
| 832 | + @Test // GH-2863, GH-1655 |
| 833 | + void shouldHandleAliasInsideCaseStatement() { |
| 834 | + |
| 835 | + Sort sort = PageRequest.of(0, 20, Sort.Direction.DESC, "newDateDue").getSort(); |
| 836 | + |
| 837 | + assertThat(createQueryFor("Select DISTINCT new " + // |
| 838 | + "com.api.dto.FilterDTO(c.id, p.id, CASE WHEN item.dateDue IS NOT NULL THEN item.dateDue ELSE p.dateDue END AS newDateDue) " |
| 839 | + + "FROM Customer c " + // |
| 840 | + "join c.productOrder p " + // |
| 841 | + "JOIN p.items item", // |
| 842 | + sort)).isEqualTo("Select DISTINCT new " + // |
| 843 | + "com.api.dto.FilterDTO(c.id, p.id, CASE WHEN item.dateDue IS NOT NULL THEN item.dateDue ELSE p.dateDue END AS newDateDue) " |
| 844 | + + "FROM Customer c " + // |
| 845 | + "join c.productOrder p " + // |
| 846 | + "JOIN p.items item " + // |
| 847 | + "order by newDateDue desc"); |
831 | 848 | }
|
832 | 849 |
|
833 | 850 | private void assertCountQuery(String originalQuery, String countQuery) {
|
|
0 commit comments