Spring Integration

org.springframework.integration.jdbc
Class JdbcMessageHandler

java.lang.Object
  extended by org.springframework.integration.jdbc.JdbcMessageHandler
All Implemented Interfaces:
MessageHandler

public class JdbcMessageHandler
extends Object
implements MessageHandler

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

Constructor Summary
JdbcMessageHandler(DataSource dataSource, String updateSql)
          Constructor taking DataSource from which the DB Connection can be obtained and the select query to execute to retrieve new rows.
JdbcMessageHandler(JdbcOperations jdbcOperations, String updateSql)
          Constructor taking JdbcOperations instance to use for query execution and the select query to execute to retrieve new rows.
 
Method Summary
 void handleMessage(Message<?> message)
          Executes the update, passing the message into the SqlParameterSourceFactory.
 void setSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory)
           
 void setUpdateSql(String updateSql)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcMessageHandler

public JdbcMessageHandler(DataSource dataSource,
                          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 - used to create a SimpleJdbcTemplate
updateSql - query to execute

JdbcMessageHandler

public JdbcMessageHandler(JdbcOperations jdbcOperations,
                          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

setUpdateSql

public void setUpdateSql(String updateSql)

setSqlParameterSourceFactory

public void setSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory)

handleMessage

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

Specified by:
handleMessage in interface MessageHandler
Parameters:
message - the message to be handled
Throws:
MessageRejectedException - if the handler doesn't select these types of messages
MessageHandlingException - when something went wrong during the handling
MessageDeliveryException - when this handler failed to deliver the reply related to the handling of the message

Spring Integration

Copyright © 2010. All Rights Reserved.