Ejemplo n.º 1
0
 public static Comparable<?> remainder(Comparable<?> param1, Comparable<?> param2)
     throws ParseException {
   if (param1 == null || param2 == null) {
     return null;
   }
   if (param1 instanceof String) {
     param1 = parse((String) param1);
   }
   if (param2 instanceof String) {
     param2 = parse((String) param2);
   }
   if (param1 instanceof Number && param2 instanceof Number) {
     // BigInteger type is not supported
     if (param1 instanceof BigDecimal || param2 instanceof BigDecimal) {
       BigDecimal b1 = getBigDecimal((Number) param1);
       BigDecimal b2 = getBigDecimal((Number) param2);
       return b1.remainder(b2);
     }
     if (param1 instanceof Double
         || param2 instanceof Double
         || param1 instanceof Float
         || param2 instanceof Float) {
       return ((Number) param1).doubleValue() % ((Number) param2).doubleValue();
     } else { // Long, Integer, Short, Byte
       long l1 = ((Number) param1).longValue();
       long l2 = ((Number) param2).longValue();
       return l1 % l2;
     }
   } else {
     throw new ParseException(
         WRONG_TYPE + "  (" + param1.getClass() + "%" + param2.getClass() + ")");
   }
 }
Ejemplo n.º 2
0
 public static java.util.Date addMonths(Comparable<?> param1, Comparable<?> param2, Calendar cal)
     throws ParseException {
   if (param1 == null && param2 == null) {
     return null;
   }
   try {
     int months = getInteger(param2);
     if (param1 instanceof Timestamp) {
       Timestamp d = (Timestamp) param1;
       cal.setTimeInMillis(d.getTime());
       cal.add(Calendar.MONTH, months);
       return new Timestamp(cal.getTimeInMillis());
     } else if (param1 instanceof java.sql.Date) {
       java.util.Date d = (java.util.Date) param1;
       cal.setTimeInMillis(d.getTime());
       cal.add(Calendar.MONTH, months);
       return new java.util.Date(cal.getTimeInMillis());
     } else {
       throw new ParseException();
     }
   } catch (ParseException e) {
     throw new ParseException(
         WRONG_TYPE + "  month_between(" + param1.getClass() + "," + param2.getClass() + ")");
   }
 }
Ejemplo n.º 3
0
    Comparable<?> coerceValue(Comparable<?> value, Class targetClass) {

      if (value == null) return null;

      if (value.getClass() == targetClass) return value;

      // FIXME: For now we convert by first converting the source value to a
      // string and then converting to the target type. This logic probably needs
      // another pass to make it more robust/optimized.

      String s = value.toString();
      Comparable<?> obj = null;

      try {
        if (targetClass == Integer.class) {
          obj = new Integer(s);
        } else if (targetClass == Long.class) {
          obj = new Long(s);
        } else if (targetClass == Short.class) {
          obj = new Short(s);
        } else if (targetClass == Boolean.class) {
          obj = new Boolean(s);
        } else if (targetClass == Float.class) {
          obj = new Float(s);
        } else if (targetClass == Double.class) {
          obj = new Double(s);
        } else if (targetClass == Byte.class) {
          obj = new Byte(s);
        } else if (targetClass == String.class) {
          obj = s;
        } else if (targetClass == Date.class) {
          SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
          dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
          try {
            obj = dateFormat.parse(s);
          } catch (ParseException exc) {
            throw new TypeMismatchStorageException(
                Date.class.getName(), value.getClass().getName(), "???");
          }
        }
      } catch (Exception exc) {
        // Ignore the exception here. In this case obj will not be set, so we'll
        // throw the StorageException below when we check for a null obj.
      }

      if (obj == null)
        throw new StorageException("Column value could not be coerced to the correct type");

      return obj;
    }
