Ejemplo n.º 1
0
  public <T> List<T> buildResultForList(
      ResultSet res,
      int containersize,
      boolean ispagine,
      Class<T> objectType,
      RowHandler rowHandler)
      throws SQLException {
    int rowcount = 0;
    if (meta == null) this.cacheResultSetMetaData(res, ispagine);

    List<T> results = new ArrayList<T>(containersize);
    // Object[] results = new Object[containersize];

    boolean go = true;
    if (ispagine) go = res.next() && rowcount < getMaxsize();
    else go = res.next();
    // 从结果集中获取当前游标后maxsize条记录

    boolean ismap = Map.class.isAssignableFrom(objectType);
    ClassInfo beanInfo = ClassUtil.getClassInfo(objectType);
    while (go) {
      T record = ResultMap.buildValueObject(res, objectType, this, rowHandler, ismap, beanInfo);
      results.add(record);
      rowcount++;
      if (ispagine) go = res.next() && rowcount < getMaxsize();
      else go = res.next();
    }

    return results;
  }
Ejemplo n.º 2
0
  public <T> ResultMap buildResultMap(
      ResultSet res,
      Class<T> objectType,
      RowHandler rowhandler,
      int containersize,
      boolean ispagine,
      int result_type)
      throws SQLException {
    ResultMap resultMap = new ResultMap();
    if (result_type == ResultMap.type_maparray
        || (result_type == ResultMap.type_objectarray && Map.class.isAssignableFrom(objectType))) {
      Record[] results = buildResult(res, containersize, ispagine);
      resultMap.setCommonresult(results);
      if (results != null) resultMap.setSize(results.length);
    } else if (result_type == ResultMap.type_list) {
      List<T> results = buildResultForList(res, containersize, ispagine, objectType, rowhandler);
      resultMap.setCommonresult(results);
      if (results != null) resultMap.setSize(results.size());
    } else if (result_type == ResultMap.type_objcet) // 分页时,不能指定返回值类型为type_objcet
    {
      if (!ispagine) {
        if (res.next()) {
          ClassInfo beanInfo = ClassUtil.getClassInfo(objectType);
          boolean ismap = Map.class.isAssignableFrom(objectType);
          T result = ResultMap.buildValueObject(res, objectType, this, rowhandler, ismap, beanInfo);
          resultMap.setCommonresult(result);
          if (result != null) {
            resultMap.setSize(1);
          }
        }
      }
      //			throw new SQLException("");
    } else if (result_type == ResultMap.type_objectarray) {
      Object[] results =
          buildResultForObjectArray(res, containersize, ispagine, objectType, rowhandler);
      resultMap.setCommonresult(results);
      if (results != null) {
        resultMap.setSize(results.length);
      }
    } else if (result_type == ResultMap.type_xml) {
      if (rowhandler == null) {
        rowhandler = new XMLRowHandler();
      }
      resultMap.setCommonresult(
          buildResultForXml(res, containersize, ispagine, objectType, rowhandler));
      resultMap.setSize(getRowcount());
    } else if (result_type == ResultMap.type_null) {
      if (rowhandler == null) {
        throw new NestedSQLException("rowhandler == null");
      }

      //            resultMap.setCommonresult(buildResultForXml(res, containersize, ispagine,
      // objectType, rowhandler));
      this.rowcount = buildResult(res, ispagine, rowhandler);
      resultMap.setSize(getRowcount());
    }
    return resultMap;
  }
Ejemplo n.º 3
0
  public Object[] buildResultForObjectArray(
      ResultSet res, int containersize, boolean ispagine, Class objectType, RowHandler rowHandler)
      throws SQLException {
    int rowcount = 0;
    if (meta == null) this.cacheResultSetMetaData(res, ispagine);

    Object[] results = new Object[containersize];

    boolean go = true;
    if (ispagine) go = res.next() && rowcount < getMaxsize();
    else go = res.next();

    // 从结果集中获取当前游标后maxsize条记录

    boolean ismap = Map.class.isAssignableFrom(objectType);
    ClassInfo beanInfo = ClassUtil.getClassInfo(objectType);
    while (go) {

      if (rowcount == results.length) {
        Object[] temp = new Object[results.length + 10];
        for (int t = 0; t < results.length; t++) {
          temp[t] = results[t];
        }
        results = temp;
      }

      Object record =
          ResultMap.buildValueObject(res, objectType, this, rowHandler, ismap, beanInfo);
      results[rowcount] = record;
      rowcount++;
      if (ispagine) go = res.next() && rowcount < getMaxsize();
      else go = res.next();
    }

    if (results[0] == null) {
      // modified by biaoping.yin on 2005.03.28
      return null;
    }

    Object[] temp = null;
    for (int i = 0; i < results.length; i++) {
      if (results[i] == null) {
        temp = new Object[i];
        break;
      } else {
        temp = new Object[results.length];
      }
    }
    for (int i = 0; i < temp.length; i++) {
      temp[i] = results[i];
    }
    results = temp;
    temp = null;
    return results;
  }