Search in sources :

Example 1 with FieldsQueryCursor

use of org.apache.ignite.cache.query.FieldsQueryCursor in project ignite by apache.

the class GridQueryProcessor method querySqlFieldsNoCache.

/**
     * Query SQL fields without strict dependency on concrete cache.
     *
     * @param qry Query.
     * @param keepBinary Keep binary flag.
     * @return Cursor.
     */
public FieldsQueryCursor<List<?>> querySqlFieldsNoCache(final SqlFieldsQuery qry, final boolean keepBinary) {
    checkxEnabled();
    validateSqlFieldsQuery(qry);
    if (qry.isLocal())
        throw new IgniteException("Local query is not supported without specific cache.");
    if (qry.getSchema() == null)
        qry.setSchema(QueryUtils.DFLT_SCHEMA);
    if (!busyLock.enterBusy())
        throw new IllegalStateException("Failed to execute query (grid is stopping).");
    try {
        IgniteOutClosureX<FieldsQueryCursor<List<?>>> clo = new IgniteOutClosureX<FieldsQueryCursor<List<?>>>() {

            @Override
            public FieldsQueryCursor<List<?>> applyx() throws IgniteCheckedException {
                GridQueryCancel cancel = new GridQueryCancel();
                return idx.queryDistributedSqlFields(qry.getSchema(), qry, keepBinary, cancel, null);
            }
        };
        return executeQuery(GridCacheQueryType.SQL_FIELDS, qry.getSql(), null, clo, true);
    } catch (IgniteCheckedException e) {
        throw new CacheException(e);
    } finally {
        busyLock.leaveBusy();
    }
}
Also used : IgniteOutClosureX(org.apache.ignite.internal.util.lang.IgniteOutClosureX) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 2 with FieldsQueryCursor

use of org.apache.ignite.cache.query.FieldsQueryCursor in project ignite by apache.

the class IgniteCacheProxy method query.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <R> QueryCursor<R> query(Query<R> qry) {
    A.notNull(qry, "qry");
    GridCacheGateway<K, V> gate = this.gate;
    CacheOperationContext prev = onEnter(gate, opCtx);
    try {
        ctx.checkSecurity(SecurityPermission.CACHE_READ);
        validate(qry);
        convertToBinary(qry);
        CacheOperationContext opCtxCall = ctx.operationContextPerCall();
        boolean keepBinary = opCtxCall != null && opCtxCall.isKeepBinary();
        if (qry instanceof ContinuousQuery)
            return (QueryCursor<R>) queryContinuous((ContinuousQuery<K, V>) qry, qry.isLocal(), keepBinary);
        if (qry instanceof SqlQuery)
            return (QueryCursor<R>) ctx.kernalContext().query().querySql(ctx, (SqlQuery) qry, keepBinary);
        if (qry instanceof SqlFieldsQuery)
            return (FieldsQueryCursor<R>) ctx.kernalContext().query().querySqlFields(ctx, (SqlFieldsQuery) qry, keepBinary);
        if (qry instanceof ScanQuery)
            return query((ScanQuery) qry, null, projection(qry.isLocal()));
        return (QueryCursor<R>) query(qry, projection(qry.isLocal()));
    } catch (Exception e) {
        if (e instanceof CacheException)
            throw (CacheException) e;
        throw new CacheException(e);
    } finally {
        onLeave(gate, prev);
    }
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) CacheException(javax.cache.CacheException) ScanQuery(org.apache.ignite.cache.query.ScanQuery) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) QueryCursor(org.apache.ignite.cache.query.QueryCursor) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor)

Example 3 with FieldsQueryCursor

use of org.apache.ignite.cache.query.FieldsQueryCursor in project ignite by apache.

the class GridQueryProcessor method querySqlFields.

/**
     * Query SQL fields.
     *
     * @param cctx Cache context.
     * @param qry Query.
     * @param keepBinary Keep binary flag.
     * @return Cursor.
     */
@SuppressWarnings("unchecked")
public FieldsQueryCursor<List<?>> querySqlFields(final GridCacheContext<?, ?> cctx, final SqlFieldsQuery qry, final boolean keepBinary) {
    checkxEnabled();
    validateSqlFieldsQuery(qry);
    boolean loc = (qry.isReplicatedOnly() && cctx.isReplicatedAffinityNode()) || cctx.isLocal() || qry.isLocal();
    if (!busyLock.enterBusy())
        throw new IllegalStateException("Failed to execute query (grid is stopping).");
    try {
        final String schemaName = qry.getSchema() != null ? qry.getSchema() : idx.schema(cctx.name());
        final int mainCacheId = CU.cacheId(cctx.name());
        IgniteOutClosureX<FieldsQueryCursor<List<?>>> clo;
        if (loc) {
            clo = new IgniteOutClosureX<FieldsQueryCursor<List<?>>>() {

                @Override
                public FieldsQueryCursor<List<?>> applyx() throws IgniteCheckedException {
                    GridQueryCancel cancel = new GridQueryCancel();
                    FieldsQueryCursor<List<?>> cur;
                    if (cctx.config().getQueryParallelism() > 1) {
                        qry.setDistributedJoins(true);
                        cur = idx.queryDistributedSqlFields(schemaName, qry, keepBinary, cancel, mainCacheId);
                    } else {
                        IndexingQueryFilter filter = idx.backupFilter(requestTopVer.get(), qry.getPartitions());
                        cur = idx.queryLocalSqlFields(schemaName, qry, keepBinary, filter, cancel);
                    }
                    sendQueryExecutedEvent(qry.getSql(), qry.getArgs(), cctx.name());
                    return cur;
                }
            };
        } else {
            clo = new IgniteOutClosureX<FieldsQueryCursor<List<?>>>() {

                @Override
                public FieldsQueryCursor<List<?>> applyx() throws IgniteCheckedException {
                    return idx.queryDistributedSqlFields(schemaName, qry, keepBinary, null, mainCacheId);
                }
            };
        }
        return executeQuery(GridCacheQueryType.SQL_FIELDS, qry.getSql(), cctx, clo, true);
    } catch (IgniteCheckedException e) {
        throw new CacheException(e);
    } finally {
        busyLock.leaveBusy();
    }
}
Also used : FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter)

Aggregations

CacheException (javax.cache.CacheException)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 FieldsQueryCursor (org.apache.ignite.cache.query.FieldsQueryCursor)3 IgniteException (org.apache.ignite.IgniteException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 EntryProcessorException (javax.cache.processor.EntryProcessorException)1 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)1 QueryCursor (org.apache.ignite.cache.query.QueryCursor)1 ScanQuery (org.apache.ignite.cache.query.ScanQuery)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 SqlQuery (org.apache.ignite.cache.query.SqlQuery)1 GridClosureException (org.apache.ignite.internal.util.lang.GridClosureException)1 IgniteOutClosureX (org.apache.ignite.internal.util.lang.IgniteOutClosureX)1 IndexingQueryFilter (org.apache.ignite.spi.indexing.IndexingQueryFilter)1