use of org.apache.ignite.client.proto.query.event.BatchExecuteResult 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.client.proto.query.event.BatchExecuteResult in project ignite-3 by apache.
the class JdbcPreparedStatement method executeBatch.
/**
* {@inheritDoc}
*/
@Override
public int[] executeBatch() throws SQLException {
ensureNotClosed();
closeResults();
if (CollectionUtils.nullOrEmpty(batchedArgs) || StringUtil.isNullOrEmpty(sql)) {
return INT_EMPTY_ARRAY;
}
BatchPreparedStmntRequest req = new BatchPreparedStmntRequest(conn.getSchema(), sql, batchedArgs);
try {
BatchExecuteResult res = conn.handler().batchPrepStatementAsync(req).join();
if (!res.hasResults()) {
throw new BatchUpdateException(res.err(), IgniteQueryErrorCode.codeToSqlState(res.getErrorCode()), res.getErrorCode(), res.updateCounts());
}
return res.updateCounts();
} finally {
batchedArgs = null;
}
}
use of org.apache.ignite.client.proto.query.event.BatchExecuteResult in project ignite-3 by apache.
the class JdbcStatement method executeBatch.
/**
* {@inheritDoc}
*/
@Override
public int[] executeBatch() throws SQLException {
ensureNotClosed();
closeResults();
if (CollectionUtils.nullOrEmpty(batch)) {
return INT_EMPTY_ARRAY;
}
BatchExecuteRequest req = new BatchExecuteRequest(conn.getSchema(), batch);
try {
BatchExecuteResult res = conn.handler().batchAsync(req).join();
if (!res.hasResults()) {
throw new BatchUpdateException(res.err(), IgniteQueryErrorCode.codeToSqlState(res.getErrorCode()), res.getErrorCode(), res.updateCounts());
}
return res.updateCounts();
} finally {
batch = null;
}
}
use of org.apache.ignite.client.proto.query.event.BatchExecuteResult 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()));
}
use of org.apache.ignite.client.proto.query.event.BatchExecuteResult in project ignite-3 by apache.
the class JdbcQueryEventHandlerImpl method handleBatchException.
private CompletableFuture<BatchExecuteResult> handleBatchException(Exception e, String query, IntList res) {
StringWriter sw = getWriterWithStackTrace(e);
String error;
if (e instanceof ClassCastException) {
error = "Unexpected result after query:" + query + ". Not an upsert statement? " + sw;
} else {
error = sw.toString();
}
return CompletableFuture.completedFuture(new BatchExecuteResult(Response.STATUS_FAILED, UNKNOWN, error, res.toIntArray()));
}
Aggregations