DATAKV-137 - Fix cached query execution.

We now make sure that cached SpelCriteria's use the appropriate EvaluationContext containing parameters from the request instead of using the EvaluationContext of the cached query.

Original Pull Request: #20
This commit is contained in:
Mark Paluch
2016-06-06 13:15:29 +02:00
committed by Christoph Strobl
parent 66534d2ae0
commit 302dfd407c
4 changed files with 173 additions and 6 deletions

View File

@@ -44,6 +44,7 @@ import org.springframework.util.ClassUtils;
*
* @author Christoph Strobl
* @author Oliver Gierke
* @author Mark Paluch
*/
public class KeyValuePartTreeQuery implements RepositoryQuery {
@@ -134,15 +135,17 @@ public class KeyValuePartTreeQuery implements RepositoryQuery {
ParametersParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
parameters);
KeyValueQuery<?> query = new KeyValueQuery(instance.getCritieria());
Object criteria = instance.getCritieria();
if (instance.getCritieria() instanceof SpelExpression) {
if (criteria instanceof SpelCriteria || criteria instanceof SpelExpression) {
SpelExpression spelExpression = getSpelExpression(criteria);
EvaluationContext context = this.evaluationContextProvider.getEvaluationContext(getQueryMethod().getParameters(),
parameters);
query = new KeyValueQuery(new SpelCriteria((SpelExpression) instance.getCritieria(), context));
criteria = new SpelCriteria(spelExpression, context);
}
KeyValueQuery<?> query = new KeyValueQuery(criteria);
Pageable pageable = accessor.getPageable();
Sort sort = accessor.getSort();
@@ -153,6 +156,19 @@ public class KeyValuePartTreeQuery implements RepositoryQuery {
return query;
}
private SpelExpression getSpelExpression(Object criteria) {
if(criteria instanceof SpelExpression){
return (SpelExpression) criteria;
}
if(criteria instanceof SpelCriteria){
return getSpelExpression(((SpelCriteria) criteria).getExpression());
}
throw new IllegalStateException(String.format("Cannot retrieve SpelExpression from %s", criteria));
}
public KeyValueQuery<?> createQuery(ParameterAccessor accessor) {
PartTree tree = new PartTree(getQueryMethod().getName(), getQueryMethod().getEntityInformation().getJavaType());