Class ReactiveMongoDatabaseUtils

java.lang.Object
org.springframework.data.mongodb.ReactiveMongoDatabaseUtils

public class ReactiveMongoDatabaseUtils extends Object
Helper class for managing reactive MongoDatabase instances via ReactiveMongoDatabaseFactory. Used for obtaining session bound resources, such as MongoDatabase and MongoCollection suitable for transactional usage.
Note: Intended for internal usage only.
Since:
2.2
Author:
Mark Paluch, Christoph Strobl, Mathieu Ouellet
  • Constructor Details

    • ReactiveMongoDatabaseUtils

      public ReactiveMongoDatabaseUtils()
  • Method Details

    • isTransactionActive

      public static reactor.core.publisher.Mono<Boolean> isTransactionActive(ReactiveMongoDatabaseFactory databaseFactory)
      Check if the ReactiveMongoDatabaseFactory is actually bound to a ClientSession that has an active transaction, or if a TransactionSynchronization has been registered for the resource and if the associated ClientSession has an active transaction.
      Parameters:
      databaseFactory - the resource to check transactions for. Must not be null.
      Returns:
      a Mono emitting true if the factory has an ongoing transaction.
    • getDatabase

      public static reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase> getDatabase(ReactiveMongoDatabaseFactory factory)
      Obtain the default database form the given factory using native session synchronization.
      Registers a MongoDB specific transaction synchronization within the subscriber Context if synchronization is active.
      Parameters:
      factory - the ReactiveMongoDatabaseFactory to get the MongoDatabase from.
      Returns:
      the MongoDatabase that is potentially associated with a transactional ClientSession.
    • getDatabase

      public static reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase> getDatabase(ReactiveMongoDatabaseFactory factory, SessionSynchronization sessionSynchronization)
      Obtain the default database form the given factory.
      Registers a MongoDB specific transaction synchronization within the subscriber Context if synchronization is active.
      Parameters:
      factory - the ReactiveMongoDatabaseFactory 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 reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase> getDatabase(String dbName, ReactiveMongoDatabaseFactory factory)
      Obtain the database with given name form the given factory using native session synchronization.
      Registers a MongoDB specific transaction synchronization within the subscriber Context if synchronization is active.
      Parameters:
      dbName - the name of the MongoDatabase to get.
      factory - the ReactiveMongoDatabaseFactory to get the MongoDatabase from.
      Returns:
      the MongoDatabase that is potentially associated with a transactional ClientSession.
    • getDatabase

      public static reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase> getDatabase(String dbName, ReactiveMongoDatabaseFactory factory, SessionSynchronization sessionSynchronization)
      Obtain the database with given name form the given factory.
      Registers a MongoDB specific transaction synchronization within the subscriber Context if synchronization is active.
      Parameters:
      dbName - the name of the MongoDatabase to get.
      factory - the ReactiveMongoDatabaseFactory 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.