Ejemplo n.º 4
0
  /**
   * 根据传入的参数决定使用哪类枚举器
   *
   * @param comp
   * @param needMergeValueInCloseInterval
   * @return
   */
  private CloseIntervalFieldsEnumeratorHandler getCloseIntervalEnumeratorHandlerByComparative(
      Comparative comp, boolean needMergeValueInCloseInterval) {
    if (!needMergeValueInCloseInterval) {
      return enumeratorMap.get(DEFAULT_ENUMERATOR);
    }
    if (comp == null) {
      throw new IllegalArgumentException("comp is null");
    }

    Comparable value = comp.getValue();
    if (value instanceof ComparativeBaseList) {
      ComparativeBaseList comparativeBaseList = (ComparativeBaseList) value;
      for (Comparative comparative : comparativeBaseList.getList()) {
        return getCloseIntervalEnumeratorHandlerByComparative(
            comparative, needMergeValueInCloseInterval);
      }

      throw new NotSupportException(); // 不可能到这一步
    } else if (value instanceof Comparative) {
      return getCloseIntervalEnumeratorHandlerByComparative(comp, needMergeValueInCloseInterval);
    } else {
      // 表明是一个comparative对象
      CloseIntervalFieldsEnumeratorHandler enumeratorHandler =
          enumeratorMap.get(value.getClass().getName());
      if (enumeratorHandler != null) {
        return enumeratorHandler;
      } else {
        return enumeratorMap.get(DEFAULT_ENUMERATOR);
      }
    }
  }
Ejemplo n.º 5
0
 private boolean compare_Comparable(int operation, Comparable<Object> value1, Object value2) {
   if (operation == SUBSTRING) {
     return false;
   }
   value2 = valueOf(value1.getClass(), (String) value2);
   if (value2 == null) {
     return false;
   }
   try {
     switch (operation) {
       case APPROX:
       case EQUAL:
         {
           return value1.compareTo(value2) == 0;
         }
       case GREATER:
         {
           return value1.compareTo(value2) >= 0;
         }
       case LESS:
         {
           return value1.compareTo(value2) <= 0;
         }
     }
   } catch (Exception e) {
     // if the compareTo method throws an exception; return false
     return false;
   }
   return false;
 }
Ejemplo n.º 6
0
 public static Boolean not(Comparable<?> param) throws ParseException {
   if (param == null) {
     return null;
   }
   if (param instanceof Boolean) {
     return ((Boolean) param).booleanValue() ? Boolean.TRUE : Boolean.FALSE;
   }
   throw new ParseException(WRONG_TYPE + " not " + param.getClass());
 }
Ejemplo n.º 7
0
  /**
   * Method getTypes returns an array of the element classes. Null if the element is null.
   *
   * @return the types (type Class[]) of this Tuple object.
   */
  public Class[] getTypes() {
    Class[] types = new Class[elements.size()];

    for (int i = 0; i < elements.size(); i++) {
      Comparable value = elements.get(i);

      if (value != null) types[i] = value.getClass();
    }

    return types;
  }
Ejemplo n.º 8
0
 public static Integer second(Comparable<?> param, Calendar cal) throws ParseException {
   if (param == null) {
     return null;
   }
   if (param instanceof Timestamp || param instanceof java.sql.Time) {
     java.util.Date ts = (java.util.Date) param;
     cal.setTimeInMillis(ts.getTime());
     return new Integer(cal.get(SECOND));
   }
   throw new ParseException(WRONG_TYPE + " second(" + param.getClass() + ")");
 }
Ejemplo n.º 9
0
    boolean matchesValue(Comparable<?> value) {
      boolean isNullEqPredicate =
          (startValue == null) && (endValue == null) && startInclusive && endInclusive;
      if (value == null) return isNullEqPredicate;

      if (isNullEqPredicate) return false;

      int result;
      Comparable<?> coercedValue;
      if (startValue != null) {
        coercedValue = coerceValue(value, startValue.getClass());
        result = ((Comparable) coercedValue).compareTo(startValue);
        if ((result < 0) || (!startInclusive && (result == 0))) return false;
      }
      if (endValue != null) {
        coercedValue = coerceValue(value, endValue.getClass());
        result = ((Comparable) coercedValue).compareTo(endValue);
        if ((result > 0) || (!endInclusive && (result == 0))) return false;
      }
      return true;
    }
