public class SplittingXmlPayloadTranslator extends XmlPayloadTranslatorImpl
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.
XmlPayloadTranslatorImpl.DocumentWrapper
StyledResultTranslatorImp.ColumnStyle
ELEMENT_NAME_COLUMN, ELEMENT_NAME_RESULTS, ELEMENT_NAME_ROW
log
Constructor and Description |
---|
SplittingXmlPayloadTranslator() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the component.
|
AdaptrisConnection |
getConnection()
Returns the
AdaptrisConnection to use for producing split
messages. |
java.lang.Boolean |
getCopyMetadata() |
java.lang.Integer |
getMaxRowsPerMessage() |
AdaptrisMessageFactory |
getMessageFactory() |
AdaptrisMessageProducer |
getProducer()
Returns the
AdaptrisMessageProducer to use for producing split
messages. |
void |
init()
Initialises the component.
|
void |
prepare()
Prepare for initialisation.
|
void |
setConnection(AdaptrisConnection conn)
Sets the
AdaptrisConnection 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 the
AdaptrisMessageProducer to use for producing split
messages. |
void |
start()
Starts the component.
|
void |
stop()
Stop the component
|
long |
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) |
createInputSource, createListFromResultSet, createTextNode, createXmlUtils, getCdataColumnRegexp, getOutputMessageEncoding, getStripIllegalXmlChars, getXmlColumnPrefix, getXmlColumnRegexp, isCdataColumn, isXmlColumn, setCdataColumnRegexp, setOutputMessageEncoding, setStripIllegalXmlChars, setXmlColumnPrefix, setXmlColumnRegexp, stripIllegalXmlChars
addColumnTranslator, getAttemptAutoConvert, getColumnTranslators, getDisplayColumnErrors, getResultCountMetadataItem, getUpdateCountMetadataItem, isDisplayColumnErrors, logColumnErrors, setAttemptAutoConvert, setColumnTranslators, setDisplayColumnErrors, setResultCountMetadataItem, setUpdateCountMetadataItem, toString, translate, updateMetadata, updateMetadataQueryCount, updateMetadataUpdateCount, withAttemptAutoConvert, withColumnTranslators, withColumnTranslators
getColumnNameStyle, setColumnNameStyle, withColumnNameStyle
public void init() throws CoreException
ComponentLifecycle
Component initialisation includes config verification, creation of connections etc.
init
in interface ComponentLifecycle
init
in class XmlPayloadTranslatorImpl
CoreException
- wrapping any underlying Exception
spublic void start() throws CoreException
ComponentLifecycle
Once a component is started it should be ready to process messages. In the case of AdaptrisMessageConsumer
, calling start
will begin message delivery.
CoreException
- wrapping any underlying Exception
spublic void prepare() throws CoreException
ComponentLifecycleExtension
prepare
in interface ComponentLifecycleExtension
prepare
in class ResultSetTranslatorBase
CoreException
public void stop()
ComponentLifecycle
A stopped component is not expected to be ready to process messages. In the case of AdaptrisMessageConsumer
, calling stop
will pause message delivery. Throwing a RuntimeException
may cause unintended consequences
public void close()
ComponentLifecycle
A closed component should release any connections it uses, etc. and clean up completely. Throwing a RuntimeException
may
cause unintended consequences
close
in interface ComponentLifecycle
close
in class XmlPayloadTranslatorImpl
public long translateResult(JdbcResult source, AdaptrisMessage inputMessage) throws java.sql.SQLException, ServiceException
translateResult
in class ResultSetTranslatorImp
java.sql.SQLException
ServiceException
public java.lang.Integer getMaxRowsPerMessage()
public void setMaxRowsPerMessage(java.lang.Integer maxRowsPerMessage)
public void setConnection(AdaptrisConnection conn)
Sets the AdaptrisConnection
to use for producing split
messages.
conn
- the AdaptrisConnection
to use for producing split
messages, may not be nullpublic AdaptrisConnection getConnection()
Returns the AdaptrisConnection
to use for producing split
messages.
AdaptrisConnection
to use for producing split
messagespublic void setProducer(AdaptrisMessageProducer prod)
Sets the AdaptrisMessageProducer
to use for producing split
messages.
prod
- the AdaptrisMessageProducer
to use for producing
split messages, may not be nullpublic AdaptrisMessageProducer getProducer()
Returns the AdaptrisMessageProducer
to use for producing split
messages.
AdaptrisMessageProducer
to use for producing split
messagespublic AdaptrisMessageFactory getMessageFactory()
public void setMessageFactory(AdaptrisMessageFactory messageFactory)
public void setCopyMetadata(java.lang.Boolean b)
Note that object metadata is never copied since the nested action is to produce the message somewhere.
b
- whether to copy metadata from the original message to the split messages (default
true)public java.lang.Boolean getCopyMetadata()
public SplittingXmlPayloadTranslator withCopyMetadata(java.lang.Boolean b)
public SplittingXmlPayloadTranslator withProducer(AdaptrisMessageProducer b)
public SplittingXmlPayloadTranslator withConnection(AdaptrisConnection b)
public SplittingXmlPayloadTranslator withMaxRowsPerMessage(java.lang.Integer b)
public SplittingXmlPayloadTranslator withMessageFactory(AdaptrisMessageFactory b)