use of com.hazelcast.query.impl.CachedQueryEntry in project hazelcast by hazelcast.
the class TransactionalMapProxy method keySet.
@Override
@SuppressWarnings("unchecked")
public Set keySet(Predicate predicate) {
checkTransactionState();
checkNotNull(predicate, "Predicate should 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.KEY).build();
QueryResult queryResult = queryEngine.execute(query, Target.ALL_NODES);
Set queryResultSet = QueryResultUtils.transformToSet(ss, queryResult, predicate, IterationType.KEY, true, tx.isOriginatedFromClient());
Extractors extractors = mapServiceContext.getExtractors(name);
Set<Object> returningKeySet = new HashSet<Object>(queryResultSet);
CachedQueryEntry cachedQueryEntry = new CachedQueryEntry();
for (Map.Entry<Data, TxnValueWrapper> entry : txMap.entrySet()) {
if (entry.getValue().type == Type.REMOVED) {
// meanwhile remove keys which are not in txMap
returningKeySet.remove(toObjectIfNeeded(entry.getKey()));
} else {
Data keyData = entry.getKey();
if (predicate == Predicates.alwaysTrue()) {
returningKeySet.add(toObjectIfNeeded(keyData));
} else {
cachedQueryEntry.init(ss, keyData, entry.getValue().value, extractors);
// apply predicate on txMap
if (predicate.apply(cachedQueryEntry)) {
returningKeySet.add(toObjectIfNeeded(keyData));
}
}
}
}
return returningKeySet;
}
use of com.hazelcast.query.impl.CachedQueryEntry 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());
}
}
use of com.hazelcast.query.impl.CachedQueryEntry in project hazelcast by hazelcast.
the class DefaultQueryCacheRecordStore method saveIndex.
/**
* Same as {@link #saveIndex}
* with explicit {@link CachedQueryEntry} arguments for reuse, to avoid
* excessive litter when adding several entries in batch.
*/
private void saveIndex(Data keyData, QueryCacheRecord currentRecord, QueryCacheRecord oldRecord, CachedQueryEntry newEntry, CachedQueryEntry oldEntry) {
if (indexes.haveAtLeastOneIndex()) {
Object currentValue = currentRecord.getValue();
QueryEntry queryEntry = new QueryEntry(ss, keyData, currentValue, extractors);
Object oldValue = oldRecord == null ? null : oldRecord.getValue();
newEntry.init(keyData, currentValue);
oldEntry.init(keyData, oldValue);
indexes.putEntry(newEntry, oldEntry, queryEntry, Index.OperationSource.USER);
}
}
use of com.hazelcast.query.impl.CachedQueryEntry in project hazelcast by hazelcast.
the class DefaultQueryCacheRecordStore method saveIndex.
private void saveIndex(Object queryCacheKey, QueryCacheRecord currentRecord, QueryCacheRecord oldRecord) {
if (indexes.haveAtLeastOneIndex()) {
Data keyData = ss.toData(queryCacheKey);
Object currentValue = currentRecord.getValue();
QueryEntry queryEntry = new QueryEntry(ss, keyData, currentValue, extractors);
Object oldValue = oldRecord == null ? null : oldRecord.getValue();
CachedQueryEntry newEntry = new CachedQueryEntry(ss, keyData, currentValue, extractors);
CachedQueryEntry oldEntry = new CachedQueryEntry(ss, keyData, oldValue, extractors);
indexes.putEntry(newEntry, oldEntry, queryEntry, Index.OperationSource.USER);
}
}
use of com.hazelcast.query.impl.CachedQueryEntry in project hazelcast by hazelcast.
the class SortingUtil method getSortedSubListData.
/**
* @param list The entry list to be sorted
* @param pagingPredicate The predicate to be used for query. The anchor list in the predicate is also updated.
* @return The list of Data for the requested page. If iteration type is KEY only key data list is returned,
* else if iterationType is VALUE the value data list is returned. If iterationType is ENTRY, then list of entry of
* (key data, value data) is returned.
*/
public static List getSortedSubListData(List<QueryableEntry> list, PagingPredicateImpl pagingPredicate) {
IterationType iterationType = pagingPredicate.getIterationType();
Map.Entry<Integer, Integer> pageIndex = getPageIndexesAndUpdateAnchor(list, pagingPredicate, iterationType);
int begin = pageIndex.getKey();
int end = pageIndex.getValue();
if (begin == -1) {
return Collections.EMPTY_LIST;
}
List result = new ArrayList(end - begin);
for (int i = begin; i < end; ++i) {
CachedQueryEntry entry = (CachedQueryEntry) list.get(i);
switch(iterationType) {
case KEY:
result.add(entry.getKeyData());
break;
case VALUE:
result.add(entry.getValueData());
break;
default:
// iteration type is ENTRY
result.add(new AbstractMap.SimpleImmutableEntry<>(entry.getKeyData(), entry.getValueData()));
}
}
return result;
}
Aggregations