Search in sources :

Example 1 with NoOperation

use of org.h2.command.dml.NoOperation in project ignite by apache.

the class IgniteH2Indexing method doRunPrepared.

/**
 * Execute an all-ready {@link SqlFieldsQuery}.
 * @param schemaName Schema name.
 * @param prepared H2 command.
 * @param qry Fields query with flags.
 * @param twoStepQry Two-step query if this query must be executed in a distributed way.
 * @param meta Metadata for {@code twoStepQry}.
 * @param keepBinary Whether binary objects must not be deserialized automatically.
 * @param cancel Query cancel state holder.    @return Query result.
 */
private List<? extends FieldsQueryCursor<List<?>>> doRunPrepared(String schemaName, Prepared prepared, SqlFieldsQuery qry, GridCacheTwoStepQuery twoStepQry, List<GridQueryFieldMetadata> meta, boolean keepBinary, GridQueryCancel cancel) {
    String sqlQry = qry.getSql();
    boolean loc = qry.isLocal();
    IndexingQueryFilter filter = (loc ? backupFilter(null, qry.getPartitions()) : null);
    if (!prepared.isQuery()) {
        if (DmlStatementsProcessor.isDmlStatement(prepared)) {
            try {
                Connection conn = connectionForSchema(schemaName);
                if (!loc)
                    return dmlProc.updateSqlFieldsDistributed(schemaName, conn, prepared, qry, cancel);
                else {
                    final GridQueryFieldsResult updRes = dmlProc.updateSqlFieldsLocal(schemaName, conn, prepared, qry, filter, cancel);
                    return Collections.singletonList(new QueryCursorImpl<>(new Iterable<List<?>>() {

                        @Override
                        public Iterator<List<?>> iterator() {
                            try {
                                return new GridQueryCacheObjectsIterator(updRes.iterator(), objectContext(), true);
                            } catch (IgniteCheckedException e) {
                                throw new IgniteException(e);
                            }
                        }
                    }, cancel));
                }
            } catch (IgniteCheckedException e) {
                throw new IgniteSQLException("Failed to execute DML statement [stmt=" + sqlQry + ", params=" + Arrays.deepToString(qry.getArgs()) + "]", e);
            }
        }
        if (DdlStatementsProcessor.isDdlStatement(prepared)) {
            if (loc)
                throw new IgniteSQLException("DDL statements are not supported for LOCAL caches", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
            try {
                return Collections.singletonList(ddlProc.runDdlStatement(sqlQry, prepared));
            } catch (IgniteCheckedException e) {
                throw new IgniteSQLException("Failed to execute DDL statement [stmt=" + sqlQry + ']', e);
            }
        }
        if (prepared instanceof NoOperation) {
            QueryCursorImpl<List<?>> resCur = (QueryCursorImpl<List<?>>) new QueryCursorImpl(Collections.singletonList(Collections.singletonList(0L)), null, false);
            resCur.fieldsMeta(UPDATE_RESULT_META);
            return Collections.singletonList(resCur);
        }
        throw new IgniteSQLException("Unsupported DDL/DML operation: " + prepared.getClass().getName());
    }
    if (twoStepQry != null) {
        if (log.isDebugEnabled())
            log.debug("Parsed query: `" + sqlQry + "` into two step query: " + twoStepQry);
        checkQueryType(qry, true);
        return Collections.singletonList(doRunDistributedQuery(schemaName, qry, twoStepQry, meta, keepBinary, cancel));
    }
    // We've encountered a local query, let's just run it.
    try {
        return Collections.singletonList(queryLocalSqlFields(schemaName, qry, keepBinary, filter, cancel));
    } catch (IgniteCheckedException e) {
        throw new IgniteSQLException("Failed to execute local statement [stmt=" + sqlQry + ", params=" + Arrays.deepToString(qry.getArgs()) + "]", e);
    }
}
Also used : IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter) Connection(java.sql.Connection) QueryCursorImpl(org.apache.ignite.internal.processors.cache.QueryCursorImpl) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) GridQueryCacheObjectsIterator(org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator) GridQueryFieldsResult(org.apache.ignite.internal.processors.query.GridQueryFieldsResult) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) NoOperation(org.h2.command.dml.NoOperation) IgniteException(org.apache.ignite.IgniteException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)1 QueryCursorImpl (org.apache.ignite.internal.processors.cache.QueryCursorImpl)1 GridQueryCacheObjectsIterator (org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator)1 GridQueryFieldsResult (org.apache.ignite.internal.processors.query.GridQueryFieldsResult)1 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)1 IndexingQueryFilter (org.apache.ignite.spi.indexing.IndexingQueryFilter)1 NoOperation (org.h2.command.dml.NoOperation)1