Search in sources :

Example 1 with PagingPredicate

use of com.hazelcast.query.PagingPredicate in project hazelcast by hazelcast.

the class MapProxyImpl method aggregate.

@Override
public <R> R aggregate(Aggregator<Map.Entry<K, V>, R> aggregator, Predicate<K, V> predicate) {
    checkNotNull(aggregator, NULL_AGGREGATOR_IS_NOT_ALLOWED);
    checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED);
    aggregator = serializationService.toObject(serializationService.toData(aggregator));
    MapQueryEngine queryEngine = getMapQueryEngine();
    if (predicate instanceof PagingPredicate) {
        throw new IllegalArgumentException("PagingPredicate now allowed with EntryAggregator.");
    }
    Query query = Query.of().mapName(getName()).predicate(predicate).iterationType(IterationType.ENTRY).aggregator(aggregator).build();
    AggregationResult result = queryEngine.execute(query, Target.ALL_NODES);
    return result.<R>getAggregator().aggregate();
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) Query(com.hazelcast.map.impl.query.Query) AggregationResult(com.hazelcast.map.impl.query.AggregationResult) MapQueryEngine(com.hazelcast.map.impl.query.MapQueryEngine)

Example 2 with PagingPredicate

use of com.hazelcast.query.PagingPredicate in project hazelcast by hazelcast.

the class ClientMapProxy method keySet.

@Override
@SuppressWarnings("unchecked")
public Set<K> keySet(Predicate predicate) {
    checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED);
    if (predicate instanceof PagingPredicate) {
        return keySetWithPagingPredicate((PagingPredicate) predicate);
    }
    ClientMessage request = MapKeySetWithPredicateCodec.encodeRequest(name, toData(predicate));
    ClientMessage response = invoke(request);
    MapKeySetWithPredicateCodec.ResponseParameters resultParameters = MapKeySetWithPredicateCodec.decodeResponse(response);
    InflatableSet.Builder<K> setBuilder = InflatableSet.newBuilder(resultParameters.response.size());
    for (Data data : resultParameters.response) {
        K key = toObject(data);
        setBuilder.add(key);
    }
    return setBuilder.build();
}
Also used : MapKeySetWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapKeySetWithPredicateCodec) InflatableSet(com.hazelcast.util.collection.InflatableSet) PagingPredicate(com.hazelcast.query.PagingPredicate) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 3 with PagingPredicate

use of com.hazelcast.query.PagingPredicate in project hazelcast by hazelcast.

the class ClientMapProxy method entrySet.

@Override
@SuppressWarnings("unchecked")
public Set<Entry<K, V>> entrySet(Predicate predicate) {
    if (predicate instanceof PagingPredicate) {
        return entrySetWithPagingPredicate((PagingPredicate) predicate);
    }
    ClientMessage request = MapEntriesWithPredicateCodec.encodeRequest(name, toData(predicate));
    ClientMessage response = invoke(request);
    MapEntriesWithPredicateCodec.ResponseParameters resultParameters = MapEntriesWithPredicateCodec.decodeResponse(response);
    InflatableSet.Builder<Entry<K, V>> setBuilder = InflatableSet.newBuilder(resultParameters.response.size());
    InternalSerializationService serializationService = ((InternalSerializationService) getContext().getSerializationService());
    for (Entry<Data, Data> row : resultParameters.response) {
        LazyMapEntry entry = new LazyMapEntry(row.getKey(), row.getValue(), serializationService);
        setBuilder.add(entry);
    }
    return setBuilder.build();
}
Also used : InflatableSet(com.hazelcast.util.collection.InflatableSet) PagingPredicate(com.hazelcast.query.PagingPredicate) LazyMapEntry(com.hazelcast.map.impl.LazyMapEntry) MapEntriesWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapEntriesWithPredicateCodec) LazyMapEntry(com.hazelcast.map.impl.LazyMapEntry) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService)

Example 4 with PagingPredicate

use of com.hazelcast.query.PagingPredicate in project hazelcast by hazelcast.

the class ClientMapProxy method values.

@Override
public Collection<V> values(Predicate predicate) {
    checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED);
    if (predicate instanceof PagingPredicate) {
        return valuesForPagingPredicate((PagingPredicate) predicate);
    }
    ClientMessage request = MapValuesWithPredicateCodec.encodeRequest(name, toData(predicate));
    ClientMessage response = invoke(request);
    MapValuesWithPredicateCodec.ResponseParameters resultParameters = MapValuesWithPredicateCodec.decodeResponse(response);
    return new UnmodifiableLazyList<V>(resultParameters.response, getSerializationService());
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) MapValuesWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapValuesWithPredicateCodec)

Example 5 with PagingPredicate

use of com.hazelcast.query.PagingPredicate in project hazelcast by hazelcast.

the class ClientPagingPredicateTest method mapPagingPredicateEmployeeObjectWithOrderedIndex.

private void mapPagingPredicateEmployeeObjectWithOrderedIndex(int maxEmployee) {
    final IMap<Integer, Employee> map = makeEmployeeMap(maxEmployee);
    map.addIndex("id", true);
    Predicate pred = Predicates.lessThan("id", 2);
    PagingPredicate<Integer, Employee> predicate = new PagingPredicate<Integer, Employee>(pred, 2);
    Collection<Employee> values;
    values = map.values(predicate);
    System.out.println(values);
    assertEquals(2, values.size());
    predicate.nextPage();
    values = map.values(predicate);
    System.out.println(values);
    assertEquals(0, values.size());
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) PagingPredicate(com.hazelcast.query.PagingPredicate) Predicate(com.hazelcast.query.Predicate)

Aggregations

PagingPredicate (com.hazelcast.query.PagingPredicate)13 Predicate (com.hazelcast.query.Predicate)5 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 Data (com.hazelcast.nio.serialization.Data)3 InflatableSet (com.hazelcast.util.collection.InflatableSet)2 Map (java.util.Map)2 MapEntriesWithPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapEntriesWithPredicateCodec)1 MapKeySetWithPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapKeySetWithPredicateCodec)1 MapValuesWithPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapValuesWithPredicateCodec)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 IMap (com.hazelcast.core.IMap)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 LazyMapEntry (com.hazelcast.map.impl.LazyMapEntry)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)1 AggregationResult (com.hazelcast.map.impl.query.AggregationResult)1 MapQueryEngine (com.hazelcast.map.impl.query.MapQueryEngine)1 Query (com.hazelcast.map.impl.query.Query)1 Record (com.hazelcast.map.impl.record.Record)1 PagingPredicateAccessor.getNearestAnchorEntry (com.hazelcast.query.PagingPredicateAccessor.getNearestAnchorEntry)1