public interface Store
Store can be opened using any of Environment.openStore() methods. If a Store is opened using StoreConfig.WITHOUT_DUPLICATES
or StoreConfig.WITHOUT_DUPLICATES_WITH_PREFIXING then it is map, otherwise it is a multi-map.
Also Store can be thought as a table with two columns, one for keys and another for values.
Both keys and values are managed using instances of ByteIterable. You can use
cursors to iterate over a Store, to find nearest key or key/value pair, etc.
All operations can only be performed within a transaction.
Stores with and without key prefixing are implemented by different types of search trees.
If Store is opened using StoreConfig.WITH_DUPLICATES or
StoreConfig.WITHOUT_DUPLICATES then B+ tree
is used, otherwise Patricia trie is used. Search tree types
differ in performance characteristics: stores with key prefixing has better random key access, whereas stores without
key prefixing are preferable for sequential access in order of keys.
Stores are rather stateless objects, so they can be used without any limitations in multi-threaded environments.
Opening Store for each database operation is ok, but it will result in some performance overhead.
A Store instance cannot be re-used after any of Environment.truncateStore(String, Transaction),
Environment.removeStore(String, Transaction) or Environment.clear() methods is called.
After truncating, any Store should be re-opened, after removing or clearing the environment it just cannot be used.
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(@NotNull Transaction txn,
@NotNull ByteIterable key,
@NotNull ByteIterable value)
Adds key/value pair to the
Store if the key doesn't exist. |
void |
close()
Deprecated.
|
long |
count(@NotNull Transaction txn) |
boolean |
delete(@NotNull Transaction txn,
@NotNull ByteIterable key)
For stores without key duplicates, deletes single key/value pair and returns
true if a pair was deleted. |
boolean |
exists(@NotNull Transaction txn,
@NotNull ByteIterable key,
@NotNull ByteIterable value)
Checks if specified key/value pair exists in the
Store. |
@Nullable ByteIterable |
get(@NotNull Transaction txn,
@NotNull ByteIterable key)
For stores without key duplicates, it returns not-null value or null if the key doesn't exist.
|
@NotNull StoreConfig |
getConfig() |
@NotNull Environment |
getEnvironment() |
@NotNull java.lang.String |
getName() |
Cursor |
openCursor(@NotNull Transaction txn)
Opens cursor over the @{code Store} associated with a transaction.
|
boolean |
put(@NotNull Transaction txn,
@NotNull ByteIterable key,
@NotNull ByteIterable value)
Puts specified key/value pair into the
Store and returns the result. |
void |
putRight(@NotNull Transaction txn,
@NotNull ByteIterable key,
@NotNull ByteIterable value)
Can be used if it is a priori known that the key is definitely greater than any other key in the
Store. |
@NotNull @NotNull Environment getEnvironment()
@Nullable @Nullable ByteIterable get(@NotNull @NotNull Transaction txn, @NotNull @NotNull ByteIterable key)
txn - transaction instancekey - requested keyboolean exists(@NotNull
@NotNull Transaction txn,
@NotNull
@NotNull ByteIterable key,
@NotNull
@NotNull ByteIterable value)
Store.txn - transaction instancekey - keyvalue - valuetrue if the key/value pair exists in the Storeboolean put(@NotNull
@NotNull Transaction txn,
@NotNull
@NotNull ByteIterable key,
@NotNull
@NotNull ByteIterable value)
Store and returns the result. For stores with key duplicates,
it returns true if the pair didn't exist in the Store. For stores without key duplicates,
it returns true if the key didn't exist or the new value differs from the existing one.
| With duplicates | Without duplicates | |
|---|---|---|
| The key exists | Adds pair, if the value didn't exist | Overwrites value |
| The key doesn't exist | Adds pair | Adds pair |
txn - transaction instancekey - not null keyvalue - not null valuetrue if specified pair was added or value by the key was overwritten.void putRight(@NotNull
@NotNull Transaction txn,
@NotNull
@NotNull ByteIterable key,
@NotNull
@NotNull ByteIterable value)
Store.
In that case, no search is been done before insertion, so putRight() can perform several times faster
than put(Transaction, ByteIterable, ByteIterable). It can be useful for auto-generated keys.txn - transaction instancekey - keyvalue - valueboolean add(@NotNull
@NotNull Transaction txn,
@NotNull
@NotNull ByteIterable key,
@NotNull
@NotNull ByteIterable value)
Store if the key doesn't exist. For stores with and without key duplicates,
it returns true if and only if the key doesn't exists. So it never overwrites value of existing key.
| With duplicates | Without duplicates | |
|---|---|---|
| The key exists | Returns false | Returns false |
| The key doesn't exist | Adds pair, returns true | Adds pair, returns true |
txn - transaction instancekey - keyvalue - valuetrue if key/value pair was addedboolean delete(@NotNull
@NotNull Transaction txn,
@NotNull
@NotNull ByteIterable key)
true if a pair was deleted.
For stores with key duplicates, it deletes all pairs with the given key and returns true if any was deleted.
To delete particular key/value pair, use cursors.txn - transaction instancekey - keytrue if a key/value pair was deleted.long count(@NotNull
@NotNull Transaction txn)
txn - transaction instanceStoreCursor openCursor(@NotNull @NotNull Transaction txn)
txn - transaction instance@Deprecated void close()
Database.close() method.@NotNull @NotNull java.lang.String getName()
Store@NotNull @NotNull StoreConfig getConfig()
StoreConfig using which the Store was opened.