Search in sources :

Example 1 with JdbcResult

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);
    }
}
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)

Example 2 with JdbcResult

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;
}
Also used : StoredProcedure(com.adaptris.jdbc.StoredProcedure) Connection(java.sql.Connection) JdbcResult(com.adaptris.jdbc.JdbcResult) ProduceException(com.adaptris.core.ProduceException) SQLException(java.sql.SQLException) ProduceException(com.adaptris.core.ProduceException)

Aggregations

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