Class SimpleReactiveMongoDatabaseFactory
java.lang.Object
org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory
- All Implemented Interfaces:
DisposableBean, CodecRegistryProvider, ReactiveMongoDatabaseFactory
public class SimpleReactiveMongoDatabaseFactory
extends Object
implements DisposableBean, ReactiveMongoDatabaseFactory
Factory to create
MongoDatabase instances from a MongoClient instance.- Since:
- 2.0
- Author:
- Mark Paluch, Christoph Strobl, Mathieu Ouellet
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleReactiveMongoDatabaseFactory(com.mongodb.ConnectionString connectionString) Creates a newSimpleReactiveMongoDatabaseFactoryinstance from the givenConnectionString.SimpleReactiveMongoDatabaseFactory(com.mongodb.reactivestreams.client.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.org.bson.codecs.configuration.CodecRegistryGet the underlyingCodecRegistryused by the reactive MongoDB Java driver.Exposes a sharedMongoExceptionTranslator.Mono<com.mongodb.reactivestreams.client.MongoDatabase> Creates a defaultMongoDatabaseinstance.Mono<com.mongodb.reactivestreams.client.MongoDatabase> getMongoDatabase(String dbName) Obtain aMongoDatabaseinstance to access the database with the given name.Mono<com.mongodb.reactivestreams.client.ClientSession> getSession(com.mongodb.ClientSessionOptions options) voidsetExceptionTranslator(PersistenceExceptionTranslator exceptionTranslator) Configures thePersistenceExceptionTranslatorto be used.voidsetWriteConcern(com.mongodb.WriteConcern writeConcern) Configures theWriteConcernto be used on theMongoDatabaseinstance being created.withSession(com.mongodb.reactivestreams.client.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
public SimpleReactiveMongoDatabaseFactory(com.mongodb.ConnectionString connectionString) 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
public SimpleReactiveMongoDatabaseFactory(com.mongodb.reactivestreams.client.MongoClient mongoClient, String databaseName) 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
-
getExceptionTranslator
Description copied from interface:ReactiveMongoDatabaseFactoryExposes a sharedMongoExceptionTranslator.- Specified by:
getExceptionTranslatorin interfaceReactiveMongoDatabaseFactory- 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
public Mono<com.mongodb.reactivestreams.client.MongoDatabase> getMongoDatabase() throws DataAccessExceptionDescription copied from interface:ReactiveMongoDatabaseFactoryCreates a defaultMongoDatabaseinstance.- Specified by:
getMongoDatabasein interfaceReactiveMongoDatabaseFactory- Returns:
- never null.
- Throws:
DataAccessException
-
getMongoDatabase
public Mono<com.mongodb.reactivestreams.client.MongoDatabase> getMongoDatabase(String dbName) throws DataAccessException 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
public org.bson.codecs.configuration.CodecRegistry 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
public Mono<com.mongodb.reactivestreams.client.ClientSession> getSession(com.mongodb.ClientSessionOptions options) Description copied from interface:ReactiveMongoDatabaseFactory- Specified by:
getSessionin interfaceReactiveMongoDatabaseFactory- Parameters:
options- must not be null.- Returns:
- never null.
-
withSession
public ReactiveMongoDatabaseFactory withSession(com.mongodb.reactivestreams.client.ClientSession session) 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.
-