Interface MongoDatabaseFactory

All Superinterfaces:
CodecRegistryProvider, MongoSessionProvider
All Known Implementing Classes:
MongoDatabaseFactorySupport, SimpleMongoClientDatabaseFactory

public interface MongoDatabaseFactory extends CodecRegistryProvider, MongoSessionProvider
Interface for factories creating MongoDatabase instances.
Since:
3.0
Author:
Mark Pollack, Thomas Darimont, Christoph Strobl, Mark Paluch
  • Method Details

    • create

      static SimpleMongoClientDatabaseFactory create(String connectionString)
      Creates a new SimpleMongoClientDatabaseFactory instance for the given connectionString. Using this factory method will create a new MongoClient instance that will be closed when calling MongoDatabaseFactorySupport.destroy().
      Parameters:
      connectionString - connection coordinates for a database connection. Must contain a database name and must not be null or empty.
      Since:
      4.5.2
      See Also:
    • create

      static SimpleMongoClientDatabaseFactory create(com.mongodb.ConnectionString connectionString)
      Creates a new SimpleMongoClientDatabaseFactory instance from the given MongoClient. Using this factory will create a new MongoClient instance that will be closed when calling MongoDatabaseFactorySupport.destroy().
      Parameters:
      connectionString - connection coordinates for a database connection. Must contain also a database name and not be null.
      Since:
      4.5.2
    • create

      static MongoDatabaseFactory create(com.mongodb.client.MongoClient mongoClient, String databaseName)
      Creates a new MongoDatabaseFactory instance from the given MongoClient. We assume a managed client instance that will be disposed by you (or the application container) once the client is no longer required for use.
      Parameters:
      mongoClient - must not be null.
      databaseName - must not be null or empty.
      Since:
      4.5.2
    • getMongoDatabase

      com.mongodb.client.MongoDatabase getMongoDatabase() throws DataAccessException
      Obtain a MongoDatabase from the underlying factory.
      Returns:
      never null.
      Throws:
      DataAccessException
    • getMongoDatabase

      com.mongodb.client.MongoDatabase getMongoDatabase(String dbName) throws DataAccessException
      Obtain a MongoDatabase instance to access the database with the given name.
      Parameters:
      dbName - must not be null.
      Returns:
      never null.
      Throws:
      DataAccessException
    • getExceptionTranslator

      PersistenceExceptionTranslator getExceptionTranslator()
      Exposes a shared MongoExceptionTranslator.
      Returns:
      will never be null.
    • getCodecRegistry

      default org.bson.codecs.configuration.CodecRegistry getCodecRegistry()
      Get the underlying CodecRegistry used by the MongoDB Java driver.
      Specified by:
      getCodecRegistry in interface CodecRegistryProvider
      Returns:
      never null.
    • getSession

      com.mongodb.client.ClientSession getSession(com.mongodb.ClientSessionOptions options)
      Obtain a ClientSession for given ClientSessionOptions.
      Specified by:
      getSession in interface MongoSessionProvider
      Parameters:
      options - must not be null.
      Returns:
      never null.
      Since:
      2.1
    • withSession

      default MongoDatabaseFactory withSession(com.mongodb.ClientSessionOptions options)
      Obtain a ClientSession bound instance of MongoDatabaseFactory returning MongoDatabase instances that are aware and bound to a new session with given options.
      Parameters:
      options - must not be null.
      Returns:
      never null.
      Since:
      2.1
    • withSession

      MongoDatabaseFactory withSession(com.mongodb.client.ClientSession session)
      Obtain a ClientSession bound instance of MongoDatabaseFactory returning MongoDatabase instances that are aware and bound to the given session.
      Parameters:
      session - must not be null.
      Returns:
      never null.
      Since:
      2.1
    • isTransactionActive

      default boolean isTransactionActive()
      Returns if the given MongoDatabaseFactory is bound to a ClientSession that has an active transaction.
      Returns:
      true if there's an active transaction, false otherwise.
      Since:
      2.1.3