use of org.apache.ignite.client.proto.query.event.QuerySingleResult 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.client.proto.query.event.QuerySingleResult in project ignite-3 by apache.
the class JdbcStatement method execute0.
/**
* Execute the query with given parameters.
*
* @param sql Sql query.
* @param args Query parameters.
* @throws SQLException Onj error.
*/
protected void execute0(JdbcStatementType stmtType, String sql, List<Object> args) throws SQLException {
ensureNotClosed();
closeResults();
if (sql == null || sql.isEmpty()) {
throw new SQLException("SQL query is empty.");
}
QueryExecuteRequest req = new QueryExecuteRequest(stmtType, schema, pageSize, maxRows, sql, args == null ? ArrayUtils.OBJECT_EMPTY_ARRAY : args.toArray());
QueryExecuteResult res = conn.handler().queryAsync(req).join();
if (!res.hasResults()) {
throw IgniteQueryErrorCode.createJdbcSqlException(res.err(), res.status());
}
for (QuerySingleResult jdbcRes : res.results()) {
if (!jdbcRes.hasResults()) {
throw IgniteQueryErrorCode.createJdbcSqlException(jdbcRes.err(), jdbcRes.status());
}
}
resSets = new ArrayList<>(res.results().size());
for (QuerySingleResult jdbcRes : res.results()) {
resSets.add(new JdbcResultSet(this, jdbcRes.cursorId(), pageSize, jdbcRes.last(), jdbcRes.items(), jdbcRes.isQuery(), false, jdbcRes.updateCount(), closeOnCompletion, conn.handler()));
}
assert !resSets.isEmpty() : "At least one results set is expected";
}
Aggregations