Beispiel #1
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)));
   }
 }
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 propertyName
  * @param lo lower value (may be null)
  * @param hi higher value (may be null)
  * @return restriction
  */
 public static Restrictions interval(String propertyName, Object lo, Object hi) {
   if (lo == null && hi == null) {
     return Restrictions.TRUE;
   }
   if (hi == null) {
     return Restrictions.greaterOrEqualThan(propertyName, lo);
   } else if (lo == null) {
     return Restrictions.lessOrEqualThan(propertyName, hi);
   } else {
     return between(propertyName, lo, hi);
   }
 }