CriteriaVisitor implements FilterVisitor { public Object visit(And filter, Object userData) { Criterion c = null; for (Filter element : filter.getChildren()) { if (c == null) { c = (Criterion) element.accept(this, userData); } else { c = Restrictions.and(c, (Criterion) element.accept(this, userData)); } } return c; } CriteriaVisitor(HibernateFeatureModel featureModel, DateFormat dateFormat); Object visit(And filter, Object userData); @Override Object visit(Not filter, Object userData); @Override Object visit(Or filter, Object userData); @Override Object visit(PropertyIsBetween filter, Object userData); @Override Object visit(PropertyIsEqualTo filter, Object userData); @Override Object visit(PropertyIsNotEqualTo filter, Object userData); @Override Object visit(PropertyIsGreaterThan filter, Object userData); @Override Object visit(PropertyIsGreaterThanOrEqualTo filter, Object userData); @Override Object visit(PropertyIsLessThan filter, Object userData); @Override Object visit(PropertyIsLessThanOrEqualTo filter, Object userData); @Override Object visit(PropertyIsLike filter, Object userData); @Override Object visit(PropertyIsNull filter, Object userData); @Override Object visit(BBOX filter, Object userData); @Override Object visit(Beyond filter, Object userData); Object visit(Contains filter, Object userData); @Override Object visit(Crosses filter, Object userData); @Override Object visit(Disjoint filter, Object userData); @Override Object visit(DWithin filter, Object userData); @Override Object visit(Equals filter, Object userData); @Override Object visit(Intersects filter, Object userData); @Override Object visit(Overlaps filter, Object userData); @Override Object visit(Touches filter, Object userData); @Override Object visit(Within filter, Object userData); @Override Object visit(ExcludeFilter filter, Object userData); @Override Object visit(IncludeFilter filter, Object userData); @Override Object visit(Id filter, Object userData); @Override Object visitNullFilter(Object userData); @Override Object visit(PropertyIsNil filter, Object extraData); @Override Object visit(After after, Object extraData); @Override Object visit(AnyInteracts anyInteracts, Object extraData); @Override Object visit(Before before, Object extraData); @Override Object visit(Begins begins, Object extraData); @Override Object visit(BegunBy begunBy, Object extraData); @Override Object visit(During during, Object userData); @Override Object visit(EndedBy endedBy, Object extraData); @Override Object visit(Ends ends, Object extraData); @Override Object visit(Meets meets, Object extraData); @Override Object visit(MetBy metBy, Object extraData); @Override Object visit(OverlappedBy overlappedBy, Object extraData); @Override Object visit(TContains contains, Object extraData); @Override Object visit(TEquals equals, Object extraData); @Override Object visit(TOverlaps contains, Object extraData);  }
@Test public void testVisitAfter() throws GeomajasException { Filter f = filterService.parseFilter("myDate AFTER 2006-11-30T01:30:00Z"); Criterion c = (Criterion) (new CriteriaVisitor((HibernateFeatureModel) layer.getFeatureModel(), DateFormat.getDateTimeInstance()).visit((After) f, null)); Date date = ISODateTimeFormat.dateTimeNoMillis().parseDateTime("2006-11-30T01:30:00Z").toDate(); Assert.assertEquals("myDate>" + date, c.toString()); }
@Test public void testVisitBefore() throws GeomajasException { Filter f = filterService.parseFilter("myDate BEFORE 2006-11-30T01:30:00Z"); Criterion c = (Criterion) (new CriteriaVisitor((HibernateFeatureModel) layer.getFeatureModel(), DateFormat.getDateTimeInstance()).visit((org.opengis.filter.temporal.Before) f, null)); Date date = ISODateTimeFormat.dateTimeNoMillis().parseDateTime("2006-11-30T01:30:00Z").toDate(); Assert.assertEquals("myDate<" + date, c.toString()); }
@Test public void testVisitDuring() throws GeomajasException { Filter f = filterService.parseFilter("myDate DURING 2006-11-30T00:30:00Z/2006-11-30T01:30:00Z"); Criterion c = (Criterion) (new CriteriaVisitor((HibernateFeatureModel) layer.getFeatureModel(), DateFormat.getDateTimeInstance()).visit((During) f, null)); Date from = ISODateTimeFormat.dateTimeNoMillis().parseDateTime("2006-11-30T00:30:00Z").toDate(); Date to = ISODateTimeFormat.dateTimeNoMillis().parseDateTime("2006-11-30T01:30:00Z").toDate(); Assert.assertEquals("myDate between " + from + " and " + to, c.toString()); }