org.springframework.data.mongodb

Class MongoDatabaseUtils



  • public class MongoDatabaseUtils
    extends Object
    Helper class for managing a MongoDatabase instances via MongoDbFactory. Used for obtaining session bound resources, such as MongoDatabase and MongoCollection suitable for transactional usage.

    Note: Intended for internal usage only.

    Since:
    2.1
    Author:
    Christoph Strobl, Mark Paluch
    • Constructor Detail

      • MongoDatabaseUtils

        public MongoDatabaseUtils()
    • Method Detail

      • getDatabase

        public static com.mongodb.client.MongoDatabase getDatabase(MongoDbFactory factory,
                                                                   SessionSynchronization sessionSynchronization)
        Obtain the default database form the given factory.

        Registers a MongoDB specific transaction synchronization within the current Thread if synchronization is active.

        Parameters:
        factory - the MongoDbFactory to get the MongoDatabase from.
        sessionSynchronization - the synchronization to use. Must not be null.
        Returns:
        the MongoDatabase that is potentially associated with a transactional ClientSession.
      • getDatabase

        public static com.mongodb.client.MongoDatabase getDatabase(String dbName,
                                                                   MongoDbFactory factory)
        Obtain the database with given name form the given factory using native session synchronization.

        Registers a MongoDB specific transaction synchronization within the current Thread if synchronization is active.

        Parameters:
        dbName - the name of the MongoDatabase to get.
        factory - the MongoDbFactory to get the MongoDatabase from.
        Returns:
        the MongoDatabase that is potentially associated with a transactional ClientSession.
      • getDatabase

        public static com.mongodb.client.MongoDatabase getDatabase(String dbName,
                                                                   MongoDbFactory factory,
                                                                   SessionSynchronization sessionSynchronization)
        Obtain the database with given name form the given factory.

        Registers a MongoDB specific transaction synchronization within the current Thread if synchronization is active.

        Parameters:
        dbName - the name of the MongoDatabase to get.
        factory - the MongoDbFactory to get the MongoDatabase from.
        sessionSynchronization - the synchronization to use. Must not be null.
        Returns:
        the MongoDatabase that is potentially associated with a transactional ClientSession.