Class SplittingXmlPayloadTranslator
- java.lang.Object
-
- com.adaptris.core.services.jdbc.ResultSetTranslatorBase
-
- com.adaptris.core.services.jdbc.StyledResultTranslatorImp
-
- com.adaptris.core.services.jdbc.ResultSetTranslatorImp
-
- com.adaptris.core.services.jdbc.XmlPayloadTranslatorImpl
-
- com.adaptris.core.services.jdbc.SplittingXmlPayloadTranslator
-
- All Implemented Interfaces:
ComponentLifecycle
,ComponentLifecycleExtension
,ResultSetTranslator
public class SplittingXmlPayloadTranslator extends XmlPayloadTranslatorImpl
Translate the ResultSet contents into some number of XML messages.The format of the output messages is as follows:
<Results> <Row> <column1>...</column1> <column2>...</column2> ... </Row> <Row> ... </Row> </Results>
Note that column1, column2, etc. is replaced by the actual column name as returned in the query. As such, the column name must be a valid XML element name. If the actual name (in the database table definition) is not valid, the query should specify an alias name in the query. E.g:
SELECT "col 1" AS "col1" FROM mytable;
The output messages will be constructed by the same MessageFactory as the incoming message. If a MessageFactory has been configured then that one will be used instead (useful in case the incoming message is file-backed, for example).
If you want to see how many rows were processed you can set one/both of the following;
Item Description Value result-count-metadata-item If set to a String metadata item name will specify the metadata item to contain the number of rows returned by your query Metadata item name update-count-metadata-item If set to a String metadata item name will specify the metadata item to contain the number of rows updated by your SQL statement Metadata item name In the adapter configuration file this class is aliased as jdbc-splitting-xml-payload-translator which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.adaptris.core.services.jdbc.XmlPayloadTranslatorImpl
XmlPayloadTranslatorImpl.DocumentWrapper
-
Nested classes/interfaces inherited from class com.adaptris.core.services.jdbc.StyledResultTranslatorImp
StyledResultTranslatorImp.ColumnStyle
-
-
Field Summary
-
Fields inherited from class com.adaptris.core.services.jdbc.XmlPayloadTranslatorImpl
ELEMENT_NAME_COLUMN, ELEMENT_NAME_RESULTS, ELEMENT_NAME_ROW
-
Fields inherited from class com.adaptris.core.services.jdbc.ResultSetTranslatorBase
log
-
-
Constructor Summary
Constructors Constructor Description SplittingXmlPayloadTranslator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the component.AdaptrisConnection
getConnection()
Returns theAdaptrisConnection
to use for producing split messages.java.lang.Boolean
getCopyMetadata()
java.lang.Integer
getMaxRowsPerMessage()
AdaptrisMessageFactory
getMessageFactory()
AdaptrisMessageProducer
getProducer()
Returns theAdaptrisMessageProducer
to use for producing split messages.void
init()
Initialises the component.void
prepare()
Prepare for initialisation.void
setConnection(AdaptrisConnection conn)
Sets theAdaptrisConnection
to use for producing split messages.void
setCopyMetadata(java.lang.Boolean b)
Whether to copy metadata from the original message to the split messages.void
setMaxRowsPerMessage(java.lang.Integer maxRowsPerMessage)
void
setMessageFactory(AdaptrisMessageFactory messageFactory)
void
setProducer(AdaptrisMessageProducer prod)
Sets theAdaptrisMessageProducer
to use for producing split messages.void
start()
Starts the component.void
stop()
Stop the componentlong
translateResult(JdbcResult source, AdaptrisMessage inputMessage)
Split the JdbcResult into possibly multiple output messages.SplittingXmlPayloadTranslator
withConnection(AdaptrisConnection b)
SplittingXmlPayloadTranslator
withCopyMetadata(java.lang.Boolean b)
SplittingXmlPayloadTranslator
withMaxRowsPerMessage(java.lang.Integer b)
SplittingXmlPayloadTranslator
withMessageFactory(AdaptrisMessageFactory b)
SplittingXmlPayloadTranslator
withProducer(AdaptrisMessageProducer b)
-
Methods inherited from class com.adaptris.core.services.jdbc.XmlPayloadTranslatorImpl
createInputSource, createListFromResultSet, createTextNode, createTransformer, createWrapper, createXmlUtils, getCdataColumnRegexp, getOutputMessageEncoding, getStripIllegalXmlChars, getXmlColumnPrefix, getXmlColumnRegexp, isCdataColumn, isXmlColumn, setCdataColumnRegexp, setOutputMessageEncoding, setStripIllegalXmlChars, setXmlColumnPrefix, setXmlColumnRegexp, stripIllegalXmlChars
-
Methods inherited from class com.adaptris.core.services.jdbc.ResultSetTranslatorImp
addColumnTranslator, getAttemptAutoConvert, getColumnTranslators, getDisplayColumnErrors, getResultCountMetadataItem, getUpdateCountMetadataItem, isDisplayColumnErrors, logColumnErrors, setAttemptAutoConvert, setColumnTranslators, setDisplayColumnErrors, setResultCountMetadataItem, setUpdateCountMetadataItem, toString, translate, updateMetadata, updateMetadataQueryCount, updateMetadataUpdateCount, withAttemptAutoConvert, withColumnTranslators, withColumnTranslators
-
Methods inherited from class com.adaptris.core.services.jdbc.StyledResultTranslatorImp
getColumnNameStyle, setColumnNameStyle, withColumnNameStyle
-
-
-
-
Method Detail
-
init
public void init() throws CoreException
Description copied from interface:ComponentLifecycle
Initialises the component.Component initialisation includes config verification, creation of connections etc.
- Specified by:
init
in interfaceComponentLifecycle
- Overrides:
init
in classXmlPayloadTranslatorImpl
- Throws:
CoreException
- wrapping any underlyingException
s
-
start
public void start() throws CoreException
Description copied from interface:ComponentLifecycle
Starts the component.Once a component is started it should be ready to process messages. In the case of
AdaptrisMessageConsumer
, calling start will begin message delivery.- Throws:
CoreException
- wrapping any underlyingException
s
-
prepare
public void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Overrides:
prepare
in classResultSetTranslatorBase
- Throws:
CoreException
-
stop
public void stop()
Description copied from interface:ComponentLifecycle
Stop the componentA stopped component is not expected to be ready to process messages. In the case of
AdaptrisMessageConsumer
, calling stop will pause message delivery. Throwing aRuntimeException
may cause unintended consequences
-
close
public void close()
Description copied from interface:ComponentLifecycle
Closes the component.A closed component should release any connections it uses, etc. and clean up completely. Throwing a
RuntimeException
may cause unintended consequences- Specified by:
close
in interfaceComponentLifecycle
- Overrides:
close
in classXmlPayloadTranslatorImpl
-
translateResult
public long translateResult(JdbcResult source, AdaptrisMessage inputMessage) throws java.sql.SQLException, ServiceException
Split the JdbcResult into possibly multiple output messages. Each ResultSet will start in a new message if there are multiple.- Specified by:
translateResult
in classResultSetTranslatorImp
- Throws:
java.sql.SQLException
ServiceException
-
getMaxRowsPerMessage
public java.lang.Integer getMaxRowsPerMessage()
-
setMaxRowsPerMessage
public void setMaxRowsPerMessage(java.lang.Integer maxRowsPerMessage)
-
setConnection
public void setConnection(AdaptrisConnection conn)
Sets the
AdaptrisConnection
to use for producing split messages.- Parameters:
conn
- theAdaptrisConnection
to use for producing split messages, may not be null
-
getConnection
public AdaptrisConnection getConnection()
Returns the
AdaptrisConnection
to use for producing split messages.- Returns:
- the
AdaptrisConnection
to use for producing split messages
-
setProducer
public void setProducer(AdaptrisMessageProducer prod)
Sets the
AdaptrisMessageProducer
to use for producing split messages.- Parameters:
prod
- theAdaptrisMessageProducer
to use for producing split messages, may not be null
-
getProducer
public AdaptrisMessageProducer getProducer()
Returns the
AdaptrisMessageProducer
to use for producing split messages.- Returns:
- the
AdaptrisMessageProducer
to use for producing split messages
-
getMessageFactory
public AdaptrisMessageFactory getMessageFactory()
-
setMessageFactory
public void setMessageFactory(AdaptrisMessageFactory messageFactory)
-
setCopyMetadata
public void setCopyMetadata(java.lang.Boolean b)
Whether to copy metadata from the original message to the split messages.Note that object metadata is never copied since the nested action is to produce the message somewhere.
- Parameters:
b
- whether to copy metadata from the original message to the split messages (default true)
-
getCopyMetadata
public java.lang.Boolean getCopyMetadata()
-
withCopyMetadata
public SplittingXmlPayloadTranslator withCopyMetadata(java.lang.Boolean b)
-
withProducer
public SplittingXmlPayloadTranslator withProducer(AdaptrisMessageProducer b)
-
withConnection
public SplittingXmlPayloadTranslator withConnection(AdaptrisConnection b)
-
withMaxRowsPerMessage
public SplittingXmlPayloadTranslator withMaxRowsPerMessage(java.lang.Integer b)
-
withMessageFactory
public SplittingXmlPayloadTranslator withMessageFactory(AdaptrisMessageFactory b)
-
-