Search in sources :

Example 1 with JdbcResultBuilder

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);
    }
}
Also used : JdbcResultBuilder(com.adaptris.jdbc.JdbcResultBuilder) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JdbcResult(com.adaptris.jdbc.JdbcResult) ServiceException(com.adaptris.core.ServiceException) SQLException(java.sql.SQLException) CoreException(com.adaptris.core.CoreException)

Aggregations

CoreException (com.adaptris.core.CoreException)1 ServiceException (com.adaptris.core.ServiceException)1 DatabaseConnection (com.adaptris.core.jdbc.DatabaseConnection)1 JdbcResult (com.adaptris.jdbc.JdbcResult)1 JdbcResultBuilder (com.adaptris.jdbc.JdbcResultBuilder)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1