Search in sources :

Example 6 with NoSuchStatementException

use of org.apache.calcite.avatica.NoSuchStatementException in project calcite-avatica by apache.

the class JdbcMeta method executeBatchProtobuf.

@Override
public ExecuteBatchResult executeBatchProtobuf(StatementHandle h, List<Requests.UpdateBatch> updateBatches) throws NoSuchStatementException {
    try {
        final StatementInfo info = statementCache.getIfPresent(h.id);
        if (null == info) {
            throw new NoSuchStatementException(h);
        }
        final PreparedStatement preparedStmt = (PreparedStatement) info.statement;
        for (Requests.UpdateBatch update : updateBatches) {
            int i = 1;
            for (Common.TypedValue value : update.getParameterValuesList()) {
                // Use the value and then increment
                preparedStmt.setObject(i++, TypedValue.protoToJdbc(value, calendar));
            }
            preparedStmt.addBatch();
        }
        return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(preparedStmt));
    } catch (SQLException e) {
        throw propagate(e);
    }
}
Also used : SQLException(java.sql.SQLException) NoSuchStatementException(org.apache.calcite.avatica.NoSuchStatementException) PreparedStatement(java.sql.PreparedStatement) AvaticaPreparedStatement(org.apache.calcite.avatica.AvaticaPreparedStatement) Requests(org.apache.calcite.avatica.proto.Requests) Common(org.apache.calcite.avatica.proto.Common)

Example 7 with NoSuchStatementException

use of org.apache.calcite.avatica.NoSuchStatementException in project calcite-avatica by apache.

the class JdbcMeta method syncResults.

public boolean syncResults(StatementHandle sh, QueryState state, long offset) throws NoSuchStatementException {
    try {
        final Connection conn = getConnection(sh.connectionId);
        final StatementInfo info = statementCache.getIfPresent(sh.id);
        if (null == info) {
            throw new NoSuchStatementException(sh);
        }
        final Statement statement = info.statement;
        // Let the state recreate the necessary ResultSet on the Statement
        info.setResultSet(state.invoke(conn, statement));
        if (null != info.getResultSet()) {
            // If it is non-null, try to advance to the requested offset.
            return info.advanceResultSetToOffset(info.getResultSet(), offset);
        }
        // No results, nothing to do. Client can move on.
        return false;
    } catch (SQLException e) {
        throw propagate(e);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) AvaticaPreparedStatement(org.apache.calcite.avatica.AvaticaPreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) NoSuchStatementException(org.apache.calcite.avatica.NoSuchStatementException)

Example 8 with NoSuchStatementException

use of org.apache.calcite.avatica.NoSuchStatementException in project druid by druid-io.

the class DruidMeta method prepare.

@Override
public StatementHandle prepare(final ConnectionHandle ch, final String sql, final long maxRowCount) {
    try {
        final StatementHandle statement = createStatement(ch);
        final DruidStatement druidStatement;
        try {
            druidStatement = getDruidStatement(statement);
        } catch (NoSuchStatementException e) {
            throw logFailure(new ISE(e, e.getMessage()));
        }
        final DruidConnection druidConnection = getDruidConnection(statement.connectionId);
        AuthenticationResult authenticationResult = authenticateConnection(druidConnection);
        if (authenticationResult == null) {
            throw logFailure(new ForbiddenException("Authentication failed."), "Authentication failed for statement[%s]", druidStatement.getStatementId());
        }
        statement.signature = druidStatement.prepare(sql, maxRowCount, authenticationResult).getSignature();
        LOG.debug("Successfully prepared statement[%s] for execution", druidStatement.getStatementId());
        return statement;
    } catch (NoSuchConnectionException e) {
        throw e;
    } catch (Throwable t) {
        throw errorHandler.sanitize(t);
    }
}
Also used : ForbiddenException(org.apache.druid.server.security.ForbiddenException) NoSuchConnectionException(org.apache.calcite.avatica.NoSuchConnectionException) NoSuchStatementException(org.apache.calcite.avatica.NoSuchStatementException) ISE(org.apache.druid.java.util.common.ISE) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult)

Example 9 with NoSuchStatementException

use of org.apache.calcite.avatica.NoSuchStatementException in project druid by druid-io.

the class DruidMeta method getDruidStatement.

@Nonnull
private DruidStatement getDruidStatement(final StatementHandle statement) throws NoSuchStatementException {
    final DruidConnection connection = getDruidConnection(statement.connectionId);
    final DruidStatement druidStatement = connection.getStatement(statement.id);
    if (druidStatement == null) {
        throw logFailure(new NoSuchStatementException(statement));
    }
    return druidStatement;
}
Also used : NoSuchStatementException(org.apache.calcite.avatica.NoSuchStatementException) Nonnull(javax.annotation.Nonnull)

Example 10 with NoSuchStatementException

use of org.apache.calcite.avatica.NoSuchStatementException in project calcite by apache.

the class CalciteMetaImpl method closeStatement.

@Override
public void closeStatement(StatementHandle h) {
    final CalciteConnectionImpl calciteConnection = getConnection();
    final CalciteServerStatement stmt;
    try {
        stmt = calciteConnection.server.getStatement(h);
    } catch (NoSuchStatementException e) {
        // statement is not valid; nothing to do
        return;
    }
    // stmt.close(); // TODO: implement
    calciteConnection.server.removeStatement(h);
}
Also used : CalciteServerStatement(org.apache.calcite.server.CalciteServerStatement) NoSuchStatementException(org.apache.calcite.avatica.NoSuchStatementException)

Aggregations

NoSuchStatementException (org.apache.calcite.avatica.NoSuchStatementException)16 SQLException (java.sql.SQLException)7 PreparedStatement (java.sql.PreparedStatement)6 AvaticaPreparedStatement (org.apache.calcite.avatica.AvaticaPreparedStatement)6 Statement (java.sql.Statement)3 ArrayList (java.util.ArrayList)3 NoSuchConnectionException (org.apache.calcite.avatica.NoSuchConnectionException)3 TypedValue (org.apache.calcite.avatica.remote.TypedValue)3 CalciteServerStatement (org.apache.calcite.server.CalciteServerStatement)3 DataContext (org.apache.calcite.DataContext)2 Meta (org.apache.calcite.avatica.Meta)2 Context (org.apache.calcite.avatica.metrics.Timer.Context)2 ISE (org.apache.druid.java.util.common.ISE)2 AuthenticationResult (org.apache.druid.server.security.AuthenticationResult)2 ForbiddenException (org.apache.druid.server.security.ForbiddenException)2 Connection (java.sql.Connection)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Nonnull (javax.annotation.Nonnull)1 AvaticaStatement (org.apache.calcite.avatica.AvaticaStatement)1 Common (org.apache.calcite.avatica.proto.Common)1