DATAJPA-148 - Remove qualification of sort reference for functions.

When applying Sort instances we now check for the presence of a ( which indicates a function to be executed.
This commit is contained in:
Oliver Gierke
2013-06-27 22:19:01 +02:00
parent bed347d223
commit 4ff0671105
2 changed files with 11 additions and 1 deletions

View File

@@ -212,7 +212,7 @@ public abstract class QueryUtils {
private static String getOrderClause(Set<String> joinAliases, String alias, Order order) {
String property = order.getProperty();
boolean qualifyReference = true;
boolean qualifyReference = !property.contains("("); // ( indicates a function
for (String joinAlias : joinAliases) {
if (property.startsWith(joinAlias)) {

View File

@@ -223,6 +223,16 @@ public class QueryUtilsUnitTests {
"select count(o) from Foo o where cb.id in (select b from Bar b)");
}
/**
* @see DATAJPA-148
*/
@Test
public void doesNotPrefixSortsIfFunction() {
Sort sort = new Sort("sum(foo)");
assertThat(applySorting("select p from Person p", sort, "p"), endsWith("order by sum(foo) asc"));
}
private void assertCountQuery(String originalQuery, String countQuery) {
assertThat(createCountQueryFor(originalQuery), is(countQuery));
}