Package org.frankframework.jdbc
Class JdbcListener<M>
java.lang.Object
org.frankframework.jdbc.JdbcFacade
org.frankframework.jdbc.JdbcListener<M>
- Type Parameters:
M- MessageWrapper or key. Key is also used as messageId
- All Implemented Interfaces:
FrankElement,HasApplicationContext,HasName,HasPhysicalDestination,IConfigurable,IHasProcessState<M>,IListener<M>,IPeekableListener<M>,IPullingListener<M>,IScopeProvider,IXAEnabled,NameAware,ConfigurableLifecycle,ReceiverAware<M>,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle
- Direct Known Subclasses:
JdbcQueryListener,JdbcTableListener
public class JdbcListener<M>
extends JdbcFacade
implements IPeekableListener<M>, IHasProcessState<M>, ReceiverAware<M>
JdbcListener base class.
- Since:
- 4.7
- Author:
- Gerrit van Brakel
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class org.frankframework.jdbc.JdbcFacade
logFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAdditionalQueryFieldsToSession(RawMessageWrapper<M> rawMessage, Map<String, Object> context) protected voidvoidafterMessageProcessed(PipeLineResult processResult, RawMessageWrapper<M> rawMessage, PipeLineSession pipeLineSession) Called to perform actions (like committing or sending a reply) after a message has been processed by the Pipeline.protected RawMessageWrapper<M> changeProcessState(Connection connection, RawMessageWrapper<M> rawMessage, ProcessState toState, String reason) changeProcessState(RawMessageWrapper<M> rawMessage, ProcessState toState, String reason) Change the processState of the message to the specified state, if that state is supported.voidcloseThread(Map<String, Object> threadContext) Finalizes a message receiving thread.voidConfigure this component.protected StringconvertQuery(String query) protected booleanexecute(Connection conn, String query, List<String> parameters) extractMessage(RawMessageWrapper<M> rawMessage, Map<String, Object> context) Extracts data from message obtained fromIPullingListener.getRawMessage(Map)orIPushingListener.wrapRawMessage(Object, PipeLineSession).protected RawMessageWrapper<M> This method returns aMessageWrappercontaining contents of the message stored in the database.protected StringgetKeyFromRawMessage(RawMessageWrapper<M> rawMessage) protected RawMessageWrapper<M> getRawMessage(Connection conn, Map<String, Object> threadContext) getRawMessage(Map<String, Object> threadContext) Retrieves messages from queue or other channel, but does no processing on it.getUpdateStatusQuery(ProcessState state) booleanprotected booleanProvides the set of ProcessStates used by this listener.Prepares a thread for receiving messages.voidsetAdditionalFields(String fieldNames) Comma-separated list of additional fields to be loaded from the table, besides Message, Key, MessageID and CorrelationID.voidsetBlobCharset(String string) Deprecated, for removal: This API element is subject to removal in a future version.voidsetBlobsCompressed(boolean b) Controls whether BLOB is considered stored compressed in the databasevoidsetBlobSmartGet(boolean b) Controls automatically whether blobdata is stored compressed and/or serialized in the database.voidsetCorrelationIdField(String fieldname) Field containing thecorrelationId.voidsetKeyField(String fieldname) Primary key field of the table, used to identify and differentiate messages.voidsetMessageField(String fieldname) Field containing the message datavoidType of the field containing the message datavoidsetMessageIdField(String fieldname) Field containing themessageId.voidsetPeekQuery(String string) (only used whenpeekUntransacted=true) peek query to determine if the select query should be executed.voidsetPeekUntransacted(boolean b) when true, then PollingListener container will execute getRawMessage() only when hasRawMessageAvailable() has returned true.protected voidsetSelectQuery(String string) voidsetSqlDialect(String string) If set, the SQL dialect in which the queries are written and should be translated from to the actual SQL dialectprotected voidsetUpdateStatusQuery(ProcessState state, String query) voidstart()Prepares the listener for receiving messages.voidstop()Close all resources used for listening.Provides the set of ProcessStates that a message in the specified state can be moved to, e.g. from a MessageBrowser for that state.Methods inherited from class org.frankframework.jdbc.JdbcFacade
getConnection, getConnectionWithTimeout, getDatasource, getDatasourceName, getDbmsSupport, getLogPrefix, getPassword, getPhysicalDestinationName, isConnectionsArePooled, isRunning, isTransacted, setAuthAlias, setConnectionsArePooled, setDatasourceName, setDbmsSupportFactory, setName, setPassword, setTransacted, setUsernameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContextMethods inherited from interface org.frankframework.lifecycle.ConfigurableLifecycle
getPhase, isAutoStartup, isConfiguredMethods inherited from interface org.frankframework.core.FrankElement
addConfigWarningMethods inherited from interface org.frankframework.core.HasApplicationContext
getApplicationContext, getConfigurationClassLoaderMethods inherited from interface org.frankframework.core.IPeekableListener
isPeekUntransactedMethods inherited from interface org.frankframework.receivers.ReceiverAware
getReceiver, setReceiverMethods inherited from interface org.springframework.context.SmartLifecycle
stop
-
Field Details
-
ADDITIONAL_QUERY_FIELDS_KEY
- See Also:
-
connection
-
-
Constructor Details
-
JdbcListener
public JdbcListener()
-
-
Method Details
-
configure
Description copied from interface:IConfigurableConfigure this component.configure()is called once at startup of the framework in the configure method of the owner of thisIConfigurable. Purpose of this method is to check whether the static configuration of the object is correct. As much as possible class-instantiating should take place in theconfigure(), to improve performance.In the case of a container, this will propagate the configure signal to all components that apply.
- Specified by:
configurein interfaceIConfigurable- Overrides:
configurein classJdbcFacade- Throws:
ConfigurationException- in case it was not able to configure the component.
-
start
public void start()Description copied from interface:IListenerPrepares the listener for receiving messages.start()is called once each time the listener is started.- Specified by:
startin interfaceConfigurableLifecycle- Specified by:
startin interfaceIListener<M>- Specified by:
startin interfaceorg.springframework.context.Lifecycle- Overrides:
startin classJdbcFacade
-
stop
public void stop()Description copied from interface:IListenerClose all resources used for listening. Called once each time the listener is stopped.- Specified by:
stopin interfaceIListener<M>- Specified by:
stopin interfaceorg.springframework.context.Lifecycle- Overrides:
stopin classJdbcFacade
-
openThread
Description copied from interface:IPullingListenerPrepares a thread for receiving messages. Called once for each thread that will listen for messages.- Specified by:
openThreadin interfaceIPullingListener<M>- Returns:
- the threadContext for this thread. The threadContext is a Map in which
thread-specific data can be stored. May not be
null, must be a mutable map type. - Throws:
ListenerException
-
closeThread
Description copied from interface:IPullingListenerFinalizes a message receiving thread. Called once for each thread that listens for messages, just beforeIListener.stop()is called.- Specified by:
closeThreadin interfaceIPullingListener<M>- Throws:
ListenerException
-
hasRawMessageAvailable
- Specified by:
hasRawMessageAvailablein interfaceIPeekableListener<M>- Throws:
ListenerException
-
hasRawMessageAvailable
- Throws:
ListenerException
-
getRawMessage
public RawMessageWrapper<M> getRawMessage(@Nonnull Map<String, Object> threadContext) throws ListenerExceptionDescription copied from interface:IPullingListenerRetrieves messages from queue or other channel, but does no processing on it. Multiple objects may try to call this method at the same time, from different threads. Implementations of this method should therefore be thread-safe, orsynchronized.Any thread-specific properties should be stored in and retrieved from the threadContext.
- Specified by:
getRawMessagein interfaceIPullingListener<M>- Throws:
ListenerException
-
getRawMessage
protected RawMessageWrapper<M> getRawMessage(Connection conn, Map<String, Object> threadContext) throws ListenerException- Throws:
ListenerException
-
extractRawMessage
This method returns aMessageWrappercontaining contents of the message stored in the database.- Parameters:
rs- JDBCResultSetfrom which to extract message data.- Returns:
- Either a
Stringbeing the message key, or aMessageWrapper. The message key asStringis returned ifmessageField,messageIdFieldandcorrelationIdFieldall are not set. IfmessageIdFieldand / orcorrelationIdFieldare set butmessageFieldis not, then the message key is returned as value of aMessagewrapped in aMessageWrapper. Otherwise the message is loaded from thersparameter and returned wrapped in aMessageWrapper. - Throws:
JdbcException- If loading the message resulted in a database exception.
-
addAdditionalValuesToMessageWrapper
protected void addAdditionalValuesToMessageWrapper(ResultSet rs, RawMessageWrapper<M> mw) throws SQLException - Throws:
SQLException
-
getKeyFromRawMessage
-
extractMessage
public Message extractMessage(@Nonnull RawMessageWrapper<M> rawMessage, @Nonnull Map<String, Object> context) throws ListenerExceptionDescription copied from interface:IListenerExtracts data from message obtained fromIPullingListener.getRawMessage(Map)orIPushingListener.wrapRawMessage(Object, PipeLineSession). May also extract other parameters from the message and put those into the context.- Specified by:
extractMessagein interfaceIListener<M>- Parameters:
rawMessage- TheRawMessageWrapperfrom which to extract theMessage.context- Context to populate. Either aPipeLineSessionor aMapthreadContext depending on caller.- Returns:
- input
Messagefor adapter. - Throws:
ListenerException
-
addAdditionalQueryFieldsToSession
protected void addAdditionalQueryFieldsToSession(@Nonnull RawMessageWrapper<M> rawMessage, @Nonnull Map<String, Object> context) -
afterMessageProcessed
public void afterMessageProcessed(PipeLineResult processResult, RawMessageWrapper<M> rawMessage, PipeLineSession pipeLineSession) throws ListenerException Description copied from interface:IListenerCalled to perform actions (like committing or sending a reply) after a message has been processed by the Pipeline.- Specified by:
afterMessageProcessedin interfaceIListener<M>- Throws:
ListenerException
-
knownProcessStates
Description copied from interface:IHasProcessStateProvides the set of ProcessStates used by this listener.- Specified by:
knownProcessStatesin interfaceIHasProcessState<M>
-
targetProcessStates
Description copied from interface:IHasProcessStateProvides the set of ProcessStates that a message in the specified state can be moved to, e.g. from a MessageBrowser for that state.- Specified by:
targetProcessStatesin interfaceIHasProcessState<M>
-
changeProcessState
public RawMessageWrapper<M> changeProcessState(RawMessageWrapper<M> rawMessage, ProcessState toState, String reason) throws ListenerException Description copied from interface:IHasProcessStateChange the processState of the message to the specified state, if that state is supported. If it is not supported, nothing changes, andfalseis returned.- Specified by:
changeProcessStatein interfaceIHasProcessState<M>- Returns:
- the moved message, or null if no message was moved.
- Throws:
ListenerException
-
changeProcessState
protected RawMessageWrapper<M> changeProcessState(Connection connection, RawMessageWrapper<M> rawMessage, ProcessState toState, String reason) throws ListenerException - Throws:
ListenerException
-
execute
protected boolean execute(Connection conn, String query, List<String> parameters) throws ListenerException - Throws:
ListenerException
-
convertQuery
- Throws:
SQLExceptionDbmsException
-
setUpdateStatusQuery
-
getUpdateStatusQuery
-
setSelectQuery
-
setPeekUntransacted
public void setPeekUntransacted(boolean b) Description copied from interface:IPeekableListenerwhen true, then PollingListener container will execute getRawMessage() only when hasRawMessageAvailable() has returned true. This avoids rolling back a lot of XA transactions, that appears to be problematic on MS SQL Server- Specified by:
setPeekUntransactedin interfaceIPeekableListener<M>
-
setPeekQuery
(only used whenpeekUntransacted=true) peek query to determine if the select query should be executed. Peek queries are, unlike select queries, executed without a transaction and without a rowlock- Default value
- selectQuery
-
setKeyField
Primary key field of the table, used to identify and differentiate messages. NB: there should be an index on this field! -
setMessageField
Field containing the message data- Default value
- same as keyField
-
setMessageFieldType
Type of the field containing the message data- Default value
- String
-
setMessageIdField
Field containing themessageId. NB: If this column is not set the default (primary key)keyFieldwill be used as messageId!- Default value
- same as keyField
-
setCorrelationIdField
Field containing thecorrelationId. NB: If this column is not set, themessageIdandcorrelationIdwill be the same!- Default value
- same as messageIdField
-
setSqlDialect
If set, the SQL dialect in which the queries are written and should be translated from to the actual SQL dialect -
setBlobsCompressed
public void setBlobsCompressed(boolean b) Controls whether BLOB is considered stored compressed in the database- Default value
- true
-
setBlobCharset
Deprecated, for removal: This API element is subject to removal in a future version.Charset used to read BLOB. When specified, then the BLOB will be converted into a string -
setBlobSmartGet
public void setBlobSmartGet(boolean b) Controls automatically whether blobdata is stored compressed and/or serialized in the database. N.B. When set true, then the BLOB will be converted into a string- Default value
- false
-
setAdditionalFields
Comma-separated list of additional fields to be loaded from the table, besides Message, Key, MessageID and CorrelationID. Any fields listed here will be added to the session as session-variables.
-