use of com.hazelcast.query.impl.QueryableEntry 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");
MapQueryEngine queryEngine = mapServiceContext.getMapQueryEngine(name);
SerializationService serializationService = getNodeEngine().getSerializationService();
Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.ENTRY).build();
QueryResult queryResylt = queryEngine.execute(query, Target.ALL_NODES);
Set result = QueryResultUtils.transformToSet(serializationService, queryResylt, predicate, IterationType.ENTRY, true);
// TODO: Can't we just use the original set?
List<Object> valueSet = new ArrayList<Object>();
Set<Object> keyWontBeIncluded = new HashSet<Object>();
Extractors extractors = mapServiceContext.getExtractors(name);
// 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);
Object keyObject = serializationService.toObject(entry.getKey());
if (isRemoved) {
keyWontBeIncluded.add(keyObject);
} else {
if (isUpdated) {
keyWontBeIncluded.add(keyObject);
}
Object entryValue = entry.getValue().value;
QueryableEntry queryEntry = new CachedQueryEntry((InternalSerializationService) serializationService, entry.getKey(), entryValue, extractors);
if (predicate.apply(queryEntry)) {
valueSet.add(queryEntry.getValue());
}
}
}
removeFromResultSet(result, valueSet, keyWontBeIncluded);
return valueSet;
}
use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.
the class AndPredicate method filter.
@Override
public Set<QueryableEntry> filter(QueryContext queryContext) {
Set<QueryableEntry> smallestIndexedResult = null;
List<Set<QueryableEntry>> otherIndexedResults = new LinkedList<Set<QueryableEntry>>();
List<Predicate> lsNoIndexPredicates = null;
for (Predicate predicate : predicates) {
boolean indexed = false;
if (predicate instanceof IndexAwarePredicate) {
IndexAwarePredicate iap = (IndexAwarePredicate) predicate;
if (iap.isIndexed(queryContext)) {
indexed = true;
Set<QueryableEntry> s = iap.filter(queryContext);
if (smallestIndexedResult == null) {
smallestIndexedResult = s;
} else if (size(s) < size(smallestIndexedResult)) {
otherIndexedResults.add(smallestIndexedResult);
smallestIndexedResult = s;
} else {
otherIndexedResults.add(s);
}
}
}
if (!indexed) {
if (lsNoIndexPredicates == null) {
lsNoIndexPredicates = new LinkedList<Predicate>();
}
lsNoIndexPredicates.add(predicate);
}
}
if (smallestIndexedResult == null) {
return null;
}
return new AndResultSet(smallestIndexedResult, otherIndexedResults, lsNoIndexPredicates);
}
use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.
the class ReplicatedQueryEventFilter method eval.
public boolean eval(Object arg) {
final QueryableEntry entry = (QueryableEntry) arg;
final Data keyData = entry.getKeyData();
return (key == null || key.equals(keyData)) && predicate.apply((Map.Entry) arg);
}
use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.
the class QueryEventFilterTest method testEval_givenFilterDoesNotContainKey_whenPredicateIsNotMatching_thenReturnFalse.
@Test
public void testEval_givenFilterDoesNotContainKey_whenPredicateIsNotMatching_thenReturnFalse() {
//given
Predicate predicate = FalsePredicate.INSTANCE;
QueryEventFilter filter = new QueryEventFilter(true, null, predicate);
//when
Data key2 = serializationService.toData("key");
QueryableEntry entry = mockEntryWithKeyData(key2);
//then
boolean result = filter.eval(entry);
assertFalse(result);
}
use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.
the class QueryEventFilterTest method testEval_givenFilterDoesNotContainKey_whenPredicateIsMatching_thenReturnTrue.
@Test
public void testEval_givenFilterDoesNotContainKey_whenPredicateIsMatching_thenReturnTrue() {
//given
Predicate predicate = TruePredicate.INSTANCE;
QueryEventFilter filter = new QueryEventFilter(true, null, predicate);
//when
Data key2 = serializationService.toData("key");
QueryableEntry entry = mockEntryWithKeyData(key2);
//then
boolean result = filter.eval(entry);
assertTrue(result);
}
Aggregations