use of org.apache.ignite.internal.sql.engine.QueryContext in project ignite-3 by apache.
the class JdbcQueryEventHandlerImpl method batchPrepStatementAsync.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<BatchExecuteResult> batchPrepStatementAsync(BatchPreparedStmntRequest req) {
IntList res = new IntArrayList(req.getArgs().size());
QueryContext context = createQueryContext(JdbcStatementType.UPDATE_STATEMENT_TYPE);
try {
for (Object[] arg : req.getArgs()) {
executeAndCollectUpdateCount(context, req.schemaName(), req.getQuery(), arg, res);
}
} catch (Exception e) {
return handleBatchException(e, req.getQuery(), res);
}
return CompletableFuture.completedFuture(new BatchExecuteResult(res.toIntArray()));
}
use of org.apache.ignite.internal.sql.engine.QueryContext in project ignite-3 by apache.
the class JdbcQueryEventHandlerImpl method queryAsync.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<QueryExecuteResult> queryAsync(QueryExecuteRequest req) {
if (req.pageSize() <= 0) {
return CompletableFuture.completedFuture(new QueryExecuteResult(Response.STATUS_FAILED, "Invalid fetch size : [fetchSize=" + req.pageSize() + ']'));
}
List<SqlCursor<List<?>>> cursors;
try {
QueryContext context = createQueryContext(req.getStmtType());
List<SqlCursor<List<?>>> queryCursors = processor.query(context, req.schemaName(), req.sqlQuery(), req.arguments() == null ? OBJECT_EMPTY_ARRAY : req.arguments());
cursors = queryCursors.stream().map(cursor -> new JdbcQueryCursor<>(req.maxRows(), cursor)).collect(Collectors.toList());
} catch (Exception e) {
StringWriter sw = getWriterWithStackTrace(e);
return CompletableFuture.completedFuture(new QueryExecuteResult(Response.STATUS_FAILED, "Exception while executing query " + req.sqlQuery() + ". Error message: " + sw));
}
if (cursors.isEmpty()) {
return CompletableFuture.completedFuture(new QueryExecuteResult(Response.STATUS_FAILED, "At least one cursor is expected for query " + req.sqlQuery()));
}
List<QuerySingleResult> results = new ArrayList<>();
try {
for (SqlCursor<List<?>> cur : cursors) {
QuerySingleResult res = createJdbcResult(cur, req);
results.add(res);
}
} catch (Exception ex) {
StringWriter sw = getWriterWithStackTrace(ex);
return CompletableFuture.completedFuture(new QueryExecuteResult(Response.STATUS_FAILED, "Failed to fetch results for query " + req.sqlQuery() + ". Error message: " + sw));
}
return CompletableFuture.completedFuture(new QueryExecuteResult(results));
}
use of org.apache.ignite.internal.sql.engine.QueryContext in project ignite-3 by apache.
the class JdbcQueryEventHandlerImpl method batchAsync.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<BatchExecuteResult> batchAsync(BatchExecuteRequest req) {
List<String> queries = req.queries();
IntList res = new IntArrayList(queries.size());
QueryContext context = createQueryContext(JdbcStatementType.UPDATE_STATEMENT_TYPE);
for (String query : queries) {
try {
executeAndCollectUpdateCount(context, req.schemaName(), query, OBJECT_EMPTY_ARRAY, res);
} catch (Exception e) {
return handleBatchException(e, query, res);
}
}
return CompletableFuture.completedFuture(new BatchExecuteResult(res.toIntArray()));
}
Aggregations