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
 
 public class MongoDBKeyValueStore extends AbstractKeyValueStoreProvider 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 SummaryFields Modifier and Type Field Description protected com.mongodb.client.MongoCollection<org.bson.Document>collstatic StringCOLLECTION_DEFAULTstatic StringCOLLECTION_PROPstatic StringID_KEYstatic StringKEYVALUE_CONNECTION_IDstatic DoubleONEstatic StringTTL_KEYstatic StringVALUE_KEY- 
Fields inherited from class org.nuxeo.runtime.kv.AbstractKeyValueStoreProvidername, UTF_8_DECODERS
 
- 
 - 
Constructor SummaryConstructors Constructor Description MongoDBKeyValueStore()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddAndGet(String key, long delta)Atomically 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[]get(String key)Retrieves the value associated to the key.Map<String,byte[]>get(Collection<String> keys)Retrieves the key/value map associated with the keys.protected DategetDateFromTTL(long ttl)LonggetLong(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 ObjectgetObject(String key)StringgetString(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.voidinitialize(KeyValueStoreDescriptor descriptor)Initializes this Key/Value store provider.Stream<String>keyStream()Returns aStreamof the keys contained in this Key/Value store provider.Stream<String>keyStream(String prefix)Returns aStreamof the keys with the given prefix contained in this Key/Value store provider.voidput(String key, byte[] bytes, long ttl)Sets the value associated to the key, and a TTL.voidput(String key, Long value)Sets the value associated to the key.voidput(String key, Long value, long ttl)Sets the value associated to the key.protected voidput(String key, Object value, long ttl)voidput(String key, String string)Sets the value associated to the key.voidput(String key, String string, long ttl)Sets the value associated to the key, and a TTL.booleansetTTL(String key, long ttl)Sets the TTL for an existing key.protected byte[]toBytes(Object value)protected LongtoLong(Object value)protected static ObjecttoStorage(byte[] bytes)protected StringtoString(Object value)- 
Methods inherited from class org.nuxeo.runtime.kv.AbstractKeyValueStoreProviderbytesToLong, bytesToString, compareAndSet, compareAndSet, longToBytes, put, stringToBytes, toString
 
- 
 
- 
- 
- 
Field Detail- 
KEYVALUE_CONNECTION_IDpublic static final String KEYVALUE_CONNECTION_ID - See Also:
- Constant Field Values
 
 - 
COLLECTION_PROPpublic static final String COLLECTION_PROP - See Also:
- Constant Field Values
 
 - 
COLLECTION_DEFAULTpublic static final String COLLECTION_DEFAULT - See Also:
- Constant Field Values
 
 - 
ID_KEYpublic static final String ID_KEY - See Also:
- Constant Field Values
 
 - 
VALUE_KEYpublic static final String VALUE_KEY - See Also:
- Constant Field Values
 
 - 
TTL_KEYpublic static final String TTL_KEY - See Also:
- Constant Field Values
 
 - 
collprotected com.mongodb.client.MongoCollection<org.bson.Document> coll 
 
- 
 - 
Constructor Detail- 
MongoDBKeyValueStorepublic MongoDBKeyValueStore() 
 
- 
 - 
Method Detail- 
initializepublic void initialize(KeyValueStoreDescriptor descriptor) Description copied from interface:KeyValueStoreProviderInitializes this Key/Value store provider.- Specified by:
- initializein interface- KeyValueStoreProvider
- Overrides:
- initializein class- AbstractKeyValueStoreProvider
- Parameters:
- descriptor- the store provider descriptor
 
 - 
keyStreampublic Stream<String> 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
 
 - 
keyStreampublic Stream<String> keyStream(String prefix) 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
 
 - 
closepublic void close() Description copied from interface:KeyValueStoreProviderCloses this Key/Value store provider.
 - 
clearpublic void clear() Description copied from interface:KeyValueStoreProviderClears the content of this Key/Value store provider.
 - 
toLongprotected Long toLong(Object value) throws NumberFormatException - Throws:
- NumberFormatException
 
 - 
getpublic byte[] get(String key) Description copied from interface:KeyValueStoreRetrieves the value associated to the key.- Parameters:
- key- the key
- Returns:
- the value, or nullif there is no value
 
 - 
getStringpublic String getString(String key) Description copied from interface:KeyValueStoreRetrieves the value associated to the key.- Specified by:
- getStringin interface- KeyValueStore
- Overrides:
- getStringin class- AbstractKeyValueStoreProvider
- Parameters:
- key- the key
- Returns:
- the value, or nullif there is no value
 
 - 
getLongpublic Long getLong(String key) throws NumberFormatException Description copied from interface:KeyValueStoreRetrieves the value associated to the key.- Specified by:
- getLongin interface- KeyValueStore
- Overrides:
- getLongin class- AbstractKeyValueStoreProvider
- Parameters:
- key- the key
- Returns:
- the value, or nullif there is no value
- Throws:
- NumberFormatException- if the value cannot be returned as a- Long
 
 - 
getpublic Map<String,byte[]> get(Collection<String> keys) Description copied from interface:KeyValueStoreRetrieves the key/value map associated with the keys.- Specified by:
- getin interface- KeyValueStore
- Overrides:
- getin class- AbstractKeyValueStoreProvider
- Parameters:
- keys- the keys
- Returns:
- the key/value map
 
 - 
getStringspublic Map<String,String> getStrings(Collection<String> keys) Description copied from interface:KeyValueStoreRetrieves the key/value map associated with the keys.- Specified by:
- getStringsin interface- KeyValueStore
- Overrides:
- getStringsin class- AbstractKeyValueStoreProvider
- Parameters:
- keys- the keys
- Returns:
- the key/value map
 
 - 
getLongspublic Map<String,Long> getLongs(Collection<String> keys) throws NumberFormatException Description copied from interface:KeyValueStoreRetrieves the key/value map associated with the keys.- Specified by:
- getLongsin interface- KeyValueStore
- Overrides:
- getLongsin class- AbstractKeyValueStoreProvider
- Parameters:
- keys- the keys
- Returns:
- the key/value map
- Throws:
- NumberFormatException- if one of the values cannot be returned as a- Long
 
 - 
findByKeysprotected void findByKeys(Collection<String> keys, Consumer<org.bson.Document> block) - Since:
- 9.10
 
 - 
getDateFromTTLprotected Date getDateFromTTL(long ttl) 
 - 
putpublic void put(String key, byte[] bytes, long ttl) Description copied from interface:KeyValueStoreSets the value associated to the key, and a TTL.- Parameters:
- key- the key
- bytes- the value, which may be- null
- ttl- the TTL, in seconds (0 for infinite)
 
 - 
putpublic void put(String key, String string) Description copied from interface:KeyValueStoreSets the value associated to the key.- Specified by:
- putin interface- KeyValueStore
- Overrides:
- putin class- AbstractKeyValueStoreProvider
- Parameters:
- key- the key
- string- the value, which may be- null
 
 - 
putpublic void put(String key, String string, long ttl) Description copied from interface:KeyValueStoreSets the value associated to the key, and a TTL.- Specified by:
- putin interface- KeyValueStore
- Overrides:
- putin class- AbstractKeyValueStoreProvider
- Parameters:
- key- the key
- string- the value, which may be- null
- ttl- the TTL, in seconds (0 for infinite)
 
 - 
putpublic void put(String key, Long value) Description copied from interface:KeyValueStoreSets the value associated to the key.- Specified by:
- putin interface- KeyValueStore
- Overrides:
- putin class- AbstractKeyValueStoreProvider
- Parameters:
- key- the key
- value- the value, which may be- null
 
 - 
putpublic void put(String key, Long value, long ttl) Description copied from interface:KeyValueStoreSets the value associated to the key.- Specified by:
- putin interface- KeyValueStore
- Overrides:
- putin class- AbstractKeyValueStoreProvider
- Parameters:
- key- the key
- value- the value, which may be- null
- ttl- the TTL, in seconds (0 for infinite)
 
 - 
addTTLprotected void addTTL(org.bson.Document doc, long ttl) 
 - 
setTTLpublic boolean setTTL(String key, long ttl) Description copied from interface:KeyValueStoreSets the TTL for an existing key.- Parameters:
- key- the key
- ttl- the TTL, in seconds (0 for infinite)
- Returns:
- trueif the TTL has been set, or- falseif the key does not exist
 
 - 
compareAndSetpublic boolean compareAndSet(String key, byte[] expected, byte[] value, long ttl) 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 key
- expected- the expected value, which may be- null
- value- the updated value, which may be- null
- ttl- the TTL, in seconds (0 for infinite)
- Returns:
- trueif the value was updated, or- falseif not (the expected value was not found)
 
 - 
compareAndSetpublic boolean compareAndSet(String key, String expected, String value, long ttl) 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 interface- KeyValueStore
- Overrides:
- compareAndSetin class- AbstractKeyValueStoreProvider
- Parameters:
- key- the key
- expected- the expected value, which may be- null
- value- the updated value, which may be- null
- ttl- the TTL, in seconds (0 for infinite)
- Returns:
- trueif the value was updated, or- falseif not (the expected value was not found)
 
 - 
compareAndSetprotected boolean compareAndSet(String key, Object expected, Object value, long ttl) 
 - 
addAndGetpublic long addAndGet(String key, long delta) throws NumberFormatException 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 interface- KeyValueStore
- Overrides:
- addAndGetin class- AbstractKeyValueStoreProvider
- Parameters:
- key- the key
- delta- the delta to add
- Returns:
- the new value
- Throws:
- NumberFormatException- if the existing value cannot be interpreted as a- long
 
 - 
addAndGetGenericprotected long addAndGetGeneric(String key, long delta) throws NumberFormatException - Throws:
- NumberFormatException
 
 
- 
 
-