|
38 | 38 | import org.mockito.junit.jupiter.MockitoExtension;
|
39 | 39 | import org.mockito.junit.jupiter.MockitoSettings;
|
40 | 40 | import org.mockito.quality.Strictness;
|
41 |
| - |
42 | 41 | import org.springframework.beans.factory.annotation.Value;
|
43 | 42 | import org.springframework.data.annotation.Id;
|
| 43 | +import org.springframework.data.domain.Sort; |
| 44 | +import org.springframework.data.domain.Sort.Direction; |
44 | 45 | import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
45 | 46 | import org.springframework.data.r2dbc.convert.R2dbcConverter;
|
46 | 47 | import org.springframework.data.r2dbc.core.DefaultReactiveDataAccessStrategy;
|
|
53 | 54 | import org.springframework.data.relational.core.mapping.RelationalMappingContext;
|
54 | 55 | import org.springframework.data.relational.core.mapping.Table;
|
55 | 56 | import org.springframework.data.relational.core.sql.LockMode;
|
| 57 | +import org.springframework.data.relational.domain.SqlSort; |
56 | 58 | import org.springframework.data.relational.repository.Lock;
|
57 | 59 | import org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor;
|
58 | 60 | import org.springframework.data.repository.Repository;
|
@@ -599,6 +601,21 @@ void throwsExceptionWhenConditionKeywordIsUnsupported() throws Exception {
|
599 | 601 | .isThrownBy(() -> createQuery(r2dbcQuery, getAccessor(queryMethod, new Object[0])));
|
600 | 602 | }
|
601 | 603 |
|
| 604 | + @Test // GH-1548 |
| 605 | + void allowsSortingByNonDomainProperties() throws Exception { |
| 606 | + |
| 607 | + R2dbcQueryMethod queryMethod = getQueryMethod("findAllByFirstName", String.class, Sort.class); |
| 608 | + PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, operations, r2dbcConverter, dataAccessStrategy); |
| 609 | + |
| 610 | + PreparedOperation<?> preparedOperation = createQuery(queryMethod, r2dbcQuery, "foo", Sort.by("foobar")); |
| 611 | + PreparedOperationAssert.assertThat(preparedOperation) // |
| 612 | + .orderBy("users.foobar ASC"); |
| 613 | + |
| 614 | + preparedOperation = createQuery(queryMethod, r2dbcQuery, "foo", SqlSort.unsafe(Direction.ASC, "sum(foobar)")); |
| 615 | + PreparedOperationAssert.assertThat(preparedOperation) // |
| 616 | + .orderBy("sum(foobar) ASC"); |
| 617 | + } |
| 618 | + |
602 | 619 | @Test // GH-282
|
603 | 620 | void throwsExceptionWhenInvalidNumberOfParameterIsGiven() throws Exception {
|
604 | 621 |
|
@@ -960,6 +977,8 @@ interface UserRepository extends Repository<User, Long> {
|
960 | 977 |
|
961 | 978 | Flux<User> findAllByIdIsEmpty();
|
962 | 979 |
|
| 980 | + Flux<User> findAllByFirstName(String firstName, Sort sort); |
| 981 | + |
963 | 982 | Flux<User> findTop3ByFirstName(String firstName);
|
964 | 983 |
|
965 | 984 | Mono<User> findFirstByFirstName(String firstName);
|
|
0 commit comments