use of com.adaptris.jdbc.JdbcResultSet in project interlok by adaptris.
the class XmlPayloadTranslator method toDocument.
private DocumentWrapper toDocument(JdbcResult rs, AdaptrisMessage msg) throws Exception {
XmlUtils xu = createXmlUtils(msg);
DocumentWrapper wrapper = createWrapper(msg);
Document doc = wrapper.document;
ColumnStyle elementNameStyle = getColumnNameStyle();
Element results = doc.createElement(elementNameStyle.format(ELEMENT_NAME_RESULTS));
doc.appendChild(results);
if (isPreserveOriginalMessage()) {
Element originalMessage = doc.createElement(elementNameStyle.format(ORIGINAL_MESSAGE_ELEMENT));
if (xu.isDocumentValid()) {
Node n = xu.getSingleNode("/").getFirstChild();
originalMessage.appendChild(doc.importNode(n, true));
} else {
// Not XML, so let's add it in as a CDATA node.
originalMessage.appendChild(createTextNode(doc, msg.getContent(), true));
wrapper.hasCDATA = true;
}
results.appendChild(originalMessage);
}
for (JdbcResultSet rSet : rs.getResultSets()) {
List<Element> elements = createListFromResultSet(wrapper, rSet);
for (Element element : elements) {
results.appendChild(element);
}
wrapper.resultSetCount += elements.size();
}
return wrapper;
}
use of com.adaptris.jdbc.JdbcResultSet in project interlok by adaptris.
the class AllRowsMetadataTranslator method translateResult.
@Override
public long translateResult(JdbcResult source, AdaptrisMessage target) throws SQLException, ServiceException {
List<MetadataElement> added = new ArrayList<MetadataElement>();
long resultSetCount = 0;
for (JdbcResultSet resultSet : source.getResultSets()) {
int counter = 0;
String resultSetPrefix = source.countResultSets() > 1 ? Long.toString(resultSetCount) + getResultSetCounterPrefix() : "";
for (JdbcResultRow row : resultSet.getRows()) {
for (int i = 0; i < row.getFieldCount(); i++) {
MetadataElement md = new MetadataElement(resultSetPrefix + getMetadataKeyPrefix() + getSeparator() + getColumnNameStyle().format(row.getFieldName(i)) + getSeparator() + counter, toString(row, i));
if (log.isTraceEnabled()) {
added.add(md);
}
target.addMetadata(md);
}
counter++;
}
// In the event that we have multiple selects (unlikely from a JdbcDataQuery) then
// row-total will have the total for each result set
// resultSetCount will have the total for all resultSets.
// if (!isEmpty(getRowTotalMetadataKey())) {
// target.addMetadata(resultSetPrefix + getRowTotalMetadataKey(), String.valueOf(counter));
// }
resultSetCount += counter;
}
if (log.isTraceEnabled()) {
log.debug("Added metadata : " + added);
}
return resultSetCount;
}
use of com.adaptris.jdbc.JdbcResultSet in project interlok by adaptris.
the class SplittingXmlPayloadTranslator method translateResult.
/**
* Split the JdbcResult into possibly multiple output messages. Each ResultSet will start in a new message if there are multiple.
*/
@Override
public long translateResult(JdbcResult source, AdaptrisMessage inputMessage) throws SQLException, ServiceException {
long resultSetCount = 0;
try {
// Handle each ResultSet separately and create as many messages as required
for (JdbcResultSet rs : source.getResultSets()) {
// While we still have rows in this ResultSet
final Iterator<JdbcResultRow> rows = rs.getRows().iterator();
while (rows.hasNext()) {
AdaptrisMessage outputMessage = newMessage(inputMessage);
// is limit the number of iterations you make.
try (LimitedResultSet lrs = new LimitedResultSet(rows, maxRowsPerMessage())) {
DocumentWrapper wrapper = toDocument(outputMessage, lrs);
XmlHelper.writeXmlDocument(wrapper.document, outputMessage, getOutputMessageEncoding(), createTransformer(wrapper));
// Use the configured producer to send the message on its way
getProducer().produce(outputMessage);
resultSetCount += wrapper.resultSetCount;
}
}
}
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException("Failed to process message", e);
}
return resultSetCount;
}
use of com.adaptris.jdbc.JdbcResultSet in project interlok by adaptris.
the class FirstRowMetadataTranslator method translateResult.
@Override
public long translateResult(JdbcResult source, AdaptrisMessage target) throws SQLException, ServiceException {
List<MetadataElement> added = new ArrayList<MetadataElement>();
long resultSetCount = 0;
Iterator<JdbcResultRow> iter;
for (JdbcResultSet resultSet : source.getResultSets()) {
if (resultSet.getRows() != null && (iter = resultSet.getRows().iterator()) != null && iter.hasNext()) {
JdbcResultRow storedProcedureResultRow = iter.next();
if (storedProcedureResultRow != null) {
for (int i = 0; i < storedProcedureResultRow.getFieldCount(); i++) {
String column = storedProcedureResultRow.getFieldName(i);
String resultSetPrefix = source.countResultSets() > 1 ? Long.toString(resultSetCount) + getResultSetCounterPrefix() : "";
MetadataElement md = new MetadataElement(resultSetPrefix + getMetadataKeyPrefix() + getSeparator() + getColumnNameStyle().format(column), toString(storedProcedureResultRow, i));
if (log.isTraceEnabled()) {
added.add(md);
}
target.addMetadata(md);
}
if (log.isTraceEnabled()) {
log.debug("Added metadata : " + added);
}
} else {
log.debug("No Rows to process");
}
resultSetCount++;
}
}
return resultSetCount;
}
use of com.adaptris.jdbc.JdbcResultSet in project interlok by adaptris.
the class MergeResultSetIntoXmlPayload method createDocument.
private DocumentWrapper createDocument(JdbcResult rs, AdaptrisMessage msg) throws Exception {
DocumentWrapper wrapper = createWrapper(msg);
Document doc = wrapper.document;
Element results = doc.createElement(getColumnNameStyle().format(ELEMENT_NAME_RESULTS));
doc.appendChild(results);
for (JdbcResultSet rSet : rs.getResultSets()) {
List<Element> elements = createListFromResultSet(wrapper, rSet);
for (Element element : elements) {
results.appendChild(element);
}
wrapper.resultSetCount += elements.size();
}
return wrapper;
}
Aggregations