Package io.permazen.kv.util
Class PrefixKVDatabase
java.lang.Object
io.permazen.kv.util.PrefixKVDatabase
- All Implemented Interfaces:
KVDatabase
Prefix
KVDatabase implementation.
Instances use a fixed byte[] key prefix for all key access, thereby providing a nested KVDatabase
view of the corresponding sub-range of keys within the containing KVDatabase. This allows, for example, multiple
KVDatabases to exist within a single containing KVDatabase under different key prefixes.
Instances ignore invocations to start() and stop(); instead, invoke these methods on the underlying
KVDatabase.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate a new transaction.createTransaction(Map<String, ?> options) Create a new transaction with the specified options.Get the containingKVDatabaseassociated with this instance.final ByteDataGet the key prefix associated with this instance.voidstart()Start this instance.voidstop()Stop this instance.
-
Constructor Details
-
PrefixKVDatabase
Constructor.- Parameters:
db- the containingKVDatabasekeyPrefix- prefix for all keys- Throws:
IllegalArgumentException- ifdborkeyPrefixis null
-
-
Method Details
-
getContainingKVDatabase
Get the containingKVDatabaseassociated with this instance.- Returns:
- the containing
KVDatabase
-
getKeyPrefix
Get the key prefix associated with this instance.- Returns:
- this instance's key prefix
-
start
public void start()Description copied from interface:KVDatabaseStart this instance. This method must be called prior to creating any transactions.This method is idempotent: if this instance is already started, nothing happens.
Whether an instance that has been started and stopped can be restarted is implementation-dependent.
- Specified by:
startin interfaceKVDatabase
-
stop
public void stop()Description copied from interface:KVDatabaseStop this instance.This method is idempotent: if this instance has not been started, or is already stopped, nothing happens.
- Specified by:
stopin interfaceKVDatabase
-
createTransaction
Description copied from interface:KVDatabaseCreate a new transaction with the specified options.- Specified by:
createTransactionin interfaceKVDatabase- Parameters:
options- optional transaction options; may be null- Returns:
- newly created transaction
-
createTransaction
Description copied from interface:KVDatabaseCreate a new transaction.- Specified by:
createTransactionin interfaceKVDatabase- Returns:
- newly created transaction
-