Spring Integration

org.springframework.integration.jdbc
Class JdbcMessageHandler

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.handler.AbstractMessageHandler
          extended by org.springframework.integration.jdbc.JdbcMessageHandler
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.core.Ordered, NamedComponent, Orderable, MessageHandler, TrackableComponent

public class JdbcMessageHandler
extends AbstractMessageHandler

A message handler that executes an SQL update. Dynamic query parameters are supported through the SqlParameterSourceFactory abstraction, the default implementation of which wraps the message so that its bean properties can be referred to by name in the query string E.g.

 INSERT INTO FOOS (MESSAGE_ID, PAYLOAD) VALUES (:headers[id], :payload)
 
N.B. do not use quotes to escape the header keys. The default SQL parameter source (from Spring JDBC) can also handle headers with dotted names (e.g. business.id)

Since:
2.0
Author:
Dave Syer

Field Summary
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
JdbcMessageHandler(javax.sql.DataSource dataSource, java.lang.String updateSql)
          Constructor taking DataSource from which the DB Connection can be obtained and the select query to execute to retrieve new rows.
JdbcMessageHandler(org.springframework.jdbc.core.JdbcOperations jdbcOperations, java.lang.String updateSql)
          Constructor taking JdbcOperations instance to use for query execution and the select query to execute to retrieve new rows.
 
Method Summary
protected  java.util.List<? extends java.util.Map<java.lang.String,java.lang.Object>> executeUpdateQuery(java.lang.Object obj, boolean keysGenerated)
           
protected  void handleMessageInternal(Message<?> message)
          Executes the update, passing the message into the SqlParameterSourceFactory.
 void setKeysGenerated(boolean keysGenerated)
          Flag to indicate that the update query is an insert with autogenerated keys, which will be logged at debug level.
 void setSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory)
           
 void setUpdateSql(java.lang.String updateSql)
           
 
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
getComponentType, getOrder, handleMessage, setOrder, setShouldTrack
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getConversionService, getTaskScheduler, onInit, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.integration.context.NamedComponent
getComponentName
 

Constructor Detail

JdbcMessageHandler

public JdbcMessageHandler(javax.sql.DataSource dataSource,
                          java.lang.String updateSql)
Constructor taking DataSource from which the DB Connection can be obtained and the select query to execute to retrieve new rows.

Parameters:
dataSource - Must not be null
updateSql - query to execute

JdbcMessageHandler

public JdbcMessageHandler(org.springframework.jdbc.core.JdbcOperations jdbcOperations,
                          java.lang.String updateSql)
Constructor taking JdbcOperations instance to use for query execution and the select query to execute to retrieve new rows.

Parameters:
jdbcOperations - instance to use for query execution
updateSql - query to execute
Method Detail

setKeysGenerated

public void setKeysGenerated(boolean keysGenerated)
Flag to indicate that the update query is an insert with autogenerated keys, which will be logged at debug level.

Parameters:
keysGenerated - the flag value to set

setUpdateSql

public void setUpdateSql(java.lang.String updateSql)

setSqlParameterSourceFactory

public void setSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory)

handleMessageInternal

protected void handleMessageInternal(Message<?> message)
                              throws MessageRejectedException,
                                     MessageHandlingException,
                                     MessageDeliveryException
Executes the update, passing the message into the SqlParameterSourceFactory.

Specified by:
handleMessageInternal in class AbstractMessageHandler
Throws:
MessageRejectedException
MessageHandlingException
MessageDeliveryException

executeUpdateQuery

protected java.util.List<? extends java.util.Map<java.lang.String,java.lang.Object>> executeUpdateQuery(java.lang.Object obj,
                                                                                                        boolean keysGenerated)

Spring Integration