DATAJPA-1198 - Consistently avoid toLower(…) translation in Querydsl case-insensitive ORDER BY translation for non-String properties.

Original pull request: #428.
This commit is contained in:
Marcus Vinícius Neves Voltolim Satelis
2020-09-19 23:57:46 -03:00
committed by Mark Paluch
parent d4ea221795
commit f5ba26eedf
2 changed files with 19 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ import com.querydsl.jpa.impl.JPAQuery;
* @author Thomas Darimont
* @author Mark Paluch
* @author Christoph Strobl
* @author Marcus Voltolim
*/
public class Querydsl {
@@ -235,7 +236,7 @@ public class Querydsl {
while (path != null) {
sortPropertyExpression = !path.hasNext() && order.isIgnoreCase() //
sortPropertyExpression = !path.hasNext() && order.isIgnoreCase() && String.class == path.getType() //
? Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower() //
: Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment());

View File

@@ -32,11 +32,14 @@ import org.springframework.transaction.annotation.Transactional;
import com.querydsl.core.types.dsl.PathBuilder;
import com.querydsl.jpa.JPQLQuery;
import java.util.stream.Stream;
/**
* Integration tests for {@link Querydsl}.
*
* @author Thomas Darimont
* @author Jens Schauder
* @author Marcus Voltolim
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:infrastructure.xml" })
@@ -52,7 +55,7 @@ public class QuerydslIntegrationTests {
@Before
public void setup() {
userPath = new PathBuilder<User>(User.class, "user");
userPath = new PathBuilder<>(User.class, "user");
querydsl = new Querydsl(em, userPath);
userQuery = querydsl.createQuery().select(userPath);
}
@@ -67,4 +70,17 @@ public class QuerydslIntegrationTests {
.doesNotContain("nulls first") //
.doesNotContain("nulls last");
}
@Test // DATAJPA-1198; DATAJPA-1779
public void orderWithIgnoreCaseAddLowerOnlyStringType() {
// firstname (String); id (Integer); dateOfBirth (Date)
Sort.Order[] orders = Stream.of("firstname", "id", "dateOfBirth").map(name -> Sort.Order.asc(name).ignoreCase()).toArray(Sort.Order[]::new);
JPQLQuery<User> result = querydsl.applySorting(Sort.by(orders), userQuery);
assertThat(result).isNotNull();
assertThat(result.toString()) //
.startsWith("select user") //
.endsWith("order by lower(user.firstname) asc, user.id asc, user.dateOfBirth asc");
}
}