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 java.lang.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, java.lang.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, java.lang.String collectionName)
    Configure the MongoDbMetadataStore by provided MongoDatabaseFactory and collection name
  • Method Summary

    Modifier and Type Method Description
    java.lang.String get​(java.lang.String key)
    Get the value for the provided key performing findOne MongoDB operation.
    void put​(java.lang.String key, java.lang.String value)
    Store a metadata value under provided key to the configured collectionName.
    java.lang.String putIfAbsent​(java.lang.String key, java.lang.String value)
    If the specified key is not already associated with a value, associate it with the given value.
    java.lang.String remove​(java.lang.String key)
    Remove the metadata entry for the provided key and return its value, if any, using findAndRemove MongoDB operation.
    boolean replace​(java.lang.String key, java.lang.String oldValue, java.lang.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, java.lang.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, java.lang.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​(java.lang.String key, java.lang.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 java.lang.String get​(java.lang.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 java.lang.String remove​(java.lang.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 java.lang.String putIfAbsent​(java.lang.String key, java.lang.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:
      ConcurrentMap.putIfAbsent(Object, Object)
    • replace

      public boolean replace​(java.lang.String key, java.lang.String oldValue, java.lang.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)