Class SimpleReactiveMongoDatabaseFactory
java.lang.Object
org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory
- All Implemented Interfaces:
DisposableBean, CodecRegistryProvider, ReactiveMongoClusterCapable, ReactiveMongoDatabaseFactory
public class SimpleReactiveMongoDatabaseFactory
extends Object
implements DisposableBean, ReactiveMongoDatabaseFactory, ReactiveMongoClusterCapable
Factory to create
MongoDatabase instances from a MongoClient instance.- Since:
- 2.0
- Author:
- Mark Paluch, Christoph Strobl, Mathieu Ouellet
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleReactiveMongoDatabaseFactory(ConnectionString connectionString) Creates a newSimpleReactiveMongoDatabaseFactoryinstance from the givenConnectionString.SimpleReactiveMongoDatabaseFactory(MongoClient mongoClient, String databaseName) Creates a newSimpleReactiveMongoDatabaseFactoryinstance from the givenMongoClient. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Clean up the Mongo instance if it was created by the factory itself.Get the underlyingCodecRegistryused by the reactive MongoDB Java driver.Exposes a sharedMongoExceptionTranslator.Return theMongoClusterassociated with this component.Creates a defaultMongoDatabaseinstance.getMongoDatabase(String dbName) Obtain aMongoDatabaseinstance to access the database with the given name.getSession(ClientSessionOptions options) voidsetExceptionTranslator(PersistenceExceptionTranslator exceptionTranslator) Configures thePersistenceExceptionTranslatorto be used.voidsetWriteConcern(WriteConcern writeConcern) Configures theWriteConcernto be used on theMongoDatabaseinstance being created.withSession(ClientSession session) Obtain aClientSessionbound instance ofReactiveMongoDatabaseFactoryreturningMongoDatabaseinstances that are aware and bound to the given session.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CodecRegistryProvider
getCodecFor, hasCodecForMethods inherited from interface ReactiveMongoDatabaseFactory
isTransactionActive
-
Constructor Details
-
SimpleReactiveMongoDatabaseFactory
Creates a newSimpleReactiveMongoDatabaseFactoryinstance from the givenConnectionString. Using this constructor will create a newMongoClientinstance that will be closed when callingdestroy().- Parameters:
connectionString- must not be null.
-
SimpleReactiveMongoDatabaseFactory
Creates a newSimpleReactiveMongoDatabaseFactoryinstance from the givenMongoClient. Note that the client will not be closed when callingdestroy()as we assume a managed client instance that we do not want to close ondestroy()meaning that you (or the application container) must dispose the client instance once it is no longer required for use.- Parameters:
mongoClient- must not be null.databaseName- must not be null.- Since:
- 1.7
-
-
Method Details
-
setExceptionTranslator
Configures thePersistenceExceptionTranslatorto be used.- Parameters:
exceptionTranslator- the exception translator to set.- Since:
- 4.4
-
getMongoCluster
Description copied from interface:ReactiveMongoClusterCapableReturn theMongoClusterassociated with this component.- Specified by:
getMongoClusterin interfaceReactiveMongoClusterCapable
-
getExceptionTranslator
Description copied from interface:ReactiveMongoDatabaseFactoryExposes a sharedMongoExceptionTranslator.- Specified by:
getExceptionTranslatorin interfaceReactiveMongoDatabaseFactory- Returns:
- will never be null.
-
setWriteConcern
Configures theWriteConcernto be used on theMongoDatabaseinstance being created.- Parameters:
writeConcern- the writeConcern to set
-
getMongoDatabase
Description copied from interface:ReactiveMongoDatabaseFactoryCreates a defaultMongoDatabaseinstance.- Specified by:
getMongoDatabasein interfaceReactiveMongoDatabaseFactory- Returns:
- never null.
- Throws:
DataAccessException
-
getMongoDatabase
Description copied from interface:ReactiveMongoDatabaseFactoryObtain aMongoDatabaseinstance to access the database with the given name.- Specified by:
getMongoDatabasein interfaceReactiveMongoDatabaseFactory- Parameters:
dbName- must not be null or empty.- Returns:
- never null.
- Throws:
DataAccessException
-
destroy
Clean up the Mongo instance if it was created by the factory itself.- Specified by:
destroyin interfaceDisposableBean- Throws:
Exception- See Also:
-
getCodecRegistry
Description copied from interface:ReactiveMongoDatabaseFactoryGet the underlyingCodecRegistryused by the reactive MongoDB Java driver.- Specified by:
getCodecRegistryin interfaceCodecRegistryProvider- Specified by:
getCodecRegistryin interfaceReactiveMongoDatabaseFactory- Returns:
- never null.
-
getSession
Description copied from interface:ReactiveMongoDatabaseFactory- Specified by:
getSessionin interfaceReactiveMongoDatabaseFactory- Parameters:
options- must not be null.- Returns:
- never null.
-
withSession
Description copied from interface:ReactiveMongoDatabaseFactoryObtain aClientSessionbound instance ofReactiveMongoDatabaseFactoryreturningMongoDatabaseinstances that are aware and bound to the given session.- Specified by:
withSessionin interfaceReactiveMongoDatabaseFactory- Parameters:
session- must not be null.- Returns:
- never null.
-