org.springframework.integration.jdbc
Class StoredProcExecutor

java.lang.Object
  extended by org.springframework.integration.jdbc.StoredProcExecutor
All Implemented Interfaces:
InitializingBean

public class StoredProcExecutor
extends java.lang.Object
implements InitializingBean

A message handler that executes Stored Procedures for update purposes. Stored procedure parameter value are by default automatically extracted from the Payload if the payload's bean properties match the parameters of the Stored Procedure. This may be sufficient for basic use cases. For more sophisticated options consider passing in one or more ProcedureParameter. If you need to handle the return parameters of the called stored procedure explicitly, please consider using a StoredProcOutboundGateway instead. Also, if you need to execute SQL Functions, please also use the StoredProcOutboundGateway. As functions are typically used to look up values, only, the Stored Procedure message handler does purposefully not support SQL function calls. If you believe there are valid use-cases for that, please file a feature request at http://jira.springsource.org.

Since:
2.1

Constructor Summary
StoredProcExecutor(javax.sql.DataSource dataSource, java.lang.String storedProcedureName)
          Constructor taking DataSource from which the DB Connection can be obtained and the select query to execute the stored procedure.
 
Method Summary
 void afterPropertiesSet()
          Verifies parameters, sets the parameters on SimpleJdbcCallOperations and ensures the appropriate SqlParameterSourceFactory is defined when ProcedureParameter are passed in.
 java.util.Map<java.lang.String,java.lang.Object> executeStoredProcedure()
          Execute a Stored Procedure or Function - Use when no Message is available to extract ProcedureParameter values from it.
 java.util.Map<java.lang.String,java.lang.Object> executeStoredProcedure(Message<?> message)
          Execute a Stored Procedure or Function - Use with Message is available to extract ProcedureParameter values from it.
 java.lang.String getStoredProcedureName()
           
 void setFunction(boolean isFunction)
           
 void setIgnoreColumnMetaData(boolean ignoreColumnMetaData)
          For fully supported databases, the underlying SimpleJdbcCall can retrieve the parameter information for the to be invoked Stored Procedure from the JDBC Meta-data.
 void setProcedureParameters(java.util.List<ProcedureParameter> procedureParameters)
          Custom Stored Procedure parameters that may contain static values or Strings representing an Expression.
 void setReturningResultSetRowMappers(java.util.Map<java.lang.String,RowMapper<?>> returningResultSetRowMappers)
          If the Stored Procedure returns ResultSets you may provide a map of RowMapper to convert the ResultSet to meaningful objects.
 void setReturnValueRequired(boolean returnValueRequired)
           
 void setSqlParameters(java.util.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 the SqlParameter explicitly.
 void setSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory)
          Provides the ability to set a custom SqlParameterSourceFactory.
 void setUsePayloadAsParameterSource(boolean usePayloadAsParameterSource)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StoredProcExecutor

public StoredProcExecutor(javax.sql.DataSource dataSource,
                          java.lang.String storedProcedureName)
Constructor taking DataSource from which the DB Connection can be obtained and the select query to execute the stored procedure.

Parameters:
dataSource - used to create a SimpleJdbcTemplate, must not be Null
storedProcedureName - Name of the Stored Procedure or function, must not be empty
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
Verifies parameters, sets the parameters on SimpleJdbcCallOperations and ensures the appropriate SqlParameterSourceFactory is defined when ProcedureParameter are passed in.

Specified by:
afterPropertiesSet in interface InitializingBean

executeStoredProcedure

public java.util.Map<java.lang.String,java.lang.Object> executeStoredProcedure()
Execute a Stored Procedure or Function - Use when no Message is available to extract ProcedureParameter values from it.

Returns:
Map containing the stored procedure results if any.

executeStoredProcedure

public java.util.Map<java.lang.String,java.lang.Object> executeStoredProcedure(Message<?> message)
Execute a Stored Procedure or Function - Use with Message is available to extract ProcedureParameter values from it.

Returns:
Map containing the stored procedure results if any.

setIgnoreColumnMetaData

public void setIgnoreColumnMetaData(boolean ignoreColumnMetaData)
For fully supported databases, the underlying SimpleJdbcCall can 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'.


setProcedureParameters

public void setProcedureParameters(java.util.List<ProcedureParameter> procedureParameters)
Custom Stored Procedure parameters that may contain static values or Strings representing an Expression.


setSqlParameters

public void setSqlParameters(java.util.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 the SqlParameter explicitly.


setSqlParameterSourceFactory

public void setSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory)
Provides the ability to set a custom SqlParameterSourceFactory. Keep in mind that if ProcedureParameter are set explicitly and you would like to provide a custom SqlParameterSourceFactory, then you must provide an instance of ExpressionEvaluatingSqlParameterSourceFactory. If not the SqlParameterSourceFactory will be replaced the default ExpressionEvaluatingSqlParameterSourceFactory.

Parameters:
sqlParameterSourceFactory -

getStoredProcedureName

public java.lang.String getStoredProcedureName()
Returns:
the name of the Stored Procedure or Function

setUsePayloadAsParameterSource

public void setUsePayloadAsParameterSource(boolean usePayloadAsParameterSource)

setFunction

public void setFunction(boolean isFunction)

setReturnValueRequired

public void setReturnValueRequired(boolean returnValueRequired)

setReturningResultSetRowMappers

public void setReturningResultSetRowMappers(java.util.Map<java.lang.String,RowMapper<?>> returningResultSetRowMappers)
If the Stored Procedure returns ResultSets you may provide a map of RowMapper to convert the ResultSet to meaningful objects.

Parameters:
returningResultSetRowMappers - The map may not be null and must not contain null values.