public class MongoDBKeyValueStore extends AbstractKeyValueStoreProvider
The following configuration properties are available:
| Modifier and Type | Field and Description |
|---|---|
protected com.mongodb.client.MongoCollection<org.bson.Document> |
coll |
static String |
COLLECTION_DEFAULT |
static String |
COLLECTION_PROP |
static String |
ID_KEY |
static String |
KEYVALUE_CONNECTION_ID |
static Double |
ONE |
static String |
TTL_KEY |
static String |
VALUE_KEY |
name, UTF_8_DECODERS| Constructor and Description |
|---|
MongoDBKeyValueStore() |
| Modifier and Type | Method and Description |
|---|---|
long |
addAndGet(String key,
long delta)
Atomically adds the delta to the value associated to the key, interpreted as a long represented as a string.
|
protected long |
addAndGetGeneric(String key,
long delta) |
protected void |
addTTL(org.bson.Document doc,
long ttl) |
void |
clear()
Clears the content of this Key/Value store provider.
|
void |
close()
Closes this Key/Value store provider.
|
boolean |
compareAndSet(String key,
byte[] expected,
byte[] value,
long ttl)
Atomically sets the value associated to the key to the given value, with the given TTL, if the current value is
the expected value.
|
protected boolean |
compareAndSet(String key,
Object expected,
Object value,
long ttl) |
boolean |
compareAndSet(String key,
String expected,
String value,
long ttl)
Atomically sets the value associated to the key to the given value, with the given TTL, if the current value is
the expected value.
|
protected void |
findByKeys(Collection<String> keys,
com.mongodb.Block<org.bson.Document> block) |
Map<String,byte[]> |
get(Collection<String> keys)
Retrieves the key/value map associated with the keys.
|
byte[] |
get(String key)
Retrieves the value associated to the key.
|
protected Date |
getDateFromTTL(long ttl) |
Long |
getLong(String key)
Retrieves the value associated to the key.
|
Map<String,Long> |
getLongs(Collection<String> keys)
Retrieves the key/value map associated with the keys.
|
protected Object |
getObject(String key) |
String |
getString(String key)
Retrieves the value associated to the key.
|
Map<String,String> |
getStrings(Collection<String> keys)
Retrieves the key/value map associated with the keys.
|
void |
initialize(KeyValueStoreDescriptor descriptor)
Initializes this Key/Value store provider.
|
Stream<String> |
keyStream()
Returns a
Stream of the keys contained in this Key/Value store provider. |
Stream<String> |
keyStream(String prefix)
Returns a
Stream of the keys with the given prefix contained in this Key/Value store provider. |
void |
put(String key,
byte[] bytes,
long ttl)
Sets the value associated to the key, and a TTL.
|
void |
put(String key,
Long value)
Sets the value associated to the key.
|
void |
put(String key,
Long value,
long ttl)
Sets the value associated to the key.
|
protected void |
put(String key,
Object value,
long ttl) |
void |
put(String key,
String string)
Sets the value associated to the key.
|
void |
put(String key,
String string,
long ttl)
Sets the value associated to the key, and a TTL.
|
boolean |
setTTL(String key,
long ttl)
Sets the TTL for an existing key.
|
protected byte[] |
toBytes(Object value) |
protected Long |
toLong(Object value) |
protected static Object |
toStorage(byte[] bytes) |
protected String |
toString(Object value) |
bytesToLong, bytesToString, compareAndSet, compareAndSet, longToBytes, put, stringToBytes, toStringpublic static final String KEYVALUE_CONNECTION_ID
public static final String COLLECTION_PROP
public static final String COLLECTION_DEFAULT
public static final String ID_KEY
public static final String VALUE_KEY
public static final String TTL_KEY
protected com.mongodb.client.MongoCollection<org.bson.Document> coll
public MongoDBKeyValueStore()
public void initialize(KeyValueStoreDescriptor descriptor)
KeyValueStoreProviderinitialize in interface KeyValueStoreProviderinitialize in class AbstractKeyValueStoreProviderdescriptor - the store provider descriptorpublic Stream<String> keyStream()
KeyValueStoreProviderStream of the keys contained in this Key/Value store provider.
This operation may be slow and should only be used for management or debug purposes.
public Stream<String> keyStream(String prefix)
KeyValueStoreProviderStream of the keys with the given prefix contained in this Key/Value store provider.
This operation may be slow and should only be used for management or debug purposes.
public void close()
KeyValueStoreProviderpublic void clear()
KeyValueStoreProviderprotected Long toLong(Object value) throws NumberFormatException
NumberFormatExceptionpublic byte[] get(String key)
KeyValueStorekey - the keynull if there is no valuepublic String getString(String key)
KeyValueStoregetString in interface KeyValueStoregetString in class AbstractKeyValueStoreProviderkey - the keynull if there is no valuepublic Long getLong(String key) throws NumberFormatException
KeyValueStoregetLong in interface KeyValueStoregetLong in class AbstractKeyValueStoreProviderkey - the keynull if there is no valueNumberFormatException - if the value cannot be returned as a Longpublic Map<String,byte[]> get(Collection<String> keys)
KeyValueStoreget in interface KeyValueStoreget in class AbstractKeyValueStoreProviderkeys - the keyspublic Map<String,String> getStrings(Collection<String> keys)
KeyValueStoregetStrings in interface KeyValueStoregetStrings in class AbstractKeyValueStoreProviderkeys - the keyspublic Map<String,Long> getLongs(Collection<String> keys) throws NumberFormatException
KeyValueStoregetLongs in interface KeyValueStoregetLongs in class AbstractKeyValueStoreProviderkeys - the keysNumberFormatException - if one of the values cannot be returned as a Longprotected void findByKeys(Collection<String> keys, com.mongodb.Block<org.bson.Document> block)
protected Date getDateFromTTL(long ttl)
public void put(String key, byte[] bytes, long ttl)
KeyValueStorekey - the keybytes - the value, which may be nullttl - the TTL, in seconds (0 for infinite)public void put(String key, String string)
KeyValueStoreput in interface KeyValueStoreput in class AbstractKeyValueStoreProviderkey - the keystring - the value, which may be nullpublic void put(String key, String string, long ttl)
KeyValueStoreput in interface KeyValueStoreput in class AbstractKeyValueStoreProviderkey - the keystring - the value, which may be nullttl - the TTL, in seconds (0 for infinite)public void put(String key, Long value)
KeyValueStoreput in interface KeyValueStoreput in class AbstractKeyValueStoreProviderkey - the keyvalue - the value, which may be nullpublic void put(String key, Long value, long ttl)
KeyValueStoreput in interface KeyValueStoreput in class AbstractKeyValueStoreProviderkey - the keyvalue - the value, which may be nullttl - the TTL, in seconds (0 for infinite)protected void addTTL(org.bson.Document doc, long ttl)
public boolean setTTL(String key, long ttl)
KeyValueStorekey - the keyttl - the TTL, in seconds (0 for infinite)true if the TTL has been set, or false if the key does not existpublic boolean compareAndSet(String key, byte[] expected, byte[] value, long ttl)
KeyValueStoreNote value comparison is done by value and not by reference.
key - the keyexpected - the expected value, which may be nullvalue - the updated value, which may be nullttl - the TTL, in seconds (0 for infinite)true if the value was updated, or false if not (the expected value was not found)public boolean compareAndSet(String key, String expected, String value, long ttl)
KeyValueStoreNote value comparison is done by value and not by reference.
compareAndSet in interface KeyValueStorecompareAndSet in class AbstractKeyValueStoreProviderkey - the keyexpected - the expected value, which may be nullvalue - the updated value, which may be nullttl - the TTL, in seconds (0 for infinite)true if the value was updated, or false if not (the expected value was not found)protected boolean compareAndSet(String key, Object expected, Object value, long ttl)
public long addAndGet(String key, long delta) throws NumberFormatException
KeyValueStore
If the value does not exist (if KeyValueStore.get(java.lang.String) would return null), it is interpreted as 0.
addAndGet in interface KeyValueStoreaddAndGet in class AbstractKeyValueStoreProviderkey - the keydelta - the delta to addNumberFormatException - if the existing value cannot be interpreted as a longprotected long addAndGetGeneric(String key, long delta) throws NumberFormatException
NumberFormatExceptionCopyright © 2019 Nuxeo. All rights reserved.