Пример #1
0
  public static void createIndex(String tableName, Index index) {
    Value table_ = cm.GetTableInformation(tableName);
    Value attr_;
    BPlusTree thisTree = new BPlusTree(index);

    String filename = tableName;
    try {
      mapInsert(tableName, index);
      RM_FileHandler rmf = RM_Manager.getInstance().openFile(filename);
      RM_FileScan rmfs =
          new RM_FileScan(
              rmf, Constant.TYPE.INT, 4, 0, Constant.COMP_OP.NO_OP, PF_Manager.intTobyteArray(1));
      RM_Record rmr = rmfs.getNextRec();

      while (rmr != null) {
        byte[] Record = rmr.getData();
        byte[] key = getColumnValue(tableName, index, Record);
        thisTree.insert(key, rmr.getRid().getPageNum(), rmr.getRid().getSlotNum());
        rmr = rmfs.getNextRec();
      }
    } catch (NullPointerException e) {
      e.printStackTrace();
      System.err.println("must not be null for key.");
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println("the index has not been created.");
    }

    // index.rootNum=thisTree.myRootBlock.blockOffset;
    setIndexRoot(index.indexName, thisTree.myRootBlock.getPageNum());
    System.out.println("Create index successfully!");
  }
Пример #2
0
 public static void deleteKey(Index index, byte[] deleteKey) throws Exception {
   try {
     // Index inx=CatalogManager.getIndex(index.indexName);
     BPlusTree thisTree = new BPlusTree(index, index.rootNum); /*This place has bugs.*/
     thisTree.delete(deleteKey);
     // index.rootNum=thisTree.myRootBlock.blockOffset;
     setIndexRoot(index.indexName, thisTree.myRootBlock.getPageNum());
   } catch (NullPointerException e) {
     System.err.println();
   }
 }
Пример #3
0
 public static RID searchEqual(Index index, byte[] key) throws Exception {
   RID off = new RID();
   try {
     // Index inx=CatalogManager.getIndex(index.indexName);
     BPlusTree thisTree = new BPlusTree(index, index.rootNum); /*This place has bugs.*/
     off = thisTree.searchKey(key);
     return off;
   } catch (NullPointerException e) {
     System.err.println();
     return null;
   }
 }