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
  • Method Summary

    Modifier and Type
    Method
    Description
    default org.bson.codecs.configuration.CodecRegistry
    Get the underlying CodecRegistry used by the MongoDB Java driver.
    org.springframework.dao.support.PersistenceExceptionTranslator
    Exposes a shared MongoExceptionTranslator.
    com.mongodb.client.MongoDatabase
    Obtain a MongoDatabase from the underlying factory.
    com.mongodb.client.MongoDatabase
    Obtain a MongoDatabase instance to access the database with the given name.
    com.mongodb.client.ClientSession
    getSession(com.mongodb.ClientSessionOptions options)
    Obtain a ClientSession for given ClientSessionOptions.
    default boolean
    Returns if the given MongoDatabaseFactory is bound to a ClientSession that has an active transaction.
    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.
    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.

    Methods inherited from interface org.springframework.data.mongodb.CodecRegistryProvider

    getCodecFor, hasCodecFor
  • Method Details

    • getMongoDatabase

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

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

      org.springframework.dao.support.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