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:
Oliver Gierke
2013-04-18 11:20:14 +02:00
parent 0bf2cb391e
commit 4c65ad1df6
2 changed files with 29 additions and 2 deletions

View File

@@ -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));
}
/**

View File

@@ -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));
}