Skip to content

DATAJPA-970 - Remove explicit group name from alias detection pattern. #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.0.BUILD-SNAPSHOT</version>
<version>1.11.0.DATAJPA-970-SNAPSHOT</version>

<name>Spring Data JPA</name>
<description>Spring Data module for JPA repositories.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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 "
Expand Down Expand Up @@ -159,7 +158,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());
}
Expand Down Expand Up @@ -325,7 +324,7 @@ private static Set<String> getFunctionAliases(String query) {

while (matcher.find()) {

String alias = matcher.group(FUNCTION_ALIAS_GROUP_NAME);
String alias = matcher.group(1);

if (StringUtils.hasText(alias)) {
result.add(alias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ public void doesNotQualifySortIfNoAliasDetected() {
}

/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test(expected = InvalidDataAccessApiUsageException.class)
public void doesNotAllowWhitespaceInSort() {
Expand All @@ -373,7 +374,8 @@ public void doesNotAllowWhitespaceInSort() {
}

/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixUnsageJpaSortFunctionCalls() {
Expand All @@ -383,7 +385,8 @@ public void doesNotPrefixUnsageJpaSortFunctionCalls() {
}

/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixMultipleAliasedFunctionCalls() {
Expand All @@ -395,7 +398,8 @@ public void doesNotPrefixMultipleAliasedFunctionCalls() {
}

/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixSingleAliasedFunctionCalls() {
Expand All @@ -407,7 +411,8 @@ public void doesNotPrefixSingleAliasedFunctionCalls() {
}

/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void prefixesSingleNonAliasedFunctionCallRelatedSortProperty() {
Expand All @@ -419,7 +424,8 @@ public void prefixesSingleNonAliasedFunctionCallRelatedSortProperty() {
}

/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void prefixesNonAliasedFunctionCallRelatedSortPropertyWhenSelectClauseContainesAliasedFunctionForDifferentProperty() {
Expand All @@ -431,7 +437,8 @@ public void prefixesNonAliasedFunctionCallRelatedSortPropertyWhenSelectClauseCon
}

/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixAliasedFunctionCallNameWithMultipleNumericParameters() {
Expand All @@ -443,7 +450,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithMultipleNumericParameters()
}

/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixAliasedFunctionCallNameWithMultipleStringParameters() {
Expand All @@ -455,7 +463,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithMultipleStringParameters() {
}

/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixAliasedFunctionCallNameWithUnderscores() {
Expand All @@ -467,7 +476,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithUnderscores() {
}

/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixAliasedFunctionCallNameWithDots() {
Expand All @@ -479,7 +489,8 @@ public void doesNotPrefixAliasedFunctionCallNameWithDots() {
}

/**
* @see DATAJPA-???
* @see DATAJPA-965
* @see DATAJPA-970
*/
@Test
public void doesNotPrefixAliasedFunctionCallNameWhenQueryStringContainsMultipleWhiteSpaces() {
Expand Down