Beispiel #1
0
  /**
   * Prints all leaf pages
   *
   * @param currentPageId
   * @param keyType
   * @throws IOException
   * @throws ConstructPageException
   * @throws IteratorException
   * @throws InvalidFrameNumberException
   * @throws HashEntryNotFoundException
   * @throws PageUnpinnedException
   * @throws ReplacerException
   */
  private static void _printAllLeafPages(PageID currentPageId, int keyType)
      throws IOException, ConstructPageException, IteratorException, InvalidFrameNumberException,
          HashEntryNotFoundException, PageUnpinnedException, ReplacerException {

    BTSortedPage sortedPage = new BTSortedPage(currentPageId, keyType);

    if (sortedPage.getType() == NodeType.INDEX) {
      BTIndexPage indexPage = new BTIndexPage((Page) sortedPage, keyType);

      _printAllLeafPages(indexPage.getPrevPage(), keyType);

      TID genid = new TID();
      for (KeyDataEntry entry = indexPage.getFirst(genid);
          entry != null;
          entry = indexPage.getNext(genid)) {
        _printAllLeafPages(((IndexData) entry.data).getData(), keyType);
      }
    }

    if (sortedPage.getType() == NodeType.LEAF) {
      printPage(currentPageId, keyType);
    }

    SystemDefs.JavabaseBM.unpinPage(currentPageId, true /*dirty*/);
  }
Beispiel #2
0
  /**
   * Prints tree
   *
   * @param currentPageId
   * @param prefix
   * @param i
   * @param keyType
   * @throws IOException
   * @throws ConstructPageException
   * @throws IteratorException
   * @throws HashEntryNotFoundException
   * @throws InvalidFrameNumberException
   * @throws PageUnpinnedException
   * @throws ReplacerException
   */
  private static void _printTree(PageID currentPageId, String prefix, int i, int keyType)
      throws IOException, ConstructPageException, IteratorException, HashEntryNotFoundException,
          InvalidFrameNumberException, PageUnpinnedException, ReplacerException {

    BTSortedPage sortedPage = new BTSortedPage(currentPageId, keyType);
    prefix = prefix + "       ";
    i++;
    if (sortedPage.getType() == NodeType.INDEX) {
      BTIndexPage indexPage = new BTIndexPage((Page) sortedPage, keyType);

      System.out.println(i + prefix + indexPage.getPrevPage());
      _printTree(indexPage.getPrevPage(), prefix, i, keyType);

      TID genid = new TID();
      for (KeyDataEntry entry = indexPage.getFirst(genid);
          entry != null;
          entry = indexPage.getNext(genid)) {
        System.out.println(i + prefix + (IndexData) entry.data);
        _printTree(((IndexData) entry.data).getData(), prefix, i, keyType);
      }
    }
    SystemDefs.JavabaseBM.unpinPage(currentPageId, true /*dirty*/);
  }
Beispiel #3
0
  /**
   * used for debug: to print a page out. The page is either BTIndexPage, or BTLeafPage.
   *
   * @param pageno the number of page. Input parameter.
   * @param keyType It specifies the type of key. It can be AttrType.attrString or
   *     AttrType.attrInteger. Input parameter.
   * @exception IOException error from the lower layer
   * @exception IteratorException error for iterator
   * @exception ConstructPageException error for BT page constructor
   * @exception HashEntryNotFoundException error from the lower layer
   * @exception ReplacerException error from the lower layer
   * @exception PageUnpinnedException error from the lower layer
   * @exception InvalidFrameNumberException error from the lower layer
   */
  public static void printPage(PageID pageno, int keyType)
      throws IOException, IteratorException, ConstructPageException, HashEntryNotFoundException,
          ReplacerException, PageUnpinnedException, InvalidFrameNumberException {
    BTSortedPage sortedPage = new BTSortedPage(pageno, keyType);
    int i;
    i = 0;
    if (sortedPage.getType() == NodeType.INDEX) {
      BTIndexPage indexPage = new BTIndexPage((Page) sortedPage, keyType);
      System.out.println("");
      System.out.println("**************To Print an Index Page ********");
      System.out.println("Current Page ID: " + indexPage.getCurPage().pid);
      System.out.println("Left Link      : " + indexPage.getLeftLink().pid);

      TID genid = new TID();

      for (KeyDataEntry entry = indexPage.getFirst(genid);
          entry != null;
          entry = indexPage.getNext(genid)) {
        if (keyType == AttrType.attrInteger)
          System.out.println(
              i
                  + " (key, pageId):   ("
                  + (IntegerKey) entry.key
                  + ",  "
                  + (IndexData) entry.data
                  + " )");
        if (keyType == AttrType.attrString)
          System.out.println(
              i
                  + " (key, pageId):   ("
                  + (StringKey) entry.key
                  + ",  "
                  + (IndexData) entry.data
                  + " )");

        i++;
      }

      System.out.println("************** END ********");
      System.out.println("");
    } else if (sortedPage.getType() == NodeType.LEAF) {
      BTLeafPage leafPage = new BTLeafPage((Page) sortedPage, keyType);
      System.out.println("");
      System.out.println("**************To Print an Leaf Page ********");
      System.out.println("Current Page ID: " + leafPage.getCurPage().pid);
      System.out.println("Left Link      : " + leafPage.getPrevPage().pid);
      System.out.println("Right Link     : " + leafPage.getNextPage().pid);

      TID genid = new TID();

      for (KeyDataEntry entry = leafPage.getFirst(genid);
          entry != null;
          entry = leafPage.getNext(genid)) {
        if (keyType == AttrType.attrInteger)
          System.out.println(
              i
                  + " (key, [pageNo, slotNo]):   ("
                  + (IntegerKey) entry.key
                  + ",  "
                  + (LeafData) entry.data
                  + " )");
        if (keyType == AttrType.attrString)
          System.out.println(
              i
                  + " (key, [pageNo, slotNo]):   ("
                  + (StringKey) entry.key
                  + ",  "
                  + (LeafData) entry.data);

        i++;
      }

      System.out.println("************** END ********");
      System.out.println("");
    } else {
      System.out.println("Sorry!!! This page is neither Index nor Leaf page.");
    }

    SystemDefs.JavabaseBM.unpinPage(pageno, true /*dirty*/);
  }