Module spring.data.mongodb
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
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 Summary
ConstructorsModifierConstructorDescriptionprotectedMongoDatabaseFactorySupport(C mongoClient, String databaseName, boolean mongoInstanceCreated, PersistenceExceptionTranslator exceptionTranslator) Create a newMongoDatabaseFactorySupportobject givenmongoClient,databaseName,mongoInstanceCreatedandPersistenceExceptionTranslator. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidClose the client instance.voiddestroy()protected abstract com.mongodb.client.MongoDatabasedoGetMongoDatabase(String dbName) Get the actualMongoDatabasefrom the client.protected StringExposes a sharedMongoExceptionTranslator.protected Ccom.mongodb.client.MongoDatabaseObtain aMongoDatabasefrom the underlying factory.com.mongodb.client.MongoDatabasegetMongoDatabase(String dbName) Obtain aMongoDatabaseinstance to access the database with the given name.voidsetExceptionTranslator(PersistenceExceptionTranslator exceptionTranslator) Configures thePersistenceExceptionTranslatorto be used.voidsetWriteConcern(com.mongodb.WriteConcern writeConcern) Configures theWriteConcernto be used on theMongoDatabaseinstance being created.withSession(com.mongodb.client.ClientSession session) Obtain aClientSessionbound instance ofMongoDatabaseFactoryreturningMongoDatabaseinstances that are aware and bound to the given session.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.mongodb.CodecRegistryProvider
getCodecFor, hasCodecForMethods inherited from interface org.springframework.data.mongodb.MongoDatabaseFactory
getCodecRegistry, getSession, isTransactionActive, withSession
-
Constructor Details
-
MongoDatabaseFactorySupport
protected MongoDatabaseFactorySupport(C mongoClient, String databaseName, boolean mongoInstanceCreated, PersistenceExceptionTranslator exceptionTranslator) Create a newMongoDatabaseFactorySupportobject givenmongoClient,databaseName,mongoInstanceCreatedandPersistenceExceptionTranslator.- Parameters:
mongoClient- must not be null.databaseName- must not be null or empty.mongoInstanceCreated- true if the client instance was created by a subclass ofMongoDatabaseFactorySupportto close the client ondestroy().exceptionTranslator- must not be null.
-
-
Method Details
-
setExceptionTranslator
Configures thePersistenceExceptionTranslatorto be used.- Parameters:
exceptionTranslator- the exception translator to set.- Since:
- 4.4
-
getExceptionTranslator
Description copied from interface:MongoDatabaseFactoryExposes a sharedMongoExceptionTranslator.- Specified by:
getExceptionTranslatorin interfaceMongoDatabaseFactory- Returns:
- will never be null.
-
setWriteConcern
public void setWriteConcern(com.mongodb.WriteConcern writeConcern) Configures theWriteConcernto be used on theMongoDatabaseinstance being created.- Parameters:
writeConcern- the writeConcern to set.
-
getMongoDatabase
Description copied from interface:MongoDatabaseFactoryObtain aMongoDatabasefrom the underlying factory.- Specified by:
getMongoDatabasein interfaceMongoDatabaseFactory- Returns:
- never null.
- Throws:
DataAccessException
-
getMongoDatabase
Description copied from interface:MongoDatabaseFactoryObtain aMongoDatabaseinstance to access the database with the given name.- Specified by:
getMongoDatabasein interfaceMongoDatabaseFactory- Parameters:
dbName- must not be null.- Returns:
- never null.
- Throws:
DataAccessException
-
doGetMongoDatabase
Get the actualMongoDatabasefrom the client.- Parameters:
dbName- must not be null or empty.- Returns:
-
destroy
- Throws:
Exception
-
withSession
Description copied from interface:MongoDatabaseFactoryObtain aClientSessionbound instance ofMongoDatabaseFactoryreturningMongoDatabaseinstances that are aware and bound to the given session.- Specified by:
withSessionin interfaceMongoDatabaseFactory- Parameters:
session- must not be null.- Returns:
- never null.
-
closeClient
protected abstract void closeClient()Close the client instance. -
getMongoClient
- Returns:
- the Mongo client object.
-
getDefaultDatabaseName
- Returns:
- the database name.
-