Ejemplo n.º 10
0
  @Override
  public Comparable value(NodeCommon node) {
    if (args.size() < 1) return null; // sysdate ?
    if (function.names.size() > 1) return null; // static

    List<Comparable> margs = ListUtil.newList();
    for (Expression arg : args) {
      margs.add(arg.value(node));
    }

    String fnName = function.names.get(0);
    Comparable target = margs.get(0);

    try {

      if (margs.size() == 1) return (Comparable) target.getClass().getMethod(fnName).invoke(target);

      Iterator argIter = Iterables.skip(margs, 1).iterator();
      Class[] argClz = new Class[margs.size() - 1];
      Object[] argObj = new Object[margs.size() - 1];
      int i = 0;
      while (argIter.hasNext()) {
        Object aobj = argIter.next();
        argClz[i] = (aobj.getClass().equals(BigDecimal.class)) ? int.class : aobj.getClass();
        argObj[i++] = (aobj instanceof BigDecimal) ? ((BigDecimal) aobj).intValue() : aobj;
      }

      final Object result = target.getClass().getMethod(fnName, argClz).invoke(target, argObj);

      if ((result instanceof Integer)
          || result instanceof Long
          || result instanceof Float
          || result instanceof Double) return NumberUtil.createBigDecimal(result.toString());
      return (Comparable) result;
    } catch (Throwable ex) {
      throw new IllegalArgumentException(ex);
    }
  }
Ejemplo n.º 11
0
 public static Integer dayOfWeek(Comparable<?> param, Calendar cal) throws ParseException {
   if (param == null) {
     return null;
   }
   if (param instanceof Timestamp || param instanceof java.sql.Date) {
     java.util.Date ts = (java.util.Date) param;
     cal.setTimeInMillis(ts.getTime());
     int dayOfWeek = cal.get(DAY_OF_WEEK) - 1;
     if (dayOfWeek == 0) {
       dayOfWeek = 7;
     }
     return new Integer(dayOfWeek);
   }
   throw new ParseException(WRONG_TYPE + " dayofweek(" + param.getClass() + ")");
 }
Ejemplo n.º 12
0
 /**
  * Adds 1 to the frequency count for v.
  *
  * <p>If other objects have already been added to this Frequency, v must be comparable to those
  * that have already been added.
  *
  * @param v the value to add.
  * @throws IllegalArgumentException if <code>v</code> is not comparable with previous entries
  */
 public void addValue(Comparable<?> v) {
   Comparable<?> obj = v;
   if (v instanceof Integer) {
     obj = Long.valueOf(((Integer) v).longValue());
   }
   try {
     Long count = freqTable.get(obj);
     if (count == null) {
       freqTable.put(obj, Long.valueOf(1));
     } else {
       freqTable.put(obj, Long.valueOf(count.longValue() + 1));
     }
   } catch (ClassCastException ex) {
     // TreeMap will throw ClassCastException if v is not comparable
     throw MathRuntimeException.createIllegalArgumentException(
         LocalizedFormats.INSTANCES_NOT_COMPARABLE_TO_EXISTING_VALUES, v.getClass().getName());
   }
 }
Ejemplo n.º 13
0
  private boolean compare_Comparable(int operation, Comparable value1, Object value2) {
    if (operation == SUBSTRING) {
      return false;
    }
    Constructor constructor;
    try {
      constructor = value1.getClass().getConstructor(constructorType);
    } catch (NoSuchMethodException e) {
      return false;
    }
    try {
      if (!constructor.isAccessible())
        AccessController.doPrivileged(new SetAccessibleAction(constructor));
      value2 = constructor.newInstance(new Object[] {((String) value2).trim()});
    } catch (IllegalAccessException e) {
      return false;
    } catch (InvocationTargetException e) {
      return false;
    } catch (InstantiationException e) {
      return false;
    }

    switch (operation) {
      case APPROX:
      case EQUAL:
        {
          return value1.compareTo(value2) == 0;
        }
      case GREATER:
        {
          return value1.compareTo(value2) >= 0;
        }
      case LESS:
        {
          return value1.compareTo(value2) <= 0;
        }
    }
    return false;
  }
