Skip to content

Commit ddd414b

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 73a7076 commit ddd414b

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
@@ -102,7 +102,6 @@ public abstract class QueryUtils {
102102
private static final int VARIABLE_NAME_GROUP_INDEX = 4;
103103

104104
private static final Pattern PUNCTATION_PATTERN = Pattern.compile(".*((?![\\._])[\\p{Punct}|\\s])");
105-
private static final String FUNCTION_ALIAS_GROUP_NAME = "alias";
106105
private static final Pattern FUNCTION_PATTERN;
107106

108107
private static final String UNSAFE_PROPERTY_REFERENCE = "Sort expression '%s' must only contain property references or "
@@ -142,7 +141,7 @@ public abstract class QueryUtils {
142141
builder = new StringBuilder();
143142
builder.append("\\s+"); // at least one space
144143
builder.append("\\w+\\([0-9a-zA-z\\._,\\s']+\\)"); // any function call including parameters within the brackets
145-
builder.append("\\s+[as|AS]+\\s+(?<" + FUNCTION_ALIAS_GROUP_NAME + ">[\\w\\.]+)"); // the potential alias
144+
builder.append("\\s+[as|AS]+\\s+(([\\w\\.]+))"); // the potential alias
146145

147146
FUNCTION_PATTERN = compile(builder.toString());
148147
}
@@ -308,7 +307,7 @@ private static Set<String> getFunctionAliases(String query) {
308307

309308
while (matcher.find()) {
310309

311-
String alias = matcher.group(FUNCTION_ALIAS_GROUP_NAME);
310+
String alias = matcher.group(1);
312311

313312
if (StringUtils.hasText(alias)) {
314313
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
@@ -335,7 +335,8 @@ public void doesNotQualifySortIfNoAliasDetected() {
335335
}
336336

337337
/**
338-
* @see DATAJPA-???
338+
* @see DATAJPA-965
339+
* @see DATAJPA-970
339340
*/
340341
@Test(expected = InvalidDataAccessApiUsageException.class)
341342
public void doesNotAllowWhitespaceInSort() {
@@ -345,7 +346,8 @@ public void doesNotAllowWhitespaceInSort() {
345346
}
346347

347348
/**
348-
* @see DATAJPA-???
349+
* @see DATAJPA-965
350+
* @see DATAJPA-970
349351
*/
350352
@Test
351353
public void doesNotPrefixUnsageJpaSortFunctionCalls() {
@@ -355,7 +357,8 @@ public void doesNotPrefixUnsageJpaSortFunctionCalls() {
355357
}
356358

357359
/**
358-
* @see DATAJPA-???
360+
* @see DATAJPA-965
361+
* @see DATAJPA-970
359362
*/
360363
@Test
361364
public void doesNotPrefixMultipleAliasedFunctionCalls() {
@@ -367,7 +370,8 @@ public void doesNotPrefixMultipleAliasedFunctionCalls() {
367370
}
368371

369372
/**
370-
* @see DATAJPA-???
373+
* @see DATAJPA-965
374+
* @see DATAJPA-970
371375
*/
372376
@Test
373377
public void doesNotPrefixSingleAliasedFunctionCalls() {
@@ -379,7 +383,8 @@ public void doesNotPrefixSingleAliasedFunctionCalls() {
379383
}
380384

381385
/**
382-
* @see DATAJPA-???
386+
* @see DATAJPA-965
387+
* @see DATAJPA-970
383388
*/
384389
@Test
385390
public void prefixesSingleNonAliasedFunctionCallRelatedSortProperty() {
@@ -391,7 +396,8 @@ public void prefixesSingleNonAliasedFunctionCallRelatedSortProperty() {
391396
}
392397

393398
/**
394-
* @see DATAJPA-???
399+
* @see DATAJPA-965
400+
* @see DATAJPA-970
395401
*/
396402
@Test
397403
public void prefixesNonAliasedFunctionCallRelatedSortPropertyWhenSelectClauseContainesAliasedFunctionForDifferentProperty() {
@@ -403,7 +409,8 @@ public void prefixesNonAliasedFunctionCallRelatedSortPropertyWhenSelectClauseCon
403409
}
404410

405411
/**
406-
* @see DATAJPA-???
412+
* @see DATAJPA-965
413+
* @see DATAJPA-970
407414
*/
408415
@Test
409416
public void doesNotPrefixAliasedFunctionCallNameWithMultipleNumericParameters() {
@@ -415,7 +422,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithMultipleNumericParameters()
415422
}
416423

417424
/**
418-
* @see DATAJPA-???
425+
* @see DATAJPA-965
426+
* @see DATAJPA-970
419427
*/
420428
@Test
421429
public void doesNotPrefixAliasedFunctionCallNameWithMultipleStringParameters() {
@@ -427,7 +435,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithMultipleStringParameters() {
427435
}
428436

429437
/**
430-
* @see DATAJPA-???
438+
* @see DATAJPA-965
439+
* @see DATAJPA-970
431440
*/
432441
@Test
433442
public void doesNotPrefixAliasedFunctionCallNameWithUnderscores() {
@@ -439,7 +448,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithUnderscores() {
439448
}
440449

441450
/**
442-
* @see DATAJPA-???
451+
* @see DATAJPA-965
452+
* @see DATAJPA-970
443453
*/
444454
@Test
445455
public void doesNotPrefixAliasedFunctionCallNameWithDots() {
@@ -451,7 +461,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithDots() {
451461
}
452462

453463
/**
454-
* @see DATAJPA-???
464+
* @see DATAJPA-965
465+
* @see DATAJPA-970
455466
*/
456467
@Test
457468
public void doesNotPrefixAliasedFunctionCallNameWhenQueryStringContainsMultipleWhiteSpaces() {

0 commit comments

Comments
 (0)