Skip to content

Commit f5ba26e

Browse files
marcusvoltolimmp911de
authored andcommitted
DATAJPA-1198 - Consistently avoid toLower(…) translation in Querydsl case-insensitive ORDER BY translation for non-String properties.
Original pull request: #428.
1 parent d4ea221 commit f5ba26e

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* @author Thomas Darimont
4848
* @author Mark Paluch
4949
* @author Christoph Strobl
50+
* @author Marcus Voltolim
5051
*/
5152
public class Querydsl {
5253

@@ -235,7 +236,7 @@ private Expression<?> buildOrderPropertyPathFrom(Order order) {
235236

236237
while (path != null) {
237238

238-
sortPropertyExpression = !path.hasNext() && order.isIgnoreCase() //
239+
sortPropertyExpression = !path.hasNext() && order.isIgnoreCase() && String.class == path.getType() //
239240
? Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower() //
240241
: Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment());
241242

src/test/java/org/springframework/data/jpa/repository/support/QuerydslIntegrationTests.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@
3232
import com.querydsl.core.types.dsl.PathBuilder;
3333
import com.querydsl.jpa.JPQLQuery;
3434

35+
import java.util.stream.Stream;
36+
3537
/**
3638
* Integration tests for {@link Querydsl}.
3739
*
3840
* @author Thomas Darimont
3941
* @author Jens Schauder
42+
* @author Marcus Voltolim
4043
*/
4144
@RunWith(SpringJUnit4ClassRunner.class)
4245
@ContextConfiguration({ "classpath:infrastructure.xml" })
@@ -52,7 +55,7 @@ public class QuerydslIntegrationTests {
5255
@Before
5356
public void setup() {
5457

55-
userPath = new PathBuilder<User>(User.class, "user");
58+
userPath = new PathBuilder<>(User.class, "user");
5659
querydsl = new Querydsl(em, userPath);
5760
userQuery = querydsl.createQuery().select(userPath);
5861
}
@@ -67,4 +70,17 @@ public void defaultOrderingShouldNotGenerateAnNullOrderingHint() {
6770
.doesNotContain("nulls first") //
6871
.doesNotContain("nulls last");
6972
}
73+
74+
@Test // DATAJPA-1198; DATAJPA-1779
75+
public void orderWithIgnoreCaseAddLowerOnlyStringType() {
76+
// firstname (String); id (Integer); dateOfBirth (Date)
77+
Sort.Order[] orders = Stream.of("firstname", "id", "dateOfBirth").map(name -> Sort.Order.asc(name).ignoreCase()).toArray(Sort.Order[]::new);
78+
JPQLQuery<User> result = querydsl.applySorting(Sort.by(orders), userQuery);
79+
80+
assertThat(result).isNotNull();
81+
assertThat(result.toString()) //
82+
.startsWith("select user") //
83+
.endsWith("order by lower(user.firstname) asc, user.id asc, user.dateOfBirth asc");
84+
}
85+
7086
}

0 commit comments

Comments
 (0)