Esempio n. 1
0
  public synchronized <K> NavigableSet<K> createTreeSet(
      String name, Comparator<K> keyComparator, Serializer<K> keySerializer) {
    try {
      assertNameNotExist(name);
      BTree<K, Object> tree = BTree.createInstance(this, keyComparator, keySerializer, null, false);
      setNamedObject(name, tree.getRecid());
      BTreeSet<K> ret = new BTreeSet<K>(new BTreeMap(tree, false));
      collections.put(name, new WeakReference<Object>(ret));
      return ret;

    } catch (IOException e) {
      throw new IOError(e);
    }
  }
Esempio n. 2
0
  public synchronized void deleteCollection(String name) {
    try {
      long nameDirectory_recid = getRoot(NAME_DIRECTORY_ROOT);
      if (nameDirectory_recid == 0) throw new IOException("Collection not found");
      HTree<String, Long> dir = fetch(nameDirectory_recid);

      Long recid = dir.get(name);
      if (recid == null) throw new IOException("Collection not found");

      Object o = fetch(recid);
      // we can not use O instance since it is not correctly initialized
      if (o instanceof LinkedList2) {
        LinkedList2 l = (LinkedList2) o;
        l.clear();
        delete(l.rootRecid);
      } else if (o instanceof BTree) {
        ((BTree) o).clear();
      } else if (o instanceof HTree) {
        HTree t = (HTree) o;
        t.clear();
        HTreeDirectory n = (HTreeDirectory) fetch(t.rootRecid, t.SERIALIZER);
        n.deleteAllChildren();
        delete(t.rootRecid);
      } else {
        throw new InternalError("unknown collection type: " + (o == null ? null : o.getClass()));
      }
      delete(recid);
      collections.remove(name);

      dir.remove(name);

    } catch (IOException e) {
      throw new IOError(e);
    }
  }
Esempio n. 3
0
 public synchronized <K, V> ConcurrentNavigableMap<K, V> createTreeMap(
     String name,
     Comparator<K> keyComparator,
     Serializer<K> keySerializer,
     Serializer<V> valueSerializer) {
   try {
     assertNameNotExist(name);
     BTree<K, V> tree =
         BTree.createInstance(this, keyComparator, keySerializer, valueSerializer, true);
     setNamedObject(name, tree.getRecid());
     ConcurrentNavigableMap<K, V> ret =
         new BTreeMap<K, V>(tree, false); // TODO put readonly flag here
     collections.put(name, new WeakReference<Object>(ret));
     return ret;
   } catch (IOException e) {
     throw new IOError(e);
   }
 }
Esempio n. 4
0
  public synchronized <K> NavigableSet<K> getTreeSet(String name) {
    Object o = getCollectionInstance(name);
    if (o != null) return (NavigableSet<K>) o;

    try {
      long recid = getNamedObject(name);
      if (recid == 0) return null;

      BTree t = BTree.<K, Object>load(this, recid);
      if (t.hasValues()) throw new ClassCastException("TreeMap is not TreeSet");
      BTreeSet<K> ret = new BTreeSet<K>(new BTreeMap(t, false));
      collections.put(name, new WeakReference<Object>(ret));
      return ret;

    } catch (IOException e) {
      throw new IOError(e);
    }
  }
Esempio n. 5
0
  public synchronized <K, V> ConcurrentNavigableMap<K, V> getTreeMap(String name) {
    Object o = getCollectionInstance(name);
    if (o != null) return (ConcurrentNavigableMap<K, V>) o;

    try {
      long recid = getNamedObject(name);
      if (recid == 0) return null;

      BTree t = BTree.<K, V>load(this, recid);
      if (!t.hasValues()) throw new ClassCastException("TreeSet is not TreeMap");
      ConcurrentNavigableMap<K, V> ret =
          new BTreeMap<K, V>(t, false); // TODO put readonly flag here
      collections.put(name, new WeakReference<Object>(ret));
      return ret;
    } catch (IOException e) {
      throw new IOError(e);
    }
  }