Search in sources :

Example 11 with QueryCacheRecord

use of com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord 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 12 with QueryCacheRecord

use of com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord in project hazelcast by hazelcast.

the class DefaultQueryCacheRecordStore method clear.

@Override
public int clear() {
    int removeCount = 0;
    Set<Data> dataKeys = keySet();
    for (Data dataKey : dataKeys) {
        QueryCacheRecord oldRecord = remove(dataKey);
        if (oldRecord != null) {
            removeCount++;
        }
    }
    return removeCount;
}
Also used : QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord) Data(com.hazelcast.nio.serialization.Data)

Example 13 with QueryCacheRecord

use of com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord in project hazelcast by hazelcast.

the class DefaultQueryCache method setInternal.

/**
 * @param doEvictionCheck when doing pre-population of query cache, set
 *                        this to false since we quit population if we reach max capacity {@link
 *                        #reachedMaxCapacity()}, eviction is not needed.
 */
private void setInternal(K key, V value, EntryEventType eventType, boolean doEvictionCheck) {
    Object queryCacheKey = recordStore.toQueryCacheKey(key);
    Data valueData = toData(value);
    QueryCacheRecord oldRecord = doEvictionCheck ? recordStore.add(queryCacheKey, valueData) : recordStore.addWithoutEvictionCheck(queryCacheKey, valueData);
    if (eventType != null) {
        publishEntryEvent(context, mapName, cacheId, queryCacheKey, valueData, oldRecord, eventType, extractors);
    }
}
Also used : QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord) Data(com.hazelcast.internal.serialization.Data)

Example 14 with QueryCacheRecord

use of com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord in project hazelcast by hazelcast.

the class AbstractInternalQueryCache method scanWithPredicate.

/**
 * Scan all key-value pairs and add matching ones with predicate to result.
 */
private void scanWithPredicate(Predicate predicate, BiConsumer consumer) {
    // needed for optimization where key and value are not an instance of Data type
    final boolean areKeyValueObjectType = !queryCacheConfig.isSerializeKeys() && InMemoryFormat.OBJECT == queryCacheConfig.getInMemoryFormat();
    CachedQueryEntry queryEntry = new CachedQueryEntry(ss, extractors);
    Set<Map.Entry<Object, QueryCacheRecord>> entries = recordStore.entrySet();
    for (Map.Entry<Object, QueryCacheRecord> entry : entries) {
        Object queryCacheKey = entry.getKey();
        Object rawValue = entry.getValue().getRawValue();
        if (areKeyValueObjectType) {
            queryEntry.initWithObjectKeyValue(queryCacheKey, rawValue);
        } else {
            queryEntry.init(queryCacheKey, rawValue);
        }
        if (!predicate.apply(queryEntry)) {
            continue;
        }
        consumer.accept(queryCacheKey, queryEntry.getByPrioritizingObjectValue());
    }
}
Also used : CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Example 15 with QueryCacheRecord

use of com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord in project hazelcast by hazelcast.

the class DefaultQueryCacheRecordStore method addWithoutEvictionCheck.

@Override
public QueryCacheRecord addWithoutEvictionCheck(Object queryCacheKey, Data valueData) {
    QueryCacheRecord newRecord = recordFactory.createRecord(valueData);
    QueryCacheRecord oldRecord = cache.put(queryCacheKey, newRecord);
    saveIndex(queryCacheKey, newRecord, oldRecord);
    return oldRecord;
}
Also used : QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord)

Aggregations

QueryCacheRecord (com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord)16 Map (java.util.Map)7 Data (com.hazelcast.nio.serialization.Data)6 CachedQueryEntry (com.hazelcast.query.impl.CachedQueryEntry)6 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)5 IMap (com.hazelcast.core.IMap)4 Data (com.hazelcast.internal.serialization.Data)3 AbstractMap (java.util.AbstractMap)3 IMap (com.hazelcast.map.IMap)2 QueryEntry (com.hazelcast.query.impl.QueryEntry)2 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 IndexConfig (com.hazelcast.config.IndexConfig)1