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.
This commit is contained in:
Christoph Strobl
2016-09-23 09:09:35 +02:00
committed by Oliver Gierke
parent 73a7076571
commit ddd414b201
2 changed files with 24 additions and 14 deletions

View File

@@ -102,7 +102,6 @@ public abstract class QueryUtils {
private static final int VARIABLE_NAME_GROUP_INDEX = 4;
private static final Pattern PUNCTATION_PATTERN = Pattern.compile(".*((?![\\._])[\\p{Punct}|\\s])");
private static final String FUNCTION_ALIAS_GROUP_NAME = "alias";
private static final Pattern FUNCTION_PATTERN;
private static final String UNSAFE_PROPERTY_REFERENCE = "Sort expression '%s' must only contain property references or "
@@ -142,7 +141,7 @@ public abstract class QueryUtils {
builder = new StringBuilder();
builder.append("\\s+"); // at least one space
builder.append("\\w+\\([0-9a-zA-z\\._,\\s']+\\)"); // any function call including parameters within the brackets
builder.append("\\s+[as|AS]+\\s+(?<" + FUNCTION_ALIAS_GROUP_NAME + ">[\\w\\.]+)"); // the potential alias
builder.append("\\s+[as|AS]+\\s+(([\\w\\.]+))"); // the potential alias
FUNCTION_PATTERN = compile(builder.toString());
}
@@ -308,7 +307,7 @@ public abstract class QueryUtils {
while (matcher.find()) {
String alias = matcher.group(FUNCTION_ALIAS_GROUP_NAME);
String alias = matcher.group(1);
if (StringUtils.hasText(alias)) {
result.add(alias);

View File

@@ -335,7 +335,8 @@ public class QueryUtilsUnitTests {
}
/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test(expected = InvalidDataAccessApiUsageException.class)
public void doesNotAllowWhitespaceInSort() {
@@ -345,7 +346,8 @@ public class QueryUtilsUnitTests {
}
/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixUnsageJpaSortFunctionCalls() {
@@ -355,7 +357,8 @@ public class QueryUtilsUnitTests {
}
/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixMultipleAliasedFunctionCalls() {
@@ -367,7 +370,8 @@ public class QueryUtilsUnitTests {
}
/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixSingleAliasedFunctionCalls() {
@@ -379,7 +383,8 @@ public class QueryUtilsUnitTests {
}
/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void prefixesSingleNonAliasedFunctionCallRelatedSortProperty() {
@@ -391,7 +396,8 @@ public class QueryUtilsUnitTests {
}
/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void prefixesNonAliasedFunctionCallRelatedSortPropertyWhenSelectClauseContainesAliasedFunctionForDifferentProperty() {
@@ -403,7 +409,8 @@ public class QueryUtilsUnitTests {
}
/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixAliasedFunctionCallNameWithMultipleNumericParameters() {
@@ -415,7 +422,8 @@ public class QueryUtilsUnitTests {
}
/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixAliasedFunctionCallNameWithMultipleStringParameters() {
@@ -427,7 +435,8 @@ public class QueryUtilsUnitTests {
}
/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixAliasedFunctionCallNameWithUnderscores() {
@@ -439,7 +448,8 @@ public class QueryUtilsUnitTests {
}
/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixAliasedFunctionCallNameWithDots() {
@@ -451,7 +461,8 @@ public class QueryUtilsUnitTests {
}
/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixAliasedFunctionCallNameWhenQueryStringContainsMultipleWhiteSpaces() {