Class ValueExpressionQueryRewriter

java.lang.Object
org.springframework.data.repository.query.ValueExpressionQueryRewriter
Direct Known Subclasses:
ValueExpressionQueryRewriter.EvaluatingValueExpressionQueryRewriter

public class ValueExpressionQueryRewriter extends Object
A ValueExpressionQueryRewriter is able to detect Value expressions in a query string and to replace them with bind variables.

Result of the parse process is a ValueExpressionQueryRewriter.ParsedQuery which provides the transformed query string. Alternatively and preferred one may provide a QueryMethodValueEvaluationContextAccessor via withEvaluationContextAccessor(QueryMethodValueEvaluationContextAccessor) which will yield the more powerful ValueExpressionQueryRewriter.EvaluatingValueExpressionQueryRewriter.

Typical usage looks like

 ValueExpressionQueryRewriter.EvaluatingValueExpressionQueryRewriter rewriter = ValueExpressionQueryRewriter
                .of(valueExpressionParser, (counter, expression) -> String.format("__$synthetic$__%d", counter), String::concat)
                .withEvaluationContextAccessor(evaluationContextProviderFactory);

 ValueExpressionQueryRewriter.QueryExpressionEvaluator evaluator = rewriter.parse(query, queryMethod.getParameters());

 evaluator.evaluate(objects).forEach(parameterMap::addValue);
 
Since:
3.3
Author:
Jens Schauder, Gerrit Meier, Mark Paluch
See Also: