Ejemplo n.º 1
0
  public void checkValid(DomainModel domainModel, Map values, Action action)
      throws ValidateException {
    Assert.notNull(domainModel, "PropertyMap对象不能为空");
    Assert.isInstanceOf(PropertyMap.class, domainModel, "属性非空有效性校验失败,传入的类型必须为PropertyMap!");
    Assert.notNull(values, "values不允许为空,请确认!");
    Assert.notNull(action, "在进行唯一性检测时传入的操作类型不能为空");

    PropertyMap pm = (PropertyMap) domainModel;
    if (pm.isUnique() == false) return; // 允许重复则不进行唯一性检测

    Object value = values.get(Validate.VALUE_CHECK_OBJ);
    Object pkValue = values.get(UniqueValidate.VALUE_CHECK_PK_OBJ); // 获取 主键值
    if (value == null || StringHelper.isNullString(value.toString())) return; // 如果是空值则不进行唯一性检测

    if (action instanceof AddAction) {
      String HQL =
          "from " + pm.getEntityMap().getEntityName() + " eo  where  " + genWhereClause(pm, value);
      logger.debug("=====================" + HQL + "============================");
      if (Udf.dbOperator.isExist(HQL)) {
        throw new ValidateException(
            "以[" + value + "]为值的字段[" + pm.getChineseName() + "]在系统中已经存在,不能重复添加!");
      }
    } else if (action instanceof ModifyAction) {
      String HQL =
          "from "
              + pm.getEntityMap().getEntityName()
              + " eo  where  "
              + genWhereClause(
                  pm.getEntityMap()
                      .getPropertyMap(pm.getEntityMap().getPKPropertyMap().getPropertyName()),
                  pkValue);
      logger.debug("=====================" + HQL + "============================");
      Object obj = Udf.dbOperator.findUniqueResult(HQL);
      Object oldValue =
          ReflectHelper.invoke(
              obj, "get" + StringHelper.converseFirstCharToUpper(pm.getPropertyName()));
      if (this.isEquals(pm, oldValue, value) == true) return; // 如果新旧两个值相等则不必进行校验,说明值没有被改变

      // 如果新旧两个值不相等,则说明新值已经发生改变,则从数据库中检测是否有重复的记录
      HQL =
          "from " + pm.getEntityMap().getEntityName() + " eo  where  " + genWhereClause(pm, value);
      logger.debug("=====================" + HQL + "============================");
      if (Udf.dbOperator.isExist(HQL)) {
        throw new ValidateException(
            "以[" + value + "]为值的字段[" + pm.getChineseName() + "]在系统中已经存在,不能修改成[" + value + "]");
      }
    }
  }
Ejemplo n.º 2
0
  protected Object sumcInvoke(Object obj, String method, String split) {
    StringBuffer buf = new StringBuffer();
    Assert.isInstanceOf(
        java.util.Collection.class, obj, "进行SumcElObject调用时传入的sumc必须是java.util.Collection对象,请确认");

    Object[] objs = ((java.util.Collection) obj).toArray();
    for (int i = 0; i < objs.length; i++) {
      // 在此将剩下的部分做为SimpleElObject来进行调用即可。
      SimpleElObject so = new SimpleElObject(getSimpleElExpression(), objs[i], this.request);
      Object o = so.calculate();
      // Object o =ReflectHelper.invoke(objs[i],method);
      if (o == null) o = "";
      buf.append(o.toString().trim());
      if (i < objs.length - 1) buf.append(split);
    }

    return buf.toString();
  }