Ejemplo n.º 14
0
 public void saveEntryIndex(QueryableEntry e) throws QueryException {
   Data key = e.getIndexKey();
   Comparable oldValue = recordValues.remove(key);
   Comparable newValue = e.getAttribute(attribute);
   if (newValue == null) {
     newValue = NULL;
   }
   recordValues.put(key, newValue);
   if (newValue.getClass().isEnum()) {
     newValue = TypeConverters.ENUM_CONVERTER.convert(newValue);
   }
   if (oldValue == null) {
     // new
     indexStore.newIndex(newValue, e);
   } else {
     // update
     indexStore.removeIndex(oldValue, key);
     indexStore.newIndex(newValue, e);
   }
   if (attributeType == null) {
     attributeType = e.getAttributeType(attribute);
   }
 }
Ejemplo n.º 15
0
 public static Comparable<?> round(Comparable<?> param, Calendar cal) throws ParseException {
   if (param == null) {
     return null;
   }
   if (param instanceof String) {
     param = parse((String) param);
   }
   if (param instanceof BigDecimal) { // BigInteger is not supported
     BigDecimal b = ((BigDecimal) param).setScale(0, BigDecimal.ROUND_HALF_UP);
     try {
       return b.longValueExact();
     } catch (ArithmeticException e) {
     }
     return b;
   }
   if (param instanceof Double || param instanceof Float) {
     return Math.round(((Number) param).doubleValue());
   }
   if (param instanceof Number) { // Long, Integer, Short, Byte
     return param;
   }
   if (param instanceof Timestamp) {
     Timestamp ts = (Timestamp) param;
     cal.setTimeInMillis(ts.getTime());
     int year = cal.get(YEAR);
     int month = cal.get(MONTH);
     int date = cal.get(DATE);
     int hour = cal.get(HOUR_OF_DAY);
     cal.clear();
     if (hour > 11) {
       date++;
     }
     cal.set(year, month, date);
     return new Timestamp(cal.getTimeInMillis());
   }
   throw new ParseException(WRONG_TYPE + " round(" + param.getClass() + ")");
 }
Ejemplo n.º 16
0
 public AttributeType getAttributeType(String attributeName) {
   return ReflectionHelper.getAttributeType(attributeValue.getClass());
 }
 public void setMinimum(final Comparable min) {
   this.min = min;
   if (min != null) {
     setValueClass(min.getClass());
   }
 }
 /**
  * Sets the maximum permissible value. If the <code>valueClass</code> has not been specified, and
  * <code>max</code> is non null, the <code>valueClass</code> will be set to that of the class of
  * <code>max</code>.
  *
  * @param max Maximum legal value that can be input
  * @see #setValueClass
  */
 public void setMaximum(Comparable max) {
   if (getValueClass() == null && max != null) {
     setValueClass(max.getClass());
   }
   this.max = max;
 }
 /**
  * Sets the minimum permissible value. If the <code>valueClass</code> has not been specified, and
  * <code>minimum</code> is non null, the <code>valueClass</code> will be set to that of the class
  * of <code>minimum</code>.
  *
  * @param minimum Minimum legal value that can be input
  * @see #setValueClass
  */
 public void setMinimum(Comparable minimum) {
   if (getValueClass() == null && minimum != null) {
     setValueClass(minimum.getClass());
   }
   min = minimum;
 }
Ejemplo n.º 20
0
  protected Boolean compare(Comparable lv, Comparable rv) {
    Class lc = lv.getClass();
    Class rc = rv.getClass();
    // If the the objects are not of the same type,
    // try to convert up to allow the comparison.
    if (lc != rc) {
      if (lc == Byte.class) {
        if (rc == Short.class) {
          lv = ((Number) lv).shortValue();
        } else if (rc == Integer.class) {
          lv = ((Number) lv).intValue();
        } else if (rc == Long.class) {
          lv = ((Number) lv).longValue();
        } else if (rc == Float.class) {
          lv = ((Number) lv).floatValue();
        } else if (rc == Double.class) {
          lv = ((Number) lv).doubleValue();
        } else {
          return Boolean.FALSE;
        }
      } else if (lc == Short.class) {
        if (rc == Integer.class) {
          lv = ((Number) lv).intValue();
        } else if (rc == Long.class) {
          lv = ((Number) lv).longValue();
        } else if (rc == Float.class) {
          lv = ((Number) lv).floatValue();
        } else if (rc == Double.class) {
          lv = ((Number) lv).doubleValue();
        } else {
          return Boolean.FALSE;
        }
      } else if (lc == Integer.class) {
        if (rc == Long.class) {
          lv = ((Number) lv).longValue();
        } else if (rc == Float.class) {
          lv = ((Number) lv).floatValue();
        } else if (rc == Double.class) {
          lv = ((Number) lv).doubleValue();
        } else {
          return Boolean.FALSE;
        }
      } else if (lc == Long.class) {
        if (rc == Integer.class) {
          rv = ((Number) rv).longValue();
        } else if (rc == Float.class) {
          lv = ((Number) lv).floatValue();
        } else if (rc == Double.class) {
          lv = ((Number) lv).doubleValue();
        } else {
          return Boolean.FALSE;
        }
      } else if (lc == Float.class) {
        if (rc == Integer.class) {
          rv = ((Number) rv).floatValue();
        } else if (rc == Long.class) {
          rv = ((Number) rv).floatValue();
        } else if (rc == Double.class) {
          lv = ((Number) lv).doubleValue();
        } else {
          return Boolean.FALSE;
        }
      } else if (lc == Double.class) {
        if (rc == Integer.class) {
          rv = ((Number) rv).doubleValue();
        } else if (rc == Long.class) {
          rv = ((Number) rv).doubleValue();
        } else if (rc == Float.class) {
          rv = ((Number) rv).doubleValue();
        } else {
          return Boolean.FALSE;
        }
      } else {
        return Boolean.FALSE;
      }
    }

    return asBoolean(lv.compareTo(rv)) ? Boolean.TRUE : Boolean.FALSE;
  }
 public void setMaximum(final Comparable max) {
   this.max = max;
   if (max != null) {
     setValueClass(max.getClass());
   }
 }
