Class MongoDbMetadataStore
java.lang.Object
org.springframework.integration.mongodb.metadata.MongoDbMetadataStore
- All Implemented Interfaces:
ConcurrentMetadataStore
,MetadataStore
public class MongoDbMetadataStore extends Object implements ConcurrentMetadataStore
MongoDbMetadataStore implementation of
ConcurrentMetadataStore
.
Use this MetadataStore
to
achieve meta-data persistence shared across application instances and
restarts.- Since:
- 4.2
- Author:
- Senthil Arumugam, Samiraj Panneer Selvam, Artem Bilan, Gary Russell
-
Constructor Summary
Constructors Constructor Description MongoDbMetadataStore(MongoTemplate template)
Configure the MongoDbMetadataStore by providedMongoTemplate
and default collection name -DEFAULT_COLLECTION_NAME
.MongoDbMetadataStore(MongoTemplate template, String collectionName)
Configure the MongoDbMetadataStore by providedMongoTemplate
and collection name.MongoDbMetadataStore(MongoDatabaseFactory factory)
Configure the MongoDbMetadataStore by providedMongoDatabaseFactory
and default collection name -DEFAULT_COLLECTION_NAME
.MongoDbMetadataStore(MongoDatabaseFactory factory, String collectionName)
Configure the MongoDbMetadataStore by providedMongoDatabaseFactory
and collection name -
Method Summary
Modifier and Type Method Description String
get(String key)
Get thevalue
for the providedkey
performingfindOne
MongoDB operation.void
put(String key, String value)
Store a metadatavalue
under providedkey
to the configuredcollectionName
.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 providedkey
and return itsvalue
, if any, usingfindAndRemove
MongoDB operation.boolean
replace(String key, String oldValue, String newValue)
Replace an existing metadata entryvalue
with a new one.
-
Constructor Details
-
MongoDbMetadataStore
Configure the MongoDbMetadataStore by providedMongoDatabaseFactory
and default collection name -DEFAULT_COLLECTION_NAME
.- Parameters:
factory
- the mongodb factory
-
MongoDbMetadataStore
Configure the MongoDbMetadataStore by providedMongoDatabaseFactory
and collection name- Parameters:
factory
- the mongodb factorycollectionName
- the collection name where it persists the data
-
MongoDbMetadataStore
Configure the MongoDbMetadataStore by providedMongoTemplate
and default collection name -DEFAULT_COLLECTION_NAME
.- Parameters:
template
- the mongodb template
-
MongoDbMetadataStore
Configure the MongoDbMetadataStore by providedMongoTemplate
and collection name.- Parameters:
template
- the mongodb templatecollectionName
- the collection name where it persists the data
-
-
Method Details
-
put
Store a metadatavalue
under providedkey
to the configuredcollectionName
.If a document does not exist with the specified
key
, the method performs aninsert
. If a document exists with the specifiedkey
, the method performs anupdate
.- Specified by:
put
in interfaceMetadataStore
- Parameters:
key
- the metadata entry keyvalue
- the metadata entry value- See Also:
MongoTemplate.execute(String, org.springframework.data.mongodb.core.CollectionCallback)
-
get
Get thevalue
for the providedkey
performingfindOne
MongoDB operation.- Specified by:
get
in interfaceMetadataStore
- Parameters:
key
- the metadata entry key- Returns:
- the metadata entry value or null if doesn't exist.
- See Also:
MongoTemplate.findOne(Query, Class, String)
-
remove
Remove the metadata entry for the providedkey
and return itsvalue
, if any, usingfindAndRemove
MongoDB operation.- Specified by:
remove
in interfaceMetadataStore
- Parameters:
key
- the metadata entry key- Returns:
- the metadata entry value or null if doesn't exist.
- See Also:
MongoTemplate.findAndRemove(Query, Class, String)
-
putIfAbsent
If the specified key is not already associated with a value, associate it with the given value. This is equivalent toif (!map.containsKey(key)) return map.put(key, value); else return map.get(key);
- Specified by:
putIfAbsent
in interfaceConcurrentMetadataStore
- Parameters:
key
- the metadata entry keyvalue
- the metadata entry value to store- Returns:
- null if successful, the old value otherwise.
- See Also:
ConcurrentMap.putIfAbsent(Object, Object)
-
replace
Replace an existing metadata entryvalue
with a new one. Otherwise does nothing. PerformsupdateFirst
if a document for the providedkey
andoldValue
exists in thecollectionName
.- Specified by:
replace
in interfaceConcurrentMetadataStore
- Parameters:
key
- the metadata entry keyoldValue
- the metadata entry old value to replacenewValue
- the metadata entry new value to put- Returns:
true
if replace was successful,false
otherwise.- See Also:
MongoTemplate.updateFirst(Query, org.springframework.data.mongodb.core.query.UpdateDefinition, String)
-