Documentation of 'org.mapdb.DB' Java class
DB
org.mapdb

Class DB

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable


    public class DB
    extends java.lang.Object
    implements java.io.Closeable
    A database with easy access to named maps and other collections.
    • Constructor Detail

      • DB

        public DB(Engine engine)
        Construct new DB. It is just thin layer over Engine which does the real work.
        Parameters:
        engine -
      • DB

        public DB(Engine engine,
                  boolean strictDBGet,
                  boolean deleteFilesAfterClose,
                  java.util.concurrent.ScheduledExecutorService executor,
                  boolean lockDisable,
                  java.util.concurrent.ScheduledExecutorService metricsExecutor,
                  long metricsLogInterval,
                  java.util.concurrent.ScheduledExecutorService storeExecutor,
                  java.util.concurrent.ScheduledExecutorService cacheExecutor,
                  Fun.Function1<java.lang.Class,java.lang.String> classLoader)
    • Method Detail

      • metricsLog

        public void metricsLog()
      • metricsGet

        public java.util.Map<java.lang.String,java.lang.Long> metricsGet()
      • catGet

        public <A> A catGet(java.lang.String name,
                            A init)
      • catGet

        public <A> A catGet(java.lang.String name)
      • catPut

        public <A> A catPut(java.lang.String name,
                            A value)
      • catPut

        public <A> A catPut(java.lang.String name,
                            A value,
                            A retValueIfNull)
      • getNameForObject

        public java.lang.String getNameForObject(java.lang.Object obj)
        Get name for object. DB keeps weak reference to all objects it instanciated
        Parameters:
        obj - object to get name for
        Returns:
        name for this object, if it has name and was instanciated by this DB
      • getHashMap

        public <K,V> HTreeMap<K,V> getHashMap(java.lang.String name)
        Deprecated. method renamed, use hashMap(String)
      • hashMap

        public <K,V> HTreeMap<K,V> hashMap(java.lang.String name)
        Opens existing or creates new Hash Tree Map. This collection perform well under concurrent access. Is best for large keys and large values.
        Parameters:
        name - of the map
        Returns:
        map
      • hashMap

        public <K,V> HTreeMap<K,V> hashMap(java.lang.String name,
                                           Serializer<K> keySerializer,
                                           Serializer<V> valueSerializer)
        Opens existing or creates new Hash Tree Map. This collection perform well under concurrent access. Is best for large keys and large values.
        Parameters:
        name - of map
        keySerializer - serializer used on keys
        valueSerializer - serializer used on values
        Returns:
        map
      • hashMap

        public <K,V> HTreeMap<K,V> hashMap(java.lang.String name,
                                           Serializer<K> keySerializer,
                                           Serializer<V> valueSerializer,
                                           Fun.Function1<V,K> valueCreator)
        Opens existing or creates new Hash Tree Map. This collection perform well under concurrent access. Is best for large keys and large values.
        Parameters:
        name - of map
        keySerializer - serializer used on keys
        valueSerializer - serializer used on values
        valueCreator - if value is not found, new is created and placed into map.
        Returns:
        map
      • namedPut

        public <V> V namedPut(java.lang.String name,
                              java.lang.Object ret)
      • hashMapCreate

        public DB.HTreeMapMaker hashMapCreate(java.lang.String name)
        Returns new builder for HashMap with given name
        Parameters:
        name - of map to create
        Returns:
        maker, call .make() to create map
        Throws:
        java.lang.IllegalArgumentException - if name is already used
      • getHashSet

        public <K> java.util.Set<K> getHashSet(java.lang.String name)
        Deprecated. method renamed, use hashSet(String)
      • hashSet

        public <K> java.util.Set<K> hashSet(java.lang.String name)
        Opens existing or creates new Hash Tree Set.
        Parameters:
        name - of the Set
        Returns:
        set
      • hashSet

        public <K> java.util.Set<K> hashSet(java.lang.String name,
                                            Serializer<K> serializer)
      • hashSetCreate

        public DB.HTreeSetMaker hashSetCreate(java.lang.String name)
        Creates new HashSet
        Parameters:
        name - of set to create
      • getTreeMap

        public <K,V> BTreeMap<K,V> getTreeMap(java.lang.String name)
        Deprecated. method renamed, use treeMap(String)
      • treeMap

        public <K,V> BTreeMap<K,V> treeMap(java.lang.String name)
        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.
        Parameters:
        name - of map
        Returns:
        map
      • treeMapCreate

        public DB.BTreeMapMaker treeMapCreate(java.lang.String name)
        Returns new builder for TreeMap with given name
        Parameters:
        name - of map to create
        Returns:
        maker, call .make() to create map
        Throws:
        java.lang.IllegalArgumentException - if name is already used
      • getCatalog

        public java.util.SortedMap<java.lang.String,java.lang.Object> getCatalog()
        Get Name Catalog. It is metatable which contains information about named collections and records. Each collection constructor takes number of parameters, this map contains those parameters. _Note:_ Do not modify this map, unless you know what you are doing!
        Returns:
        Name Catalog
      • getTreeSet

        public <K> java.util.NavigableSet<K> getTreeSet(java.lang.String name)
        Deprecated. method renamed, use treeSet(String)
      • treeSet

        public <K> java.util.NavigableSet<K> treeSet(java.lang.String name)
        Opens existing or creates new B-linked-tree Set.
        Parameters:
        name - of set
        Returns:
        set
      • treeSet

        public <K> java.util.NavigableSet<K> treeSet(java.lang.String name,
                                                     Serializer serializer)
      • treeSet

        public <K> java.util.NavigableSet<K> treeSet(java.lang.String name,
                                                     BTreeKeySerializer serializer)
      • treeSetCreate

        public DB.BTreeSetMaker treeSetCreate(java.lang.String name)
        Creates new TreeSet.
        Parameters:
        name - of set to create
        Returns:
        maker used to construct set
        Throws:
        java.lang.IllegalArgumentException - if name is already used
      • treeSetCreate

        public <K> java.util.NavigableSet<K> treeSetCreate(DB.BTreeSetMaker m)
      • getQueue

        public <E> java.util.concurrent.BlockingQueue<E> getQueue(java.lang.String name)
        Deprecated. queues API is going to be reworked

        Why are queues methods deprecated?

        I am not really happy with current implementation. But I also have no time to rewrite them in 2.0. So current version is going to stay in 2.0 with deprecated flag.

        I am not sure what will happen in 2.1. Most likely I will redesign and extend Queues to include blocking, counted, full-dequeue implementation, multiple/single consumers/producers... etc. API will switch to some sort of Maker style pattern.

        In case of new queue framework, I might keep old implementation, but move it to separate JAR. So storage format will not change, but it will use different API to instantiate Queues.

        But there is also small chance I will remove deprecation flag and keep current implementation. I am not going to leave MapDB without at least some sort of Queue support.

        So feel free to use current implementation, it will be supported for 2.0 lifecycle (probably 6+ months). But once 2.1 release with long-term support is out, there might be some migration needed.

        Hope this makes sense

      • createQueue

        public <E> java.util.concurrent.BlockingQueue<E> createQueue(java.lang.String name,
                                                                     Serializer<E> serializer,
                                                                     boolean useLocks)
        Deprecated. queues API is going to be reworked

        Why are queues methods deprecated?

        I am not really happy with current implementation. But I also have no time to rewrite them in 2.0. So current version is going to stay in 2.0 with deprecated flag.

        I am not sure what will happen in 2.1. Most likely I will redesign and extend Queues to include blocking, counted, full-dequeue implementation, multiple/single consumers/producers... etc. API will switch to some sort of Maker style pattern.

        In case of new queue framework, I might keep old implementation, but move it to separate JAR. So storage format will not change, but it will use different API to instantiate Queues.

        But there is also small chance I will remove deprecation flag and keep current implementation. I am not going to leave MapDB without at least some sort of Queue support.

        So feel free to use current implementation, it will be supported for 2.0 lifecycle (probably 6+ months). But once 2.1 release with long-term support is out, there might be some migration needed.

        Hope this makes sense

      • getStack

        public <E> java.util.concurrent.BlockingQueue<E> getStack(java.lang.String name)
        Deprecated. queues API is going to be reworked

        Why are queues methods deprecated?

        I am not really happy with current implementation. But I also have no time to rewrite them in 2.0. So current version is going to stay in 2.0 with deprecated flag.

        I am not sure what will happen in 2.1. Most likely I will redesign and extend Queues to include blocking, counted, full-dequeue implementation, multiple/single consumers/producers... etc. API will switch to some sort of Maker style pattern.

        In case of new queue framework, I might keep old implementation, but move it to separate JAR. So storage format will not change, but it will use different API to instantiate Queues.

        But there is also small chance I will remove deprecation flag and keep current implementation. I am not going to leave MapDB without at least some sort of Queue support.

        So feel free to use current implementation, it will be supported for 2.0 lifecycle (probably 6+ months). But once 2.1 release with long-term support is out, there might be some migration needed.

        Hope this makes sense

      • createStack

        public <E> java.util.concurrent.BlockingQueue<E> createStack(java.lang.String name,
                                                                     Serializer<E> serializer,
                                                                     boolean useLocks)
        Deprecated. queues API is going to be reworked

        Why are queues methods deprecated?

        I am not really happy with current implementation. But I also have no time to rewrite them in 2.0. So current version is going to stay in 2.0 with deprecated flag.

        I am not sure what will happen in 2.1. Most likely I will redesign and extend Queues to include blocking, counted, full-dequeue implementation, multiple/single consumers/producers... etc. API will switch to some sort of Maker style pattern.

        In case of new queue framework, I might keep old implementation, but move it to separate JAR. So storage format will not change, but it will use different API to instantiate Queues.

        But there is also small chance I will remove deprecation flag and keep current implementation. I am not going to leave MapDB without at least some sort of Queue support.

        So feel free to use current implementation, it will be supported for 2.0 lifecycle (probably 6+ months). But once 2.1 release with long-term support is out, there might be some migration needed.

        Hope this makes sense

      • getCircularQueue

        public <E> java.util.concurrent.BlockingQueue<E> getCircularQueue(java.lang.String name)
        Deprecated. queues API is going to be reworked

        Why are queues methods deprecated?

        I am not really happy with current implementation. But I also have no time to rewrite them in 2.0. So current version is going to stay in 2.0 with deprecated flag.

        I am not sure what will happen in 2.1. Most likely I will redesign and extend Queues to include blocking, counted, full-dequeue implementation, multiple/single consumers/producers... etc. API will switch to some sort of Maker style pattern.

        In case of new queue framework, I might keep old implementation, but move it to separate JAR. So storage format will not change, but it will use different API to instantiate Queues.

        But there is also small chance I will remove deprecation flag and keep current implementation. I am not going to leave MapDB without at least some sort of Queue support.

        So feel free to use current implementation, it will be supported for 2.0 lifecycle (probably 6+ months). But once 2.1 release with long-term support is out, there might be some migration needed.

        Hope this makes sense

      • createCircularQueue

        public <E> java.util.concurrent.BlockingQueue<E> createCircularQueue(java.lang.String name,
                                                                             Serializer<E> serializer,
                                                                             long size)
        Deprecated. queues API is going to be reworked

        Why are queues methods deprecated?

        I am not really happy with current implementation. But I also have no time to rewrite them in 2.0. So current version is going to stay in 2.0 with deprecated flag.

        I am not sure what will happen in 2.1. Most likely I will redesign and extend Queues to include blocking, counted, full-dequeue implementation, multiple/single consumers/producers... etc. API will switch to some sort of Maker style pattern.

        In case of new queue framework, I might keep old implementation, but move it to separate JAR. So storage format will not change, but it will use different API to instantiate Queues.

        But there is also small chance I will remove deprecation flag and keep current implementation. I am not going to leave MapDB without at least some sort of Queue support.

        So feel free to use current implementation, it will be supported for 2.0 lifecycle (probably 6+ months). But once 2.1 release with long-term support is out, there might be some migration needed.

        Hope this makes sense

      • atomicLongCreate

        public Atomic.Long atomicLongCreate(java.lang.String name,
                                            long initValue)
      • atomicLong

        public Atomic.Long atomicLong(java.lang.String name)
      • atomicIntegerCreate

        public Atomic.Integer atomicIntegerCreate(java.lang.String name,
                                                  int initValue)
      • atomicInteger

        public Atomic.Integer atomicInteger(java.lang.String name)
      • atomicBooleanCreate

        public Atomic.Boolean atomicBooleanCreate(java.lang.String name,
                                                  boolean initValue)
      • atomicBoolean

        public Atomic.Boolean atomicBoolean(java.lang.String name)
      • checkShouldCreate

        public void checkShouldCreate(java.lang.String name)
      • atomicStringCreate

        public Atomic.String atomicStringCreate(java.lang.String name,
                                                java.lang.String initValue)
      • atomicString

        public Atomic.String atomicString(java.lang.String name)
      • atomicVarCreate

        public <E> Atomic.Var<E> atomicVarCreate(java.lang.String name,
                                                 E initValue,
                                                 Serializer<E> serializer)
      • atomicVar

        public <E> Atomic.Var<E> atomicVar(java.lang.String name)
      • atomicVar

        public <E> Atomic.Var<E> atomicVar(java.lang.String name,
                                           Serializer<E> serializer)
      • get

        public <E> E get(java.lang.String name)
        return record with given name or null if name does not exist
      • exists

        public boolean exists(java.lang.String name)
      • delete

        public void delete(java.lang.String name)
        delete record/collection with given name
      • getAll

        public java.util.Map<java.lang.String,java.lang.Object> getAll()
        return map of all named collections/records
      • rename

        public void rename(java.lang.String oldName,
                           java.lang.String newName)
        rename named record into newName
        Parameters:
        oldName - current name of record/collection
        newName - new name of record/collection
        Throws:
        java.util.NoSuchElementException - if oldName does not exist
      • checkNameNotExists

        public void checkNameNotExists(java.lang.String name)
        Checks that object with given name does not exist yet.
        Parameters:
        name - to check
        Throws:
        java.lang.IllegalArgumentException - if name is already used
      • close

        public void close()

        Closes database. All other methods will throw 'IllegalAccessError' after this method was called.

        !! it is necessary to call this method before JVM exits!!

        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface java.lang.AutoCloseable
      • getFromWeakCollection

        public java.lang.Object getFromWeakCollection(java.lang.String name)
        All collections are weakly referenced to prevent two instances of the same collection in memory. This is mainly for locking, two instances of the same lock would not simply work.
      • checkNotClosed

        public void checkNotClosed()
      • isClosed

        public boolean isClosed()
        Returns:
        true if DB is closed and can no longer be used
      • commit

        public void commit()
        Commit changes made on collections loaded by this DB
        See Also:
        Engine.commit()
      • rollback

        public void rollback()
        Rollback changes made on collections loaded by this DB
        See Also:
        Engine.rollback()
      • compact

        public void compact()
        Perform storage maintenance. Typically compact underlying storage and reclaim unused space.

        NOTE: MapDB does not have smart defragmentation algorithms. So compaction usually recreates entire store from scratch. This may require additional disk space.

      • snapshot

        public DB snapshot()
        Make readonly snapshot view of DB and all of its collection Collections loaded by this instance are not affected (are still mutable). You have to load new collections from DB returned by this method
        Returns:
        readonly snapshot view
      • getDefaultSerializer

        public Serializer getDefaultSerializer()
        Returns:
        default serializer used in this DB, it handles POJO and other stuff.
      • getEngine

        public Engine getEngine()
        Returns:
        underlying engine which takes care of persistence for this DB.
      • checkType

        public void checkType(java.lang.String type,
                              java.lang.String expected)
      • consistencyLock

        public java.util.concurrent.locks.ReadWriteLock consistencyLock()
        Returns consistency lock which groups operation together and ensures consistency. Operations which depends on each other are performed under read lock. Snapshots, close etc are performed under write-lock.
        Returns:

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.