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