Class MongoDatabaseFactorySupport<C>

java.lang.Object
org.springframework.data.mongodb.core.MongoDatabaseFactorySupport<C>
Type Parameters:
C - Client type.
All Implemented Interfaces:
CodecRegistryProvider, MongoDatabaseFactory, MongoSessionProvider
Direct Known Subclasses:
SimpleMongoClientDatabaseFactory

public abstract class MongoDatabaseFactorySupport<C> extends Object implements MongoDatabaseFactory
Common base class for usage with both MongoClients defining common properties such as database name and exception translator.
Not intended to be used directly.
Since:
3.0
Author:
Christoph Strobl, Mark Paluch
See Also:
  • Constructor Details

  • 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 com.mongodb.client.MongoDatabase getMongoDatabase() throws DataAccessException
      Description copied from interface: MongoDatabaseFactory
      Obtain a MongoDatabase from the underlying factory.
      Specified by:
      getMongoDatabase in interface MongoDatabaseFactory
      Returns:
      never null.
      Throws:
      DataAccessException
    • getMongoDatabase

      public com.mongodb.client.MongoDatabase getMongoDatabase(String dbName) throws DataAccessException
      Description copied from interface: MongoDatabaseFactory
      Obtain a MongoDatabase instance to access the database with the given name.
      Specified by:
      getMongoDatabase in interface MongoDatabaseFactory
      Parameters:
      dbName - must not be null.
      Returns:
      never null.
      Throws:
      DataAccessException
    • doGetMongoDatabase

      protected abstract com.mongodb.client.MongoDatabase doGetMongoDatabase(String dbName)
      Get the actual MongoDatabase from the client.
      Parameters:
      dbName - must not be null or empty.
      Returns:
    • destroy

      public void destroy() throws Exception
      Throws:
      Exception
    • getExceptionTranslator

      public PersistenceExceptionTranslator getExceptionTranslator()
      Description copied from interface: MongoDatabaseFactory
      Exposes a shared MongoExceptionTranslator.
      Specified by:
      getExceptionTranslator in interface MongoDatabaseFactory
      Returns:
      will never be null.
    • withSession

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

      protected abstract void closeClient()
      Close the client instance.
    • getMongoClient

      protected C getMongoClient()
      Returns:
      the Mongo client object.
    • getDefaultDatabaseName

      protected String getDefaultDatabaseName()
      Returns:
      the database name.