DATAJPA-296 - Fixed application of ignore case flag on string queries.
The ignore-case flag held in a Sort.Order is now also applied when manually defining queries.
This commit is contained in:
@@ -190,7 +190,7 @@ public abstract class QueryUtils {
|
||||
Set<String> aliases = getOuterJoinAliases(query);
|
||||
|
||||
for (Order order : sort) {
|
||||
builder.append(getOrderClause(aliases, alias, order));
|
||||
builder.append(getOrderClause(aliases, alias, order)).append(", ");
|
||||
}
|
||||
|
||||
builder.delete(builder.length() - 2, builder.length());
|
||||
@@ -219,7 +219,10 @@ public abstract class QueryUtils {
|
||||
}
|
||||
}
|
||||
|
||||
return String.format("%s%s %s, ", qualifyReference ? alias + "." : "", property, toJpaDirection(order));
|
||||
String reference = qualifyReference ? String.format("%s.%s", alias, property) : property;
|
||||
String wrapped = order.isIgnoreCase() ? String.format("lower(%s)", reference) : reference;
|
||||
|
||||
return String.format("%s %s", wrapped, toJpaDirection(order));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -179,6 +179,30 @@ public class QueryUtilsUnitTests {
|
||||
assertThat(applySorting(query, new Sort("firstname"), "p"), endsWith("order by p.lastname asc, p.firstname asc"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-296
|
||||
*/
|
||||
@Test
|
||||
public void appliesIgnoreCaseOrderingCorrectly() {
|
||||
|
||||
Sort sort = new Sort(new Sort.Order("firstname").ignoreCase());
|
||||
|
||||
String query = "select p from Person p";
|
||||
assertThat(applySorting(query, sort, "p"), endsWith("order by lower(p.firstname) asc"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-296
|
||||
*/
|
||||
@Test
|
||||
public void appendsIgnoreCaseOrderingCorrectly() {
|
||||
|
||||
Sort sort = new Sort(new Sort.Order("firstname").ignoreCase());
|
||||
|
||||
String query = "select p from Person p order by p.lastname asc";
|
||||
assertThat(applySorting(query, sort, "p"), endsWith("order by p.lastname asc, lower(p.firstname) asc"));
|
||||
}
|
||||
|
||||
private void assertCountQuery(String originalQuery, String countQuery) {
|
||||
assertThat(createCountQueryFor(originalQuery), is(countQuery));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user