use of com.adaptris.jdbc.JdbcResult in project interlok by adaptris.
the class JdbcDataQueryService method doService.
/**
* The main service method, which sees the specified query executed and the results returned in an XML message.
*
* @see com.adaptris.core.Service#doService(com.adaptris.core.AdaptrisMessage)
*/
@Override
@SuppressWarnings({ "lgtm [java/database-resource-leak]" })
public void doService(AdaptrisMessage msg) throws ServiceException {
log.trace("Beginning doService");
JdbcResult result = null;
Connection conn = null;
try {
Connection c = getConnection(msg);
if (!c.equals(actor.getSqlConnection())) {
actor.reInitialise(c);
}
conn = actor.getSqlConnection();
initXmlHelper(msg);
String statement = getStatementCreator().createStatement(msg);
PreparedStatement preparedStatement = actor.getQueryStatement(statement);
preparedStatement.clearParameters();
log.trace("Executing statement [{}]", statement);
this.getParameterApplicator().applyStatementParameters(msg, preparedStatement, getStatementParameters(), statement);
try {
// closed by the finally block which closes the JdbcResult
ResultSet rs = preparedStatement.executeQuery();
result = new JdbcResultBuilder().setHasResultSet(true).setResultSet(rs).build();
} catch (SQLException e) {
if (ignoreExecuteQueryErrors()) {
log.debug("Ignore ExecuteQuery Errors enabled); using empty ResultSet");
result = new JdbcResultBuilder().setHasResultSet(false).build();
} else {
throw e;
}
}
resultSetTranslator.translate(result, msg);
destroyXmlHelper(msg);
JdbcUtil.commit(conn, msg);
} catch (Exception e) {
JdbcUtil.rollback(conn, msg);
throw ExceptionHelper.wrapServiceException(e);
} finally {
JdbcUtil.closeQuietly(result);
JdbcUtil.closeQuietly(conn);
}
}
use of com.adaptris.jdbc.JdbcResult in project interlok by adaptris.
the class JdbcStoredProcedureProducer method doRequest.
@Override
protected AdaptrisMessage doRequest(AdaptrisMessage msg, String endpoint, long timeout) throws ProduceException {
Connection connection = null;
JdbcResult results = null;
try {
connection = getConnection(msg);
StoredProcedure storedProcedure = new StoredProcedure();
storedProcedure.setConnection(connection);
storedProcedure.setName(endpoint);
storedProcedure.setStatementCreator(getStatementCreator());
storedProcedure.setParameters(parseInParameters(msg));
storedProcedure.setStatementExecutor(getStatementExecutor());
storedProcedure.setTimeout(defaultTimeout());
storedProcedure.setAdaptrisMessage(msg);
storedProcedure.setResultSetTranslator(getResultSetTranslator());
results = storedProcedure.execute();
parseOutParameters(msg, results.getParameters());
commit(connection, msg);
} catch (Exception e) {
rollback(connection, msg);
throw new ProduceException(e);
} finally {
JdbcUtil.closeQuietly(results);
JdbcUtil.closeQuietly(connection);
}
return msg;
}
Aggregations