Class ExpressionEvaluatingSqlParameterSourceFactory

All Implemented Interfaces:
Aware, BeanFactoryAware, InitializingBean, SqlParameterSourceFactory

public class ExpressionEvaluatingSqlParameterSourceFactory extends AbstractExpressionEvaluator implements SqlParameterSourceFactory
An implementation of SqlParameterSourceFactory which creates an SqlParameterSource that evaluates Spring EL expressions. In addition the user can supply static parameters that always take precedence.
Dave Syer, Oleg Zhurakousky, Gary Russell, Artem Bilan, Meherzad Lahewala
  • Constructor Details

    • ExpressionEvaluatingSqlParameterSourceFactory

      public ExpressionEvaluatingSqlParameterSourceFactory()
  • Method Details

    • setStaticParameters

      public void setStaticParameters(Map<String,Object> staticParameters)
      Define some static parameter values. These take precedence over those defined as expressions in the parameterExpressions, so a parameter in the query will be filled from here first, and then from the expressions.
      staticParameters - the static parameters to set
    • setParameterExpressions

      public void setParameterExpressions(Map<String,String> parameterExpressions)
      Optionally maps parameter names to explicit expressions. The named parameter support in Spring is limited to simple parameter names with no special characters, so this feature allows you to specify a simple name in the SQL query and then have it translated into an expression at runtime. The target of the expression depends on the context: generally in an outbound setting it is a Message, and in an inbound setting it is a result set row (a Map or a domain object if a RowMapper has been provided). The static parameters can be referred to in an expression using the variable #staticParameters, for example:


      Parameter Expressions Samples
      Key Value (Expression) Example SQL
      id payload.businessKey select * from items where id=:id
      date headers['timestamp'] select * from items where created>:date
      key #staticParameters['foo'].toUpperCase() select * from items where name=:key
      parameterExpressions - the parameter expressions to set
    • setSqlParameterTypes

      public void setSqlParameterTypes(Map<String,Integer> sqlParametersTypes)
      Specify sql types for the parameters. Optional. Use Types to get the parameter type value.
      sqlParametersTypes - the parameter types to use
      See Also:
    • createParameterSource

      public SqlParameterSource createParameterSource(Object input)
      Description copied from interface: SqlParameterSourceFactory
      Return a new SqlParameterSource.
      Specified by:
      createParameterSource in interface SqlParameterSourceFactory
      input - the raw message or query result to be transformed into a SqlParameterSource
      The parameter source.
    • createParameterSourceNoCache

      public SqlParameterSource createParameterSourceNoCache(Object input)
      Create an expression evaluating SqlParameterSource that does not cache it's results. Useful for cases where the source is used multiple times, for example in a <int-jdbc:inbound-channel-adapter/> for the select-sql-parameter-source attribute.
      input - The root object for the evaluation.
      The parameter source.
    • onInit

      protected void onInit()
      onInit in class AbstractExpressionEvaluator