Package org.eweb4j.orm.dao

Examples of org.eweb4j.orm.dao.DAOException


          }
        }

      }
    } catch (Exception e) {
      throw new DAOException("", e);
    }

    return ids;
  }
View Full Code Here


      int rs = (Integer) JdbcUtil.updateWithArgs(con, sql, args);
      if (rs > 0) {
        id = DAOUtil.selectMaxId(clazz, ds.getConnection(), dbType);
      }
    } catch (Exception e) {
      throw new DAOException("", e);
    }

    return id;
  }
View Full Code Here

          }
        }

      }
    } catch (Exception e) {
      throw new DAOException("", e);
    }

    return ids;
  }
View Full Code Here

          }
        }

      }
    } catch (Exception e) {
      throw new DAOException("", e);
    }

    return ids;
  }
View Full Code Here

    this.table = ORMConfigBeanUtil.getTable(this.t.getClass());
    // 主类的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);

    this.idColumn = ORMConfigBeanUtil.getIdColumn(this.t.getClass());
   
    try {
      Object _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

   
          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,idVal);
      } else {
        // 删除指定关联的记录
        String to = tos[0].name();
        Class<?> tarClass = ann.targetEntity();
        if (void.class.isAssignableFrom(tarClass)) {
          tarClass = ClassUtil.getGenericType(f);
        }
       
        // "delete from {relTable} where {from} = {idVal} 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

          }
        });
       

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

          int rs = (Integer) JdbcUtil.update(con, sqls[0]);
          ids[i] = rs;
        }
      }
    } catch (Exception e) {
      throw new DAOException("", e);
    }

    return ids;
  }
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.