Search in sources :

Example 1 with IgniteSingletonIterator

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);
    }
}
Also used : IgniteSingletonIterator(org.apache.ignite.internal.util.lang.IgniteSingletonIterator) IgniteClusterReadOnlyException(org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) BatchUpdateException(java.sql.BatchUpdateException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteClusterReadOnlyException(org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException) CacheServerNotFoundException(org.apache.ignite.cache.CacheServerNotFoundException) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

BatchUpdateException (java.sql.BatchUpdateException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 CacheException (javax.cache.CacheException)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 CacheServerNotFoundException (org.apache.ignite.cache.CacheServerNotFoundException)1 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)1 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)1 IgniteClusterReadOnlyException (org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException)1 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)1 TraceSurroundings (org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)1 IgniteSingletonIterator (org.apache.ignite.internal.util.lang.IgniteSingletonIterator)1 IndexingQueryFilter (org.apache.ignite.spi.indexing.IndexingQueryFilter)1