Пример #1
0
  /**
   * Prints the SelectResults contents up to the specified rowCount.
   *
   * @param sr
   * @param startRowNum
   * @param rowCount
   * @return The number of rows printed
   */
  public static int printSelectResults(
      SelectResults sr, int startIndex, int startRowNum, int rowCount) {
    if (sr == null) {
      PadoShell.printlnError("SelectResults is null");
      return 0;
    }

    int endIndex = startIndex + rowCount; // exclusive
    if (endIndex >= sr.size()) {
      endIndex = sr.size();
    }

    if (startIndex >= endIndex) {
      return 0;
    }

    CollectionType type = sr.getCollectionType();
    ObjectType elementType = type.getElementType();
    int row = 1;
    if (rowCount == -1) {
      rowCount = sr.size();
    }

    HashSet elementNameSet = new HashSet();
    Object element = null;
    boolean isStructType = false;
    StructType structType = null;
    Struct struct = null;
    List srList = sr.asList();

    row = startRowNum;
    for (int i = startIndex; i < endIndex; i++) {
      element = srList.get(i);

      if (elementType.isStructType()) {

        struct = (Struct) element;
        printStruct(row, struct, 0);
        PadoShell.println("");

      } else {
        PadoShell.println(row + ". " + getPrintableType(element));
        printObject(null, element, 1);
        PadoShell.println("");
      }
      row++;
    }
    PadoShell.println("");
    for (Object elementClassName : elementNameSet) {
      PadoShell.println("Class: " + elementClassName);
    }
    return endIndex - startIndex;
  }
Пример #2
0
  private static int printSelectResults_iterator(SelectResults sr, int startRowNum, int rowCount) {
    if (sr == null) {
      PadoShell.printlnError("SelectResults is null");
      return 0;
    }

    CollectionType type = sr.getCollectionType();
    ObjectType elementType = type.getElementType();
    int row = 1;
    if (rowCount == -1) {
      rowCount = sr.size();
    }

    HashSet elementNameSet = new HashSet();
    ArrayList maxLenList = new ArrayList();
    Object element = null;
    boolean isStructType = false;
    StructType structType = null;
    Struct struct = null;
    for (Iterator iter = sr.iterator(); iter.hasNext() && row <= rowCount; ) {
      element = iter.next();
      if (elementType.isStructType()) {
        structType = (StructType) elementType;
        struct = (Struct) element;
        computeMaxLengths(maxLenList, structType, struct);
        isStructType = true;
      } else {
        computeMaxLengths(maxLenList, element, false);
        elementNameSet.add(element.getClass().getName());
      }
      row++;
    }

    if (element == null && struct == null) {
      return 0;
    }

    int rowMax = String.valueOf(startRowNum + rowCount - 1).length();
    if (rowMax < 3) {
      rowMax = 3;
    }
    if (isStructType) {
      printHeaders(maxLenList, structType, struct, rowMax);
    } else {
      printHeaders(maxLenList, element, rowMax);
    }

    row = startRowNum;
    int lastRow = startRowNum + rowCount - 1;
    for (Iterator iter = sr.iterator(); iter.hasNext() && row <= lastRow; ) {
      element = iter.next();

      if (elementType.isStructType()) {
        StringBuffer printStr = new StringBuffer();
        structType = (StructType) elementType;
        struct = (Struct) element;
        printStr.append(StringUtil.getRightPaddedString(row + "", rowMax, ' '));
        printStr.append("  ");
        PadoShell.println(printStr.toString());

      } else {
        StringBuffer printStr = new StringBuffer();
        printStr.append(StringUtil.getRightPaddedString(row + "", rowMax, ' '));
        printStr.append("  ");
        String printObjStr = printObject(maxLenList, element, false);
        printStr.append(printObjStr);
        PadoShell.println(printStr.toString());
      }
      row++;
    }
    PadoShell.println("");
    for (Object elementClassName : elementNameSet) {
      PadoShell.println("Class: " + elementClassName);
    }
    return row - 1;
  }