Search in sources :

Example 91 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class TransactionalMapKeySetWithPredicateMessageTask method innerCall.

@Override
protected Object innerCall() throws Exception {
    final TransactionContext context = getEndpoint().getTransactionContext(parameters.txnId);
    final TransactionalMap map = context.getMap(parameters.name);
    Predicate predicate = serializationService.toObject(parameters.predicate);
    Set keySet = map.keySet(predicate);
    List<Data> list = new ArrayList<Data>(keySet.size());
    for (Object o : keySet) {
        list.add(serializationService.toData(o));
    }
    return list;
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) Set(java.util.Set) TransactionContext(com.hazelcast.transaction.TransactionContext) ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data) Predicate(com.hazelcast.query.Predicate)

Example 92 with Predicate

use of com.hazelcast.query.Predicate 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);
}
Also used : QueryableEntry(com.hazelcast.query.impl.QueryableEntry) TruePredicate(com.hazelcast.query.TruePredicate) FalsePredicate(com.hazelcast.query.impl.FalsePredicate) Predicate(com.hazelcast.query.Predicate)

Example 93 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class BetweenVisitor method rewriteAttribute.

private int rewriteAttribute(Boundaries boundaries, Predicate[] originalPredicates, int toBeRemovedCount) {
    GreaterLessPredicate leftBoundary = boundaries.leftBoundary;
    GreaterLessPredicate rightBoundary = boundaries.rightBoundary;
    Predicate rewritten = boundaries.createEquivalentPredicate();
    for (int i = 0; i < originalPredicates.length; i++) {
        Predicate currentPredicate = originalPredicates[i];
        if (currentPredicate == leftBoundary) {
            originalPredicates[i] = rewritten;
        } else if (currentPredicate == rightBoundary) {
            originalPredicates[i] = null;
            toBeRemovedCount++;
        } else if (boundaries.canBeEliminated(currentPredicate)) {
            originalPredicates[i] = null;
            toBeRemovedCount++;
        }
    }
    return toBeRemovedCount;
}
Also used : FalsePredicate(com.hazelcast.query.impl.FalsePredicate) Predicate(com.hazelcast.query.Predicate)

Example 94 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class FlatteningVisitor method visit.

@Override
public Predicate visit(OrPredicate orPredicate, Indexes indexes) {
    Predicate[] originalPredicates = orPredicate.predicates;
    List<Predicate> toBeAdded = null;
    boolean modified = false;
    Predicate[] target = originalPredicates;
    for (int i = 0; i < target.length; i++) {
        Predicate predicate = target[i];
        if (predicate instanceof OrPredicate) {
            Predicate[] subPredicates = ((OrPredicate) predicate).predicates;
            if (!modified) {
                modified = true;
                target = createCopy(target);
            }
            toBeAdded = replaceFirstAndStoreOthers(target, subPredicates, i, toBeAdded);
        }
    }
    Predicate[] newInners = createNewInners(target, toBeAdded);
    if (newInners == originalPredicates) {
        return orPredicate;
    }
    return new OrPredicate(newInners);
}
Also used : Predicate(com.hazelcast.query.Predicate)

Example 95 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class FlatteningVisitor method visit.

@Override
public Predicate visit(AndPredicate andPredicate, Indexes indexes) {
    Predicate[] originalPredicates = andPredicate.predicates;
    List<Predicate> toBeAdded = null;
    boolean modified = false;
    Predicate[] target = originalPredicates;
    for (int i = 0; i < target.length; i++) {
        Predicate predicate = target[i];
        if (predicate instanceof AndPredicate) {
            Predicate[] subPredicates = ((AndPredicate) predicate).predicates;
            if (!modified) {
                modified = true;
                target = createCopy(target);
            }
            toBeAdded = replaceFirstAndStoreOthers(target, subPredicates, i, toBeAdded);
        }
    }
    Predicate[] newInners = createNewInners(target, toBeAdded);
    if (newInners == originalPredicates) {
        return andPredicate;
    }
    return new AndPredicate(newInners);
}
Also used : Predicate(com.hazelcast.query.Predicate)

Aggregations

Predicate (com.hazelcast.query.Predicate)160 Test (org.junit.Test)125 QuickTest (com.hazelcast.test.annotation.QuickTest)124 ParallelTest (com.hazelcast.test.annotation.ParallelTest)107 TruePredicate (com.hazelcast.query.TruePredicate)41 SqlPredicate (com.hazelcast.query.SqlPredicate)33 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)23 PredicateBuilder (com.hazelcast.query.PredicateBuilder)19 EntryListener (com.hazelcast.core.EntryListener)16 MapListener (com.hazelcast.map.listener.MapListener)16 EntryObject (com.hazelcast.query.EntryObject)14 IndexAwarePredicate (com.hazelcast.query.IndexAwarePredicate)12 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)10 Value (com.hazelcast.query.SampleObjects.Value)9 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)9 ArrayList (java.util.ArrayList)9 EntryEvent (com.hazelcast.core.EntryEvent)8 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)8 ValueType (com.hazelcast.query.SampleObjects.ValueType)7