Class ExpressionEvaluatingSqlParameterSourceFactory
java.lang.Object
org.springframework.integration.util.AbstractExpressionEvaluator
org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.InitializingBean,SqlParameterSourceFactory
public class ExpressionEvaluatingSqlParameterSourceFactory extends org.springframework.integration.util.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.- Since:
- 2.0
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ExpressionEvaluatingSqlParameterSourceFactory() -
Method Summary
Modifier and Type Method Description org.springframework.jdbc.core.namedparam.SqlParameterSourcecreateParameterSource(java.lang.Object input)Return a newSqlParameterSource.org.springframework.jdbc.core.namedparam.SqlParameterSourcecreateParameterSourceNoCache(java.lang.Object input)Create an expression evaluatingSqlParameterSourcethat does not cache it's results.protected voidonInit()voidsetParameterExpressions(java.util.Map<java.lang.String,java.lang.String> parameterExpressions)Optionally maps parameter names to explicit expressions.voidsetSqlParameterTypes(java.util.Map<java.lang.String,java.lang.Integer> sqlParametersTypes)Specify sql types for the parameters.voidsetStaticParameters(java.util.Map<java.lang.String,java.lang.Object> staticParameters)Define some static parameter values.Methods inherited from class org.springframework.integration.util.AbstractExpressionEvaluator
afterPropertiesSet, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, getBeanFactory, getEvaluationContext, getEvaluationContext, getMessageBuilderFactory, setBeanFactory, setConversionService
-
Constructor Details
-
ExpressionEvaluatingSqlParameterSourceFactory
public ExpressionEvaluatingSqlParameterSourceFactory()
-
-
Method Details
-
setStaticParameters
public void setStaticParameters(java.util.Map<java.lang.String,java.lang.Object> staticParameters)Define some static parameter values. These take precedence over those defined as expressions in theparameterExpressions, so a parameter in the query will be filled from here first, and then from the expressions.- Parameters:
staticParameters- the static parameters to set
-
setParameterExpressions
public void setParameterExpressions(java.util.Map<java.lang.String,java.lang.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). Thestatic parameterscan be referred to in an expression using the variable#staticParameters, for example:Parameter Expressions Samples Key Value (Expression) Example SQL id payload.businessKeyselect * from items where id=:iddate headers['timestamp']select * from items where created>:datekey #staticParameters['foo'].toUpperCase()select * from items where name=:key- Parameters:
parameterExpressions- the parameter expressions to set
-
setSqlParameterTypes
public void setSqlParameterTypes(java.util.Map<java.lang.String,java.lang.Integer> sqlParametersTypes)Specify sql types for the parameters. Optional. UseTypesto get the parameter type value.- Parameters:
sqlParametersTypes- the parameter types to use- Since:
- 5.0
- See Also:
Types
-
createParameterSource
public org.springframework.jdbc.core.namedparam.SqlParameterSource createParameterSource(java.lang.Object input)Description copied from interface:SqlParameterSourceFactoryReturn a newSqlParameterSource.- Specified by:
createParameterSourcein interfaceSqlParameterSourceFactory- Parameters:
input- the raw message or query result to be transformed into a SqlParameterSource- Returns:
- The parameter source.
-
createParameterSourceNoCache
public org.springframework.jdbc.core.namedparam.SqlParameterSource createParameterSourceNoCache(java.lang.Object input)Create an expression evaluatingSqlParameterSourcethat 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 theselect-sql-parameter-sourceattribute.- Parameters:
input- The root object for the evaluation.- Returns:
- The parameter source.
-
onInit
protected void onInit()- Overrides:
onInitin classorg.springframework.integration.util.AbstractExpressionEvaluator
-