Skip to content

Commit 5ef4579

Browse files
schauderSergiiTsypanov
authored andcommitted
DATAJPA-1061 - Polishing.
Tweaked the formatting and the naming of variables. Original pull request: spring-projects#276.
1 parent 4d56219 commit 5ef4579

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,12 @@ public static String applySorting(String query, Sort sort, @Nullable String alia
262262
builder.append(", ");
263263
}
264264

265-
Set<String> aliases = getOuterJoinAliases(query);
266-
Set<String> fieldAliases = getFunctionAliases(query);
267-
fieldAliases.addAll(getFieldAliases(query));
265+
Set<String> joinAliases = getOuterJoinAliases(query);
266+
Set<String> selectionAliases = getFunctionAliases(query);
267+
selectionAliases.addAll(getFieldAliases(query));
268268

269269
for (Order order : sort) {
270-
builder.append(getOrderClause(aliases, fieldAliases, alias, order)).append(", ");
270+
builder.append(getOrderClause(joinAliases, selectionAliases, alias, order)).append(", ");
271271
}
272272

273273
builder.delete(builder.length() - 2, builder.length());
@@ -284,14 +284,14 @@ public static String applySorting(String query, Sort sort, @Nullable String alia
284284
* @param order the order object to build the clause for. Must not be {@literal null}.
285285
* @return a String containing a order clause. Guaranteed to be not {@literal null}.
286286
*/
287-
private static String getOrderClause(Set<String> joinAliases, Set<String> fieldAlias, @Nullable String alias,
287+
private static String getOrderClause(Set<String> joinAliases, Set<String> selectionAlias, @Nullable String alias,
288288
Order order) {
289289

290290
String property = order.getProperty();
291291

292292
checkSortExpression(order);
293293

294-
if (fieldAlias.contains(property)) {
294+
if (selectionAlias.contains(property)) {
295295
return String.format("%s %s", property, toJpaDirection(order));
296296
}
297297

src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java

+9
Original file line numberDiff line numberDiff line change
@@ -426,25 +426,34 @@ public void createCountQuerySupportsWhitespaceCharacters() {
426426

427427
@Test // DATAJPA-1061
428428
public void appliesSortCorrectlyForFieldAliases() {
429+
429430
String query = "SELECT m.price, lower(m.title) AS title, a.name as authorName FROM Magazine m INNER JOIN m.author a";
430431
Sort sort = Sort.by("authorName");
432+
431433
String fullQuery = applySorting(query, sort);
434+
432435
assertThat(fullQuery, endsWith("order by authorName asc"));
433436
}
434437

435438
@Test // DATAJPA-1061
436439
public void appliesSortCorrectlyForFunctionAliases() {
440+
437441
String query = "SELECT m.price, lower(m.title) AS title, a.name as authorName FROM Magazine m INNER JOIN m.author a";
438442
Sort sort = Sort.by("title");
443+
439444
String fullQuery = applySorting(query, sort);
445+
440446
assertThat(fullQuery, endsWith("order by title asc"));
441447
}
442448

443449
@Test // DATAJPA-1061
444450
public void appliesSortCorrectlyForSimpleField() {
451+
445452
String query = "SELECT m.price, lower(m.title) AS title, a.name as authorName FROM Magazine m INNER JOIN m.author a";
446453
Sort sort = Sort.by("price");
454+
447455
String fullQuery = applySorting(query, sort);
456+
448457
assertThat(fullQuery, endsWith("order by m.price asc"));
449458
}
450459

0 commit comments

Comments
 (0)