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
Not intended to be used directly.
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
ModifierConstructorDescriptionprotected
MongoDatabaseFactorySupport
(C mongoClient, String databaseName, boolean mongoInstanceCreated, PersistenceExceptionTranslator exceptionTranslator) Create a newMongoDatabaseFactorySupport
object givenmongoClient
,databaseName
,mongoInstanceCreated
andPersistenceExceptionTranslator
. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
Close the client instance.void
destroy()
protected abstract com.mongodb.client.MongoDatabase
doGetMongoDatabase
(String dbName) Get the actualMongoDatabase
from the client.protected String
Exposes a sharedMongoExceptionTranslator
.protected C
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.void
setWriteConcern
(com.mongodb.WriteConcern writeConcern) Configures theWriteConcern
to be used on theMongoDatabase
instance being created.withSession
(com.mongodb.client.ClientSession session) Obtain aClientSession
bound instance ofMongoDatabaseFactory
returningMongoDatabase
instances 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, wait
Methods inherited from interface org.springframework.data.mongodb.CodecRegistryProvider
getCodecFor, hasCodecFor
Methods 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 newMongoDatabaseFactorySupport
object givenmongoClient
,databaseName
,mongoInstanceCreated
andPersistenceExceptionTranslator
.- Parameters:
mongoClient
- must not be null.databaseName
- must not be null or empty.mongoInstanceCreated
- true if the client instance was created by a subclass ofMongoDatabaseFactorySupport
to close the client ondestroy()
.exceptionTranslator
- must not be null.
-
-
Method Details
-
setWriteConcern
public void setWriteConcern(com.mongodb.WriteConcern writeConcern) Configures theWriteConcern
to be used on theMongoDatabase
instance being created.- Parameters:
writeConcern
- the writeConcern to set
-
getMongoDatabase
Description copied from interface:MongoDatabaseFactory
Obtain aMongoDatabase
from the underlying factory.- Specified by:
getMongoDatabase
in interfaceMongoDatabaseFactory
- Returns:
- never null.
- Throws:
DataAccessException
-
getMongoDatabase
Description copied from interface:MongoDatabaseFactory
Obtain aMongoDatabase
instance to access the database with the given name.- Specified by:
getMongoDatabase
in interfaceMongoDatabaseFactory
- Parameters:
dbName
- must not be null.- Returns:
- never null.
- Throws:
DataAccessException
-
doGetMongoDatabase
Get the actualMongoDatabase
from the client.- Parameters:
dbName
- must not be null or empty.- Returns:
-
destroy
- Throws:
Exception
-
getExceptionTranslator
Description copied from interface:MongoDatabaseFactory
Exposes a sharedMongoExceptionTranslator
.- Specified by:
getExceptionTranslator
in interfaceMongoDatabaseFactory
- Returns:
- will never be null.
-
withSession
Description copied from interface:MongoDatabaseFactory
Obtain aClientSession
bound instance ofMongoDatabaseFactory
returningMongoDatabase
instances that are aware and bound to the given session.- Specified by:
withSession
in 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.
-