Beispiel #1
0
 /**
  * merges all restrictions in list by "OR".
  *
  * @param rlist the list
  * @return the restriction joined by OR function
  */
 private static Restrictions toOr(List<Restrictions> rlist) {
   if (rlist == null || rlist.size() == 0) {
     return Restrictions.TRUE;
   }
   if (rlist.size() > 1) {
     return Restrictions.or(
         rlist.get(0), rlist.subList(1, rlist.size()).toArray(new Restrictions[rlist.size()]));
   } else {
     return rlist.get(0);
   }
 }
Beispiel #2
0
 /**
  * if both 'lo' and 'hi' are passed, creates {@link #between(String, Object, Object)}. If 'hi' is
  * null, creates value >= 'lo', if 'lo' is null, creates value <= 'hi'. If both are null, do
  * nothing (returns {@link #TRUE} ).
  *
  * @param property1Name
  * @param lo lower value (may be null)
  * @param hi higher value (may be null)
  * @return restriction
  */
 public static Restrictions overlap(
     String property1Name, String property2Name, Object lo, Object hi) {
   if (lo == null && hi == null) {
     return Restrictions.TRUE;
   }
   if (hi == null) {
     return Restrictions.or(
         Restrictions.isNull(property1Name), Restrictions.greaterOrEqualThan(property1Name, lo));
   } else if (lo == null) {
     return Restrictions.or(
         Restrictions.isNull(property2Name), Restrictions.lessOrEqualThan(property2Name, hi));
   } else {
     return Restrictions.and(
         Restrictions.or(
             Restrictions.isNull(property1Name),
             Restrictions.greaterOrEqualThan(property1Name, lo)),
         Restrictions.or(
             Restrictions.isNull(property2Name), Restrictions.lessOrEqualThan(property2Name, hi)));
   }
 }