Exemplo n.º 1
0
  /**
   * 级联查找,子查找
   *
   * @param csc
   * @return
   */
  private List<CscQueryResult> cscSubQuery(CascadeSqlSelectEntity csc) {
    List<CscQueryResult> retval = new ArrayList<CscQueryResult>();
    try {
      String tableName = csc.getTableInfo().getTableName();
      String keyName = csc.getTableInfo().getKey().getName();

      // 宏替换,生成ISQL
      csc.marcoReplace();
      ISql selSql = csc.genSql();
      // 查找
      List<Map<String, String>> selList =
          this.query(selSql, new ResultSetHandleListMapStringString());
      List<String> keyLst = this.getKeyList(keyName, selList);
      csc.addValue(keyName, keyLst);
      // 生成结果
      for (Map<String, String> sel : selList) {
        CscQueryResult temp = new CscQueryResult();
        temp.setTableName(tableName);
        temp.setValues(sel);
        retval.add(temp);
      }

      // 执行子SQL
      List<CascadeSqlEntity> subs = csc.getSubs();
      if (selList.size() > 0 && subs != null && !subs.isEmpty()) {
        for (CascadeSqlEntity sub : subs) {
          if (!(sub instanceof CascadeSqlSelectEntity)) {
            continue;
          }
          List<CscQueryResult> subResults = this.cscSubQuery((CascadeSqlSelectEntity) sub);
          for (CscQueryResult subResult : subResults) {
            String parentPriValue =
                subResult.getValues().get(((CascadeSqlSelectEntity) sub).getFilterField());
            if (parentPriValue != null) {
              for (CscQueryResult pResult : retval) {
                if (pResult.getValues().get(keyName).equals(parentPriValue)) {
                  pResult.addSub(subResult);
                }
              }
            }
          }
        }
      }

    } catch (Exception ex) {
      throw new UncheckedOrmException(ex);
    }
    return retval;
  }
Exemplo n.º 2
0
  /**
   * 自循环查找
   *
   * @param csc
   */
  public CscQueryResult cscLoopQuery(CascadeSqlSelectEntity csc) {
    CscQueryResult retval = new CscQueryResult();
    boolean isSelf = false;
    try {
      isSelf = this.transBegin();
      String tableName = csc.getTableInfo().getTableName();
      String keyName = csc.getTableInfo().getKey().getName();

      // 宏替换,生成ISQL
      csc.marcoReplace();
      ISql selSql = csc.genSql();
      // 查找
      Map<String, String> selMap = this.query(selSql, new ResultSetHandleMapStringString());
      String keyValue = selMap.get(keyName);
      retval.setTableName(tableName);
      retval.setValues(selMap);
      // 自循环
      String selLoop = csc.getSelfLoop();
      if (selLoop != null) {
        ISql loopSql = this.genSelfLoopSql(csc.getTableInfo(), keyValue, selLoop);
        List<Map<String, String>> loopSelList =
            this.query(loopSql, new ResultSetHandleListMapStringString());
        while (!loopSelList.isEmpty()) {
          List<String> tempKeyLst = this.getKeyList(tableName, loopSelList);
          for (Map<String, String> loopSel : loopSelList) {
            CscQueryResult temp = new CscQueryResult();
            temp.setTableName(tableName);
            temp.setValues(loopSel);
            retval.addSub(temp);
          }

          loopSql = this.genSelfLoopSql(csc.getTableInfo(), tempKeyLst, selLoop);
          loopSelList = this.query(loopSql, new ResultSetHandleListMapStringString());
        }
      }
      this.transCommit(isSelf);
    } catch (Exception ex) {
      this.transRollback(isSelf);
      throw new UncheckedOrmException(ex);
    }
    return retval;
  }
Exemplo n.º 3
0
  /**
   * 级联查找
   *
   * @param batch
   */
  public CscQueryResult cscQuery(CascadeSqlSelectEntity csc) {
    CscQueryResult retval = null;
    boolean isSelf = false;
    try {
      isSelf = this.transBegin();
      String tableName = csc.getTableInfo().getTableName();
      String keyName = csc.getTableInfo().getKey().getName();

      // 宏替换,生成ISQL
      csc.marcoReplace();
      ISql selSql = csc.genSql();
      // 查找
      Map<String, String> selList = this.query(selSql, new ResultSetHandleMapStringString());

      if (selList != null && !selList.isEmpty()) {
        retval = new CscQueryResult();
        retval.setTableName(tableName);
        retval.setValues(selList);

        String keyValue = selList.get(keyName);
        csc.addValue(keyName, keyValue);

        // 执行子SQL
        if (selList.size() > 0) {
          List<CascadeSqlEntity> subs = csc.getSubs();
          if (subs != null && !subs.isEmpty()) {
            for (CascadeSqlEntity sub : subs) {
              List<CscQueryResult> temp = this.cscSubQuery((CascadeSqlSelectEntity) sub);
              if (temp != null && !temp.isEmpty()) {
                retval.addSub(temp);
              }
            }
          }
        }
      }
      this.transCommit(isSelf);
    } catch (Exception ex) {
      this.transRollback(isSelf);
      throw new UncheckedOrmException(ex);
    }
    return retval;
  }