DATAJPA-375 - Fixed application of sort to queries with existing order by.
Improved existingin order by detection to detect the existing clause independent of the case. Before we only detected lower case "order by" expressions.
This commit is contained in:
@@ -79,6 +79,7 @@ public abstract class QueryUtils {
|
||||
private static final Pattern LEFT_JOIN_PATTERN = Pattern.compile(LEFT_JOIN, Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private static final String EQUALS_CONDITION_STRING = "%s.%s = :%s";
|
||||
private static final Pattern ORDER_BY = Pattern.compile(".*order\\s+by\\s+.*", CASE_INSENSITIVE);
|
||||
|
||||
private static final Set<PersistentAttributeType> ASSOCIATION_TYPES;
|
||||
|
||||
@@ -186,7 +187,7 @@ public abstract class QueryUtils {
|
||||
|
||||
StringBuilder builder = new StringBuilder(query);
|
||||
|
||||
if (!query.contains("order by")) {
|
||||
if (!ORDER_BY.matcher(query).matches()) {
|
||||
builder.append(" order by ");
|
||||
} else {
|
||||
builder.append(", ");
|
||||
|
||||
@@ -244,6 +244,17 @@ public class QueryUtilsUnitTests {
|
||||
"select count(distinct m.genre) from Media m where m.user = ?1");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-375
|
||||
*/
|
||||
@Test
|
||||
public void findsExistingOrderByIndependentOfCase() {
|
||||
|
||||
Sort sort = new Sort("lastname");
|
||||
String query = applySorting("select p from Person p ORDER BY p.firstname", sort, "p");
|
||||
assertThat(query, endsWith("ORDER BY p.firstname, p.lastname asc"));
|
||||
}
|
||||
|
||||
private void assertCountQuery(String originalQuery, String countQuery) {
|
||||
assertThat(createCountQueryFor(originalQuery), is(countQuery));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user