Class SimpleReactiveMongoDatabaseFactory

java.lang.Object
org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory
All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean, CodecRegistryProvider, ReactiveMongoDatabaseFactory

public class SimpleReactiveMongoDatabaseFactory extends Object implements org.springframework.beans.factory.DisposableBean, ReactiveMongoDatabaseFactory
Factory to create MongoDatabase instances from a MongoClient instance.
Since:
2.0
Author:
Mark Paluch, Christoph Strobl, Mathieu Ouellet
  • Constructor Details

    • SimpleReactiveMongoDatabaseFactory

      public SimpleReactiveMongoDatabaseFactory(com.mongodb.ConnectionString connectionString)
      Creates a new SimpleReactiveMongoDatabaseFactory instance from the given ConnectionString.
      Parameters:
      connectionString - must not be null.
    • SimpleReactiveMongoDatabaseFactory

      public SimpleReactiveMongoDatabaseFactory(com.mongodb.reactivestreams.client.MongoClient mongoClient, String databaseName)
      Creates a new SimpleReactiveMongoDatabaseFactory instance from the given MongoClient.
      Parameters:
      mongoClient - must not be null.
      databaseName - must not be null.
      Since:
      1.7
  • Method Details

    • setWriteConcern

      public void setWriteConcern(com.mongodb.WriteConcern writeConcern)
      Configures the WriteConcern to be used on the MongoDatabase instance being created.
      Parameters:
      writeConcern - the writeConcern to set
    • getMongoDatabase

      public reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase> getMongoDatabase() throws org.springframework.dao.DataAccessException
      Description copied from interface: ReactiveMongoDatabaseFactory
      Creates a default MongoDatabase instance.
      Specified by:
      getMongoDatabase in interface ReactiveMongoDatabaseFactory
      Returns:
      never null.
      Throws:
      org.springframework.dao.DataAccessException
    • getMongoDatabase

      public reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase> getMongoDatabase(String dbName) throws org.springframework.dao.DataAccessException
      Description copied from interface: ReactiveMongoDatabaseFactory
      Obtain a MongoDatabase instance to access the database with the given name.
      Specified by:
      getMongoDatabase in interface ReactiveMongoDatabaseFactory
      Parameters:
      dbName - must not be null or empty.
      Returns:
      never null.
      Throws:
      org.springframework.dao.DataAccessException
    • destroy

      public void destroy() throws Exception
      Clean up the Mongo instance if it was created by the factory itself.
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Throws:
      Exception
      See Also:
      • DisposableBean.destroy()
    • getExceptionTranslator

      public org.springframework.dao.support.PersistenceExceptionTranslator getExceptionTranslator()
      Description copied from interface: ReactiveMongoDatabaseFactory
      Exposes a shared MongoExceptionTranslator.
      Specified by:
      getExceptionTranslator in interface ReactiveMongoDatabaseFactory
      Returns:
      will never be null.
    • getCodecRegistry

      public org.bson.codecs.configuration.CodecRegistry getCodecRegistry()
      Description copied from interface: ReactiveMongoDatabaseFactory
      Get the underlying CodecRegistry used by the reactive MongoDB Java driver.
      Specified by:
      getCodecRegistry in interface CodecRegistryProvider
      Specified by:
      getCodecRegistry in interface ReactiveMongoDatabaseFactory
      Returns:
      never null.
    • getSession

      public reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.ClientSession> getSession(com.mongodb.ClientSessionOptions options)
      Description copied from interface: ReactiveMongoDatabaseFactory
      Obtain a Mono emitting a ClientSession for given options.
      Specified by:
      getSession in interface ReactiveMongoDatabaseFactory
      Parameters:
      options - must not be null.
      Returns:
      never null.
    • withSession

      public ReactiveMongoDatabaseFactory withSession(com.mongodb.reactivestreams.client.ClientSession session)
      Description copied from interface: ReactiveMongoDatabaseFactory
      Obtain a ClientSession bound instance of ReactiveMongoDatabaseFactory returning MongoDatabase instances that are aware and bound to the given session.
      Specified by:
      withSession in interface ReactiveMongoDatabaseFactory
      Parameters:
      session - must not be null.
      Returns:
      never null.