public class DB extends Object implements Closeable
| Modifier and Type | Class and Description |
|---|---|
static class |
DB.BTreeMapMaker |
class |
DB.BTreeSetMaker |
static class |
DB.HTreeMapMaker |
class |
DB.HTreeSetMaker |
protected static class |
DB.IdentityWrapper
changes object hash and equals method to use identity
|
protected static interface |
DB.Keys |
| Modifier and Type | Field and Description |
|---|---|
protected ScheduledExecutorService |
cacheExecutor |
protected SortedMap<String,Object> |
catalog
view over named records
|
protected ReadWriteLock |
consistencyLock |
protected boolean |
deleteFilesAfterClose |
protected Engine |
engine
Engine which provides persistence for this DB
|
protected ScheduledExecutorService |
executor |
protected static Logger |
LOG |
static String |
METRICS_CACHE_HIT |
static String |
METRICS_CACHE_MISS |
static String |
METRICS_DATA_READ |
static String |
METRICS_DATA_WRITE |
static String |
METRICS_RECORD_READ |
static String |
METRICS_RECORD_WRITE |
protected ScheduledExecutorService |
metricsExecutor |
protected Map<String,WeakReference<?>> |
namesInstanciated
already loaded named collections.
|
protected Map<DB.IdentityWrapper,String> |
namesLookup |
protected SerializerPojo |
serializerPojo |
protected ScheduledExecutorService |
storeExecutor |
protected boolean |
strictDBGet |
protected Set<String> |
unknownClasses |
| Constructor and Description |
|---|
DB(Engine engine)
Construct new DB.
|
DB(Engine engine,
boolean strictDBGet,
boolean deleteFilesAfterClose,
ScheduledExecutorService executor,
boolean lockDisable,
ScheduledExecutorService metricsExecutor,
long metricsLogInterval,
ScheduledExecutorService storeExecutor,
ScheduledExecutorService cacheExecutor,
Fun.Function1<Class,String> classLoader) |
| Modifier and Type | Method and Description |
|---|---|
Atomic.Boolean |
atomicBoolean(String name) |
Atomic.Boolean |
atomicBooleanCreate(String name,
boolean initValue) |
Atomic.Integer |
atomicInteger(String name) |
Atomic.Integer |
atomicIntegerCreate(String name,
int initValue) |
Atomic.Long |
atomicLong(String name) |
Atomic.Long |
atomicLongCreate(String name,
long initValue) |
Atomic.String |
atomicString(String name) |
Atomic.String |
atomicStringCreate(String name,
String initValue) |
<E> Atomic.Var<E> |
atomicVar(String name) |
<E> Atomic.Var<E> |
atomicVar(String name,
Serializer<E> serializer) |
<E> Atomic.Var<E> |
atomicVarCreate(String name,
E initValue,
Serializer<E> serializer) |
<A> A |
catGet(String name) |
<A> A |
catGet(String name,
A init) |
<A> A |
catPut(String name,
A value) |
<A> A |
catPut(String name,
A value,
A retValueIfNull) |
void |
checkNameNotExists(String name)
Checks that object with given name does not exist yet.
|
void |
checkNotClosed() |
protected <K> K |
checkPlaceholder(String nameCatParam,
K fromConstructor) |
void |
checkShouldCreate(String name) |
void |
checkType(String type,
String expected) |
void |
close()
Closes database.
|
void |
commit()
Commit changes made on collections loaded by this DB
|
void |
compact()
Perform storage maintenance.
|
ReadWriteLock |
consistencyLock()
Returns consistency lock which groups operation together and ensures consistency.
|
Atomic.Boolean |
createAtomicBoolean(String name,
boolean initValue)
Deprecated.
method renamed, use
atomicBooleanCreate(String, boolean) |
Atomic.Integer |
createAtomicInteger(String name,
int initValue)
Deprecated.
method renamed, use
atomicIntegerCreate(String, int) |
Atomic.Long |
createAtomicLong(String name,
long initValue)
Deprecated.
method renamed, use
atomicLongCreate(String, long) |
Atomic.String |
createAtomicString(String name,
String initValue)
Deprecated.
method renamed, use
atomicStringCreate(String, String) |
<E> Atomic.Var<E> |
createAtomicVar(String name,
E initValue,
Serializer<E> serializer)
Deprecated.
method renamed, use
atomicVarCreate(String, Object, Serializer) |
<E> BlockingQueue<E> |
createCircularQueue(String name,
Serializer<E> serializer,
long size)
Deprecated.
queues API is going to be reworked
|
DB.HTreeMapMaker |
createHashMap(String name)
Deprecated.
method renamed, use
hashMapCreate(String) |
DB.HTreeSetMaker |
createHashSet(String name)
Deprecated.
method renamed, use
hashSetCreate(String) |
<E> BlockingQueue<E> |
createQueue(String name,
Serializer<E> serializer,
boolean useLocks)
Deprecated.
queues API is going to be reworked
|
<E> BlockingQueue<E> |
createStack(String name,
Serializer<E> serializer,
boolean useLocks)
Deprecated.
queues API is going to be reworked
|
DB.BTreeMapMaker |
createTreeMap(String name)
Deprecated.
method renamed, use
treeMapCreate(String) |
DB.BTreeSetMaker |
createTreeSet(String name)
Deprecated.
method renamed, use
treeSetCreate(String) |
void |
delete(String name)
delete record/collection with given name
|
boolean |
exists(String name) |
protected BTreeKeySerializer<?,?> |
fillNulls(BTreeKeySerializer<?,?> keySerializer)
Replace nulls in tuple serializers with default (Comparable) values
|
<E> E |
get(String name)
return record with given name or null if name does not exist
|
Map<String,Object> |
getAll()
return map of all named collections/records
|
Atomic.Boolean |
getAtomicBoolean(String name)
Deprecated.
method renamed, use
atomicBoolean(String) |
Atomic.Integer |
getAtomicInteger(String name)
Deprecated.
method renamed, use
atomicInteger(String) |
Atomic.Long |
getAtomicLong(String name)
Deprecated.
method renamed, use
atomicLong(String) |
Atomic.String |
getAtomicString(String name)
Deprecated.
method renamed, use
atomicString(String) |
<E> Atomic.Var<E> |
getAtomicVar(String name)
Deprecated.
method renamed, use
atomicVar(String) |
SortedMap<String,Object> |
getCatalog()
Get Name Catalog.
|
<E> BlockingQueue<E> |
getCircularQueue(String name)
Deprecated.
queues API is going to be reworked
|
Serializer |
getDefaultSerializer() |
Engine |
getEngine() |
Object |
getFromWeakCollection(String name)
All collections are weakly referenced to prevent two instances of the same collection in memory.
|
<K,V> HTreeMap<K,V> |
getHashMap(String name)
Deprecated.
method renamed, use
hashMap(String) |
<K,V> HTreeMap<K,V> |
getHashMap(String name,
Fun.Function1<V,K> valueCreator)
Deprecated.
method renamed, use
hashMap(String,Serializer, Serializer, org.mapdb.Fun.Function1) |
<K> Set<K> |
getHashSet(String name)
Deprecated.
method renamed, use
hashSet(String) |
String |
getNameForObject(Object obj)
Get name for object.
|
<E> BlockingQueue<E> |
getQueue(String name)
Deprecated.
queues API is going to be reworked
|
<E> BlockingQueue<E> |
getStack(String name)
Deprecated.
queues API is going to be reworked
|
<K,V> BTreeMap<K,V> |
getTreeMap(String name)
Deprecated.
method renamed, use
treeMap(String) |
<K> NavigableSet<K> |
getTreeSet(String name)
Deprecated.
method renamed, use
treeSet(String) |
<K,V> HTreeMap<K,V> |
hashMap(String name)
Opens existing or creates new Hash Tree Map.
|
<K,V> HTreeMap<K,V> |
hashMap(String name,
Serializer<K> keySerializer,
Serializer<V> valueSerializer)
Opens existing or creates new Hash Tree Map.
|
<K,V> HTreeMap<K,V> |
hashMap(String name,
Serializer<K> keySerializer,
Serializer<V> valueSerializer,
Fun.Function1<V,K> valueCreator)
Opens existing or creates new Hash Tree Map.
|
protected <K,V> HTreeMap<K,V> |
hashMapCreate(DB.HTreeMapMaker m)
Creates new HashMap with more specific arguments
|
DB.HTreeMapMaker |
hashMapCreate(String name)
Returns new builder for HashMap with given name
|
<K> Set<K> |
hashSet(String name)
Opens existing or creates new Hash Tree Set.
|
<K> Set<K> |
hashSet(String name,
Serializer<K> serializer) |
protected <K> Set<K> |
hashSetCreate(DB.HTreeSetMaker m) |
DB.HTreeSetMaker |
hashSetCreate(String name)
Creates new HashSet
|
boolean |
isClosed() |
Map<String,Long> |
metricsGet() |
void |
metricsLog() |
<V> V |
namedPut(String name,
Object ret) |
protected void |
reinit() |
void |
rename(String oldName,
String newName)
rename named record into newName
|
void |
rollback()
Rollback changes made on collections loaded by this DB
|
protected Object |
serializableOrPlaceHolder(Object o) |
DB |
snapshot()
Make readonly snapshot view of DB and all of its collection
Collections loaded by this instance are not affected (are still mutable).
|
<K,V> BTreeMap<K,V> |
treeMap(String name)
Opens existing or creates new B-linked-tree Map.
|
<K,V> BTreeMap<K,V> |
treeMap(String name,
BTreeKeySerializer keySerializer,
Serializer<V> valueSerializer) |
<K,V> BTreeMap<K,V> |
treeMap(String name,
Serializer<K> keySerializer,
Serializer<V> valueSerializer) |
protected <K,V> BTreeMap<K,V> |
treeMapCreate(DB.BTreeMapMaker m) |
DB.BTreeMapMaker |
treeMapCreate(String name)
Returns new builder for TreeMap with given name
|
<K> NavigableSet<K> |
treeSet(String name)
Opens existing or creates new B-linked-tree Set.
|
<K> NavigableSet<K> |
treeSet(String name,
BTreeKeySerializer serializer) |
<K> NavigableSet<K> |
treeSet(String name,
Serializer serializer) |
<K> NavigableSet<K> |
treeSetCreate(DB.BTreeSetMaker m) |
DB.BTreeSetMaker |
treeSetCreate(String name)
Creates new TreeSet.
|
protected static final Logger LOG
public static final String METRICS_DATA_WRITE
public static final String METRICS_RECORD_WRITE
public static final String METRICS_DATA_READ
public static final String METRICS_RECORD_READ
public static final String METRICS_CACHE_HIT
public static final String METRICS_CACHE_MISS
protected final boolean strictDBGet
protected final boolean deleteFilesAfterClose
protected Engine engine
protected Map<String,WeakReference<?>> namesInstanciated
protected Map<DB.IdentityWrapper,String> namesLookup
protected ScheduledExecutorService executor
protected SerializerPojo serializerPojo
protected ScheduledExecutorService metricsExecutor
protected ScheduledExecutorService storeExecutor
protected ScheduledExecutorService cacheExecutor
protected final ReadWriteLock consistencyLock
public DB(Engine engine)
Engine which does the real work.engine - public DB(Engine engine, boolean strictDBGet, boolean deleteFilesAfterClose, ScheduledExecutorService executor, boolean lockDisable, ScheduledExecutorService metricsExecutor, long metricsLogInterval, ScheduledExecutorService storeExecutor, ScheduledExecutorService cacheExecutor, Fun.Function1<Class,String> classLoader)
public void metricsLog()
protected void reinit()
public <A> A catGet(String name, A init)
public <A> A catGet(String name)
public <A> A catPut(String name, A value)
public <A> A catPut(String name, A value, A retValueIfNull)
public String getNameForObject(Object obj)
obj - object to get name forpublic <K,V> HTreeMap<K,V> getHashMap(String name)
hashMap(String)public <K,V> HTreeMap<K,V> hashMap(String name)
name - of the mappublic <K,V> HTreeMap<K,V> getHashMap(String name, Fun.Function1<V,K> valueCreator)
hashMap(String,Serializer, Serializer, org.mapdb.Fun.Function1)public <K,V> HTreeMap<K,V> hashMap(String name, Serializer<K> keySerializer, Serializer<V> valueSerializer)
name - of mapkeySerializer - serializer used on keysvalueSerializer - serializer used on valuespublic <K,V> HTreeMap<K,V> hashMap(String name, Serializer<K> keySerializer, Serializer<V> valueSerializer, Fun.Function1<V,K> valueCreator)
name - of mapkeySerializer - serializer used on keysvalueSerializer - serializer used on valuesvalueCreator - if value is not found, new is created and placed into map.protected <K> K checkPlaceholder(String nameCatParam, K fromConstructor)
public DB.HTreeMapMaker createHashMap(String name)
hashMapCreate(String)public DB.HTreeMapMaker hashMapCreate(String name)
name - of map to create.make() to create mapIllegalArgumentException - if name is already usedprotected <K,V> HTreeMap<K,V> hashMapCreate(DB.HTreeMapMaker m)
IllegalArgumentException - if name is already usedpublic <K> Set<K> getHashSet(String name)
hashSet(String)public <K> Set<K> hashSet(String name)
name - of the Setpublic <K> Set<K> hashSet(String name, Serializer<K> serializer)
public DB.HTreeSetMaker createHashSet(String name)
hashSetCreate(String)public DB.HTreeSetMaker hashSetCreate(String name)
name - of set to createprotected <K> Set<K> hashSetCreate(DB.HTreeSetMaker m)
public <K,V> BTreeMap<K,V> getTreeMap(String name)
treeMap(String)public <K,V> BTreeMap<K,V> treeMap(String name)
name - of mappublic <K,V> BTreeMap<K,V> treeMap(String name, Serializer<K> keySerializer, Serializer<V> valueSerializer)
public <K,V> BTreeMap<K,V> treeMap(String name, BTreeKeySerializer keySerializer, Serializer<V> valueSerializer)
public DB.BTreeMapMaker createTreeMap(String name)
treeMapCreate(String)public DB.BTreeMapMaker treeMapCreate(String name)
name - of map to create.make() to create mapIllegalArgumentException - if name is already usedprotected <K,V> BTreeMap<K,V> treeMapCreate(DB.BTreeMapMaker m)
protected BTreeKeySerializer<?,?> fillNulls(BTreeKeySerializer<?,?> keySerializer)
keySerializer - with nullspublic SortedMap<String,Object> getCatalog()
public <K> NavigableSet<K> getTreeSet(String name)
treeSet(String)public <K> NavigableSet<K> treeSet(String name)
name - of setpublic <K> NavigableSet<K> treeSet(String name, Serializer serializer)
public <K> NavigableSet<K> treeSet(String name, BTreeKeySerializer serializer)
public DB.BTreeSetMaker createTreeSet(String name)
treeSetCreate(String)public DB.BTreeSetMaker treeSetCreate(String name)
name - of set to createIllegalArgumentException - if name is already usedpublic <K> NavigableSet<K> treeSetCreate(DB.BTreeSetMaker m)
public <E> BlockingQueue<E> getQueue(String name)
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
public <E> BlockingQueue<E> createQueue(String name, Serializer<E> serializer, boolean useLocks)
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
public <E> BlockingQueue<E> getStack(String name)
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
public <E> BlockingQueue<E> createStack(String name, Serializer<E> serializer, boolean useLocks)
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
public <E> BlockingQueue<E> getCircularQueue(String name)
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
public <E> BlockingQueue<E> createCircularQueue(String name, Serializer<E> serializer, long size)
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
public Atomic.Long createAtomicLong(String name, long initValue)
atomicLongCreate(String, long)public Atomic.Long atomicLongCreate(String name, long initValue)
public Atomic.Long getAtomicLong(String name)
atomicLong(String)public Atomic.Long atomicLong(String name)
public Atomic.Integer createAtomicInteger(String name, int initValue)
atomicIntegerCreate(String, int)public Atomic.Integer atomicIntegerCreate(String name, int initValue)
public Atomic.Integer getAtomicInteger(String name)
atomicInteger(String)public Atomic.Integer atomicInteger(String name)
public Atomic.Boolean createAtomicBoolean(String name, boolean initValue)
atomicBooleanCreate(String, boolean)public Atomic.Boolean atomicBooleanCreate(String name, boolean initValue)
public Atomic.Boolean getAtomicBoolean(String name)
atomicBoolean(String)public Atomic.Boolean atomicBoolean(String name)
public void checkShouldCreate(String name)
public Atomic.String createAtomicString(String name, String initValue)
atomicStringCreate(String, String)public Atomic.String atomicStringCreate(String name, String initValue)
public Atomic.String getAtomicString(String name)
atomicString(String)public Atomic.String atomicString(String name)
public <E> Atomic.Var<E> createAtomicVar(String name, E initValue, Serializer<E> serializer)
atomicVarCreate(String, Object, Serializer)public <E> Atomic.Var<E> atomicVarCreate(String name, E initValue, Serializer<E> serializer)
public <E> Atomic.Var<E> getAtomicVar(String name)
atomicVar(String)public <E> Atomic.Var<E> atomicVar(String name)
public <E> Atomic.Var<E> atomicVar(String name, Serializer<E> serializer)
public <E> E get(String name)
public boolean exists(String name)
public void delete(String name)
public void rename(String oldName, String newName)
oldName - current name of record/collectionnewName - new name of record/collectionNoSuchElementException - if oldName does not existpublic void checkNameNotExists(String name)
name - to checkIllegalArgumentException - if name is already usedpublic 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!!
close in interface Closeableclose in interface AutoCloseablepublic Object getFromWeakCollection(String name)
public void checkNotClosed()
public boolean isClosed()
public void commit()
Engine.commit()public void rollback()
Engine.rollback()public void compact()
NOTE: MapDB does not have smart defragmentation algorithms. So compaction usually recreates entire store from scratch. This may require additional disk space.
public DB snapshot()
public Serializer getDefaultSerializer()
public Engine getEngine()
public ReadWriteLock consistencyLock()
Copyright © 2015. All Rights Reserved.