Search in sources :

Example 1 with CreatePreparedStatementResp

use of org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp in project drill by axbaretto.

the class DrillJdbc41Factory method newServerPreparedStatement.

private DrillJdbc41PreparedStatement newServerPreparedStatement(DrillConnectionImpl connection, StatementHandle h, Meta.Signature signature, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
    String sql = signature.sql;
    try {
        DrillRpcFuture<CreatePreparedStatementResp> respFuture = connection.getClient().createPreparedStatement(signature.sql);
        CreatePreparedStatementResp resp;
        try {
            resp = respFuture.get();
        } catch (InterruptedException e) {
            // Preserve evidence that the interruption occurred so that code higher up
            // on the call stack can learn of the interruption and respond to it if it
            // wants to.
            Thread.currentThread().interrupt();
            throw new SQLException("Interrupted", e);
        }
        final RequestStatus status = resp.getStatus();
        if (status != RequestStatus.OK) {
            final String errMsgFromServer = resp.getError() != null ? resp.getError().getMessage() : "";
            if (status == RequestStatus.TIMEOUT) {
                logger.error("Request timed out to create prepare statement: {}", errMsgFromServer);
                throw new SQLTimeoutException("Failed to create prepared statement: " + errMsgFromServer);
            }
            if (status == RequestStatus.FAILED) {
                logger.error("Failed to create prepared statement: {}", errMsgFromServer);
                throw new SQLException("Failed to create prepared statement: " + errMsgFromServer);
            }
            logger.error("Failed to create prepared statement. Unknown status: {}, Error: {}", status, errMsgFromServer);
            throw new SQLException(String.format("Failed to create prepared statement. Unknown status: %s, Error: %s", status, errMsgFromServer));
        }
        return new DrillJdbc41PreparedStatement(connection, h, signature, resp.getPreparedStatement(), resultSetType, resultSetConcurrency, resultSetHoldability);
    } catch (SQLException e) {
        throw e;
    } catch (RuntimeException e) {
        throw Helper.INSTANCE.createException("Error while preparing statement [" + sql + "]", e);
    } catch (Exception e) {
        throw Helper.INSTANCE.createException("Error while preparing statement [" + sql + "]", e);
    }
}
Also used : SQLException(java.sql.SQLException) SQLTimeoutException(java.sql.SQLTimeoutException) CreatePreparedStatementResp(org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp) SQLTimeoutException(java.sql.SQLTimeoutException) SQLException(java.sql.SQLException) RequestStatus(org.apache.drill.exec.proto.UserProtos.RequestStatus)

Example 2 with CreatePreparedStatementResp

use of org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp in project drill by apache.

the class DrillJdbc41Factory method newServerPreparedStatement.

private DrillJdbc41PreparedStatement newServerPreparedStatement(DrillConnectionImpl connection, StatementHandle h, Meta.Signature signature, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
    String sql = signature.sql;
    try {
        DrillRpcFuture<CreatePreparedStatementResp> respFuture = connection.getClient().createPreparedStatement(signature.sql);
        CreatePreparedStatementResp resp;
        try {
            resp = respFuture.get();
        } catch (InterruptedException e) {
            // Preserve evidence that the interruption occurred so that code higher up
            // on the call stack can learn of the interruption and respond to it if it
            // wants to.
            Thread.currentThread().interrupt();
            throw new SQLException("Interrupted", e);
        }
        final RequestStatus status = resp.getStatus();
        if (status != RequestStatus.OK) {
            final String errMsgFromServer = resp.getError() != null ? resp.getError().getMessage() : "";
            if (status == RequestStatus.TIMEOUT) {
                logger.error("Request timed out to create prepare statement: {}", errMsgFromServer);
                throw new SQLTimeoutException("Failed to create prepared statement: " + errMsgFromServer);
            }
            if (status == RequestStatus.FAILED) {
                logger.error("Failed to create prepared statement: {}", errMsgFromServer);
                throw new SQLException("Failed to create prepared statement: " + errMsgFromServer);
            }
            logger.error("Failed to create prepared statement. Unknown status: {}, Error: {}", status, errMsgFromServer);
            throw new SQLException(String.format("Failed to create prepared statement. Unknown status: %s, Error: %s", status, errMsgFromServer));
        }
        return new DrillJdbc41PreparedStatement(connection, h, signature, resp.getPreparedStatement(), resultSetType, resultSetConcurrency, resultSetHoldability);
    } catch (SQLException e) {
        throw e;
    } catch (Exception e) {
        throw Helper.INSTANCE.createException("Error while preparing statement [" + sql + "]", e);
    }
}
Also used : SQLException(java.sql.SQLException) SQLTimeoutException(java.sql.SQLTimeoutException) CreatePreparedStatementResp(org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp) SQLTimeoutException(java.sql.SQLTimeoutException) SQLException(java.sql.SQLException) RequestStatus(org.apache.drill.exec.proto.UserProtos.RequestStatus)

Aggregations

SQLException (java.sql.SQLException)2 SQLTimeoutException (java.sql.SQLTimeoutException)2 CreatePreparedStatementResp (org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp)2 RequestStatus (org.apache.drill.exec.proto.UserProtos.RequestStatus)2