use of com.adaptris.jdbc.JdbcResultBuilder 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);
}
}
Aggregations