Package org.frankframework.jdbc
Class JdbcListener<M>
java.lang.Object
org.frankframework.jndi.JndiBase
org.frankframework.jdbc.JdbcFacade
org.frankframework.jdbc.JdbcListener<M>
- Type Parameters:
M
- MessageWrapper or key. Key is also used as messageId
- All Implemented Interfaces:
HasPhysicalDestination
,IConfigurable
,IConfigurationAware
,IHasProcessState<M>
,IListener<M>
,INamedObject
,IPeekableListener<M>
,IPullingListener<M>
,IScopeProvider
,IXAEnabled
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
JdbcQueryListener
,JdbcTableListener
public class JdbcListener<M>
extends JdbcFacade
implements IPeekableListener<M>, IHasProcessState<M>
JdbcListener base class.
- Since:
- 4.7
- Author:
- Gerrit van Brakel
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterMessageProcessed
(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.void
closeThread
(Map<String, Object> threadContext) Finalizes a message receiving thread.void
configure()
is called once at startup of the framework in theconfigure()
method of the owner of this listener.protected String
convertQuery
(String query) protected boolean
execute
(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 MessageWrapper<M>
This method returns aMessageWrapper
containing contents of the message stored in the database.protected String
getKeyFromRawMessage
(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) boolean
protected boolean
boolean
boolean
boolean
boolean
isTrace()
Provides the set of ProcessStates used by this listener.Prepares a thread for receiving messages.void
setBlobCharset
(String string) Deprecated, for removal: This API element is subject to removal in a future version.void
setBlobsCompressed
(boolean b) Controls whether BLOB is considered stored compressed in the databasevoid
setBlobSmartGet
(boolean b) Controls automatically whether blobdata is stored compressed and/or serialized in the database.void
setCorrelationIdField
(String fieldname) Field containing thecorrelationId
.void
setKeyField
(String fieldname) Primary key field of the table, used to identify and differentiate messages.void
setMessageField
(String fieldname) Field containing the message datavoid
Type of the field containing the message datavoid
setMessageIdField
(String fieldname) Field containing themessageId
.void
setPeekQuery
(String string) (only used whenpeekUntransacted
=true
) peek query to determine if the select query should be executed.void
setPeekUntransacted
(boolean b) when true, then PollingListener container will execute getRawMessage() only when hasRawMessageAvailable() has returned true.protected void
setSelectQuery
(String string) void
setSqlDialect
(String string) If set, the SQL dialect in which the queries are written and should be translated from to the actual SQL dialectvoid
setTrace
(boolean trace) protected void
setUpdateStatusQuery
(ProcessState state, String query) void
start()
Prepares the listener for receiving messages.void
stop()
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
getAuthAlias, getConnection, getConnectionWithTimeout, getDatasource, getDataSourceFactory, getDatasourceInfo, getDatasourceName, getDbmsSupport, getDomain, getLogPrefix, getPassword, getPhysicalDestinationName, getUsername, isConnectionsArePooled, isTransacted, setAuthAlias, setConnectionsArePooled, setDataSourceFactory, setDatasourceName, setDbmsSupportFactory, setJmsRealm, setPassword, setTransacted, setUsername
Methods inherited from class org.frankframework.jndi.JndiBase
getApplicationContext, getAuthentication, getConfigurationClassLoader, getContext, getCredentials, getInitialContextFactoryName, getJmsRealmName, getJndiAuthAlias, getJndiContextPrefix, getJndiEnv, getJndiProperties, getName, getPrincipal, getProviderURL, getSecurityProtocol, getUrlPkgPrefixes, setApplicationContext, setAuthentication, setCredentials, setInitialContextFactoryName, setJndiAuthAlias, setJndiContextPrefix, setJndiProperties, setName, setPrincipal, setProviderURL, setSecurityProtocol, setUrlPkgPrefixes, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContext
Methods inherited from interface org.frankframework.core.IConfigurationAware
getApplicationContext, getName
Methods inherited from interface org.frankframework.core.INamedObject
getName, setName
Methods inherited from interface org.frankframework.core.IScopeProvider
getConfigurationClassLoader
-
Field Details
-
connection
-
-
Constructor Details
-
JdbcListener
public JdbcListener()
-
-
Method Details
-
configure
Description copied from interface:IListener
configure()
is called once at startup of the framework in theconfigure()
method of the owner of this listener. Purpose of this method is to reduce creating connections to databases etc. in theIPullingListener.getRawMessage(Map)
method. As much as possible class-instantiating should take place in theconfigure()
orIListener.start()
method, to improve performance.- Specified by:
configure
in interfaceIConfigurable
- Specified by:
configure
in interfaceIListener<M>
- Overrides:
configure
in classJdbcFacade
- Throws:
ConfigurationException
-
start
public void start()Description copied from interface:IListener
Prepares the listener for receiving messages.open()
is called once each time the listener is started. -
stop
public void stop()Description copied from interface:IListener
Close all resources used for listening. Called once each time the listener is stopped. -
openThread
Description copied from interface:IPullingListener
Prepares a thread for receiving messages. Called once for each thread that will listen for messages.- Specified by:
openThread
in 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:IPullingListener
Finalizes a message receiving thread. Called once for each thread that listens for messages, just beforeIListener.stop()
is called.- Specified by:
closeThread
in interfaceIPullingListener<M>
- Throws:
ListenerException
-
hasRawMessageAvailable
- Specified by:
hasRawMessageAvailable
in interfaceIPeekableListener<M>
- Throws:
ListenerException
-
hasRawMessageAvailable
- Throws:
ListenerException
-
getRawMessage
public RawMessageWrapper<M> getRawMessage(@Nonnull Map<String, Object> threadContext) throws ListenerExceptionDescription copied from interface:IPullingListener
Retrieves 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:
getRawMessage
in interfaceIPullingListener<M>
- Throws:
ListenerException
-
getRawMessage
protected RawMessageWrapper<M> getRawMessage(Connection conn, Map<String, Object> threadContext) throws ListenerException- Throws:
ListenerException
-
extractRawMessage
This method returns aMessageWrapper
containing contents of the message stored in the database.- Parameters:
rs
- JDBCResultSet
from which to extract message data.- Returns:
- Either a
String
being the message key, or aMessageWrapper
. The message key asString
is returned ifmessageField
,messageIdField
andcorrelationIdField
all are not set. IfmessageIdField
and / orcorrelationIdField
are set butmessageField
is not, then the message key is returned as value of aMessage
wrapped in aMessageWrapper
. Otherwise the message is loaded from thers
parameter and returned wrapped in aMessageWrapper
. - Throws:
JdbcException
- If loading the message resulted in a database exception.
-
getKeyFromRawMessage
- Throws:
ListenerException
-
extractMessage
public Message extractMessage(@Nonnull RawMessageWrapper<M> rawMessage, @Nonnull Map<String, Object> context) throws ListenerExceptionDescription copied from interface:IListener
Extracts 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:
extractMessage
in interfaceIListener<M>
- Parameters:
rawMessage
- TheRawMessageWrapper
from which to extract theMessage
.context
- Context to populate. Either aPipeLineSession
or aMap
threadContext depending on caller.- Returns:
- input
Message
for adapter. - Throws:
ListenerException
-
afterMessageProcessed
public void afterMessageProcessed(PipeLineResult processResult, RawMessageWrapper<M> rawMessage, PipeLineSession pipeLineSession) throws ListenerException Description copied from interface:IListener
Called to perform actions (like committing or sending a reply) after a message has been processed by the Pipeline.- Specified by:
afterMessageProcessed
in interfaceIListener<M>
- Throws:
ListenerException
-
knownProcessStates
Description copied from interface:IHasProcessState
Provides the set of ProcessStates used by this listener.- Specified by:
knownProcessStates
in interfaceIHasProcessState<M>
-
targetProcessStates
Description copied from interface:IHasProcessState
Provides 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:
targetProcessStates
in interfaceIHasProcessState<M>
-
changeProcessState
public RawMessageWrapper<M> changeProcessState(RawMessageWrapper<M> rawMessage, ProcessState toState, String reason) throws ListenerException Description copied from interface:IHasProcessState
Change the processState of the message to the specified state, if that state is supported. If it is not supported, nothing changes, andfalse
is returned.- Specified by:
changeProcessState
in 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:
SQLException
DbmsException
-
setUpdateStatusQuery
-
getUpdateStatusQuery
-
setSelectQuery
-
setPeekUntransacted
public void setPeekUntransacted(boolean b) Description copied from interface:IPeekableListener
when 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:
setPeekUntransacted
in 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)keyField
will be used as messageId!- Default value
- same as keyField
-
setCorrelationIdField
Field containing thecorrelationId
. NB: If this column is not set, themessageId
andcorrelationId
will 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
-
getSelectQuery
-
getPeekQuery
-
getKeyField
-
getMessageField
-
getMessageIdField
-
getCorrelationIdField
-
getMessageFieldType
-
getSqlDialect
-
getBlobCharset
-
isBlobsCompressed
public boolean isBlobsCompressed() -
isBlobSmartGet
public boolean isBlobSmartGet() -
setTrace
public void setTrace(boolean trace) -
isTrace
public boolean isTrace() -
isPeekUntransacted
public boolean isPeekUntransacted()- Specified by:
isPeekUntransacted
in interfaceIPeekableListener<M>
-