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
KVDatabase
s 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
-
Method Summary
Modifier and TypeMethodDescriptionCreate a new transaction.createTransaction
(Map<String, ?> options) Create a new transaction with the specified options.Get the containingKVDatabase
associated with this instance.final byte[]
Get the key prefix associated with this instance.void
start()
Start this instance.void
stop()
Stop this instance.
-
Constructor Details
-
PrefixKVDatabase
Constructor.- Parameters:
db
- the containingKVDatabase
keyPrefix
- prefix for all keys- Throws:
IllegalArgumentException
- ifdb
orkeyPrefix
is null
-
-
Method Details
-
getContainingKVDatabase
Get the containingKVDatabase
associated with this instance.- Returns:
- the containing
KVDatabase
-
getKeyPrefix
public final byte[] getKeyPrefix()Get the key prefix associated with this instance.- Returns:
- (a copy of) this instance's key prefix
-
start
public void start()Description copied from interface:KVDatabase
Start 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:
start
in interfaceKVDatabase
-
stop
public void stop()Description copied from interface:KVDatabase
Stop this instance.This method is idempotent: if this instance has not been started, or is already stopped, nothing happens.
- Specified by:
stop
in interfaceKVDatabase
-
createTransaction
Description copied from interface:KVDatabase
Create a new transaction with the specified options.- Specified by:
createTransaction
in interfaceKVDatabase
- Parameters:
options
- optional transaction options; may be null- Returns:
- newly created transaction
-
createTransaction
Description copied from interface:KVDatabase
Create a new transaction.- Specified by:
createTransaction
in interfaceKVDatabase
- Returns:
- newly created transaction
-