Search in sources :

Example 1 with PartitionPredicate

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

the class PredicateDataSerializerHook method createFactory.

@Override
public DataSerializableFactory createFactory() {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
    constructors[SQL_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new SqlPredicate();
        }
    };
    constructors[AND_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new AndPredicate();
        }
    };
    constructors[BETWEEN_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new BetweenPredicate();
        }
    };
    constructors[EQUAL_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new EqualPredicate();
        }
    };
    constructors[GREATERLESS_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new GreaterLessPredicate();
        }
    };
    constructors[LIKE_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new LikePredicate();
        }
    };
    constructors[ILIKE_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new ILikePredicate();
        }
    };
    constructors[IN_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new InPredicate();
        }
    };
    constructors[INSTANCEOF_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new InstanceOfPredicate();
        }
    };
    constructors[NOTEQUAL_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new NotEqualPredicate();
        }
    };
    constructors[NOT_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new NotPredicate();
        }
    };
    constructors[OR_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new OrPredicate();
        }
    };
    constructors[REGEX_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new RegexPredicate();
        }
    };
    constructors[FALSE_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return FalsePredicate.INSTANCE;
        }
    };
    constructors[TRUE_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return TruePredicate.INSTANCE;
        }
    };
    constructors[PAGING_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new PagingPredicate();
        }
    };
    constructors[PARTITION_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new PartitionPredicate();
        }
    };
    constructors[NULL_OBJECT] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new IndexImpl.NullObject();
        }
    };
    return new ArrayDataSerializableFactory(constructors);
}
Also used : IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) SqlPredicate(com.hazelcast.query.SqlPredicate) ConstructorFunction(com.hazelcast.util.ConstructorFunction) PagingPredicate(com.hazelcast.query.PagingPredicate) PartitionPredicate(com.hazelcast.query.PartitionPredicate) IndexImpl(com.hazelcast.query.impl.IndexImpl) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)

Example 2 with PartitionPredicate

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

the class PartitionPredicateTest method testSerialization.

@Test
public void testSerialization() {
    SerializationService serializationService = getSerializationService(local);
    Data serialized = serializationService.toData(predicate);
    PartitionPredicate deserialized = serializationService.toObject(serialized);
    assertEquals(partitionKey, deserialized.getPartitionKey());
    assertEquals(TruePredicate.INSTANCE, deserialized.getTarget());
}
Also used : PartitionPredicate(com.hazelcast.query.PartitionPredicate) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with PartitionPredicate

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

the class MapProxyImpl method executePredicate.

private Set executePredicate(Predicate predicate, IterationType iterationType, boolean uniqueResult) {
    checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED);
    MapQueryEngine queryEngine = getMapQueryEngine();
    QueryResult result;
    if (predicate instanceof PartitionPredicate) {
        PartitionPredicate partitionPredicate = (PartitionPredicate) predicate;
        Data key = toData(partitionPredicate.getPartitionKey());
        int partitionId = getNodeEngine().getPartitionService().getPartitionId(key);
        Query query = Query.of().mapName(getName()).predicate(partitionPredicate.getTarget()).iterationType(iterationType).build();
        result = queryEngine.execute(query, Target.of().partitionOwner(partitionId).build());
    } else {
        Query query = Query.of().mapName(getName()).predicate(predicate).iterationType(iterationType).build();
        result = queryEngine.execute(query, Target.ALL_NODES);
    }
    return QueryResultUtils.transformToSet(serializationService, result, predicate, iterationType, uniqueResult);
}
Also used : QueryResult(com.hazelcast.map.impl.query.QueryResult) PartitionPredicate(com.hazelcast.query.PartitionPredicate) Query(com.hazelcast.map.impl.query.Query) Data(com.hazelcast.nio.serialization.Data) MapQueryEngine(com.hazelcast.map.impl.query.MapQueryEngine)

Aggregations

PartitionPredicate (com.hazelcast.query.PartitionPredicate)3 Data (com.hazelcast.nio.serialization.Data)2 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 MapQueryEngine (com.hazelcast.map.impl.query.MapQueryEngine)1 Query (com.hazelcast.map.impl.query.Query)1 QueryResult (com.hazelcast.map.impl.query.QueryResult)1 IdentifiedDataSerializable (com.hazelcast.nio.serialization.IdentifiedDataSerializable)1 PagingPredicate (com.hazelcast.query.PagingPredicate)1 SqlPredicate (com.hazelcast.query.SqlPredicate)1 IndexImpl (com.hazelcast.query.impl.IndexImpl)1 SerializationService (com.hazelcast.spi.serialization.SerializationService)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 ConstructorFunction (com.hazelcast.util.ConstructorFunction)1 Test (org.junit.Test)1