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.ManagementOverridesEXPRESSION_PARSER, loggerMETER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE| 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, onSubscribebuildSendTimer, configureMetrics, destroy, getActiveCount, getActiveCountLong, getDuration, getErrorCount, getErrorCountLong, getHandleCount, getHandleCountLong, getHandlerMetrics, getIntegrationPatternType, getManagedName, getManagedType, getMaxDuration, getMeanDuration, getMetricsCaptor, getMinDuration, getOrder, getOverrides, getStandardDeviationDuration, isCountsEnabled, isLoggingEnabled, isStatsEnabled, registerMetricsCaptor, reset, sendTimer, setCountsEnabled, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, setStatsEnabled, shouldTrackafterPropertiesSet, 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, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waiterrorCount, handleCountgetBeanName, getComponentNamepublic 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()
IntegrationObjectSupportgetComponentType in interface NamedComponentgetComponentType in class MessageHandlerSupportprotected void onInit()
IntegrationObjectSupportonInit in class MessageHandlerSupportprotected void handleMessageInternal(Message<?> message)
SqlParameterSourceFactory.handleMessageInternal in class AbstractMessageHandler