use of org.apache.ignite.internal.util.lang.IgniteSingletonIterator in project ignite by apache.
the class IgniteH2Indexing method executeDml.
/**
* Execute an all-ready {@link SqlFieldsQuery}.
*
* @param qryDesc Plan key.
* @param qryParams Parameters.
* @param dml DML.
* @param cancel Query cancel state holder.
* @return Query result.
*/
private List<? extends FieldsQueryCursor<List<?>>> executeDml(QueryDescriptor qryDesc, QueryParameters qryParams, QueryParserResultDml dml, GridQueryCancel cancel) {
IndexingQueryFilter filter = (qryDesc.local() ? backupFilter(null, qryParams.partitions()) : null);
long qryId = registerRunningQuery(qryDesc, qryParams, cancel, dml.statement());
Exception failReason = null;
try (TraceSurroundings ignored = MTC.support(ctx.tracing().create(SQL_DML_QRY_EXECUTE, MTC.span()))) {
if (!dml.mvccEnabled() && !updateInTxAllowed && ctx.cache().context().tm().inUserTx()) {
throw new IgniteSQLException("DML statements are not allowed inside a transaction over " + "cache(s) with TRANSACTIONAL atomicity mode (change atomicity mode to " + "TRANSACTIONAL_SNAPSHOT or disable this error message with system property " + "\"-DIGNITE_ALLOW_DML_INSIDE_TRANSACTION=true\")");
}
if (!qryDesc.local()) {
return executeUpdateDistributed(qryId, qryDesc, qryParams, dml, cancel);
} else {
UpdateResult updRes = executeUpdate(qryId, qryDesc, qryParams, dml, true, filter, cancel);
return singletonList(new QueryCursorImpl<>(new Iterable<List<?>>() {
@Override
public Iterator<List<?>> iterator() {
return new IgniteSingletonIterator<>(singletonList(updRes.counter()));
}
}, cancel, true, false));
}
} catch (IgniteException e) {
failReason = e;
throw e;
} catch (IgniteCheckedException e) {
failReason = e;
IgniteClusterReadOnlyException roEx = X.cause(e, IgniteClusterReadOnlyException.class);
if (roEx != null) {
throw new IgniteSQLException("Failed to execute DML statement. Cluster in read-only mode [stmt=" + qryDesc.sql() + ", params=" + Arrays.deepToString(qryParams.arguments()) + "]", IgniteQueryErrorCode.CLUSTER_READ_ONLY_MODE_ENABLED, e);
}
throw new IgniteSQLException("Failed to execute DML statement [stmt=" + qryDesc.sql() + ", params=" + Arrays.deepToString(qryParams.arguments()) + "]", e);
} finally {
runningQryMgr.unregister(qryId, failReason);
}
}
Aggregations