Skip to content

Commit e5b3984

Browse files
christophstroblodrotbohm
authored andcommitted
DATAJPA-970 - Remove explicit group name from alias detection pattern.
We now use the group index instead of an explicit name. This fixes problems when using the pattern on Java 6. Original pull request: #181.
1 parent 79bc398 commit e5b3984

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public abstract class QueryUtils {
105105
private static final int VARIABLE_NAME_GROUP_INDEX = 4;
106106

107107
private static final Pattern PUNCTATION_PATTERN = Pattern.compile(".*((?![\\._])[\\p{Punct}|\\s])");
108-
private static final String FUNCTION_ALIAS_GROUP_NAME = "alias";
109108
private static final Pattern FUNCTION_PATTERN;
110109

111110
private static final String UNSAFE_PROPERTY_REFERENCE = "Sort expression '%s' must only contain property references or "
@@ -159,7 +158,7 @@ public abstract class QueryUtils {
159158
builder = new StringBuilder();
160159
builder.append("\\s+"); // at least one space
161160
builder.append("\\w+\\([0-9a-zA-z\\._,\\s']+\\)"); // any function call including parameters within the brackets
162-
builder.append("\\s+[as|AS]+\\s+(?<" + FUNCTION_ALIAS_GROUP_NAME + ">[\\w\\.]+)"); // the potential alias
161+
builder.append("\\s+[as|AS]+\\s+(([\\w\\.]+))"); // the potential alias
163162

164163
FUNCTION_PATTERN = compile(builder.toString());
165164
}
@@ -325,7 +324,7 @@ private static Set<String> getFunctionAliases(String query) {
325324

326325
while (matcher.find()) {
327326

328-
String alias = matcher.group(FUNCTION_ALIAS_GROUP_NAME);
327+
String alias = matcher.group(1);
329328

330329
if (StringUtils.hasText(alias)) {
331330
result.add(alias);

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ public void doesNotQualifySortIfNoAliasDetected() {
363363
}
364364

365365
/**
366-
* @see DATAJPA-???
366+
* @see DATAJPA-965
367+
* @see DATAJPA-970
367368
*/
368369
@Test(expected = InvalidDataAccessApiUsageException.class)
369370
public void doesNotAllowWhitespaceInSort() {
@@ -373,7 +374,8 @@ public void doesNotAllowWhitespaceInSort() {
373374
}
374375

375376
/**
376-
* @see DATAJPA-???
377+
* @see DATAJPA-965
378+
* @see DATAJPA-970
377379
*/
378380
@Test
379381
public void doesNotPrefixUnsageJpaSortFunctionCalls() {
@@ -383,7 +385,8 @@ public void doesNotPrefixUnsageJpaSortFunctionCalls() {
383385
}
384386

385387
/**
386-
* @see DATAJPA-???
388+
* @see DATAJPA-965
389+
* @see DATAJPA-970
387390
*/
388391
@Test
389392
public void doesNotPrefixMultipleAliasedFunctionCalls() {
@@ -395,7 +398,8 @@ public void doesNotPrefixMultipleAliasedFunctionCalls() {
395398
}
396399

397400
/**
398-
* @see DATAJPA-???
401+
* @see DATAJPA-965
402+
* @see DATAJPA-970
399403
*/
400404
@Test
401405
public void doesNotPrefixSingleAliasedFunctionCalls() {
@@ -407,7 +411,8 @@ public void doesNotPrefixSingleAliasedFunctionCalls() {
407411
}
408412

409413
/**
410-
* @see DATAJPA-???
414+
* @see DATAJPA-965
415+
* @see DATAJPA-970
411416
*/
412417
@Test
413418
public void prefixesSingleNonAliasedFunctionCallRelatedSortProperty() {
@@ -419,7 +424,8 @@ public void prefixesSingleNonAliasedFunctionCallRelatedSortProperty() {
419424
}
420425

421426
/**
422-
* @see DATAJPA-???
427+
* @see DATAJPA-965
428+
* @see DATAJPA-970
423429
*/
424430
@Test
425431
public void prefixesNonAliasedFunctionCallRelatedSortPropertyWhenSelectClauseContainesAliasedFunctionForDifferentProperty() {
@@ -431,7 +437,8 @@ public void prefixesNonAliasedFunctionCallRelatedSortPropertyWhenSelectClauseCon
431437
}
432438

433439
/**
434-
* @see DATAJPA-???
440+
* @see DATAJPA-965
441+
* @see DATAJPA-970
435442
*/
436443
@Test
437444
public void doesNotPrefixAliasedFunctionCallNameWithMultipleNumericParameters() {
@@ -443,7 +450,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithMultipleNumericParameters()
443450
}
444451

445452
/**
446-
* @see DATAJPA-???
453+
* @see DATAJPA-965
454+
* @see DATAJPA-970
447455
*/
448456
@Test
449457
public void doesNotPrefixAliasedFunctionCallNameWithMultipleStringParameters() {
@@ -455,7 +463,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithMultipleStringParameters() {
455463
}
456464

457465
/**
458-
* @see DATAJPA-???
466+
* @see DATAJPA-965
467+
* @see DATAJPA-970
459468
*/
460469
@Test
461470
public void doesNotPrefixAliasedFunctionCallNameWithUnderscores() {
@@ -467,7 +476,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithUnderscores() {
467476
}
468477

469478
/**
470-
* @see DATAJPA-???
479+
* @see DATAJPA-965
480+
* @see DATAJPA-970
471481
*/
472482
@Test
473483
public void doesNotPrefixAliasedFunctionCallNameWithDots() {
@@ -479,7 +489,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithDots() {
479489
}
480490

481491
/**
482-
* @see DATAJPA-???
492+
* @see DATAJPA-965
493+
* @see DATAJPA-970
483494
*/
484495
@Test
485496
public void doesNotPrefixAliasedFunctionCallNameWhenQueryStringContainsMultipleWhiteSpaces() {

0 commit comments

Comments
 (0)