Search in sources :

Example 1 with GridCacheQueryAdapter

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter in project ignite by apache.

the class GridCacheSetImpl method iterator0.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
private GridCloseableIterator<T> iterator0() {
    try {
        CacheQuery qry = new GridCacheQueryAdapter<>(ctx, SET, null, null, new GridSetQueryPredicate<>(id, collocated), null, false, false);
        Collection<ClusterNode> nodes = dataNodes(ctx.affinity().affinityTopologyVersion());
        qry.projection(ctx.grid().cluster().forNodes(nodes));
        CacheQueryFuture<Map.Entry<T, ?>> fut = qry.execute();
        CacheWeakQueryIteratorsHolder.WeakReferenceCloseableIterator it = ctx.itHolder().iterator(fut, new CacheIteratorConverter<T, Map.Entry<T, ?>>() {

            @Override
            protected T convert(Map.Entry<T, ?> e) {
                return e.getKey();
            }

            @Override
            protected void remove(T item) {
                GridCacheSetImpl.this.remove(item);
            }
        });
        if (rmvd) {
            ctx.itHolder().removeIterator(it);
            checkRemoved();
        }
        return it;
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CacheQuery(org.apache.ignite.internal.processors.cache.query.CacheQuery) CacheWeakQueryIteratorsHolder(org.apache.ignite.internal.processors.cache.CacheWeakQueryIteratorsHolder) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SET(org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SET) Map(java.util.Map) GridCacheQueryAdapter(org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter)

Example 2 with GridCacheQueryAdapter

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter in project ignite by apache.

the class GridCacheSetImpl method size.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public int size() {
    try {
        onAccess();
        if (separated) {
            // Non collocated IgniteSet uses a separate cache which contains additional header element.
            return cache.sizeAsync(new CachePeekMode[] {}).get() - 1;
        }
        CacheQuery qry = new GridCacheQueryAdapter<>(ctx, SET, null, null, new GridSetQueryPredicate<>(id, collocated), collocated ? hdrPart : null, false, false, null);
        Collection<ClusterNode> nodes = dataNodes(ctx.affinity().affinityTopologyVersion());
        qry.projection(ctx.grid().cluster().forNodes(nodes));
        CacheQueryFuture<Integer> qryFut = qry.execute(new SumReducer());
        int sum = 0;
        Integer val;
        while ((val = qryFut.next()) != null) sum += val;
        return sum;
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheQuery(org.apache.ignite.internal.processors.cache.query.CacheQuery) GridCacheQueryAdapter(org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter)

Example 3 with GridCacheQueryAdapter

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter in project ignite by apache.

the class GridCacheSetImpl method sharedCacheIterator.

/**
 * @return Shared cache iterator.
 */
@SuppressWarnings("unchecked")
private WeakReferenceCloseableIterator<T> sharedCacheIterator() throws IgniteCheckedException {
    CacheQuery qry = new GridCacheQueryAdapter<>(ctx, SET, null, null, new GridSetQueryPredicate<>(id, collocated), collocated ? hdrPart : null, false, false, null);
    Collection<ClusterNode> nodes = dataNodes(ctx.affinity().affinityTopologyVersion());
    qry.projection(ctx.grid().cluster().forNodes(nodes));
    CacheQueryFuture<Map.Entry<T, ?>> fut = qry.execute();
    return ctx.itHolder().iterator(fut, new CacheIteratorConverter<T, Map.Entry<T, ?>>() {

        @Override
        protected T convert(Map.Entry<T, ?> e) {
            return e.getKey();
        }

        @Override
        protected void remove(T item) {
            GridCacheSetImpl.this.remove(item);
        }
    });
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) SET(org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SET) Map(java.util.Map) CacheQuery(org.apache.ignite.internal.processors.cache.query.CacheQuery) GridCacheQueryAdapter(org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter)

Aggregations

ClusterNode (org.apache.ignite.cluster.ClusterNode)3 CacheQuery (org.apache.ignite.internal.processors.cache.query.CacheQuery)3 GridCacheQueryAdapter (org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter)3 Map (java.util.Map)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 SET (org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SET)2 CacheWeakQueryIteratorsHolder (org.apache.ignite.internal.processors.cache.CacheWeakQueryIteratorsHolder)1