DATAJPA-1200 - Polishing.

Original pull request: #231.
This commit is contained in:
Oliver Gierke
2017-10-25 11:34:14 +02:00
parent b4175919c4
commit f846badfa1
3 changed files with 12 additions and 12 deletions

View File

@@ -86,6 +86,7 @@ public abstract class QueryUtils {
// P Punctuation
static final String IDENTIFIER = "[._[\\P{Z}&&\\P{Cc}&&\\P{Cf}&&\\P{P}]]+";
static final String COLON_NO_DOUBLE_COLON = "(?<![:\\\\]):";
static final String IDENTIFIER_GROUP = String.format("(%s)", IDENTIFIER);
private static final String COUNT_REPLACEMENT_TEMPLATE = "select count(%s) $5$6$7";
private static final String SIMPLE_COUNT_VALUE = "$2";
@@ -98,8 +99,6 @@ public abstract class QueryUtils {
private static final Pattern NO_DIGITS = Pattern.compile("\\D+");
private static final String IDENTIFIER_GROUP = String.format("(%s)", IDENTIFIER);
private static final String JOIN = "join\\s+(fetch\\s+)?" + IDENTIFIER + "\\s+(as\\s+)?" + IDENTIFIER_GROUP;
private static final Pattern JOIN_PATTERN = Pattern.compile(JOIN, Pattern.CASE_INSENSITIVE);

View File

@@ -152,7 +152,9 @@ class StringQuery {
builder.append("(");
builder.append("%?(\\?(\\d+))%?"); // position parameter and parameter index
builder.append("|"); // or
builder.append("%?("+QueryUtils.COLON_NO_DOUBLE_COLON + "(" + QueryUtils.IDENTIFIER + "+))%?"); // named parameter and the parameter name
// named parameter and the parameter name
builder.append("%?(" + QueryUtils.COLON_NO_DOUBLE_COLON + QueryUtils.IDENTIFIER_GROUP + ")%?");
builder.append("|"); // or
builder.append("%?((:|\\?)#\\{([^}]+)\\})%?"); // expression parameter and expression
builder.append(")");

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.jpa.repository.query;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +31,7 @@ import org.springframework.data.jpa.repository.query.StringQuery.ParameterBindin
public class ParameterBindingParserUnitTests {
@Test // DATAJPA-1200
public void idenficationOfParameters(){
public void idenficationOfParameters() {
SoftAssertions softly = new SoftAssertions();
@@ -46,17 +44,18 @@ public class ParameterBindingParserUnitTests {
checkHasParameter(softly, ":lowercase", true, "lowercase");
checkHasParameter(softly, ":2something", true, "beginning digit");
checkHasParameter(softly, ":2", true, "only digit");
checkHasParameter(softly, ":.something", true, "dot"); // <--
checkHasParameter(softly, ":.something", true, "dot"); // <--
checkHasParameter(softly, ":_something", true, "underscore");
checkHasParameter(softly, ":$something", true, "dollar"); // <--
checkHasParameter(softly, ":\uFE0F", true, "non basic latin emoji"); // <--
checkHasParameter(softly, ":\uFE0F", true, "non basic latin emoji"); // <--
checkHasParameter(softly, ":\u4E01", true, "chinese japanese korean");
checkHasParameter(softly, "select something from x where id = ?1", true, "indexed parameter");
checkHasParameter(softly, "select something from x where id = #something", false, "hash"); // <-- should we accept hash as named parameter start?
// <-- should we accept hash as named parameter start?
checkHasParameter(softly, "select something from x where id = #something", false, "hash");
checkHasParameter(softly, "no bind variable", false, "no bind variable");
checkHasParameter(softly, ":\u2004whitespace", false, "non basic latin whitespace"); // <--
checkHasParameter(softly, ":\u2004whitespace", false, "non basic latin whitespace"); // <--
checkHasParameter(softly, "::", false, "double colon");
checkHasParameter(softly, ":", false, "end of query");
checkHasParameter(softly, ":\u0003", false, "non-printable");
@@ -70,10 +69,10 @@ public class ParameterBindingParserUnitTests {
public void checkHasParameter(SoftAssertions softly, String query, boolean containsParameter, String label) {
List<ParameterBinding> bindings = new ArrayList();
List<ParameterBinding> bindings = new ArrayList<>();
ParameterBindingParser.INSTANCE.parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQuery(query, bindings);
softly.assertThat(bindings.size()) //
.describedAs(String.format("<%s> (%s)", query, label)) //
.isEqualTo(containsParameter ? 1 : 0);
}
}
}