Package org.eweb4j.orm.dao

Examples of org.eweb4j.orm.dao.DAOException


          continue;
       
        tarSetter.invoke(t, tarList);
      } catch (Exception e) {

        throw new DAOException("", e);
      }
    }
  }
View Full Code Here


            DAOFactory.getDAO(tarClass, dsName).update().set(new String[]{mappedBy}, newIdVal).where().field(mappedBy).equal(idVal).execute();
          }
        }
      });
    } catch (Exception e) {
      throw new DAOException("", e);
    }
  }
View Full Code Here

    this.ru = new ReflectUtil(this.t);
    // 主类的ID属性名
    this.idField = ORMConfigBeanUtil.getIdField(this.t.getClass());
    this.idSetter = ru.getSetter(idField);
    if (this.idSetter == null)
      throw new DAOException("can not get idSetter.", null);

    this.idGetter = ru.getGetter(idField);
    if (this.idGetter == null)
      throw new DAOException("can not get idGetter.", null);

    Object idVal;
    try {
      idVal = idGetter.invoke(this.t);
      this.fromVal = idVal == null ? null : String.valueOf(idVal);
    } catch (Exception e) {
      throw new DAOException(idGetter + " invoke exception ", e);
    }
  }
View Full Code Here

      Object _tarObj = null;
      try {
        _tarObj = tarGetter.invoke(t);
      } catch (Exception e) {
        throw new DAOException(tarGetter + " invoke exception ", e);
      }
      // 检查一下目标对象是否存在于数据库
      if (_tarObj == null)
        continue;

      List<?> tarList = (List<?>) _tarObj;
      for (int i = 0; i < tarList.size(); i++) {
        Object tarObj = tarList.get(i);
        String from = froms[0].name();
        String to = tos[0].name();

        ReflectUtil tarRu = new ReflectUtil(tarObj);
        Method tarIdGetter = tarRu.getGetter(tarIdField);
        Object _tarIdVal = null;

        try {
          _tarIdVal = tarIdGetter.invoke(tarObj);
        } catch (Exception e) {
          throw new DAOException(tarIdGetter + " invoke exception ",
              e);
        }

        if (_tarIdVal == null)
          continue;

        String tarIdVal = String.valueOf(_tarIdVal);
        Object tempObj = DAOFactory.getSelectDAO(dsName).selectOne(
            tarClass, new String[] { tarIdField },
            new String[] { tarIdVal });

        if (tempObj == null) {
          // 如果目标对象不存在于数据库,则将目标对象插入到数据库
          Object tarIdValObj = DAOFactory.getInsertDAO(dsName)
              .insert(tarObj);
          // 将获取到的id值注入到tarObj中
          Method tarIdSetter = tarRu.getSetter(tarIdField);
          try {
            tarIdSetter.invoke(tarObj, tarIdValObj);
          } catch (Exception e) {
            throw new DAOException(tarIdSetter
                + " invoke exception ", e);
          }
          tarIdVal = String.valueOf(tarIdValObj);
        }
View Full Code Here

      List<?> tarList = null;

      try {
        tarList = (List<?>) tarGetter.invoke(t);
      } catch (Exception e) {
        throw new DAOException(tarGetter + " invoke exception ", e);
      }

      if (tarList == null || tarList.size() == 0) {
        String sql = String.format(format, relTable, from);
        // 删除所有关联记录
        DAOFactory.getUpdateDAO(dsName).updateBySQLWithArgs(sql,
            fromVal);
      } else {
        // 删除指定关联的记录
        String to = tos[0].name();
        Class<?> tarClass = ann.targetEntity();
        // "delete from {relTable} where {from} = {fromVal} and to = {toVal}"
        String _format = "delete from %s where %s = ? and %s = ?";
        for (int i = 0; i < tarList.size(); i++) {
          Object tarObj = tarList.get(i);
          if (tarObj == null)
            continue;
          ReflectUtil tarRu = new ReflectUtil(tarObj);
          String tarIdField = ORMConfigBeanUtil.getIdField(tarClass);
          Method tarIdGetter = tarRu.getGetter(tarIdField);
          Object toValObj = null;

          try {
            toValObj = tarIdGetter.invoke(tarObj);
          } catch (Exception e) {
            throw new DAOException(tarIdGetter
                + "invoke exception ", e);
          }

          if (toValObj == null)
            continue;
View Full Code Here

        Method tarSetter = ru.getSetter(f.getName());

        tarSetter.invoke(t, tarList);
      } catch (Exception e) {
        e.printStackTrace();
        throw new DAOException("", e);
      }
    }
  }
View Full Code Here

    try {
      idVal = idGetter.invoke(this.t);
      this.idVal = idVal == null ? null : String.valueOf(idVal);
    } catch (Exception e) {

      throw new DAOException("", e);
    }
  }
View Full Code Here

        String sql = String.format(format, table, column, idColumn);
        DAOFactory.getUpdateDAO(dsName).updateBySQLWithArgs(sql,
            tarIdValObj, idVal);

      } catch (Exception e) {
        throw new DAOException("", e);
      }
    }
  }
View Full Code Here

          continue;

        Method tarSetter = ru.getSetter(f.getName());
        tarSetter.invoke(t, tarObj);
      } catch (Exception e) {
        throw new DAOException("", e);
      }
    }
  }
View Full Code Here

    this.ru = new ReflectUtil(this.t);
    // 主类的ID属性名
    this.idField = ORMConfigBeanUtil.getIdField(this.t.getClass());
    this.idGetter = ru.getGetter(idField);
    if (idGetter == null)
      throw new DAOException("can not find idGetter.", null);

    Object idVal = null;
    try {
      idVal = idGetter.invoke(this.t);
      this.idVal = idVal == null ? null : String.valueOf(idVal);
    } catch (Exception e) {
      throw new DAOException(idGetter + " invoke exception ", e);
    }

  }
View Full Code Here

TOP

Related Classes of org.eweb4j.orm.dao.DAOException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.