Class AbstractJdbcListener
java.lang.Object
org.frankframework.jdbc.JdbcFacade
org.frankframework.jdbc.AbstractJdbcListener
- All Implemented Interfaces:
FrankElement, HasApplicationContext, HasName, HasPhysicalDestination, IConfigurable, IListener<Serializable>, IPeekableListener<Serializable>, IPullingListener<Serializable>, IScopeProvider, NameAware, TransactionAware, ConfigurableLifecycle, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle
- Direct Known Subclasses:
JdbcListener, StatelessJdbcListener
public abstract class AbstractJdbcListener
extends JdbcFacade
implements IPeekableListener<Serializable>
Abstract base class for JDBC listeners (excluding the deprecated and broken "SimpleJdbcListener").
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected booleanprotected Stringprotected Stringprotected Stringprotected booleanFields inherited from class JdbcFacade
logFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidcloseThread(@NonNull Map<String, Object> threadContext) Finalizes a message receiving thread.voidConfigure this component.protected booleanexecute(@NonNull Connection conn, @Nullable String query, @NonNull List<String> parameters) extractMessage(@NonNull RawMessageWrapper<Serializable> rawMessage, @NonNull Map<String, Object> context) Extracts data from message obtained fromIPullingListener.getRawMessage(Map)orIPushingListener.wrapRawMessage(Object, PipeLineSession).protected @NonNull MessageWrapper<Serializable> extractRawMessage(@NonNull ResultSet rs) This method returns aMessageWrappercontaining contents of the message stored in the database.protected @Nullable StringgetColumnValueOrDefault(@NonNull ResultSet rs, @Nullable String columnName, @Nullable String defaultValue) Get column value fromResultSet, or the default if either the column-name is empty (unconfigured) or if the result-set does not contain a column of this name.protected static @Nullable StringgetMessageKeyOrNull(RawMessageWrapper<Serializable> messageWrapper) Get the storage-key for the Message from theRawMessageWrapper, or NULL allowing for key-field not being configured for the listener.booleanPrepares 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.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 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) Methods inherited from class JdbcFacade
convertQuery, getConnection, getConnectionWithTimeout, getDatasource, getDatasourceName, getDbmsSupport, getLogPrefix, getPassword, getPhysicalDestinationName, isRunning, setAuthAlias, setBlobCharset, setBlobsCompressed, setBlobSmartGet, setDatasourceName, setDbmsSupportFactory, setName, setPassword, setSqlDialect, setUsername, start, stop, withConnection, withConnectionMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContextMethods inherited from interface ConfigurableLifecycle
getPhase, isAutoStartup, isConfiguredMethods inherited from interface FrankElement
addConfigWarningMethods inherited from interface HasApplicationContext
getApplicationContext, getConfigurationClassLoaderMethods inherited from interface IListener
afterMessageProcessed, start, stopMethods inherited from interface IPeekableListener
isPeekUntransactedMethods inherited from interface IPullingListener
getRawMessageMethods inherited from interface org.springframework.context.SmartLifecycle
isPauseable, stop
-
Field Details
-
ADDITIONAL_QUERY_FIELDS_KEY
- See Also:
-
selectQuery
-
messageField
-
messageIdField
-
correlationIdField
-
preparedSelectQuery
-
preparedPeekQuery
-
peekQuery
-
keyField
-
additionalFields
-
additionalFieldsList
-
peekUntransacted
protected boolean peekUntransacted -
trace
protected boolean trace
-
-
Constructor Details
-
AbstractJdbcListener
public AbstractJdbcListener()
-
-
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.
-
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<Serializable>- 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.
-
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<Serializable>
-
hasRawMessageAvailable
- Specified by:
hasRawMessageAvailablein interfaceIPeekableListener<Serializable>- Throws:
ListenerException
-
getColumnValueOrDefault
protected @Nullable String getColumnValueOrDefault(@NonNull ResultSet rs, @Nullable String columnName, @Nullable String defaultValue) throws SQLException Get column value fromResultSet, or the default if either the column-name is empty (unconfigured) or if the result-set does not contain a column of this name.
Notably, if the column exists in the resultset but has a null value, null is returned instead of the defaultValue.- Parameters:
rs- TheResultSetfrom which to get the column.columnName- The name of the column, can benullor empty.defaultValue- Default value for the column if columnName was empty, or not present in theResultSet. Can benull.- Returns:
- Value from the
ResultSet, or the default if columName was empty or not present in the ResultSet. - Throws:
SQLException- Propagates theSQLExceptionwhich may be thrown from theResultSet.
-
addAdditionalValuesToMessageWrapper
protected void addAdditionalValuesToMessageWrapper(ResultSet rs, MessageWrapper<Serializable> mw) throws SQLException - Throws:
SQLException
-
execute
protected boolean execute(@NonNull Connection conn, @Nullable String query, @NonNull List<String> parameters) throws ListenerException - Throws:
ListenerException
-
extractRawMessage
protected @NonNull MessageWrapper<Serializable> extractRawMessage(@NonNull ResultSet rs) throws SQLException, IOException, DbmsException 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:
SQLException- If loading the message resulted in a database exception.IOException- If loading the message resulted in an IO exceptionDbmsException
-
extractMessage
public Message extractMessage(@NonNull RawMessageWrapper<Serializable> 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.The
Receiverdoes not call this method when the listener implementation returned an instance ofMessageWrapperfromIPullingListener.getRawMessage(Map)or *IPushingListener.wrapRawMessage(Object, PipeLineSession).- Specified by:
extractMessagein interfaceIListener<Serializable>- Parameters:
rawMessage- TheRawMessageWrapperfrom which to extract theMessage.context- Context to populate. Either aPipeLineSessionor aMapthreadContext depending on caller.- Returns:
- input
Messagefor adapter. - Throws:
ListenerException
-
getMessageKeyOrNull
protected static @Nullable String getMessageKeyOrNull(RawMessageWrapper<Serializable> messageWrapper) Get the storage-key for the Message from theRawMessageWrapper, or NULL allowing for key-field not being configured for the listener. -
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<Serializable>
-
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
-
setMessageIdField
-
setCorrelationIdField
Field containing thecorrelationId. NB: If this column is not set, or set to a column which cannot be found in the query result, themessageIdandcorrelationIdwill be the same!- Default value
- same as messageIdField
-
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, with the prefix ADDITIONAL_QUERY_FIELDS_KEY. So if for example you specifyadditionalFields = "updated_at", then in the session there will be a variableADDITIONAL_QUERY_FIELDS.updated_at.
-