public class DBMaker<DBMakerT extends DBMaker<DBMakerT>>
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
DBMaker.Keys |
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Properties |
props |
protected java.lang.String |
TRUE |
| Modifier | Constructor and Description |
|---|---|
protected |
DBMaker()
use static factory methods, or make subclass
|
protected |
DBMaker(java.io.File file) |
| Modifier and Type | Method and Description |
|---|---|
protected DBMakerT |
_newAppendFileDB(java.io.File file) |
DBMakerT |
_newFileDB(java.io.File file) |
DBMakerT |
_newHeapDB() |
DBMakerT |
_newMemoryDB() |
DBMakerT |
_newMemoryDirectDB() |
private void |
assertNotInMemoryVolume() |
DBMakerT |
asyncWriteEnable()
Enables mode where all modifications are queued and written into disk on Background Writer Thread.
|
DBMakerT |
asyncWriteFlushDelay(int delay)
Set flush interval for write cache, by default is 0
When BTreeMap is constructed from ordered set, tree node size is increasing linearly with each
item added.
|
DBMakerT |
asyncWriteQueueSize(int queueSize)
Set size of async Write Queue.
|
DBMakerT |
cacheDisable()
Instance cache is enabled by default.
|
DBMakerT |
cacheHardRefEnable()
Enables unbounded hard reference cache.
|
DBMakerT |
cacheLRUEnable()
Enables Least Recently Used cache.
|
DBMakerT |
cacheSize(int cacheSize)
Set cache size.
|
DBMakerT |
cacheSoftRefEnable()
Enables unbounded cache which uses
SoftReference. |
DBMakerT |
cacheWeakRefEnable()
Enables unbounded cache which uses
WeakReference. |
DBMakerT |
checksumEnable()
Adds CRC32 checksum at end of each record to check data integrity.
|
DBMakerT |
closeOnJvmShutdown()
Adds JVM shutdown hook and closes DB just before JVM;
|
DBMakerT |
commitFileSyncDisable()
Disables file sync on commit.
|
DBMakerT |
compressionEnable()
Enables record compression.
|
DBMakerT |
deleteFilesAfterClose()
Try to delete files after DB is closed.
|
DBMakerT |
encryptionEnable(byte[] password)
Encrypt storage using XTEA algorithm.
|
DBMakerT |
encryptionEnable(java.lang.String password)
Encrypt storage using XTEA algorithm.
|
protected void |
extendArgumentCheck() |
protected Engine |
extendAsyncWriteEngine(Engine engine) |
protected Engine |
extendCacheHardRef(Engine engine) |
protected Engine |
extendCacheHashTable(Engine engine) |
protected Engine |
extendCacheLRU(Engine engine) |
protected Engine |
extendCacheSoftRef(Engine engine) |
protected Engine |
extendCacheWeakRef(Engine engine) |
protected Engine |
extendHeapStore() |
protected Engine |
extendSnapshotEngine(Engine engine) |
protected Engine |
extendStoreAppend() |
protected Engine |
extendStoreDirect(Volume.Factory folFac) |
protected Volume.Factory |
extendStoreVolumeFactory() |
protected Engine |
extendStoreWAL(Volume.Factory folFac) |
protected Engine |
extendWrapCache(Engine engine) |
protected Engine |
extendWrapSnapshotEngine(Engine engine) |
protected Engine |
extendWrapStore(Engine engine) |
DBMakerT |
freeSpaceReclaimQ(int q)
Set free space reclaim Q.
|
protected static byte[] |
fromHexa(java.lang.String s) |
protected DBMakerT |
getThis() |
protected static boolean |
JVMSupportsLargeMappedFiles()
Check if large files can be mapped into memory.
|
DB |
make()
constructs DB using current settings
|
Engine |
makeEngine()
constructs Engine using current settings
|
TxMaker |
makeTxMaker() |
DBMakerT |
mmapFileCleanerHackDisable()
Disables cleaner hack.
|
DBMakerT |
mmapFileEnable()
Enables Memory Mapped Files, much faster storage option.
|
DBMakerT |
mmapFileEnableIfSupported()
Enable Memory Mapped Files only if current JVM supports it (is 64bit).
|
DBMakerT |
mmapFileEnablePartial()
Keeps small-frequently-used part of storage files memory mapped, but main area is accessed using Random Access File.
|
protected static DBMaker |
newAppendFileDB(java.io.File file)
Creates or open append-only database stored in file.
|
static <K,V> HTreeMap<K,V> |
newCache(double size)
Creates new cache with maximal size in GBs.
|
static <K,V> HTreeMap<K,V> |
newCacheDirect(double size)
Creates new off-heap cache with maximal size in GBs.
|
static DBMaker |
newFileDB(java.io.File file)
Creates or open database stored in file.
|
static DBMaker |
newHeapDB()
Creates new in-memory database which stores all data on heap without serialization.
|
static DBMaker |
newMemoryDB()
Creates new in-memory database.
|
static DBMaker |
newMemoryDirectDB()
Creates new in-memory database.
|
static DBMaker |
newTempFileDB()
Creates new database in temporary folder.
|
static <K,V> HTreeMap<K,V> |
newTempHashMap()
Create new HTreeMap backed by temporary file storage.
|
static <K> java.util.Set<K> |
newTempHashSet()
Create new HashSet backed by temporary file storage.
|
static <K,V> BTreeMap<K,V> |
newTempTreeMap()
Create new BTreeMap backed by temporary file storage.
|
static <K> java.util.NavigableSet<K> |
newTempTreeSet()
Create new TreeSet backed by temporary file storage.
|
protected boolean |
propsGetBool(java.lang.String key) |
protected int |
propsGetInt(java.lang.String key,
int defValue) |
protected long |
propsGetLong(java.lang.String key,
long defValue) |
protected int |
propsGetRafMode() |
protected byte[] |
propsGetXteaEncKey() |
DBMakerT |
readOnly()
Open store in read-only mode.
|
DBMakerT |
sizeLimit(double maxSize)
Sets store size limit.
|
DBMakerT |
snapshotEnable()
MapDB supports snapshots.
|
DBMakerT |
strictDBGet()
DB Get methods such as
DB.getTreeMap(String) or DB.getAtomicLong(String) auto create
new record with default values, if record with given name does not exist. |
protected static java.lang.String |
toHexa(byte[] bb) |
DBMakerT |
transactionDisable()
Transaction journal is enabled by default
You must call DB.commit() to save your changes.
|
protected final java.lang.String TRUE
protected java.util.Properties props
protected DBMaker()
protected DBMaker(java.io.File file)
public static DBMaker newHeapDB()
public DBMakerT _newHeapDB()
public static DBMaker newMemoryDB()
public DBMakerT _newMemoryDB()
public static DBMaker newMemoryDirectDB()
public DBMakerT _newMemoryDirectDB()
protected static DBMaker newAppendFileDB(java.io.File file)
file - protected DBMakerT _newAppendFileDB(java.io.File file)
public static <K,V> BTreeMap<K,V> newTempTreeMap()
Storage is created in temp folder and deleted on JVM shutdown
public static <K,V> HTreeMap<K,V> newTempHashMap()
Storage is created in temp folder and deleted on JVM shutdown
public static <K> java.util.NavigableSet<K> newTempTreeSet()
Storage is created in temp folder and deleted on JVM shutdown
public static <K> java.util.Set<K> newTempHashSet()
Storage is created in temp folder and deleted on JVM shutdown
public static DBMaker newTempFileDB()
public static <K,V> HTreeMap<K,V> newCacheDirect(double size)
ByteBuffer.allocateDirect(int)size - maximal size of off-heap store in gigabytes.public static <K,V> HTreeMap<K,V> newCache(double size)
ByteBuffer.allocate(int)size - maximal size of off-heap store in gigabytes.public static DBMaker newFileDB(java.io.File file)
public DBMakerT _newFileDB(java.io.File file)
protected DBMakerT getThis()
public DBMakerT transactionDisable()
public DBMakerT cacheDisable()
public DBMakerT cacheHardRefEnable()
public DBMakerT cacheWeakRefEnable()
WeakReference.
Items are removed from cache by Garbage Collectorpublic DBMakerT cacheSoftRefEnable()
SoftReference.
Items are removed from cache by Garbage Collectorpublic DBMakerT cacheLRUEnable()
public DBMakerT mmapFileEnable()
public DBMakerT mmapFileCleanerHackDisable()
Disables cleaner hack. Enable this option if you experience JVM crashes with memory mapped files.
Instead of closing mmaped files at DB.close(), they will be closed eventually by Garbage Collection. See relevant JVM bug. Cleaner hack could cause all sort of problems, including JVM crash. It is enabled by default in MapDB 1.0 for compatibility reasons and is disabled by defualt in MapDB 2.0
Memory mapped files in Java are not unmapped when file closes.
Unmapping happens when DirectByteBuffer is garbage collected.
Delay between file close and GC could be very long, possibly even hours.
This causes file descriptor to remain open, causing all sort of problems:
On Windows opened file can not be deleted or accessed by different process. It remains locked even after JVM process exits until Windows restart. This is causing problems during compaction etc.
On Linux (and other systems) opened files consumes file descriptor. Eventually JVM process could run out of available file descriptors (couple of thousands) and would be unable to open new files or sockets.
On Oracle and OpenJDK JVMs there is option to unmap files after closing. However it is not officially supported and could result in all sort of strange behaviour. In MapDB it was linked to JVM crashes, and was disabled by default in MapDB 2.0, it is still enabled in 1.0, this option disables it.
public DBMakerT mmapFileEnablePartial()
private void assertNotInMemoryVolume()
public DBMakerT mmapFileEnableIfSupported()
public DBMakerT cacheSize(int cacheSize)
cacheSize - new cache sizepublic DBMakerT snapshotEnable()
public DBMakerT asyncWriteEnable()
public DBMakerT asyncWriteFlushDelay(int delay)
delay - flush write cache every N milisecondspublic DBMakerT asyncWriteQueueSize(int queueSize)
queueSize - of queuepublic DBMakerT deleteFilesAfterClose()
public DBMakerT closeOnJvmShutdown()
public DBMakerT compressionEnable()
public DBMakerT encryptionEnable(java.lang.String password)
password - for encryptionpublic DBMakerT encryptionEnable(byte[] password)
password - for encryptionpublic DBMakerT checksumEnable()
public DBMakerT strictDBGet()
DB.getTreeMap(String) or DB.getAtomicLong(String) auto create
new record with default values, if record with given name does not exist. This could be problem if you would like to enforce
stricter database schema. So this parameter disables record auto creation.
If this set, `DB.getXX()` will throw an exception if given name does not exist, instead of creating new record (or collection)public DBMakerT readOnly()
UnsupportedOperationException("Read-only")public DBMakerT freeSpaceReclaimQ(int q)
public DBMakerT commitFileSyncDisable()
public DBMakerT sizeLimit(double maxSize)
maxSize - maximal store size in GBpublic DB make()
public TxMaker makeTxMaker()
public Engine makeEngine()
protected int propsGetInt(java.lang.String key,
int defValue)
protected long propsGetLong(java.lang.String key,
long defValue)
protected boolean propsGetBool(java.lang.String key)
protected byte[] propsGetXteaEncKey()
protected static boolean JVMSupportsLargeMappedFiles()
protected int propsGetRafMode()
protected void extendArgumentCheck()
protected Engine extendHeapStore()
protected Engine extendStoreAppend()
protected Engine extendStoreDirect(Volume.Factory folFac)
protected Engine extendStoreWAL(Volume.Factory folFac)
protected Volume.Factory extendStoreVolumeFactory()
protected static java.lang.String toHexa(byte[] bb)
protected static byte[] fromHexa(java.lang.String s)