DATAJPA-483 - Fixed parameter binding detection with parentheses.
When a parameter was listed with parentheses we didn't detect a custom binding and fell back to the standard binding. This effectively disabled the array-to-collection binding which is currently necessary for in bindings as some persistence providers do not bind arrays to in-clauses correctly. Tweaked the regular expression to detect the bindings to accept the optional parentheses.
This commit is contained in:
@@ -157,11 +157,13 @@ class StringQuery {
|
||||
builder.append(StringUtils.collectionToDelimitedString(keywords, "|")); // keywords
|
||||
builder.append(")?");
|
||||
builder.append("(?: )?"); // some whitespace
|
||||
builder.append("\\(?"); // optional braces around paramters
|
||||
builder.append("(");
|
||||
builder.append("%?(\\?(\\d+))%?"); // position parameter
|
||||
builder.append("|"); // or
|
||||
builder.append("%?(:(\\w+))%?"); // named parameter;
|
||||
builder.append(")");
|
||||
builder.append("\\)?"); // optional braces around paramters
|
||||
|
||||
PARAMETER_BINDING_PATTERN = Pattern.compile(builder.toString(), CASE_INSENSITIVE);
|
||||
}
|
||||
|
||||
@@ -212,6 +212,20 @@ public class StringQueryUnitTests {
|
||||
+ " OR a.content LIKE :escapedWord ESCAPE '~' OR a.title = :word ORDER BY a.articleId DESC"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-483
|
||||
*/
|
||||
@Test
|
||||
public void detectsInBindingWithParentheses() {
|
||||
|
||||
StringQuery query = new StringQuery("select count(we) from MyEntity we where we.status in (:statuses)");
|
||||
|
||||
List<ParameterBinding> bindings = query.getParameterBindings();
|
||||
|
||||
assertThat(bindings, hasSize(1));
|
||||
assertNamedBinding(InParameterBinding.class, "statuses", bindings.get(0));
|
||||
}
|
||||
|
||||
private void assertPositionalBinding(Class<? extends ParameterBinding> bindingType, Integer position,
|
||||
ParameterBinding expectedBinding) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user