Package org.springframework.data.mongodb
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
-
Method Summary
Modifier and TypeMethodDescriptiondefault org.bson.codecs.configuration.CodecRegistry
Get the underlyingCodecRegistry
used by the MongoDB Java driver.Exposes a sharedMongoExceptionTranslator
.com.mongodb.client.MongoDatabase
Obtain aMongoDatabase
from the underlying factory.com.mongodb.client.MongoDatabase
getMongoDatabase
(String dbName) Obtain aMongoDatabase
instance to access the database with the given name.com.mongodb.client.ClientSession
getSession
(com.mongodb.ClientSessionOptions options) Obtain aClientSession
for given ClientSessionOptions.default boolean
Returns if the givenMongoDatabaseFactory
is bound to aClientSession
that has anactive transaction
.withSession
(com.mongodb.client.ClientSession session) Obtain aClientSession
bound instance ofMongoDatabaseFactory
returningMongoDatabase
instances that are aware and bound to the given session.default MongoDatabaseFactory
withSession
(com.mongodb.ClientSessionOptions options) Obtain aClientSession
bound instance ofMongoDatabaseFactory
returningMongoDatabase
instances that are aware and bound to a new session with givenoptions
.Methods inherited from interface org.springframework.data.mongodb.CodecRegistryProvider
getCodecFor, hasCodecFor
-
Method Details
-
getMongoDatabase
Obtain aMongoDatabase
from the underlying factory.- Returns:
- never null.
- Throws:
DataAccessException
-
getMongoDatabase
Obtain aMongoDatabase
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 sharedMongoExceptionTranslator
.- Returns:
- will never be null.
-
getCodecRegistry
default org.bson.codecs.configuration.CodecRegistry getCodecRegistry()Get the underlyingCodecRegistry
used by the MongoDB Java driver.- Specified by:
getCodecRegistry
in interfaceCodecRegistryProvider
- Returns:
- never null.
-
getSession
com.mongodb.client.ClientSession getSession(com.mongodb.ClientSessionOptions options) Obtain aClientSession
for given ClientSessionOptions.- Specified by:
getSession
in interfaceMongoSessionProvider
- Parameters:
options
- must not be null.- Returns:
- never null.
- Since:
- 2.1
-
withSession
Obtain aClientSession
bound instance ofMongoDatabaseFactory
returningMongoDatabase
instances 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 aClientSession
bound instance ofMongoDatabaseFactory
returningMongoDatabase
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 givenMongoDatabaseFactory
is bound to aClientSession
that has anactive transaction
.- Returns:
- true if there's an active transaction, false otherwise.
- Since:
- 2.1.3
-