Spring Integration

org.springframework.integration.jdbc
Class StoredProcExecutor

java.lang.Object
  extended by org.springframework.integration.jdbc.StoredProcExecutor
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean

@ManagedResource
public class StoredProcExecutor
extends java.lang.Object
implements org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.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

Constructor Summary
StoredProcExecutor(javax.sql.DataSource dataSource)
          Constructor taking DataSource from which the DB Connection can be obtained.
 
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.
 com.google.common.cache.CacheStats getJdbcCallOperationsCacheStatistics()
          Allows for the retrieval of metrics (CacheStats}) for the jdbcCallOperationsCache, which is used to store instances of SimpleJdbcCallOperations.
 java.util.Map<java.lang.String,java.lang.Object> getJdbcCallOperationsCacheStatisticsAsMap()
          Allows for the retrieval of metrics (CacheStats}) for the jdbcCallOperationsCache.
 java.lang.String getStoredProcedureName()
           
 java.lang.String getStoredProcedureNameExpressionAsString()
           
 void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
          Allows to set the optional BeanFactory which is used to add a BeanResolver to the StandardEvaluationContext.
 void setFunction(boolean isFunction)
          Deprecated. Please use setIsFunction(boolean) instead.
 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 setIsFunction(boolean isFunction)
          Indicates whether a Stored Procedure or a Function is being executed.
 void setJdbcCallOperationsCacheSize(int jdbcCallOperationsCacheSize)
          Defines the maximum number of SimpleJdbcCallOperations (SimpleJdbcCall) instances to be held by jdbcCallOperationsCache.
 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,org.springframework.jdbc.core.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)
          Indicates the procedure's return value should be included in the results returned.
 void setSkipUndeclaredResults(boolean skipUndeclaredResults)
          If this variable is set to true then all results from a stored procedure call that don't have a corresponding SqlOutParameter declaration will be bypassed.
 void setSqlParameters(java.util.List<org.springframework.jdbc.core.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 setStoredProcedureName(java.lang.String storedProcedureName)
          The name of the Stored Procedure or Stored Function to be executed.
 void setStoredProcedureNameExpression(org.springframework.expression.Expression storedProcedureNameExpression)
          Using the storedProcedureNameExpression the Message can be used as source for the name of the Stored Procedure or Stored Function.
 void setUsePayloadAsParameterSource(boolean usePayloadAsParameterSource)
          If set to 'true', the payload of the Message will be used as a source for providing parameters.
 
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)
Constructor taking DataSource from which the DB Connection can be obtained.

Parameters:
dataSource - used to create a SimpleJdbcCall instance, must not be Null
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 org.springframework.beans.factory.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<org.springframework.jdbc.core.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

@ManagedAttribute(defaultValue="Null if not Set.")
public java.lang.String getStoredProcedureName()
Returns:
the name of the Stored Procedure or Function if set. Null otherwise.

getStoredProcedureNameExpressionAsString

@ManagedAttribute(defaultValue="Null if not Set.")
public java.lang.String getStoredProcedureNameExpressionAsString()
Returns:
the Stored Procedure Name Expression as a String if set. Null otherwise.

setStoredProcedureName

public void setStoredProcedureName(java.lang.String storedProcedureName)
The name of the Stored Procedure or Stored Function to be executed. If isFunction is set to "true", then this property specifies the Stored Function name. Alternatively you can also specify the Stored Procedure name via setStoredProcedureNameExpression(Expression). E.g., that way you can specify the name of the Stored Procedure or Stored Function through MessageHeaders.

Parameters:
storedProcedureName - Must not be null and must not be empty
See Also:
setStoredProcedureNameExpression(Expression)

setStoredProcedureNameExpression

public void setStoredProcedureNameExpression(org.springframework.expression.Expression storedProcedureNameExpression)
Using the storedProcedureNameExpression the Message can be used as source for the name of the Stored Procedure or Stored Function. If isFunction is 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: Alternatively you can also specify the Stored Procedure name via 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 entire Message will be available as a source for parameters. If no ProcedureParameter are passed in, this property will default to true. This means that using a default BeanPropertySqlParameterSourceFactory the bean properties of the payload will be used as a source for parameter values for the to-be-executed Stored Procedure or Function. However, if ProcedureParameters are passed in, then this property will by default evaluate to false. ProcedureParameter allow for SpEl Expressions to be provided and therefore it is highly beneficial to have access to the entire Message.

Parameters:
usePayloadAsParameterSource - If false the entire Message is used as parameter source.

setFunction

@Deprecated
public void setFunction(boolean isFunction)
Deprecated. Please use setIsFunction(boolean) instead.

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.

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 -

setSkipUndeclaredResults

public void setSkipUndeclaredResults(boolean skipUndeclaredResults)
If this variable is set to true then all results from a stored procedure call that don't have a corresponding SqlOutParameter declaration 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 underlying JdbcTemplate. Only few developers will probably ever like to process update counts, thus the value defaults to true.


setReturningResultSetRowMappers

public void setReturningResultSetRowMappers(java.util.Map<java.lang.String,org.springframework.jdbc.core.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.

getJdbcCallOperationsCacheStatistics

public com.google.common.cache.CacheStats getJdbcCallOperationsCacheStatistics()
Allows for the retrieval of metrics (CacheStats}) for the jdbcCallOperationsCache, which is used to store instances of SimpleJdbcCallOperations.

Returns:
Cache statistics for jdbcCallOperationsCache

getJdbcCallOperationsCacheStatisticsAsMap

@ManagedMetric
public java.util.Map<java.lang.String,java.lang.Object> getJdbcCallOperationsCacheStatisticsAsMap()
Allows for the retrieval of metrics (CacheStats}) for the jdbcCallOperationsCache. Provides the properties of CacheStats as a Map. This allows for exposing the those properties easily via JMX.

Returns:
Map containing metrics of the JdbcCallOperationsCache
See Also:
getJdbcCallOperationsCacheStatistics()

setJdbcCallOperationsCacheSize

public void setJdbcCallOperationsCacheSize(int jdbcCallOperationsCacheSize)
Defines the maximum number of SimpleJdbcCallOperations (SimpleJdbcCall) instances to be held by jdbcCallOperationsCache. A value of zero will disable the cache. The default is 10.

Parameters:
jdbcCallOperationsCacheSize - Must not be negative.
See Also:
CacheBuilder.maximumSize(long)

setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
Allows to set the optional BeanFactory which is used to add a BeanResolver to the StandardEvaluationContext. If not set this property defaults to null.

Specified by:
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
Parameters:
beanFactory - If set must not be null.

Spring Integration