Class SpelQueryContext

java.lang.Object
org.springframework.data.repository.query.SpelQueryContext
Direct Known Subclasses:
SpelQueryContext.EvaluatingSpelQueryContext

public class SpelQueryContext extends Object
A SpelQueryContext is able to find SpEL expressions in a query string and to replace them with bind variables.

Result o the parse process is a SpelQueryContext.SpelExtractor which offers the transformed query string. Alternatively and preferred one may provide a QueryMethodEvaluationContextProvider via withEvaluationContextProvider(QueryMethodEvaluationContextProvider) which will yield the more powerful SpelQueryContext.EvaluatingSpelQueryContext.

Typical usage looks like

 
     SpelQueryContext.EvaluatingSpelQueryContext queryContext = SpelQueryContext
         .of((counter, expression) -> String.format("__$synthetic$__%d", counter), String::concat)
         .withEvaluationContextProvider(evaluationContextProvider);

     SpelEvaluator spelEvaluator = queryContext.parse(query, queryMethod.getParameters());

     spelEvaluator.evaluate(objects).forEach(parameterMap::addValue);
 
 
Since:
2.1
Author:
Jens Schauder, Gerrit Meier, Mark Paluch