Class JdbcMessageHandler
- All Implemented Interfaces:
- org.reactivestreams.Subscriber<Message<?>>,- Aware,- BeanFactoryAware,- BeanNameAware,- DisposableBean,- InitializingBean,- ApplicationContextAware,- Ordered,- ComponentSourceAware,- ExpressionCapable,- Orderable,- IntegrationPattern,- NamedComponent,- IntegrationManagement,- TrackableComponent,- MessageHandler,- reactor.core.CoreSubscriber<Message<?>>
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 ITEMS (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. The item is wrapped only if it is not a Message already.
 
 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)
- Since:
- 2.0
- Author:
- Dave Syer, Artem Bilan, Trung Pham
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagementIntegrationManagement.ManagementOverrides
- 
Field SummaryFields inherited from class org.springframework.integration.context.IntegrationObjectSupportEXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagementMETER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructorsConstructorDescriptionJdbcMessageHandler(DataSource dataSource, String updateSql) Constructor takingDataSourcefrom which the DB Connection can be obtained and the select query to execute to retrieve new rows.JdbcMessageHandler(JdbcOperations jdbcOperations, String updateSql) Constructor takingJdbcOperationsinstance to use for query execution and the select query to execute to retrieve new rows.
- 
Method SummaryModifier and TypeMethodDescriptionexecuteUpdateQuery(Message<?> message, boolean keysGenerated) Execute an update for the provided message and generated keys flag.Subclasses may implement this method to provide component type information.protected voidhandleMessageInternal(Message<?> message) Executes the update, passing the message into theSqlParameterSourceFactory.protected voidonInit()Subclasses may implement this for initialization logic.voidsetKeysGenerated(boolean keysGenerated) Flag to indicate that the update query is an insert with auto-generated keys, which will be logged at debug level.voidsetPreparedStatementSetter(MessagePreparedStatementSetter preparedStatementSetter) Specify aMessagePreparedStatementSetterto populate parameters on thePreparedStatementwith theMessagecontext.voidsetSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory) Configure anSqlParameterSourceFactory.voidsetUsePayloadAsParameterSource(boolean usePayloadAsParameterSource) If set to 'true', the payload of the Message will be used as a source for providing parameters.Methods inherited from class org.springframework.integration.handler.AbstractMessageHandlerhandleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods inherited from class org.springframework.integration.handler.MessageHandlerSupportbuildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods inherited from class org.springframework.integration.context.IntegrationObjectSupportafterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscribercurrentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagementgetThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponentgetBeanName, getComponentName
- 
Constructor Details- 
JdbcMessageHandlerConstructor takingDataSourcefrom 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
 
- 
JdbcMessageHandlerConstructor takingJdbcOperationsinstance 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 Details- 
setKeysGeneratedpublic 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.- Parameters:
- keysGenerated- the flag value to set
 
- 
setSqlParameterSourceFactoryConfigure anSqlParameterSourceFactory.- Parameters:
- sqlParameterSourceFactory- the- SqlParameterSourceFactoryto use.
 
- 
setUsePayloadAsParameterSourcepublic void setUsePayloadAsParameterSource(boolean usePayloadAsParameterSource) If set to 'true', the payload of the Message will be used as a source for providing parameters. If false the entireMessagewill be available as a source for parameters. Makes sense only ifsetPreparedStatementSetter(MessagePreparedStatementSetter)is not provided.- Parameters:
- usePayloadAsParameterSource- false for the entire- Messageas parameter source.
- Since:
- 6.5
 
- 
setPreparedStatementSetterpublic void setPreparedStatementSetter(@Nullable MessagePreparedStatementSetter preparedStatementSetter) Specify aMessagePreparedStatementSetterto populate parameters on thePreparedStatementwith theMessagecontext.This is a low-level alternative to the SqlParameterSourceFactory.- Parameters:
- preparedStatementSetter- the- MessagePreparedStatementSetterto set.
- Since:
- 4.2
 
- 
getComponentTypeDescription copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
- getComponentTypein interface- NamedComponent
- Overrides:
- getComponentTypein class- MessageHandlerSupport
 
- 
onInitprotected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
- onInitin class- IntegrationObjectSupport
 
- 
handleMessageInternalExecutes the update, passing the message into theSqlParameterSourceFactory.- Specified by:
- handleMessageInternalin class- AbstractMessageHandler
 
- 
executeUpdateQueryprotected List<? extends Map<String,Object>> executeUpdateQuery(Message<?> message, boolean keysGenerated) Execute an update for the provided message and generated keys flag.- Parameters:
- message- the message to use for update query params.
- keysGenerated- generate key or not.
- Returns:
- a generated keys for update.
 
 
-