-
Couldn't load subscription status.
- Fork 8
Chaining restrictions
gert-wijns edited this page Sep 13, 2014
·
3 revisions
Restriction chaining to add multiple and/or restricitions to the where clause.
Person person = query.from(Person.class);
query.where(person.getAge()).lt(20).
and(person.getName()).startsWith("Alex");
=> "from Person hobj1
where hobj1.age < :np1
and hobj1.name like :np2"
params [np1=20, np2="Alex%"]When one property needs to be checked for multiple conditions, it is possible to continue restricting the same property. When adding a range check for example, there is no method to check a range because there is ambiguity whether or not the start and end of the range is included or excluded. By using the continued restriction building it is easy to set up a clear unambiguous range check.
Date date1 = DateUtils.addYears(new Date(), -5);
Date date2 = DateUtils.addYears(new Date(), -3);
Building building = query.from(Building.class);
// construction date will be used for the
// 'after' and the 'before' date check.
query.where(building.getConstructionDate()).
after(date1).before(date2);
=> "from Building hobj1
where hobj1.constructionDate > :np1
and hobj1.constructionDate < :np2"
params [np1=now-5y, np2=now-3y]