use of com.hazelcast.query.impl.CachedQueryEntry in project hazelcast by hazelcast.
the class AbstractInternalQueryCache method doFullValueScan.
protected void doFullValueScan(Predicate predicate, Set<V> resultingSet) {
InternalSerializationService serializationService = this.serializationService;
CachedQueryEntry queryEntry = new CachedQueryEntry();
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.init(serializationService, keyData, value, Extractors.empty());
boolean valid = predicate.apply(queryEntry);
if (valid) {
Object valueObject = queryEntry.getValue();
resultingSet.add((V) valueObject);
}
}
}
use of com.hazelcast.query.impl.CachedQueryEntry in project hazelcast by hazelcast.
the class AbstractInternalQueryCache method doFullEntryScan.
protected void doFullEntryScan(Predicate predicate, Set<Map.Entry<K, V>> resultingSet) {
InternalSerializationService serializationService = this.serializationService;
CachedQueryEntry queryEntry = new CachedQueryEntry();
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.init(serializationService, keyData, value, Extractors.empty());
boolean valid = predicate.apply(queryEntry);
if (valid) {
Object keyObject = queryEntry.getKey();
Object valueObject = queryEntry.getValue();
Map.Entry simpleEntry = new AbstractMap.SimpleEntry(keyObject, valueObject);
resultingSet.add(simpleEntry);
}
}
}
use of com.hazelcast.query.impl.CachedQueryEntry in project hazelcast by hazelcast.
the class AbstractMapQueryWithPagingPredicateMessageTask method reduce.
@Override
protected Object reduce(Collection<QueryResultRow> result) {
ArrayList<QueryableEntry> accumulatedList = new ArrayList<>(result.size());
// TODO: The following lines will be replaced by k-way merge sort algorithm as described at
// https://github.com/hazelcast/hazelcast/issues/12205
result.forEach(row -> accumulatedList.add(new CachedQueryEntry(serializationService, row.getKey(), row.getValue(), null)));
PagingPredicateImpl pagingPredicateImpl = getPagingPredicate();
List pageData = SortingUtil.getSortedSubListData(accumulatedList, pagingPredicateImpl);
return new AbstractMap.SimpleImmutableEntry(getPagingPredicate().getAnchorList(), pageData);
}
use of com.hazelcast.query.impl.CachedQueryEntry 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);
}
}
use of com.hazelcast.query.impl.CachedQueryEntry in project hazelcast by hazelcast.
the class TransactionalMapProxy method values.
@Override
@SuppressWarnings("unchecked")
public Collection values(Predicate predicate) {
checkTransactionState();
checkNotNull(predicate, "Predicate can not be null!");
checkNotInstanceOf(PagingPredicate.class, predicate, "Paging is not supported for Transactional queries");
QueryEngine queryEngine = mapServiceContext.getQueryEngine(name);
Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.ENTRY).build();
QueryResult queryResult = queryEngine.execute(query, Target.ALL_NODES);
Set result = QueryResultUtils.transformToSet(ss, queryResult, predicate, IterationType.ENTRY, true, true);
// TODO: can't we just use the original set?
List<Object> valueSet = new ArrayList<>();
Set<Data> keyWontBeIncluded = new HashSet<>();
Extractors extractors = mapServiceContext.getExtractors(name);
CachedQueryEntry cachedQueryEntry = new CachedQueryEntry();
// iterate over the txMap and see if the values are updated or removed
for (Map.Entry<Data, TxnValueWrapper> entry : txMap.entrySet()) {
boolean isRemoved = Type.REMOVED.equals(entry.getValue().type);
boolean isUpdated = Type.UPDATED.equals(entry.getValue().type);
if (isRemoved) {
keyWontBeIncluded.add(entry.getKey());
} else {
if (isUpdated) {
keyWontBeIncluded.add(entry.getKey());
}
Object entryValue = entry.getValue().value;
cachedQueryEntry.init(ss, entry.getKey(), entryValue, extractors);
if (predicate.apply(cachedQueryEntry)) {
valueSet.add(toObjectIfNeeded(cachedQueryEntry.getValueData()));
}
}
}
removeFromResultSet(result, valueSet, keyWontBeIncluded);
return valueSet;
}
Aggregations