spring-projects/spring-data-jpa — pull request #101 by thomasdarimont (2014-06-30 17:12:13+00:00)
Title: DATAJPA-564 - Support for SpEL based parameter expressions in repository query methods.

We now support the discovery and dynamic registration of SpEL expression parameters in String based queries. Introduced an ExpressionEvaluationContextProvider that provides access to
a potentially shared SpEL EvaluationContext that is defined in the application context. This allow shared spring beans to be used within query expressions.
The SpEL expressions are evaluated in org.springframework.data.jpa.repository.query.SpelExpressionStringQueryParameterBinder.potentiallyBindSyntheticParameters(T) by using a hierarchal EvaluationContext with the RootObject set to the RootObject of the parent EvaluationContext. The method arguments are exposed via the {{#args}} variable.
We enhanced the parsing of ParameterBindings in ParameterBindingParser to support "synthetic" Parameters like SpEL expressions that should be evaluated at query time.

This feature works with Hibernate, EclipseLink as well as OpenJPA.

We currently support those variants:
Indexed parameter:
@Query("select c from Customer c where c.firstname = ?1 and c.attribute1 like ?#{#args[0] + ' ' + #args[1]})
To determine the index for the expression parameter we determine the max parameter index present and use that as an offset to generate appropriate parameter indices.

Named parameter:
@Query("select c from Customer c where c.firstname = :firstname and c.attribute1 like :#{#args[0] + ' ' + #args[1]})
whereby we generate a name like __$synthetic$__0 for SpEL parameter expression.

We also support the dynamic discovery and binding of SpEL Expression parameters in query derivation. Introduced ExpressionAwareParameterBinder for generic SpEL expression evaluation support.