Package org.nuxeo.ecm.core.mongodb.kv
Class MongoDBKeyValueStore
java.lang.Object
org.nuxeo.runtime.kv.AbstractKeyValueStoreProvider
org.nuxeo.ecm.core.mongodb.kv.MongoDBKeyValueStore
- All Implemented Interfaces:
KeyValueStore,KeyValueStoreProvider
MongoDB implementation of a Key/Value Store Provider.
The following configuration properties are available:
- collection: the MongoDB collection prefix to use, the default is "kv". This will be followed by the Store name.
- Since:
- 9.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.mongodb.client.MongoCollection<org.bson.Document>static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Doublestatic final Stringstatic final StringFields inherited from class org.nuxeo.runtime.kv.AbstractKeyValueStoreProvider
name, UTF_8_DECODERS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongAtomically adds the delta to the value associated to the key, interpreted as a long represented as a string.protected longaddAndGetGeneric(String key, long delta) protected voidaddTTL(org.bson.Document doc, long ttl) voidclear()Clears the content of this Key/Value store provider.voidclose()Closes this Key/Value store provider.booleancompareAndSet(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 booleancompareAndSet(String key, Object expected, Object value, long ttl) booleancompareAndSet(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 voidfindByKeys(Collection<String> keys, Consumer<org.bson.Document> block) byte[]Retrieves the value associated to the key.get(Collection<String> keys) Retrieves the key/value map associated with the keys.protected DategetDateFromTTL(long ttl) Retrieves the value associated to the key.getLongs(Collection<String> keys) Retrieves the key/value map associated with the keys.protected ObjectRetrieves the value associated to the key.getStrings(Collection<String> keys) Retrieves the key/value map associated with the keys.voidinitialize(KeyValueStoreDescriptor descriptor) Initializes this Key/Value store provider.Returns aStreamof the keys contained in this Key/Value store provider.Returns aStreamof the keys with the given prefix contained in this Key/Value store provider.voidSets the value associated to the key, and a TTL.voidSets the value associated to the key.voidSets the value associated to the key.protected voidvoidSets the value associated to the key.voidSets the value associated to the key, and a TTL.byte[]Retrieves and removes the value associated to the key.removeLong(String key) Retrieves and removes the value associated to the key.protected ObjectremoveObject(String key) removeString(String key) Retrieves and removes the value associated to the key.booleanSets the TTL for an existing key.protected byte[]protected Longprotected static ObjecttoStorage(byte[] bytes) protected StringMethods inherited from class org.nuxeo.runtime.kv.AbstractKeyValueStoreProvider
bytesToLong, bytesToString, compareAndSet, compareAndSet, longToBytes, put, stringToBytes, toString
-
Field Details
-
KEYVALUE_CONNECTION_ID
- See Also:
-
COLLECTION_PROP
- See Also:
-
COLLECTION_DEFAULT
- See Also:
-
ID_KEY
- See Also:
-
VALUE_KEY
- See Also:
-
TTL_KEY
- See Also:
-
ONE
-
coll
protected com.mongodb.client.MongoCollection<org.bson.Document> coll
-
-
Constructor Details
-
MongoDBKeyValueStore
public MongoDBKeyValueStore()
-
-
Method Details
-
initialize
Description copied from interface:KeyValueStoreProviderInitializes this Key/Value store provider.- Specified by:
initializein interfaceKeyValueStoreProvider- Overrides:
initializein classAbstractKeyValueStoreProvider- Parameters:
descriptor- the store provider descriptor
-
keyStream
Description copied from interface:KeyValueStoreProviderReturns aStreamof the keys contained in this Key/Value store provider.This operation may be slow and should only be used for management or debug purposes.
- Returns:
- the stream of keys
-
keyStream
Description copied from interface:KeyValueStoreProviderReturns aStreamof 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.
- Returns:
- the stream of keys
-
close
public void close()Description copied from interface:KeyValueStoreProviderCloses this Key/Value store provider. -
clear
public void clear()Description copied from interface:KeyValueStoreProviderClears the content of this Key/Value store provider. -
toStorage
-
toBytes
-
toString
-
toLong
- Throws:
NumberFormatException
-
get
Description copied from interface:KeyValueStoreRetrieves the value associated to the key.- Parameters:
key- the key- Returns:
- the value, or
nullif there is no value
-
getString
Description copied from interface:KeyValueStoreRetrieves the value associated to the key.- Specified by:
getStringin interfaceKeyValueStore- Overrides:
getStringin classAbstractKeyValueStoreProvider- Parameters:
key- the key- Returns:
- the value, or
nullif there is no value
-
getLong
Description copied from interface:KeyValueStoreRetrieves the value associated to the key.- Specified by:
getLongin interfaceKeyValueStore- Overrides:
getLongin classAbstractKeyValueStoreProvider- Parameters:
key- the key- Returns:
- the value, or
nullif there is no value - Throws:
NumberFormatException- if the value cannot be returned as aLong
-
getObject
-
remove
Description copied from interface:KeyValueStoreRetrieves and removes the value associated to the key.- Parameters:
key- the key- Returns:
- the value, or
nullif there is no value
-
removeString
Description copied from interface:KeyValueStoreRetrieves and removes the value associated to the key.- Parameters:
key- the key- Returns:
- the value, or
nullif there is no value
-
removeLong
Description copied from interface:KeyValueStoreRetrieves and removes the value associated to the key.- Parameters:
key- the key- Returns:
- the value, or
nullif there is no value - Throws:
NumberFormatException- if the value cannot be returned as aLong
-
removeObject
-
get
Description copied from interface:KeyValueStoreRetrieves the key/value map associated with the keys.- Specified by:
getin interfaceKeyValueStore- Overrides:
getin classAbstractKeyValueStoreProvider- Parameters:
keys- the keys- Returns:
- the key/value map
-
getStrings
Description copied from interface:KeyValueStoreRetrieves the key/value map associated with the keys.- Specified by:
getStringsin interfaceKeyValueStore- Overrides:
getStringsin classAbstractKeyValueStoreProvider- Parameters:
keys- the keys- Returns:
- the key/value map
-
getLongs
Description copied from interface:KeyValueStoreRetrieves the key/value map associated with the keys.- Specified by:
getLongsin interfaceKeyValueStore- Overrides:
getLongsin classAbstractKeyValueStoreProvider- Parameters:
keys- the keys- Returns:
- the key/value map
- Throws:
NumberFormatException- if one of the values cannot be returned as aLong
-
findByKeys
- Since:
- 9.10
-
getDateFromTTL
-
put
Description copied from interface:KeyValueStoreSets the value associated to the key, and a TTL.- Parameters:
key- the keybytes- the value, which may benullttl- the TTL, in seconds (0 for infinite)
-
put
Description copied from interface:KeyValueStoreSets the value associated to the key.- Specified by:
putin interfaceKeyValueStore- Overrides:
putin classAbstractKeyValueStoreProvider- Parameters:
key- the keystring- the value, which may benull
-
put
Description copied from interface:KeyValueStoreSets the value associated to the key, and a TTL.- Specified by:
putin interfaceKeyValueStore- Overrides:
putin classAbstractKeyValueStoreProvider- Parameters:
key- the keystring- the value, which may benullttl- the TTL, in seconds (0 for infinite)
-
put
Description copied from interface:KeyValueStoreSets the value associated to the key.- Specified by:
putin interfaceKeyValueStore- Overrides:
putin classAbstractKeyValueStoreProvider- Parameters:
key- the keyvalue- the value, which may benull
-
put
Description copied from interface:KeyValueStoreSets the value associated to the key.- Specified by:
putin interfaceKeyValueStore- Overrides:
putin classAbstractKeyValueStoreProvider- Parameters:
key- the keyvalue- the value, which may benullttl- the TTL, in seconds (0 for infinite)
-
put
-
addTTL
protected void addTTL(org.bson.Document doc, long ttl) -
setTTL
Description copied from interface:KeyValueStoreSets the TTL for an existing key.- Parameters:
key- the keyttl- the TTL, in seconds (0 for infinite)- Returns:
trueif the TTL has been set, orfalseif the key does not exist
-
compareAndSet
Description copied from interface:KeyValueStoreAtomically sets the value associated to the key to the given value, with the given TTL, if the current value is the expected value.Note value comparison is done by value and not by reference.
- Parameters:
key- the keyexpected- the expected value, which may benullvalue- the updated value, which may benullttl- the TTL, in seconds (0 for infinite)- Returns:
trueif the value was updated, orfalseif not (the expected value was not found)
-
compareAndSet
Description copied from interface:KeyValueStoreAtomically sets the value associated to the key to the given value, with the given TTL, if the current value is the expected value.Note value comparison is done by value and not by reference.
- Specified by:
compareAndSetin interfaceKeyValueStore- Overrides:
compareAndSetin classAbstractKeyValueStoreProvider- Parameters:
key- the keyexpected- the expected value, which may benullvalue- the updated value, which may benullttl- the TTL, in seconds (0 for infinite)- Returns:
trueif the value was updated, orfalseif not (the expected value was not found)
-
compareAndSet
-
addAndGet
Description copied from interface:KeyValueStoreAtomically adds the delta to the value associated to the key, interpreted as a long represented as a string.If the value does not exist (if
KeyValueStore.get(java.lang.String)would returnnull), it is interpreted as0.- Specified by:
addAndGetin interfaceKeyValueStore- Overrides:
addAndGetin classAbstractKeyValueStoreProvider- Parameters:
key- the keydelta- the delta to add- Returns:
- the new value
- Throws:
NumberFormatException- if the existing value cannot be interpreted as along
-
addAndGetGeneric
- Throws:
NumberFormatException
-