Ejemplo n.º 22
0
 public static Comparable<?> round(Comparable<?> param1, Comparable<?> param2, Calendar cal)
     throws ParseException {
   if (param1 == null || param2 == null) {
     return null;
   }
   if (param1 instanceof String) {
     param1 = parse((String) param1);
   }
   if (param1 instanceof Number) {
     int scale;
     try {
       scale = getInteger(param2);
     } catch (ParseException e) {
       throw new ParseException(PARAM_EXCEPTION);
     }
     if (scale < 0) {
       return ZERO;
     }
     if (param1 instanceof BigDecimal) { // BigInteger is not supported
       return ((BigDecimal) param1).setScale(scale, BigDecimal.ROUND_HALF_UP);
     }
     if (param1 instanceof Double || param1 instanceof Float) {
       double d = ((Number) param1).doubleValue();
       long mult = 1;
       for (int i = 0; i < scale; i++) {
         mult *= 10;
       }
       d *= mult;
       return (Math.round(d)) / mult;
     }
     if (param1 instanceof Number) { // Long, Integer, Short, Byte
       return param1;
     }
     throw new ParseException(
         WRONG_TYPE + " round(" + param1.getClass() + "," + param2.getClass() + ")");
   } else if (param1 instanceof java.util.Date) {
     if (param2 instanceof String) {
       String s = (String) param2;
       java.util.Date d = (java.util.Date) param1;
       cal.setTimeInMillis(d.getTime());
       if (s.equalsIgnoreCase("CC") || s.equalsIgnoreCase("SCC")) {
         if (d instanceof java.sql.Time) {
           throw new ParseException(Trunc.TIME_EXCEPTION);
         }
         int year = cal.get(YEAR);
         int year1 = (year / 100) * 100;
         if (year - year1 > 50) {
           year1 += 100;
         }
         cal.clear();
         cal.set(year1 + 1, 0, 1);
         return new Timestamp(cal.getTimeInMillis());
       } else if (s.equalsIgnoreCase("SYYYY")
           || s.equalsIgnoreCase("YYYY")
           || s.equalsIgnoreCase("YYY")
           || s.equalsIgnoreCase("Y")
           || s.equalsIgnoreCase("YEAR")
           || s.equalsIgnoreCase("SYEAR")) {
         if (d instanceof java.sql.Time) {
           throw new ParseException(Trunc.TIME_EXCEPTION);
         }
         int year = cal.get(YEAR);
         int month = cal.get(MONTH);
         if (month > 6) {
           year++;
         }
         cal.clear();
         cal.set(year, 0, 1);
         return new Timestamp(cal.getTimeInMillis());
       } else if (s.equalsIgnoreCase("IYYY")
           || s.equalsIgnoreCase("IY")
           || s.equalsIgnoreCase("I")) {
         throw new ParseException(NOT_IMPLIMENTED_EXCEPTION);
       } else if (s.equalsIgnoreCase("Q")) {
         if (d instanceof java.sql.Time) {
           throw new ParseException(Trunc.TIME_EXCEPTION);
         }
         int year = cal.get(YEAR);
         int month = cal.get(MONTH);
         int q = (month / 3) * 3;
         if (month > q + 1) {
           q++;
         } else if (month > q) {
           int day = cal.get(DAY_OF_MONTH);
           if (day > 15) {
             q++;
           }
         }
         cal.clear();
         cal.set(year, q, 1);
         return new Timestamp(cal.getTimeInMillis());
       } else if (s.equalsIgnoreCase("MONTH")
           || s.equalsIgnoreCase("MON")
           || s.equalsIgnoreCase("MM")
           || s.equalsIgnoreCase("RM")) {
         if (d instanceof java.sql.Time) {
           throw new ParseException(Trunc.TIME_EXCEPTION);
         }
         int year = cal.get(YEAR);
         int month = cal.get(MONTH);
         int day = cal.get(DAY_OF_MONTH);
         if (day > 15) {
           month++;
         }
         cal.clear();
         cal.set(year, month, 1);
         return new Timestamp(cal.getTimeInMillis());
       } else if (s.equalsIgnoreCase("WW")) {
         if (d instanceof java.sql.Time) {
           throw new ParseException(Trunc.TIME_EXCEPTION);
         }
         int year = cal.get(YEAR);
         int month = cal.get(MONTH);
         int day = cal.get(DAY_OF_MONTH);
         int dw = cal.get(DAY_OF_WEEK);
         cal.clear();
         cal.set(year, 0, 1);
         int dayOfWeek = cal.get(DAY_OF_WEEK);
         int delta = (dw < dayOfWeek ? 7 - (dayOfWeek - dw) : dw - dayOfWeek);
         if (delta > 2) {
           delta = delta - 7;
         }
         cal.set(year, month, day - delta);
         return new Timestamp(cal.getTimeInMillis());
       } else if (s.equalsIgnoreCase("W")) {
         if (d instanceof java.sql.Time) {
           throw new ParseException(Trunc.TIME_EXCEPTION);
         }
         int year = cal.get(YEAR);
         int month = cal.get(MONTH);
         int day = cal.get(DAY_OF_MONTH);
         int dw = cal.get(DAY_OF_WEEK);
         cal.clear();
         cal.set(year, month, 1);
         int dayOfWeek = cal.get(DAY_OF_WEEK);
         int delta = (dw < dayOfWeek ? 7 - (dayOfWeek - dw) : dw - dayOfWeek);
         if (delta > 2) {
           delta = delta - 7;
         }
         cal.set(year, month, day - delta);
         return new Timestamp(cal.getTimeInMillis());
       } else if (s.equalsIgnoreCase("IW")) {
         throw new ParseException(NOT_IMPLIMENTED_EXCEPTION);
       } else if (s.equalsIgnoreCase("DAY")
           || s.equalsIgnoreCase("DY")
           || s.equalsIgnoreCase("D")) {
         if (d instanceof java.sql.Time) {
           throw new ParseException(Trunc.TIME_EXCEPTION);
         }
         int year = cal.get(YEAR);
         int month = cal.get(MONTH);
         int day = cal.get(DAY_OF_MONTH);
         int dw = cal.get(DAY_OF_WEEK);
         int delta = dw - cal.getFirstDayOfWeek();
         if (delta > 2) {
           delta = delta - 7;
         }
         cal.clear();
         cal.set(year, month, day - delta);
         return new Timestamp(cal.getTimeInMillis());
       } else if (s.equalsIgnoreCase("HH")
           || s.equalsIgnoreCase("HH12")
           || s.equalsIgnoreCase("HH24")) {
         if (d instanceof java.sql.Date) {
           throw new ParseException(Trunc.DATE_EXCEPTION);
         }
         int minute = cal.get(MINUTE);
         if (minute >= 30) {
           cal.get(HOUR_OF_DAY);
           cal.add(HOUR_OF_DAY, 1);
         }
         cal.set(MINUTE, 0);
         cal.set(SECOND, 0);
         cal.set(MILLISECOND, 0);
         return new Timestamp(cal.getTimeInMillis());
       } else if (s.equalsIgnoreCase("MI")) {
         if (d instanceof java.sql.Date) {
           throw new ParseException(Trunc.DATE_EXCEPTION);
         }
         int second = cal.get(SECOND);
         if (second >= 30) {
           cal.get(MINUTE);
           cal.add(MINUTE, 1);
         }
         cal.set(SECOND, 0);
         cal.set(MILLISECOND, 0);
         return new Timestamp(cal.getTimeInMillis());
       } else {
         throw new ParseException(Trunc.FORMAT_EXCEPTION);
       }
     }
   }
   throw new ParseException(
       WRONG_TYPE + " trunc(" + param1.getClass() + "," + param2.getClass() + ")");
 }
  // lazy load
  private void internal_lazyLoadChilderenIfNeeded(Object obj) {
    if (obj instanceof UserNode) {
      UserNode un = (UserNode) obj;
      if (!un.isInitialized()) {
        un.flagInitialized();

        // check if we have multiple child relations
        RelationInfo[] relationInfos = bindingInfo.getNRelationInfos(un);
        if (relationInfos != null && relationInfos.length > 0) {
          int id = 0;
          for (RelationInfo relationInfo : relationInfos)
            un.add(new RelationNode(id++, relationInfo));
          return;
        }

        IRecord rec = un.getRecord();
        if (rec != null) {
          IFoundSet nfs;
          String n_relationName = bindingInfo.getNRelationName(un);
          String m_relationName = bindingInfo.getMRelationName(un);

          nfs = rec.getRelatedFoundSet(n_relationName);
          if (nfs != null && nfs.getSize() > 0) {
            if (m_relationName == null) {
              List sortColumns =
                  getSortColumns(
                      (Table) ((IFoundSetInternal) nfs).getTable(),
                      bindingInfo.getChildSortDataprovider(un));
              if (sortColumns != null) {
                try {
                  nfs.sort(sortColumns);
                } catch (Exception ex) {
                  Debug.error(ex);
                }
              }
              for (int i = 0; i < nfs.getSize(); i++) {
                nfs.getRecord(i); // to force next record loading
                createChildNode(un, nfs, i);
              }
            } else {
              ArrayList mfsRecordsSortedIdx = new ArrayList();
              ArrayList mfsSorted = new ArrayList();

              int sortOrder = SortColumn.ASCENDING;

              for (int ii = 0; ii < nfs.getSize(); ii++) {
                IRecord rel = nfs.getRecord(ii);
                IFoundSet mfs = rel.getRelatedFoundSet(m_relationName);
                if (mfs != null) {
                  for (int i = 0; i < mfs.getSize(); i++) {
                    IRecord mfsRec = mfs.getRecord(i);

                    // if sorting add mfs value o right position
                    List sortColumns =
                        getSortColumns(
                            (Table) ((IFoundSetInternal) mfs).getTable(),
                            bindingInfo.getChildSortDataprovider(un));
                    if (sortColumns != null) {
                      SortColumn sortCol = (SortColumn) sortColumns.get(0);
                      String sortDataProvider = sortCol.getDataProviderID();
                      sortOrder = sortCol.getSortOrder();
                      if (mfsRec != null) {
                        if (mfsRec.getValue(sortDataProvider) != null
                            && mfsRec.getValue(sortDataProvider) instanceof Comparable) {
                          Comparable sMfsRecValue = (Comparable) mfsRec.getValue(sortDataProvider);
                          Comparable sSortedValue;
                          int n;
                          for (n = 0; n < mfsRecordsSortedIdx.size(); n++) {
                            int nSortedRecIdx = ((Integer) mfsRecordsSortedIdx.get(n)).intValue();
                            sSortedValue =
                                (Comparable)
                                    ((IFoundSet) mfsSorted.get(n))
                                        .getRecord(nSortedRecIdx)
                                        .getValue(sortDataProvider);

                            if (sSortedValue == null) continue;

                            if (sMfsRecValue
                                    .getClass()
                                    .getName()
                                    .equals(sSortedValue.getClass().getName())
                                && sMfsRecValue.compareTo(sSortedValue) < 0) {
                              break;
                            }
                          }

                          mfsRecordsSortedIdx.add(n, new Integer(i));
                          mfsSorted.add(n, mfs);
                        } else {
                          mfsRecordsSortedIdx.add(0, new Integer(i));
                          mfsSorted.add(0, mfs);
                        }
                      }
                    } else {
                      mfsRecordsSortedIdx.add(new Integer(i));
                      mfsSorted.add(mfs);
                    }
                  }
                }
              }

              // should be done better
              if (sortOrder == SortColumn.ASCENDING) {
                for (int i = 0; i < mfsRecordsSortedIdx.size(); i++) {
                  createChildNode(
                      (DefaultMutableTreeNode) un,
                      (IFoundSet) mfsSorted.get(i),
                      ((Integer) mfsRecordsSortedIdx.get(i)).intValue());
                }
              } else {
                for (int i = mfsRecordsSortedIdx.size() - 1; i >= 0; i--) {
                  createChildNode(
                      (DefaultMutableTreeNode) un,
                      (IFoundSet) mfsSorted.get(i),
                      ((Integer) mfsRecordsSortedIdx.get(i)).intValue());
                }
              }
            }
          }
        }
      }
    } else if (obj instanceof RelationNode) {
      RelationNode un = (RelationNode) obj;
      if (!un.isInitialized()) {
        un.flagInitialized();

        UserNode parentUserNode = (UserNode) un.getParent();
        IRecord parentRecord = parentUserNode.getRecord();

        IFoundSet nfs =
            parentRecord.getRelatedFoundSet(((RelationInfo) un.getUserObject()).getNRelationName());

        if (nfs != null && nfs.getSize() > 0) {
          for (int i = 0; i < nfs.getSize(); i++) {
            createChildNode(un, nfs, i);
            nfs.getRecord(i);
          }
        }
      }
    }
  }