Class SimpleMongoClientDatabaseFactory
java.lang.Object
org.springframework.data.mongodb.core.MongoDatabaseFactorySupport<com.mongodb.client.MongoClient>
org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory
- All Implemented Interfaces:
DisposableBean, CodecRegistryProvider, MongoDatabaseFactory, MongoSessionProvider
public class SimpleMongoClientDatabaseFactory
extends MongoDatabaseFactorySupport<com.mongodb.client.MongoClient>
implements DisposableBean
Factory to create
MongoDatabase instances from a MongoClient instance.- Since:
- 3.0
- Author:
- Christoph Strobl
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleMongoClientDatabaseFactory(com.mongodb.client.MongoClient mongoClient, String databaseName) Creates a newSimpleMongoClientDatabaseFactoryinstance from the givenMongoClient.SimpleMongoClientDatabaseFactory(com.mongodb.ConnectionString connectionString) Creates a newSimpleMongoClientDatabaseFactoryinstance from the givenMongoClient.SimpleMongoClientDatabaseFactory(String connectionString) Creates a newSimpleMongoClientDatabaseFactoryinstance for the givenconnectionString. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidClose the client instance.protected com.mongodb.client.MongoDatabasedoGetMongoDatabase(String dbName) Get the actualMongoDatabasefrom the client.com.mongodb.client.ClientSessiongetSession(com.mongodb.ClientSessionOptions options) Obtain aClientSessionfor given ClientSessionOptions.Methods inherited from class MongoDatabaseFactorySupport
destroy, getDefaultDatabaseName, getExceptionTranslator, getMongoClient, getMongoDatabase, getMongoDatabase, setExceptionTranslator, setWriteConcern, withSessionMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CodecRegistryProvider
getCodecFor, hasCodecForMethods inherited from interface DisposableBean
destroyMethods inherited from interface MongoDatabaseFactory
getCodecRegistry, isTransactionActive, withSession
-
Constructor Details
-
SimpleMongoClientDatabaseFactory
Creates a newSimpleMongoClientDatabaseFactoryinstance for the givenconnectionString. Using this constructor will create a newMongoClientinstance that will be closed when callingMongoDatabaseFactorySupport.destroy().- Parameters:
connectionString- connection coordinates for a database connection. Must contain a database name and must not be null or empty.- See Also:
-
SimpleMongoClientDatabaseFactory
public SimpleMongoClientDatabaseFactory(com.mongodb.ConnectionString connectionString) Creates a newSimpleMongoClientDatabaseFactoryinstance from the givenMongoClient. Using this constructor will create a newMongoClientinstance that will be closed when callingMongoDatabaseFactorySupport.destroy().- Parameters:
connectionString- connection coordinates for a database connection. Must contain also a database name and not be null.
-
SimpleMongoClientDatabaseFactory
public SimpleMongoClientDatabaseFactory(com.mongodb.client.MongoClient mongoClient, String databaseName) Creates a newSimpleMongoClientDatabaseFactoryinstance from the givenMongoClient. Note that the client will not be closed when callingMongoDatabaseFactorySupport.destroy()as we assume a managed client instance that we do not want to close onMongoDatabaseFactorySupport.destroy()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 or empty.
-
-
Method Details
-
getSession
public com.mongodb.client.ClientSession getSession(com.mongodb.ClientSessionOptions options) Description copied from interface:MongoDatabaseFactoryObtain aClientSessionfor given ClientSessionOptions.- Specified by:
getSessionin interfaceMongoDatabaseFactory- Specified by:
getSessionin interfaceMongoSessionProvider- Parameters:
options- must not be null.- Returns:
- never null.
-
closeClient
protected void closeClient()Description copied from class:MongoDatabaseFactorySupportClose the client instance.- Specified by:
closeClientin classMongoDatabaseFactorySupport<com.mongodb.client.MongoClient>
-
doGetMongoDatabase
Description copied from class:MongoDatabaseFactorySupportGet the actualMongoDatabasefrom the client.- Specified by:
doGetMongoDatabasein classMongoDatabaseFactorySupport<com.mongodb.client.MongoClient>- Parameters:
dbName- must not be null or empty.- Returns:
-