public class MongoDbMetadataStore extends Object implements ConcurrentMetadataStore
ConcurrentMetadataStore.
Use this MetadataStore to
achieve meta-data persistence shared across application instances and
restarts.| Constructor and Description |
|---|
MongoDbMetadataStore(MongoDatabaseFactory factory)
Configure the MongoDbMetadataStore by provided
MongoDatabaseFactory and
default collection name - DEFAULT_COLLECTION_NAME. |
MongoDbMetadataStore(MongoDatabaseFactory factory,
String collectionName)
Configure the MongoDbMetadataStore by provided
MongoDatabaseFactory and
collection name |
MongoDbMetadataStore(MongoTemplate template)
Configure the MongoDbMetadataStore by provided
MongoTemplate and
default collection name - DEFAULT_COLLECTION_NAME. |
MongoDbMetadataStore(MongoTemplate template,
String collectionName)
Configure the MongoDbMetadataStore by provided
MongoTemplate and collection name. |
| Modifier and Type | Method and Description |
|---|---|
String |
get(String key)
Get the
value for the provided key performing findOne MongoDB operation. |
void |
put(String key,
String value)
|
String |
putIfAbsent(String key,
String value)
If the specified key is not already associated with a value, associate it with the given value.
|
String |
remove(String key)
Remove the metadata entry for the provided
key and return its value, if any,
using findAndRemove MongoDB operation. |
boolean |
replace(String key,
String oldValue,
String newValue)
Replace an existing metadata entry
value with a new one. |
public MongoDbMetadataStore(MongoDatabaseFactory factory)
MongoDatabaseFactory and
default collection name - DEFAULT_COLLECTION_NAME.factory - the mongodb factorypublic MongoDbMetadataStore(MongoDatabaseFactory factory, String collectionName)
MongoDatabaseFactory and
collection namefactory - the mongodb factorycollectionName - the collection name where it persists the datapublic MongoDbMetadataStore(MongoTemplate template)
MongoTemplate and
default collection name - DEFAULT_COLLECTION_NAME.template - the mongodb templatepublic MongoDbMetadataStore(MongoTemplate template, String collectionName)
MongoTemplate and collection name.template - the mongodb templatecollectionName - the collection name where it persists the datapublic void put(String key, String value)
value under provided key to the configured
collectionName.
If a document does not exist with the specified key, the method performs an insert.
If a document exists with the specified key, the method performs an update.
put in interface MetadataStorekey - the metadata entry keyvalue - the metadata entry valueMongoTemplate.execute(String, org.springframework.data.mongodb.core.CollectionCallback)public String get(String key)
value for the provided key performing findOne MongoDB operation.get in interface MetadataStorekey - the metadata entry keyMongoTemplate.findOne(Query, Class, String)public String remove(String key)
key and return its value, if any,
using findAndRemove MongoDB operation.remove in interface MetadataStorekey - the metadata entry keyMongoTemplate.findAndRemove(Query, Class, String)public String putIfAbsent(String key, String value)
if (!map.containsKey(key))
return map.put(key, value);
else
return map.get(key);
except that the action is performed atomically.
putIfAbsent in interface ConcurrentMetadataStorekey - the metadata entry keyvalue - the metadata entry value to storeConcurrentMap.putIfAbsent(Object, Object)public boolean replace(String key, String oldValue, String newValue)
value with a new one. Otherwise does nothing.
Performs updateFirst if a document for the provided key and oldValue
exists in the collectionName.replace in interface ConcurrentMetadataStorekey - the metadata entry keyoldValue - the metadata entry old value to replacenewValue - the metadata entry new value to puttrue if replace was successful, false otherwise.MongoTemplate.updateFirst(Query, org.springframework.data.mongodb.core.query.UpdateDefinition, String)