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