Spring Integration

org.springframework.integration.jdbc
Class StoredProcPollingChannelAdapter

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.jdbc.StoredProcPollingChannelAdapter
All Implemented Interfaces:
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, NamedComponent, MessageSource<java.lang.Object>

public class StoredProcPollingChannelAdapter
extends IntegrationObjectSupport
implements MessageSource<java.lang.Object>

A polling channel adapter that creates messages from the payload returned by executing a stored procedure or Sql function. Optionally an update can be executed after the execution of the Stored Procedure or Function in order to update processed rows.

Since:
2.1
Author:
Gunnar Hillert

Field Summary
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Constructor Summary
StoredProcPollingChannelAdapter(javax.sql.DataSource dataSource, java.lang.String storedProcedureName)
          Constructor taking DataSource from which the DB Connection can be obtained and the stored procedure name to execute.
 
Method Summary
protected  java.util.Map<java.lang.String,?> doPoll()
           
 java.lang.String getComponentType()
          Subclasses may implement this method to provide component type information.
protected  void onInit()
          Subclasses may implement this for initialization logic.
 Message<java.lang.Object> receive()
          Executes the query.
 void setExpectSingleResult(boolean expectSingleResult)
          This parameter indicates that only one result object shall be returned from the Stored Procedure/Function Call.
 void setFunction(boolean isFunction)
          Indicates whether a Stored Procedure or a Function is being executed.
 void setIgnoreColumnMetaData(boolean ignoreColumnMetaData)
          If true, the JDBC parameter definitions for the stored procedure are not automatically derived from the underlying JDBC connection.
 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)
          Does your stored procedure return one or more result sets? If so, you can use the provided method for setting the respective Rowmappers.
 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)
          Explicit declarations are necessary if the database you use is not a Spring-supported database.
 void setSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory)
          Provides the ability to set a custom SqlParameterSourceFactory.
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getConversionService, getTaskScheduler, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StoredProcPollingChannelAdapter

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

Parameters:
dataSource - used to create a SimpleJdbcCall
storedProcedureName - Name of the Stored Procedure or Function to execute
Method Detail

onInit

protected void onInit()
               throws java.lang.Exception
Description copied from class: IntegrationObjectSupport
Subclasses may implement this for initialization logic.

Overrides:
onInit in class IntegrationObjectSupport
Throws:
java.lang.Exception

receive

public Message<java.lang.Object> receive()
Executes the query. If a query result set contains one or more rows, the Message payload will contain either a List of Maps for each row or, if a RowMapper has been provided, the values mapped from those rows. If the query returns no rows, this method will return null.

Specified by:
receive in interface MessageSource<java.lang.Object>

doPoll

protected java.util.Map<java.lang.String,?> doPoll()

getComponentType

public java.lang.String getComponentType()
Description copied from class: IntegrationObjectSupport
Subclasses may implement this method to provide component type information.

Specified by:
getComponentType in interface NamedComponent
Overrides:
getComponentType in class IntegrationObjectSupport

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 by the default ExpressionEvaluatingSqlParameterSourceFactory.

Parameters:
sqlParameterSourceFactory -

setSqlParameters

public void setSqlParameters(java.util.List<org.springframework.jdbc.core.SqlParameter> sqlParameters)
Explicit declarations are necessary if the database you use is not a Spring-supported database. Currently Spring supports metadata lookup of stored procedure calls for the following databases: , , We also support metadata lookup of stored functions for the following databases: See also: http://static.springsource.org/spring/docs/3.1.0.M2/spring-framework-reference/html/jdbc.html


setReturningResultSetRowMappers

public void setReturningResultSetRowMappers(java.util.Map<java.lang.String,org.springframework.jdbc.core.RowMapper<?>> returningResultSetRowMappers)
Does your stored procedure return one or more result sets? If so, you can use the provided method for setting the respective Rowmappers.


setIgnoreColumnMetaData

public void setIgnoreColumnMetaData(boolean ignoreColumnMetaData)
If true, the JDBC parameter definitions for the stored procedure are not automatically derived from the underlying JDBC connection. In that case you must pass in SqlParameter explicitly..

Parameters:
ignoreColumnMetaData - Defaults to false.

setReturnValueRequired

public void setReturnValueRequired(boolean returnValueRequired)
Indicates the procedure's return value should be included in the results returned.

Parameters:
returnValueRequired -

setProcedureParameters

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


setFunction

public void setFunction(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.

setExpectSingleResult

public void setExpectSingleResult(boolean expectSingleResult)
This parameter indicates that only one result object shall be returned from the Stored Procedure/Function Call. If set to true, a resultMap that contains only 1 element, will have that 1 element extracted and returned as payload. If the resultMap contains more than 1 element and expectSingleResult is true, then a MessagingException is thrown. Otherwise the complete resultMap is returned as the Message payload. Important Note: Several databases such as H2 are not fully supported. The H2 database, for example, does not fully support the CallableStatement semantics and when executing function calls against H2, a result list is returned rather than a single value. Therefore, even if you set expectSingleResult = true, you may end up with a collection being returned.

Parameters:
expectSingleResult -

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.


Spring Integration