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();
}
}
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);
}
}
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();
}
}
Aggregations