Class StoredProcExecutor
java.lang.Object
org.springframework.integration.jdbc.StoredProcExecutor
- All Implemented Interfaces:
Aware,BeanFactoryAware,InitializingBean
public class StoredProcExecutor extends Object implements BeanFactoryAware, InitializingBean
This class is used by all Stored Procedure (Stored Function) components and
provides the core functionality to execute those.
- Since:
- 2.1
- Author:
- Gunnar Hillert, Artem Bilan, Gary Russell
-
Constructor Summary
Constructors Constructor Description StoredProcExecutor(DataSource dataSource)Constructor takingDataSourcefrom which the DB Connection can be obtained. -
Method Summary
Modifier and Type Method Description voidafterPropertiesSet()Verifies parameters, sets the parameters onSimpleJdbcCallOperationsand ensures the appropriateSqlParameterSourceFactoryis defined whenProcedureParameterare passed in.Map<String,Object>executeStoredProcedure()Execute a Stored Procedure or Function - Use when noMessageis available to extractProcedureParametervalues from it.Map<String,Object>executeStoredProcedure(Message<?> message)Execute a Stored Procedure or Function - Use withMessageis available to extractProcedureParametervalues from it.StringgetStoredProcedureName()StringgetStoredProcedureNameExpressionAsString()voidsetBeanFactory(BeanFactory beanFactory)Allows to set the optionalBeanFactorywhich is used to add aBeanResolverto theStandardEvaluationContext.voidsetIgnoreColumnMetaData(boolean ignoreColumnMetaData)For fully supported databases, the underlyingSimpleJdbcCallcan retrieve the parameter information for the to be invoked Stored Procedure from the JDBC Meta-data.voidsetIsFunction(boolean isFunction)Indicates whether a Stored Procedure or a Function is being executed.voidsetJdbcCallOperationsCacheSize(int jdbcCallOperationsCacheSize)Defines the maximum number ofSimpleJdbcCallOperationsA value of zero will disable the cache.voidsetProcedureParameters(List<ProcedureParameter> procedureParameters)Custom Stored Procedure parameters that may contain static values or Strings representing anExpression.voidsetReturningResultSetRowMappers(Map<String,RowMapper<?>> returningResultSetRowMappers)voidsetReturnValueRequired(boolean returnValueRequired)Indicates the procedure's return value should be included in the results returned.voidsetSkipUndeclaredResults(boolean skipUndeclaredResults)If this variable is set totruethen all results from a stored procedure call that don't have a correspondingSqlOutParameterdeclaration will be bypassed.voidsetSqlParameters(List<SqlParameter> sqlParameters)If you database system is not fully supported by Spring and thus obtaining parameter definitions from the JDBC Meta-data is not possible, you must define theSqlParameterexplicitly.voidsetSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory)Provides the ability to set a customSqlParameterSourceFactory.voidsetStoredProcedureName(String storedProcedureName)The name of the Stored Procedure or Stored Function to be executed.voidsetStoredProcedureNameExpression(Expression storedProcedureNameExpression)Using thestoredProcedureNameExpressiontheMessagecan be used as source for the name of the Stored Procedure or Stored Function.voidsetUsePayloadAsParameterSource(boolean usePayloadAsParameterSource)If set to 'true', the payload of the Message will be used as a source for providing parameters.
-
Constructor Details
-
StoredProcExecutor
Constructor takingDataSourcefrom which the DB Connection can be obtained.- Parameters:
dataSource- used to create aSimpleJdbcCallinstance, must not be Null
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()Verifies parameters, sets the parameters onSimpleJdbcCallOperationsand ensures the appropriateSqlParameterSourceFactoryis defined whenProcedureParameterare passed in.- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
executeStoredProcedure
Execute a Stored Procedure or Function - Use when noMessageis available to extractProcedureParametervalues from it.- Returns:
- Map containing the stored procedure results if any.
-
executeStoredProcedure
Execute a Stored Procedure or Function - Use withMessageis available to extractProcedureParametervalues from it.- Parameters:
message- A message.- Returns:
- Map containing the stored procedure results if any.
-
setIgnoreColumnMetaData
public void setIgnoreColumnMetaData(boolean ignoreColumnMetaData)For fully supported databases, the underlyingSimpleJdbcCallcan retrieve the parameter information for the to be invoked Stored Procedure from the JDBC Meta-data. However, if the used database does not support meta data lookups or if you like to provide customized parameter definitions, this flag can be set to 'true'. It defaults to 'false'.- Parameters:
ignoreColumnMetaData- true to ignore column metadata.
-
setProcedureParameters
Custom Stored Procedure parameters that may contain static values or Strings representing anExpression.- Parameters:
procedureParameters- The parameters.
-
setSqlParameters
If you database system is not fully supported by Spring and thus obtaining parameter definitions from the JDBC Meta-data is not possible, you must define theSqlParameterexplicitly.- Parameters:
sqlParameters- The parameters.
-
setSqlParameterSourceFactory
Provides the ability to set a customSqlParameterSourceFactory. Keep in mind that ifProcedureParameterare set explicitly and you would like to provide a customSqlParameterSourceFactory, then you must provide an instance ofExpressionEvaluatingSqlParameterSourceFactory. If not the SqlParameterSourceFactory will be replaced the defaultExpressionEvaluatingSqlParameterSourceFactory.- Parameters:
sqlParameterSourceFactory- the parameter source factory.
-
getStoredProcedureName
- Returns:
- the name of the Stored Procedure or Function if set. Null otherwise.
-
getStoredProcedureNameExpressionAsString
- Returns:
- the Stored Procedure Name Expression as a String if set. Null otherwise.
-
setStoredProcedureName
The name of the Stored Procedure or Stored Function to be executed. IfisFunctionis set to "true", then this property specifies the Stored Function name. Alternatively you can also specify the Stored Procedure name viasetStoredProcedureNameExpression(Expression). E.g., that way you can specify the name of the Stored Procedure or Stored Function throughMessageHeaders.- Parameters:
storedProcedureName- Must not be null and must not be empty- See Also:
setStoredProcedureNameExpression(Expression)
-
setStoredProcedureNameExpression
Using thestoredProcedureNameExpressiontheMessagecan be used as source for the name of the Stored Procedure or Stored Function. IfisFunctionis set to "true", then this property specifies the Stored Function name. By providing a SpEL expression as value for this setter, a subset of the original payload, a header value or any other resolvable SpEL expression can be used as the basis for the Stored Procedure / Function. For the Expression evaluation the full message is available as the root object. For instance the following SpEL expressions (among others) are possible:- payload.foo
- headers.foobar
- new java.util.Date()
- 'foo' + 'bar'
setStoredProcedureName(String)- Parameters:
storedProcedureNameExpression- Must not be null.
-
setUsePayloadAsParameterSource
public void setUsePayloadAsParameterSource(boolean usePayloadAsParameterSource)If set to 'true', the payload of the Message will be used as a source for providing parameters. If false the entireMessagewill be available as a source for parameters. If noProcedureParameterare passed in, this property will default totrue. This means that using a defaultBeanPropertySqlParameterSourceFactorythe bean properties of the payload will be used as a source for parameter values for the to-be-executed Stored Procedure or Function. However, ifProcedureParameters are passed in, then this property will by default evaluate tofalse.ProcedureParameterallow for SpEl Expressions to be provided and therefore it is highly beneficial to have access to the entireMessage.- Parameters:
usePayloadAsParameterSource- If false the entireMessageis used as parameter source.
-
setIsFunction
public void setIsFunction(boolean isFunction)Indicates whether a Stored Procedure or a Function is being executed. The default value is false.- Parameters:
isFunction- If set to true an Sql Function is executed rather than a Stored Procedure.
-
setReturnValueRequired
public void setReturnValueRequired(boolean returnValueRequired)Indicates the procedure's return value should be included in the results returned.- Parameters:
returnValueRequired- true to include the return value.
-
setSkipUndeclaredResults
public void setSkipUndeclaredResults(boolean skipUndeclaredResults)If this variable is set totruethen all results from a stored procedure call that don't have a correspondingSqlOutParameterdeclaration will be bypassed. E.g. Stored Procedures may return an update count value, even though your Stored Procedure only declared a single result parameter. The exact behavior depends on the used database. The value is set on the underlyingJdbcTemplate. Only few developers will probably ever like to process update counts, thus the value defaults totrue.- Parameters:
skipUndeclaredResults- The boolean.
-
setReturningResultSetRowMappers
public void setReturningResultSetRowMappers(Map<String,RowMapper<?>> returningResultSetRowMappers)If the Stored Procedure returns ResultSets you may provide a map ofRowMapperto convert theResultSetto meaningful objects.- Parameters:
returningResultSetRowMappers- The map may not be null and must not contain null values.
-
setJdbcCallOperationsCacheSize
public void setJdbcCallOperationsCacheSize(int jdbcCallOperationsCacheSize)Defines the maximum number ofSimpleJdbcCallOperationsA value of zero will disable the cache. The default is 10.- Parameters:
jdbcCallOperationsCacheSize- Must not be negative.
-
setBeanFactory
Allows to set the optionalBeanFactorywhich is used to add aBeanResolverto theStandardEvaluationContext. If not set this property defaults to null.- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Parameters:
beanFactory- If set must not be null.
-