use of com.hazelcast.query.impl.QueryableEntry 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!");
MapQueryEngine queryEngine = mapServiceContext.getMapQueryEngine(name);
SerializationService serializationService = getNodeEngine().getSerializationService();
Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.KEY).build();
QueryResult queryResult = queryEngine.execute(query, Target.ALL_NODES);
Set result = QueryResultUtils.transformToSet(serializationService, queryResult, predicate, IterationType.KEY, true);
// TODO: Can't we just use the original set?
Set<Object> keySet = new HashSet<Object>(result);
Extractors extractors = mapServiceContext.getExtractors(name);
for (Map.Entry<Data, TxnValueWrapper> entry : txMap.entrySet()) {
Data keyData = entry.getKey();
if (!Type.REMOVED.equals(entry.getValue().type)) {
Object value = (entry.getValue().value instanceof Data) ? toObjectIfNeeded(entry.getValue().value) : entry.getValue().value;
QueryableEntry queryEntry = new CachedQueryEntry((InternalSerializationService) serializationService, keyData, value, extractors);
// apply predicate on txMap
if (predicate.apply(queryEntry)) {
Object keyObject = serializationService.toObject(keyData);
keySet.add(keyObject);
}
} else {
// meanwhile remove keys which are not in txMap
Object keyObject = serializationService.toObject(keyData);
keySet.remove(keyObject);
}
}
return keySet;
}
use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.
the class AbstractRecordStore method saveIndex.
protected void saveIndex(Record record, Object oldValue) {
Data dataKey = record.getKey();
final Indexes indexes = mapContainer.getIndexes();
if (indexes.hasIndex()) {
Object value = Records.getValueOrCachedValue(record, serializationService);
// When using format InMemoryFormat.NATIVE, just copy key & value to heap.
if (NATIVE == inMemoryFormat) {
dataKey = (Data) copyToHeap(dataKey);
value = copyToHeap(value);
oldValue = copyToHeap(oldValue);
}
QueryableEntry queryableEntry = mapContainer.newQueryEntry(dataKey, value);
indexes.saveEntryIndex(queryableEntry, oldValue);
}
}
use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.
the class PartitionWideEntryOperation method applyPredicate.
private boolean applyPredicate(Data key, Object value) {
Predicate predicate = getPredicate();
if (predicate == null || TruePredicate.INSTANCE == predicate) {
return true;
}
if (FalsePredicate.INSTANCE == predicate) {
return false;
}
QueryableEntry queryEntry = mapContainer.newQueryEntry(key, value);
return getPredicate().apply(queryEntry);
}
use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.
the class PartitionWideEntryWithPredicateOperationFactory method getKeysFromIndex.
private Set<Data> getKeysFromIndex(NodeEngine nodeEngine) {
// Do not use index in this case, because it requires full-table-scan.
if (predicate == TruePredicate.INSTANCE) {
return emptySet();
}
// get indexes
MapService mapService = nodeEngine.getService(SERVICE_NAME);
MapServiceContext mapServiceContext = mapService.getMapServiceContext();
Indexes indexes = mapServiceContext.getMapContainer(name).getIndexes();
// optimize predicate
QueryOptimizer queryOptimizer = mapServiceContext.getQueryOptimizer();
predicate = queryOptimizer.optimize(predicate, indexes);
Set<QueryableEntry> querySet = indexes.query(predicate);
if (querySet == null) {
return emptySet();
}
List<Data> keys = null;
for (QueryableEntry e : querySet) {
if (keys == null) {
keys = new ArrayList<Data>(querySet.size());
}
keys.add(e.getKeyData());
}
return keys == null ? Collections.<Data>emptySet() : newBuilder(keys).build();
}
use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.
the class AbstractFilteringStrategy method evaluateQueryEventFilter.
protected boolean evaluateQueryEventFilter(EventFilter filter, Data dataKey, Object testValue, String mapNameOrNull) {
Extractors extractors = getExtractorsForMapName(mapNameOrNull);
QueryEventFilter queryEventFilter = (QueryEventFilter) filter;
QueryableEntry entry = new CachedQueryEntry((InternalSerializationService) serializationService, dataKey, testValue, extractors);
return queryEventFilter.eval(entry);
}
Aggregations