示例#1
0
 public void testDefrag1() throws IOException {
   String file = newTestFile();
   DBStore m = new DBStore(file, false, false, false);
   long loc = m.insert("123");
   m.defrag(true);
   m.close();
   m = new DBStore(file, false, false, false);
   assertEquals(m.fetch(loc), "123");
 }
示例#2
0
  public void testDefragBtree() throws IOException {
    String file = newTestFile();
    DBStore m = new DBStore(file, false, false, false);
    Map t = m.createTreeMap("aa");
    TreeMap t2 = new TreeMap();
    for (int i = 0; i < 10000; i++) {
      t.put(i, "" + i);
      t2.put(i, "" + i);
    }

    m.defrag(true);
    m.close();
    m = new DBStore(file, false, false, false);
    t = m.getTreeMap("aa");
    assertEquals(t, t2);
  }
示例#3
0
 /**
  * This method is used to convert an RMI remote reference to a Base object to a reference to the
  * local copy.
  *
  * <p>Needed for RMI under JDK 1.1.
  */
 public DBObjectBase getBaseFromKey(short id) {
   if (editor != null) {
     return (DBObjectBase) baseHash.get(Short.valueOf(id));
   } else {
     return store.getObjectBase(id);
   }
 }
示例#4
0
  public void testDefrag2() throws IOException {
    String file = newTestFile();
    DBStore m = new DBStore(file, false, false, false);
    TreeMap<Long, String> map = new TreeMap<Long, String>();
    for (int i = 0; i < 10000; i++) {
      long loc = m.insert("" + i);
      map.put(loc, "" + i);
    }

    m.defrag(true);
    m.close();
    m = new DBStore(file, false, false, false);
    for (Long l : map.keySet()) {
      String val = map.get(l);
      assertEquals(val, m.fetch(l));
    }
  }
示例#5
0
  /**
   * This method tells the CategoryNode what it's containing category is.
   *
   * @see arlut.csd.ganymede.rmi.CategoryNode
   */
  public void setCategory(Category category) {
    DBBaseCategory cat;
    String path;

    /* -- */

    if (category == null) {
      parent = null;
      return;
    }

    if (!(category instanceof DBBaseCategory)) {
      // we need a local reference

      try {
        path = category.getPath();
      } catch (RemoteException ex) {
        throw new RuntimeException("couldn't get path of remote category: " + ex);
      }

      if (debug) {
        System.err.println("** Attempting to find local copy of category " + path);
      }

      // getCategoryNode could also return a DBObjectBase, but not
      // in this context

      if (editor == null) {
        cat = (DBBaseCategory) store.getCategoryNode(path);
      } else {
        cat = (DBBaseCategory) editor.getCategoryNode(path);
      }

      if (cat == null) {
        throw new RuntimeException("setCategory: couldn't find local parent category");
      }

      parent = cat;
    } else {
      parent = (DBBaseCategory) category;
    }
  }
示例#6
0
  public void testDefragLinkedList() throws Exception {
    String file = newTestFile();
    DBStore r = new DBStore(file, false, false, false);
    List l = r.createLinkedList("test");
    Map<Long, Double> junk = new LinkedHashMap<Long, Double>();

    for (int i = 0; i < 1e4; i++) {
      // insert some junk
      Double d = Math.random();
      l.add(d);
      junk.put(r.insert(d), d);
    }
    r.commit();
    // make copy of linked list
    List l2 = new ArrayList(l);
    long oldRecCount = r.countRecords();
    r.defrag(true);

    r.close();
    r = new DBStore(file, false, false, false);
    assertEquals(oldRecCount, r.countRecords());

    // compare that list was unchanged
    assertEquals(l2, new ArrayList(r.getLinkedList("test")));

    // and check that random junk still have the same recids
    for (Long recid : junk.keySet()) {
      assertEquals(junk.get(recid), r.fetch(recid));
    }

    r.close();
  }
示例#7
0
  /** Reads this category and its contents from &lt;in&gt;, in ganymede.db form. */
  synchronized void receive(DataInput in, DBBaseCategory parent) throws IOException {
    String pathName;

    int count, lastSlash;

    /* -- */

    // read in category name

    pathName = in.readUTF();

    // we stopped using an explicitly stored display order field at
    // DBStore 2.0

    if (store.isLessThan(2, 0)) {
      tmp_displayOrder = in.readInt();
    } else {
      tmp_displayOrder = -1;
    }

    // now parse our path name to get our path

    lastSlash = pathName.lastIndexOf('/');

    // and take our leaf's name

    name = pathName.substring(lastSlash + 1);

    // and get our parent

    this.parent = parent;

    // how many nodes under this category?

    count = in.readInt();

    if (false) {
      System.err.println(
          "DBBaseCategory.receive(): reading in " + count + " subcategories and bases");
    }

    for (int i = 0; i < count; i++) {
      // starting at 2.0, we started reading DBObjectBases in during
      // category reading.

      if (store.isAtLeast(2, 0)) {
        if (in.readBoolean()) {
          DBObjectBase tempBase = new DBObjectBase(in, store);

          store.setBase(tempBase); // register in DBStore objectBases hash

          // we want to add this node to the end of this
          // category, since we are reading them in order.

          addNodeAfter(tempBase, null);
        } else {
          // we want to add this node to the end of this
          // category, since we are reading them in order.

          addNodeAfter(new DBBaseCategory(store, in), null);
        }
      } else {
        // we're reading an old file, and we'll never see a
        // DBObjectBase here

        addNodeAfter(new DBBaseCategory(store, in), null);
      }
    }
  }