Interface MongoDatabaseFactory
- All Superinterfaces:
CodecRegistryProvider, MongoSessionProvider
- All Known Implementing Classes:
MongoDatabaseFactorySupport, SimpleMongoClientDatabaseFactory
Interface for factories creating
MongoDatabase instances.- Since:
- 3.0
- Author:
- Mark Pollack, Thomas Darimont, Christoph Strobl, Mark Paluch
-
Method Summary
Modifier and TypeMethodDescriptionstatic MongoDatabaseFactorycreate(MongoClient mongoClient, String databaseName) Creates a newMongoDatabaseFactoryinstance from the givenMongoClient.create(ConnectionString connectionString) Creates a newSimpleMongoClientDatabaseFactoryinstance from the givenMongoClient.Creates a newSimpleMongoClientDatabaseFactoryinstance for the givenconnectionString.default CodecRegistryGet the underlyingCodecRegistryused by the MongoDB Java driver.Exposes a sharedMongoExceptionTranslator.Obtain aMongoDatabasefrom the underlying factory.getMongoDatabase(String dbName) Obtain aMongoDatabaseinstance to access the database with the given name.getSession(ClientSessionOptions options) Obtain aClientSessionfor given ClientSessionOptions.default booleanReturns if the givenMongoDatabaseFactoryis bound to aClientSessionthat has anactive transaction.withSession(ClientSession session) Obtain aClientSessionbound instance ofMongoDatabaseFactoryreturningMongoDatabaseinstances that are aware and bound to the given session.default MongoDatabaseFactorywithSession(ClientSessionOptions options) Obtain aClientSessionbound instance ofMongoDatabaseFactoryreturningMongoDatabaseinstances that are aware and bound to a new session with givenoptions.Methods inherited from interface CodecRegistryProvider
getCodecFor, hasCodecFor
-
Method Details
-
create
Creates a newSimpleMongoClientDatabaseFactoryinstance for the givenconnectionString. Using this factory method will create a newMongoClientinstance that will be closed when callingMongoDatabaseFactorySupport.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
Creates a newSimpleMongoClientDatabaseFactoryinstance from the givenMongoClient. Using this factory will create a newMongoClientinstance that will be closed when callingMongoDatabaseFactorySupport.destroy().- Parameters:
connectionString- connection coordinates for a database connection. Must contain also a database name and not be null.- Since:
- 4.5.2
-
create
Creates a newMongoDatabaseFactoryinstance from the givenMongoClient. 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
Obtain aMongoDatabasefrom the underlying factory.- Returns:
- never null.
- Throws:
DataAccessException
-
getMongoDatabase
Obtain aMongoDatabaseinstance to access the database with the given name.- Parameters:
dbName- must not be null.- Returns:
- never null.
- Throws:
DataAccessException
-
getExceptionTranslator
PersistenceExceptionTranslator getExceptionTranslator()Exposes a sharedMongoExceptionTranslator.- Returns:
- will never be null.
-
getCodecRegistry
Get the underlyingCodecRegistryused by the MongoDB Java driver.- Specified by:
getCodecRegistryin interfaceCodecRegistryProvider- Returns:
- never null.
-
getSession
Obtain aClientSessionfor given ClientSessionOptions.- Specified by:
getSessionin interfaceMongoSessionProvider- Parameters:
options- must not be null.- Returns:
- never null.
- Since:
- 2.1
-
withSession
Obtain aClientSessionbound instance ofMongoDatabaseFactoryreturningMongoDatabaseinstances that are aware and bound to a new session with givenoptions.- Parameters:
options- must not be null.- Returns:
- never null.
- Since:
- 2.1
-
withSession
Obtain aClientSessionbound instance ofMongoDatabaseFactoryreturningMongoDatabaseinstances 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 givenMongoDatabaseFactoryis bound to aClientSessionthat has anactive transaction.- Returns:
- true if there's an active transaction, false otherwise.
- Since:
- 2.1.3
-