Search in sources :

Example 1 with QueryEntry

use of com.hazelcast.query.impl.QueryEntry in project hazelcast by hazelcast.

the class DefaultQueryCache method addIndex.

@Override
public void addIndex(IndexConfig config) {
    checkNotNull(config, "Index config cannot be null.");
    assert indexes.isGlobal();
    IndexConfig config0 = getNormalizedIndexConfig(config);
    indexes.addOrGetIndex(config0);
    InternalSerializationService serializationService = context.getSerializationService();
    CachedQueryEntry<?, ?> newEntry = new CachedQueryEntry<>(serializationService, extractors);
    Set<Map.Entry<Object, QueryCacheRecord>> entries = recordStore.entrySet();
    for (Map.Entry<Object, QueryCacheRecord> entry : entries) {
        Object queryCacheKey = entry.getKey();
        QueryCacheRecord record = entry.getValue();
        Object value = record.getValue();
        Data keyData = toData(queryCacheKey);
        QueryEntry queryable = new QueryEntry(serializationService, keyData, value, extractors);
        newEntry.init(keyData, value);
        indexes.putEntry(newEntry, null, queryable, Index.OperationSource.USER);
    }
}
Also used : CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryEntry(com.hazelcast.query.impl.QueryEntry) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryEntry(com.hazelcast.query.impl.QueryEntry) IndexConfig(com.hazelcast.config.IndexConfig) QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Example 2 with QueryEntry

use of com.hazelcast.query.impl.QueryEntry in project hazelcast by hazelcast.

the class NodeQueryCacheEventService method canPassFilter.

private boolean canPassFilter(LocalEntryEventData localEntryEventData, EventFilter filter) {
    if (filter == null || filter instanceof TrueEventFilter) {
        return true;
    }
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    SerializationService serializationService = nodeEngine.getSerializationService();
    Data keyData = localEntryEventData.getKeyData();
    Object value = getValueOrOldValue(localEntryEventData);
    QueryableEntry entry = new QueryEntry((InternalSerializationService) serializationService, keyData, value, Extractors.empty());
    return filter.eval(entry);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) QueryEntry(com.hazelcast.query.impl.QueryEntry) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData) EventData(com.hazelcast.map.impl.event.EventData) Data(com.hazelcast.nio.serialization.Data) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 3 with QueryEntry

use of com.hazelcast.query.impl.QueryEntry in project hazelcast by hazelcast.

the class DefaultQueryCache method addIndex.

@Override
public void addIndex(String attribute, boolean ordered) {
    getIndexes().addOrGetIndex(attribute, ordered);
    InternalSerializationService serializationService = context.getSerializationService();
    Set<Map.Entry<Data, QueryCacheRecord>> entries = recordStore.entrySet();
    for (Map.Entry<Data, QueryCacheRecord> entry : entries) {
        Data keyData = entry.getKey();
        QueryCacheRecord record = entry.getValue();
        Object value = record.getValue();
        QueryEntry queryable = new QueryEntry(serializationService, keyData, value, Extractors.empty());
        indexes.saveEntryIndex(queryable, null);
    }
}
Also used : QueryEntry(com.hazelcast.query.impl.QueryEntry) QueryEntry(com.hazelcast.query.impl.QueryEntry) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord) Data(com.hazelcast.nio.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap)

Example 4 with QueryEntry

use of com.hazelcast.query.impl.QueryEntry in project hazelcast by hazelcast.

the class DefaultQueryCacheRecordStore method saveIndex.

private void saveIndex(Data keyData, QueryCacheRecord currentRecord, QueryCacheRecord oldRecord) {
    if (indexes.hasIndex()) {
        Object currentValue = currentRecord.getValue();
        QueryEntry queryEntry = new QueryEntry(serializationService, keyData, currentValue, Extractors.empty());
        Object oldValue = oldRecord == null ? null : oldRecord.getValue();
        indexes.saveEntryIndex(queryEntry, oldValue);
    }
}
Also used : QueryEntry(com.hazelcast.query.impl.QueryEntry)

Example 5 with QueryEntry

use of com.hazelcast.query.impl.QueryEntry in project hazelcast by hazelcast.

the class ClientPagingPredicateTest method pagingPredicateWithEmployeeObjectTest.

private List<Employee> pagingPredicateWithEmployeeObjectTest(IMap<Integer, Employee> map, Predicate<Integer, Employee> predicate, int pageSize) {
    PagingPredicate<Integer, Employee> pagingPredicate = new PagingPredicate<Integer, Employee>(predicate, pageSize);
    Set<Map.Entry<Integer, Employee>> set;
    List<Employee> results = new ArrayList<Employee>();
    do {
        set = map.entrySet(pagingPredicate);
        for (Map.Entry<Integer, Employee> entry : set) {
            Employee e = entry.getValue();
            QueryEntry qe = new QueryEntry((InternalSerializationService) serializationService, serializationService.toData(e.getId()), e, Extractors.empty());
            assertTrue(predicate.apply(qe));
            results.add(e);
        }
        pagingPredicate.nextPage();
    } while (!set.isEmpty());
    return results;
}
Also used : QueryEntry(com.hazelcast.query.impl.QueryEntry) PagingPredicate(com.hazelcast.query.PagingPredicate) QueryEntry(com.hazelcast.query.impl.QueryEntry) ArrayList(java.util.ArrayList) Map(java.util.Map) IMap(com.hazelcast.core.IMap)

Aggregations

QueryEntry (com.hazelcast.query.impl.QueryEntry)11 Data (com.hazelcast.internal.serialization.Data)5 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)4 EventData (com.hazelcast.map.impl.event.EventData)4 Map (java.util.Map)4 LocalEntryEventData (com.hazelcast.map.impl.querycache.event.LocalEntryEventData)3 CachedQueryEntry (com.hazelcast.query.impl.CachedQueryEntry)3 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)3 TrueEventFilter (com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)3 IMap (com.hazelcast.core.IMap)2 LocalCacheWideEventData (com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData)2 QueryCacheRecord (com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord)2 Data (com.hazelcast.nio.serialization.Data)2 ArrayList (java.util.ArrayList)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 IndexConfig (com.hazelcast.config.IndexConfig)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 IMap (com.hazelcast.map.IMap)1 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)1 MapEventData (com.hazelcast.map.impl.event.MapEventData)1