use of org.apache.calcite.avatica.NoSuchStatementException in project calcite by apache.
the class CalciteConnectionImpl method enumerable.
public <T> Enumerable<T> enumerable(Meta.StatementHandle handle, CalcitePrepare.CalciteSignature<T> signature) throws SQLException {
Map<String, Object> map = Maps.newLinkedHashMap();
AvaticaStatement statement = lookupStatement(handle);
final List<TypedValue> parameterValues = TROJAN.getParameterValues(statement);
if (MetaImpl.checkParameterValueHasNull(parameterValues)) {
throw new SQLException("exception while executing query: unbound parameter");
}
for (Ord<TypedValue> o : Ord.zip(parameterValues)) {
map.put("?" + o.i, o.e.toLocal());
}
map.putAll(signature.internalParameters);
final AtomicBoolean cancelFlag;
try {
cancelFlag = getCancelFlag(handle);
} catch (NoSuchStatementException e) {
throw new RuntimeException(e);
}
map.put(DataContext.Variable.CANCEL_FLAG.camelName, cancelFlag);
final DataContext dataContext = createDataContext(map, signature.rootSchema);
return signature.enumerable(dataContext);
}
use of org.apache.calcite.avatica.NoSuchStatementException in project calcite by apache.
the class CalciteMetaImpl method prepare.
@Override
public StatementHandle prepare(ConnectionHandle ch, String sql, long maxRowCount) {
final StatementHandle h = createStatement(ch);
final CalciteConnectionImpl calciteConnection = getConnection();
final CalciteServerStatement statement;
try {
statement = calciteConnection.server.getStatement(h);
} catch (NoSuchStatementException e) {
// Not possible. We just created a statement.
throw new AssertionError("missing statement", e);
}
final Context context = statement.createPrepareContext();
final CalcitePrepare.Query<Object> query = toQuery(context, sql);
h.signature = calciteConnection.parseQuery(query, context, maxRowCount);
statement.setSignature(h.signature);
return h;
}
use of org.apache.calcite.avatica.NoSuchStatementException in project calcite-avatica by apache.
the class LocalService method apply.
public ExecuteResponse apply(ExecuteRequest request) {
try (final Context ignore = executeTimer.start()) {
try {
final Meta.ExecuteResult executeResult = meta.execute(request.statementHandle, request.parameterValues, AvaticaUtils.toSaturatedInt(request.maxRowCount));
final List<ResultSetResponse> results = new ArrayList<>(executeResult.resultSets.size());
for (Meta.MetaResultSet metaResultSet : executeResult.resultSets) {
results.add(toResponse(metaResultSet));
}
return new ExecuteResponse(results, false, serverLevelRpcMetadata);
} catch (NoSuchStatementException e) {
return new ExecuteResponse(null, true, serverLevelRpcMetadata);
}
}
}
use of org.apache.calcite.avatica.NoSuchStatementException in project calcite-avatica by apache.
the class JdbcMeta method execute.
@Override
public ExecuteResult execute(StatementHandle h, List<TypedValue> parameterValues, int maxRowsInFirstFrame) throws NoSuchStatementException {
try {
if (MetaImpl.checkParameterValueHasNull(parameterValues)) {
throw new SQLException("exception while executing query: unbound parameter");
}
final StatementInfo statementInfo = statementCache.getIfPresent(h.id);
if (null == statementInfo) {
throw new NoSuchStatementException(h);
}
final List<MetaResultSet> resultSets;
final PreparedStatement preparedStatement = (PreparedStatement) statementInfo.statement;
if (parameterValues != null) {
for (int i = 0; i < parameterValues.size(); i++) {
TypedValue o = parameterValues.get(i);
preparedStatement.setObject(i + 1, o.toJdbc(calendar));
}
}
if (preparedStatement.execute()) {
final Signature signature2;
if (preparedStatement.isWrapperFor(AvaticaPreparedStatement.class)) {
signature2 = h.signature;
} else {
h.signature = signature(preparedStatement.getMetaData(), preparedStatement.getParameterMetaData(), h.signature.sql, Meta.StatementType.SELECT);
signature2 = h.signature;
}
// Make sure we set this for subsequent fetch()'s to find the result set.
statementInfo.setResultSet(preparedStatement.getResultSet());
if (statementInfo.getResultSet() == null) {
resultSets = Collections.<MetaResultSet>singletonList(JdbcResultSet.empty(h.connectionId, h.id, signature2));
} else {
resultSets = Collections.<MetaResultSet>singletonList(JdbcResultSet.create(h.connectionId, h.id, statementInfo.getResultSet(), maxRowsInFirstFrame, signature2));
}
} else {
resultSets = Collections.<MetaResultSet>singletonList(JdbcResultSet.count(h.connectionId, h.id, preparedStatement.getUpdateCount()));
}
return new ExecuteResult(resultSets);
} catch (SQLException e) {
throw propagate(e);
}
}
use of org.apache.calcite.avatica.NoSuchStatementException in project calcite-avatica by apache.
the class JdbcMeta method prepareAndExecuteBatch.
@Override
public ExecuteBatchResult prepareAndExecuteBatch(StatementHandle h, List<String> sqlCommands) throws NoSuchStatementException {
try {
// Get the statement
final StatementInfo info = statementCache.getIfPresent(h.id);
if (info == null) {
throw new NoSuchStatementException(h);
}
// addBatch() for each sql command
final Statement stmt = info.statement;
for (String sqlCommand : sqlCommands) {
stmt.addBatch(sqlCommand);
}
// Execute the batch and return the results
return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(stmt));
} catch (SQLException e) {
throw propagate(e);
}
}
Aggregations