Search in sources :

Example 1 with ObjectFilter

use of org.infinispan.objectfilter.ObjectFilter in project infinispan by infinispan.

the class AbstractMatcherTest method testObjectFilterWithDSLSamePredicate2.

@Test
public void testObjectFilterWithDSLSamePredicate2() throws Exception {
    Matcher matcher = createMatcher();
    Object person = createPerson1();
    QueryFactory qf = createQueryFactory();
    // use the same "like 'Jo%'" predicate (in positive and negative form) on the same attribute to demonstrate they do not interfere (see ISPN-4654)
    Query<Person> q = qf.from(Person.class).having("name").like("Jo%").and(qf.not().having("name").like("Jo%").or().having("id").lt(1000)).build();
    ObjectFilter objectFilter = matcher.getObjectFilter(q);
    ObjectFilter.FilterResult result = objectFilter.filter(person);
    assertNotNull(result);
    assertSame(person, result.getInstance());
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) Matcher(org.infinispan.objectfilter.Matcher) ObjectFilter(org.infinispan.objectfilter.ObjectFilter) Person(org.infinispan.objectfilter.test.model.Person) Test(org.junit.Test)

Example 2 with ObjectFilter

use of org.infinispan.objectfilter.ObjectFilter in project infinispan by infinispan.

the class RowMatcherTest method testObjectFilterWithDSLSamePredicate1.

@Test
public void testObjectFilterWithDSLSamePredicate1() {
    Matcher matcher = createMatcher();
    Object person = createPerson1();
    // use the same '< 1000' predicate on two different attributes to demonstrate they do not interfere (see ISPN-4654)
    Query<Person> q = queryFactory.create("FROM " + Person.class.getName() + " WHERE id < 1000 AND age < 1000");
    ObjectFilter objectFilter = matcher.getObjectFilter(q);
    ObjectFilter.FilterResult result = objectFilter.filter(person);
    assertNotNull(result);
    assertSame(person, result.getInstance());
}
Also used : Matcher(org.infinispan.objectfilter.Matcher) RowMatcher(org.infinispan.objectfilter.impl.RowMatcher) ObjectFilter(org.infinispan.objectfilter.ObjectFilter) Person(org.infinispan.objectfilter.test.model.Person) Test(org.junit.Test)

Example 3 with ObjectFilter

use of org.infinispan.objectfilter.ObjectFilter in project infinispan by infinispan.

the class IckleContinuousQueryCacheEventFilterConverter method filterAndConvert.

@Override
public C filterAndConvert(K key, V oldValue, Metadata oldMetadata, V newValue, Metadata newMetadata, EventType eventType) {
    if (eventType.isExpired()) {
        // expired events have the expired value as newValue
        oldValue = newValue;
        newValue = null;
    }
    ObjectFilter objectFilter = getObjectFilter();
    ObjectFilter.FilterResult f1 = oldValue == null ? null : objectFilter.filter(key, oldValue);
    ObjectFilter.FilterResult f2 = newValue == null ? null : objectFilter.filter(key, newValue);
    if (f1 == null) {
        if (f2 != null) {
            // result joining
            return (C) new ContinuousQueryResult<>(ContinuousQueryResult.ResultType.JOINING, f2.getProjection() == null ? newValue : null, f2.getProjection());
        }
    } else {
        if (f2 != null) {
            // result updated
            return (C) new ContinuousQueryResult<>(ContinuousQueryResult.ResultType.UPDATED, f2.getProjection() == null ? newValue : null, f2.getProjection());
        } else {
            // result leaving
            return (C) new ContinuousQueryResult<V>(ContinuousQueryResult.ResultType.LEAVING, null, null);
        }
    }
    return null;
}
Also used : ObjectFilter(org.infinispan.objectfilter.ObjectFilter)

Example 4 with ObjectFilter

use of org.infinispan.objectfilter.ObjectFilter in project infinispan by infinispan.

the class BaseMatcher method getObjectFilter.

@Override
public ObjectFilter getObjectFilter(FilterSubscription filterSubscription) {
    FilterSubscriptionImpl<TypeMetadata, AttributeMetadata, AttributeId> filterSubscriptionImpl = (FilterSubscriptionImpl<TypeMetadata, AttributeMetadata, AttributeId>) filterSubscription;
    ObjectFilter objectFilter = getObjectFilter(filterSubscriptionImpl.getQueryString());
    return filterSubscriptionImpl.getNamedParameters() != null ? objectFilter.withParameters(filterSubscriptionImpl.getNamedParameters()) : objectFilter;
}
Also used : ObjectFilter(org.infinispan.objectfilter.ObjectFilter)

Example 5 with ObjectFilter

use of org.infinispan.objectfilter.ObjectFilter in project infinispan by infinispan.

the class IckleContinuousQueryProtobufCacheEventFilterConverter method filterAndConvert.

@Override
public Object filterAndConvert(Object key, Object oldValue, Metadata oldMetadata, Object newValue, Metadata newMetadata, EventType eventType) {
    if (eventType.isExpired()) {
        // expired events have the expired value as newValue
        oldValue = newValue;
        newValue = null;
    }
    ObjectFilter objectFilter = getObjectFilter();
    ObjectFilter.FilterResult f1 = oldValue == null ? null : objectFilter.filter(key, oldValue);
    ObjectFilter.FilterResult f2 = newValue == null ? null : objectFilter.filter(key, newValue);
    if (f1 == null && f2 != null) {
        // result joining
        return makeFilterResult(ContinuousQueryResult.ResultType.JOINING, key, f2.getProjection() == null ? newValue : null, f2.getProjection());
    } else if (f1 != null && f2 == null) {
        // result leaving
        return makeFilterResult(ContinuousQueryResult.ResultType.LEAVING, key, null, null);
    } else {
        return null;
    }
}
Also used : ObjectFilter(org.infinispan.objectfilter.ObjectFilter)

Aggregations

ObjectFilter (org.infinispan.objectfilter.ObjectFilter)16 Matcher (org.infinispan.objectfilter.Matcher)13 Test (org.junit.Test)12 Person (org.infinispan.objectfilter.test.model.Person)8 RowMatcher (org.infinispan.objectfilter.impl.RowMatcher)6 FilterSubscription (org.infinispan.objectfilter.FilterSubscription)4 QueryFactory (org.infinispan.query.dsl.QueryFactory)4 ReflectionMatcher (org.infinispan.objectfilter.impl.ReflectionMatcher)1