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());
}
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());
}
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;
}
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;
}
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;
}
}
Aggregations