Class MongoDbMetadataStore

java.lang.Object
org.springframework.integration.mongodb.metadata.MongoDbMetadataStore
All Implemented Interfaces:
org.springframework.integration.metadata.ConcurrentMetadataStore, org.springframework.integration.metadata.MetadataStore

public class MongoDbMetadataStore extends Object implements org.springframework.integration.metadata.ConcurrentMetadataStore
MongoDbMetadataStore implementation of ConcurrentMetadataStore. Use this MetadataStore to achieve meta-data persistence shared across application instances and restarts.
Since:
4.2
  • Constructor Summary

    Constructors
    Constructor
    Description
    MongoDbMetadataStore(org.springframework.data.mongodb.core.MongoTemplate template)
    Configure the MongoDbMetadataStore by provided MongoTemplate and default collection name - DEFAULT_COLLECTION_NAME.
    MongoDbMetadataStore(org.springframework.data.mongodb.core.MongoTemplate template, String collectionName)
    Configure the MongoDbMetadataStore by provided MongoTemplate and collection name.
    MongoDbMetadataStore(org.springframework.data.mongodb.MongoDatabaseFactory factory)
    Configure the MongoDbMetadataStore by provided MongoDatabaseFactory and default collection name - DEFAULT_COLLECTION_NAME.
    MongoDbMetadataStore(org.springframework.data.mongodb.MongoDatabaseFactory factory, String collectionName)
    Configure the MongoDbMetadataStore by provided MongoDatabaseFactory and collection name.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(String key)
    Get the value for the provided key performing findOne MongoDB operation.
    void
    put(String key, String value)
    Store a metadata value under provided key to the configured collectionName.
    putIfAbsent(String key, String value)
    If the specified key is not already associated with a value, associate it with the given value.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MongoDbMetadataStore

      public MongoDbMetadataStore(org.springframework.data.mongodb.MongoDatabaseFactory factory)
      Configure the MongoDbMetadataStore by provided MongoDatabaseFactory and default collection name - DEFAULT_COLLECTION_NAME.
      Parameters:
      factory - the mongodb factory
    • MongoDbMetadataStore

      public MongoDbMetadataStore(org.springframework.data.mongodb.MongoDatabaseFactory factory, String collectionName)
      Configure the MongoDbMetadataStore by provided MongoDatabaseFactory and collection name.
      Parameters:
      factory - the mongodb factory
      collectionName - the collection name where it persists the data
    • MongoDbMetadataStore

      public MongoDbMetadataStore(org.springframework.data.mongodb.core.MongoTemplate template)
      Configure the MongoDbMetadataStore by provided MongoTemplate and default collection name - DEFAULT_COLLECTION_NAME.
      Parameters:
      template - the mongodb template
    • MongoDbMetadataStore

      public MongoDbMetadataStore(org.springframework.data.mongodb.core.MongoTemplate template, String collectionName)
      Configure the MongoDbMetadataStore by provided MongoTemplate and collection name.
      Parameters:
      template - the mongodb template
      collectionName - the collection name where it persists the data
  • Method Details

    • put

      public void put(String key, String value)
      Store a metadata 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.

      Specified by:
      put in interface org.springframework.integration.metadata.MetadataStore
      Parameters:
      key - the metadata entry key
      value - the metadata entry value
      See Also:
      • MongoTemplate.execute(String, org.springframework.data.mongodb.core.CollectionCallback)
    • get

      public String get(String key)
      Get the value for the provided key performing findOne MongoDB operation.
      Specified by:
      get in interface org.springframework.integration.metadata.MetadataStore
      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

      public String remove(String key)
      Remove the metadata entry for the provided key and return its value, if any, using findAndRemove MongoDB operation.
      Specified by:
      remove in interface org.springframework.integration.metadata.MetadataStore
      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

      public String putIfAbsent(String key, String value)
      If the specified key is not already associated with a value, associate it with the given value. This is equivalent to
       
       if (!map.containsKey(key))
         return map.put(key, value);
       else
         return map.get(key);
       
      except that the action is performed atomically.
      Specified by:
      putIfAbsent in interface org.springframework.integration.metadata.ConcurrentMetadataStore
      Parameters:
      key - the metadata entry key
      value - the metadata entry value to store
      Returns:
      null if successful, the old value otherwise.
      See Also:
    • replace

      public boolean replace(String key, String oldValue, String newValue)
      Replace an existing metadata entry value with a new one. Otherwise does nothing. Performs updateFirst if a document for the provided key and oldValue exists in the collectionName.
      Specified by:
      replace in interface org.springframework.integration.metadata.ConcurrentMetadataStore
      Parameters:
      key - the metadata entry key
      oldValue - the metadata entry old value to replace
      newValue - 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)