public class JdbcMessageHandler extends AbstractMessageHandler
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)
When a message payload is an instance of Iterable
, a
NamedParameterJdbcOperations.batchUpdate(String, SqlParameterSource[])
is performed, where each
SqlParameterSource
instance is based on items wrapped into an internal Message
implementation with
headers from the request message.
When a preparedStatementSetter
is configured, it is applied for each item in the appropriate
JdbcOperations.batchUpdate(String, BatchPreparedStatementSetter)
function.
NOTE: The batch update is not supported when keysGenerated
is in use.
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
)
IntegrationManagement.ManagementOverrides
EXPRESSION_PARSER, logger
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Constructor and Description |
---|
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. |
Modifier and Type | Method and Description |
---|---|
protected List<? extends Map<String,Object>> |
executeUpdateQuery(Message<?> message,
boolean keysGenerated) |
String |
getComponentType()
Subclasses may implement this method to provide component type information.
|
protected void |
handleMessageInternal(Message<?> message)
Executes the update, passing the message into the
SqlParameterSourceFactory . |
protected void |
onInit()
Subclasses may implement this for initialization logic.
|
void |
setKeysGenerated(boolean keysGenerated)
Flag to indicate that the update query is an insert with auto-generated keys,
which will be logged at debug level.
|
void |
setPreparedStatementSetter(MessagePreparedStatementSetter preparedStatementSetter)
Specify a
MessagePreparedStatementSetter to populate parameters on the
PreparedStatement with the Message context. |
void |
setSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory) |
handleMessage, onComplete, onError, onNext, onSubscribe
buildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getThisAs
getBeanName, getComponentName
public JdbcMessageHandler(DataSource dataSource, String updateSql)
DataSource
from which the DB Connection can be obtained and the select query to
execute to retrieve new rows.dataSource
- Must not be nullupdateSql
- query to executepublic JdbcMessageHandler(JdbcOperations jdbcOperations, String updateSql)
JdbcOperations
instance to use for query execution and the select query to execute to
retrieve new rows.jdbcOperations
- instance to use for query executionupdateSql
- query to executepublic void setKeysGenerated(boolean keysGenerated)
keysGenerated
- the flag value to setpublic void setSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory)
public void setPreparedStatementSetter(@Nullable MessagePreparedStatementSetter preparedStatementSetter)
MessagePreparedStatementSetter
to populate parameters on the
PreparedStatement
with the Message
context.
This is a low-level alternative to the SqlParameterSourceFactory
.
preparedStatementSetter
- the MessagePreparedStatementSetter
to set.public String getComponentType()
IntegrationObjectSupport
getComponentType
in interface NamedComponent
getComponentType
in class MessageHandlerSupport
protected void onInit()
IntegrationObjectSupport
onInit
in class IntegrationObjectSupport
protected void handleMessageInternal(Message<?> message)
SqlParameterSourceFactory
.handleMessageInternal
in class AbstractMessageHandler