Example #1
0
File: DB.java Project: rhauch/MapDB
  /**
   * Opens existing or creates new Hash Tree Set.
   *
   * @param name of Set
   * @param <K> values in set
   * @return set
   */
  public synchronized <K> Set<K> getHashSet(String name) {
    checkNotClosed();
    Set<K> ret = (Set<K>) getFromWeakCollection(name);
    if (ret != null) return ret;
    String type = catGet(name + ".type", null);
    if (type == null) {
      checkShouldCreate(name);
      return createHashSet(name, false, null);
    }

    // check type
    checkType(type, "HashSet");
    // open existing map
    ret =
        new HTreeMap(
                engine,
                (Long) catGet(name + ".counterRecid"),
                (Integer) catGet(name + ".hashSalt"),
                (long[]) catGet(name + ".segmentRecids"),
                catGet(name + ".serializer", getDefaultSerializer()),
                null,
                0L,
                0L,
                0L,
                0L,
                null,
                null,
                null)
            .keySet();

    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Example #2
0
File: DB.java Project: rhauch/MapDB
  /**
   * Opens existing or creates new B-linked-tree Set.
   *
   * @param name of set
   * @param <K> values in set
   * @return set
   */
  public synchronized <K> NavigableSet<K> getTreeSet(String name) {
    checkNotClosed();
    NavigableSet<K> ret = (NavigableSet<K>) getFromWeakCollection(name);
    if (ret != null) return ret;
    String type = catGet(name + ".type", null);
    if (type == null) {
      checkShouldCreate(name);
      return createTreeSet(name).make();
    }
    checkType(type, "TreeSet");

    ret =
        new BTreeMap<K, Object>(
                engine,
                (Long) catGet(name + ".rootRecidRef"),
                catGet(name + ".maxNodeSize", 32),
                false,
                catGet(name + ".counterRecid", 0L),
                (BTreeKeySerializer)
                    catGet(
                        name + ".keySerializer",
                        new BTreeKeySerializer.BasicKeySerializer(getDefaultSerializer())),
                null,
                (Comparator) catGet(name + ".comparator", Utils.COMPARABLE_COMPARATOR))
            .keySet();

    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Example #3
0
File: DB.java Project: rhauch/MapDB
  /**
   * Opens existing or creates new Hash Tree Map. This collection perform well under concurrent
   * access. Is best for large keys and large values.
   *
   * @param name of map
   * @param valueCreator if value is not found, new is created and placed into map.
   * @param <K> key
   * @param <V> value
   * @return map
   */
  public synchronized <K, V> HTreeMap<K, V> getHashMap(
      String name, Fun.Function1<V, K> valueCreator) {
    checkNotClosed();
    HTreeMap<K, V> ret = (HTreeMap<K, V>) getFromWeakCollection(name);
    if (ret != null) return ret;
    String type = catGet(name + ".type", null);
    if (type == null) {
      checkShouldCreate(name);
      return createHashMap(name).make();
    }

    // check type
    checkType(type, "HashMap");
    // open existing map
    ret =
        new HTreeMap<K, V>(
            engine,
            (Long) catGet(name + ".counterRecid"),
            (Integer) catGet(name + ".hashSalt"),
            (long[]) catGet(name + ".segmentRecids"),
            catGet(name + ".keySerializer", getDefaultSerializer()),
            catGet(name + ".valueSerializer", getDefaultSerializer()),
            catGet(name + ".expireTimeStart", 0L),
            catGet(name + ".expire", 0L),
            catGet(name + ".expireAccess", 0L),
            catGet(name + ".expireMaxSize", 0L),
            (long[]) catGet(name + ".expireHeads", null),
            (long[]) catGet(name + ".expireTails", null),
            valueCreator);

    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Example #4
0
  /**
   * Opens existing or creates new B-linked-tree Map. This collection performs well under concurrent
   * access. Only trade-off are deletes, which causes tree fragmentation. It is ordered and best
   * suited for small keys and values.
   *
   * @param name of map
   * @param <K> key
   * @param <V> value
   * @return map
   */
  public synchronized <K, V> BTreeMap<K, V> getTreeMap(String name) {
    checkNotClosed();
    BTreeMap<K, V> ret = (BTreeMap<K, V>) getFromWeakCollection(name);
    if (ret != null) return ret;
    String type = catGet(name + ".type", null);
    if (type == null) {
      checkShouldCreate(name);
      return createTreeMap(name).make();
    }
    checkType(type, "TreeMap");

    ret =
        new BTreeMap<K, V>(
            engine,
            (Long) catGet(name + ".rootRecidRef"),
            catGet(name + ".maxNodeSize", 32),
            catGet(name + ".valuesOutsideNodes", false),
            catGet(name + ".counterRecid", 0L),
            (BTreeKeySerializer)
                catGet(
                    name + ".keySerializer",
                    new BTreeKeySerializer.BasicKeySerializer(getDefaultSerializer())),
            catGet(name + ".valueSerializer", getDefaultSerializer()),
            (Comparator) catGet(name + ".comparator", Utils.COMPARABLE_COMPARATOR));
    namedPut(name, ret);
    return ret;
  }
Example #5
0
File: DB.java Project: rhauch/MapDB
  public synchronized Atomic.Long getAtomicLong(String name) {
    checkNotClosed();
    Atomic.Long ret = (Atomic.Long) getFromWeakCollection(name);
    if (ret != null) return ret;
    String type = catGet(name + ".type", null);
    if (type == null) {
      checkShouldCreate(name);
      return createAtomicLong(name, 0L);
    }
    checkType(type, "AtomicLong");

    ret = new Atomic.Long(engine, (Long) catGet(name + ".recid"));
    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Example #6
0
  public synchronized Atomic.String getAtomicString(String name) {
    checkNotClosed();
    Atomic.String ret = (Atomic.String) getFromWeakCollection(name);
    if (ret != null) return ret;
    String type = catGet(name + ".type", null);
    if (type == null) {
      checkShouldCreate(name);
      return createAtomicString(name, "");
    }
    checkType(type, "AtomicString");

    ret = new Atomic.String(engine, (Long) catGet(name + ".recid"));
    namedPut(name, ret);
    return ret;
  }
Example #7
0
File: DB.java Project: rhauch/MapDB
  public synchronized <E> Atomic.Var<E> getAtomicVar(String name) {
    checkNotClosed();
    Atomic.Var ret = (Atomic.Var) getFromWeakCollection(name);
    if (ret != null) return ret;
    String type = catGet(name + ".type", null);
    if (type == null) {
      checkShouldCreate(name);
      return createAtomicVar(name, null, getDefaultSerializer());
    }
    checkType(type, "AtomicString");

    ret =
        new Atomic.Var(
            engine, (Long) catGet(name + ".recid"), (Serializer) catGet(name + ".serializer"));
    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Example #8
0
File: DB.java Project: rhauch/MapDB
  public synchronized <E> Queue<E> getStack(String name) {
    checkNotClosed();
    Queues.Stack<E> ret = (Queues.Stack<E>) getFromWeakCollection(name);
    if (ret != null) return ret;
    String type = catGet(name + ".type", null);
    if (type == null) {
      checkShouldCreate(name);
      return createStack(name, null, true);
    }

    checkType(type, "Stack");

    ret =
        new Queues.Stack<E>(
            engine,
            (Serializer<E>) catGet(name + ".serializer", getDefaultSerializer()),
            (Long) catGet(name + ".headRecid"),
            (Boolean) catGet(name + ".useLocks"));

    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
Example #9
0
  public synchronized <E> Queue<E> getQueue(String name) {
    checkNotClosed();
    Queues.Queue<E> ret = (Queues.Queue<E>) getFromWeakCollection(name);
    if (ret != null) return ret;
    String type = catGet(name + ".type", null);
    if (type == null) {
      checkShouldCreate(name);
      return createQueue(name, null);
    }
    checkType(type, "Queue");

    ret =
        new Queues.Queue<E>(
            engine,
            (Serializer<E>) catGet(name + ".serializer", getDefaultSerializer()),
            (Long) catGet(name + ".headRecid"),
            (Long) catGet(name + ".nextTailRecid"),
            (Long) catGet(name + ".sizeRecid"));

    namedPut(name, ret);
    return ret;
  }
Example #10
0
File: DB.java Project: rhauch/MapDB
  public synchronized <E> Queue<E> getCircularQueue(String name) {
    checkNotClosed();
    Queue<E> ret = (Queue<E>) getFromWeakCollection(name);
    if (ret != null) return ret;
    String type = catGet(name + ".type", null);
    if (type == null) {
      checkShouldCreate(name);
      return createCircularQueue(name, null, 1024);
    }

    checkType(type, "CircularQueue");

    ret =
        new Queues.CircularQueue<E>(
            engine,
            (Serializer<E>) catGet(name + ".serializer", getDefaultSerializer()),
            (Long) catGet(name + ".headRecid"),
            (Long) catGet(name + ".headInsertRecid"),
            (Long) catGet(name + ".size"));

    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }