Beispiel #1
0
  /**
   * 解析数据关联关系
   *
   * @param list
   * @param fieldName
   * @param keyMethod
   * @param table
   * @param refKey
   * @param ids
   * @throws NoSuchFieldException
   * @throws NoSuchMethodException
   * @throws IllegalAccessException
   * @throws InvocationTargetException
   */
  private void parseReference(
      List<T> list,
      String fieldName,
      Method keyMethod,
      String table,
      String refKey,
      StringBuffer ids)
      throws NoSuchFieldException, NoSuchMethodException, IllegalAccessException,
          InvocationTargetException {
    Coupler<Entity> childCoupler = childCouplers.get(fieldName);
    Class<Entity> childClass = childCoupler.getClazz();
    TreeDao<Entity> childDao = DaoFactory.getTreeDao(childClass);

    String childSql = buildChildQuerySql(table, refKey, ids, ordersMap, fieldName);

    if (entityClass == childClass) {
      int count = dao.count(childSql);
      if (count == 0) {
        return;
      }
    }

    List<Entity> childEntities = childDao.queryForTree(childSql);

    Class<?> fileType = entityClass.getDeclaredField(fieldName).getType();
    if (fileType == List.class) {
      setListValue(list, keyMethod, fieldName, childEntities, childClass, refKey);
    } else {
      setSingleValue(list, keyMethod, fieldName, childEntities, childClass, fileType, refKey);
    }
  }
Beispiel #2
0
 public SimpleTreeDao(Class<T> clazz) {
   this.entityClass = clazz;
   dao = DaoFactory.getDao(entityClass);
   treeCoupler = CouplerFactory.getTreeCoupler(entityClass);
   coupler = treeCoupler.getCoupler();
   childCouplers = treeCoupler.getChildCouplers();
   oneToOneMap = coupler.getOneToOneMap();
   oneToManyMap = coupler.getOneToManyMap();
   manyToOneMap = coupler.getManyToOneMap();
   ordersMap = coupler.getOrdersMap();
 }