use of com.adaptris.jdbc.JdbcResultRow in project interlok by adaptris.
the class IntegerColumnTranslatorTest method testFormattedDouble.
@Test
public void testFormattedDouble() throws Exception {
translator.setFormat("%05d");
Double doubleVal = Double.valueOf("123");
JdbcResultRow row = new JdbcResultRow();
row.setFieldValue("testField", doubleVal, Types.INTEGER);
try {
translator.translate(row, 0);
fail();
} catch (Exception ex) {
// expected
}
try {
translator.translate(row, "testField");
fail();
} catch (Exception ex) {
// expected
}
}
use of com.adaptris.jdbc.JdbcResultRow in project interlok by adaptris.
the class XmlPayloadTranslatorImpl method createListFromResultSet.
protected List<Element> createListFromResultSet(DocumentWrapper wrapper, JdbcResultSet rs) throws SQLException {
List<Element> results = new ArrayList<Element>();
List<String> elementNames = new ArrayList<>();
boolean firstRecord = true;
Document doc = wrapper.document;
for (JdbcResultRow row : rs.getRows()) {
Element elementRow = doc.createElement(getColumnNameStyle().format(ELEMENT_NAME_ROW));
// let's go through and build up the element names we need once.
if (firstRecord) {
firstRecord = false;
elementNames = createElementNames(row);
}
for (int i = 0; i < row.getFieldCount(); i++) {
String columnName = row.getFieldName(i);
String value = toString(row, i);
Element node = doc.createElement(elementNames.get(i));
if (isXmlColumn(columnName)) {
try {
Document xmlColumn = null;
xmlColumn = wrapper.builder.parse(createInputSource(value));
node.appendChild(doc.importNode(xmlColumn.getFirstChild(), true));
} catch (Exception e) {
if (isDisplayColumnErrors()) {
log.warn("Failed to parse column {} as an XML Document, treating as text.", columnName);
log.trace("Failed to parse column {} as an XML Document", columnName, e);
}
node.appendChild(createTextNode(doc, value, isCdataColumn(columnName, wrapper)));
}
} else {
node.appendChild(createTextNode(doc, value, isCdataColumn(columnName, wrapper)));
}
elementRow.appendChild(node);
}
results.add(elementRow);
}
return results;
}
use of com.adaptris.jdbc.JdbcResultRow 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.JdbcResultRow 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.JdbcResultRow 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;
}
Aggregations