DATAJPA-712 - Fix binding of SpEL parameters with IN-clause.

We now ensure that all the SpEL parameters are correctly substituted when used together with an IN-clause. Previously we incorrectly used the initial query as the result again which then only substituted the very last parameter correctly.

Original pull request: #148.
This commit is contained in:
Thomas Darimont
2015-05-19 12:44:19 +02:00
committed by Oliver Gierke
parent 92d8baac15
commit d64edde007
2 changed files with 26 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -255,7 +255,6 @@ class StringQuery {
checkAndRegister(new InParameterBinding(parameterName, expression), bindings);
}
result = query;
break;
case AS_IS: // fall-through we don't need a special parameter binding for the given parameter.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -312,7 +312,31 @@ public class StringQueryUnitTests {
public void rejectsDifferentBindingsForRepeatedParameter2() {
new StringQuery("select u from User u where u.firstname like ?1 and u.lastname like %?1");
}
/**
* @see @DATAJPA-712
*/
@Test
public void shouldReplaceAllNamedExpressionParametersWithInClause() {
StringQuery query = new StringQuery("select a from A a where a.b in :#{#bs} and a.c in :#{#cs}");
String queryString = query.getQueryString();
assertThat(queryString, is("select a from A a where a.b in :__$synthetic$__1 and a.c in :__$synthetic$__2"));
}
/**
* @see @DATAJPA-712
*/
@Test
public void shouldReplaceAllPositionExpressionParametersWithInClause() {
StringQuery query = new StringQuery("select a from A a where a.b in ?#{#bs} and a.c in ?#{#cs}");
String queryString = query.getQueryString();
assertThat(queryString, is("select a from A a where a.b in ?1 and a.c in ?2"));
}
private void assertPositionalBinding(Class<? extends ParameterBinding> bindingType, Integer position,
ParameterBinding expectedBinding) {