org.springframework.integration.jdbc
Class JdbcMessageStore

java.lang.Object
  extended by org.springframework.integration.jdbc.JdbcMessageStore
All Implemented Interfaces:
MessageStore

public class JdbcMessageStore
extends java.lang.Object
implements MessageStore

Implementation of MessageStore using a relational database via JDBC. SQL scripts to create the necessary tables are packaged as org/springframework/integration/jdbc/schema-*.sql, where * is the target database type.

Author:
Dave Syer

Field Summary
static int DEFAULT_LONG_STRING_LENGTH
           
static java.lang.String DEFAULT_TABLE_PREFIX
          Default value for the table prefix property.
static java.lang.String ID_KEY
          The name of the message header that stores the surrogate key used by this message store
static java.lang.String VERSION_KEY
          The name of the message header that stores the version used by this message store to implement optimistic locking
 
Constructor Summary
JdbcMessageStore()
          Convenient constructor for configuration use.
JdbcMessageStore(javax.sql.DataSource dataSource, org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer incrementer)
          Create a MessageStore with all mandatory properties.
 
Method Summary
 void afterPropertiesSet()
          Check mandatory properties (data source and incrementer).
 Message<?> delete(java.lang.Object id)
          Remove the Message with the given id from the MessageStore, if present, and return it.
 Message<?> get(java.lang.Object id)
          Return the Message with the given id, or null if no Message with that id exists in the MessageStore.
protected  java.lang.String getQuery(java.lang.String base)
          Replace patterns in the input to produce a valid SQL query.
 java.util.List<Message<?>> list()
          Return all Messages currently in the MessageStore.
 java.util.List<Message<?>> list(java.lang.Object correlationId)
          Return all Messages currently in the MessageStore that contain the provided correlationId header value.
<T> Message<T>
put(Message<T> message)
          Put the provided Message into the MessageStore.
 void setDataSource(javax.sql.DataSource dataSource)
          The JDBC DataSource to use when interacting with the database.
 void setIncrementer(org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer incrementer)
          Setter for DataFieldMaxValueIncrementer to be used when generating primary keys for Message instances.
 void setJdbcTemplate(org.springframework.jdbc.core.JdbcOperations jdbcTemplate)
          The JdbcOperations to use when interacting with the database.
 void setLobHandler(org.springframework.jdbc.support.lob.LobHandler lobHandler)
          Override the LobHandler that is used to create and unpack large objects in SQL queries.
 void setTablePrefix(java.lang.String tablePrefix)
          Public setter for the table prefix property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TABLE_PREFIX

public static final java.lang.String DEFAULT_TABLE_PREFIX
Default value for the table prefix property.

See Also:
Constant Field Values

DEFAULT_LONG_STRING_LENGTH

public static final int DEFAULT_LONG_STRING_LENGTH
See Also:
Constant Field Values

ID_KEY

public static final java.lang.String ID_KEY
The name of the message header that stores the surrogate key used by this message store


VERSION_KEY

public static final java.lang.String VERSION_KEY
The name of the message header that stores the version used by this message store to implement optimistic locking

Constructor Detail

JdbcMessageStore

public JdbcMessageStore()
Convenient constructor for configuration use.


JdbcMessageStore

public JdbcMessageStore(javax.sql.DataSource dataSource,
                        org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer incrementer)
Create a MessageStore with all mandatory properties.

Parameters:
dataSource - a DataSource
incrementer - a DataFieldMaxValueIncrementer
Method Detail

getQuery

protected java.lang.String getQuery(java.lang.String base)
Replace patterns in the input to produce a valid SQL query. This implementation replaces the table prefix.

Parameters:
base - the SQL query to be transformed
Returns:
a transformed query with replacements

setTablePrefix

public void setTablePrefix(java.lang.String tablePrefix)
Public setter for the table prefix property. This will be prefixed to all the table names before queries are executed. Defaults to DEFAULT_TABLE_PREFIX.

Parameters:
tablePrefix - the tablePrefix to set

setDataSource

public void setDataSource(javax.sql.DataSource dataSource)
The JDBC DataSource to use when interacting with the database. Either this property can be set or the jdbcTemplate.

Parameters:
dataSource - a DataSource

setJdbcTemplate

public void setJdbcTemplate(org.springframework.jdbc.core.JdbcOperations jdbcTemplate)
The JdbcOperations to use when interacting with the database. Either this property can be set or the dataSource.

Parameters:
dataSource - a DataSource

setIncrementer

public void setIncrementer(org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer incrementer)
Setter for DataFieldMaxValueIncrementer to be used when generating primary keys for Message instances. The message store manages its own surrogate keys for messages to avoid any ambiguity. When you put a message in the store it should come back as a new instance with a header called ID_KEY.

Parameters:
incrementer - the DataFieldMaxValueIncrementer

setLobHandler

public void setLobHandler(org.springframework.jdbc.support.lob.LobHandler lobHandler)
Override the LobHandler that is used to create and unpack large objects in SQL queries. The default is fine for almost all platforms, but some Oracle drivers require a native implementation.

Parameters:
lobHandler - a LobHandler

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Check mandatory properties (data source and incrementer).

Throws:
java.lang.Exception

delete

public Message<?> delete(java.lang.Object id)
Description copied from interface: MessageStore
Remove the Message with the given id from the MessageStore, if present, and return it. If no Message with that id is present in the store, this will return null.

Specified by:
delete in interface MessageStore

get

public Message<?> get(java.lang.Object id)
Description copied from interface: MessageStore
Return the Message with the given id, or null if no Message with that id exists in the MessageStore.

Specified by:
get in interface MessageStore

list

public java.util.List<Message<?>> list()
Description copied from interface: MessageStore
Return all Messages currently in the MessageStore.

Specified by:
list in interface MessageStore

list

public java.util.List<Message<?>> list(java.lang.Object correlationId)
Description copied from interface: MessageStore
Return all Messages currently in the MessageStore that contain the provided correlationId header value.

Specified by:
list in interface MessageStore
See Also:
MessageHeaders.getCorrelationId()

put

public <T> Message<T> put(Message<T> message)
Description copied from interface: MessageStore
Put the provided Message into the MessageStore. Its id will be used as an index so that the MessageStore.get(Object) and MessageStore.delete(Object) behave properly. If available, its correlationId header will also be stored so that the MessageStore.list(Object) method behaves properly.

Specified by:
put in interface MessageStore