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
ConstructorDescriptionSimpleMongoClientDatabaseFactory
(com.mongodb.client.MongoClient mongoClient, String databaseName) Creates a newSimpleMongoClientDatabaseFactory
instance from the givenMongoClient
.SimpleMongoClientDatabaseFactory
(com.mongodb.ConnectionString connectionString) Creates a newSimpleMongoClientDatabaseFactory
instance from the givenMongoClient
.SimpleMongoClientDatabaseFactory
(String connectionString) Creates a newSimpleMongoClientDatabaseFactory
instance for the givenconnectionString
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Close the client instance.protected com.mongodb.client.MongoDatabase
doGetMongoDatabase
(String dbName) Get the actualMongoDatabase
from the client.com.mongodb.client.ClientSession
getSession
(com.mongodb.ClientSessionOptions options) Obtain aClientSession
for given ClientSessionOptions.Methods inherited from class org.springframework.data.mongodb.core.MongoDatabaseFactorySupport
destroy, getDefaultDatabaseName, getExceptionTranslator, getMongoClient, getMongoDatabase, getMongoDatabase, setWriteConcern, withSession
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.beans.factory.DisposableBean
destroy
Methods inherited from interface org.springframework.data.mongodb.MongoDatabaseFactory
getCodecRegistry, isTransactionActive, withSession
-
Constructor Details
-
SimpleMongoClientDatabaseFactory
Creates a newSimpleMongoClientDatabaseFactory
instance for the givenconnectionString
.- 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 newSimpleMongoClientDatabaseFactory
instance from the givenMongoClient
.- 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 newSimpleMongoClientDatabaseFactory
instance from the givenMongoClient
.- 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:MongoDatabaseFactory
Obtain aClientSession
for given ClientSessionOptions.- Specified by:
getSession
in interfaceMongoDatabaseFactory
- Specified by:
getSession
in interfaceMongoSessionProvider
- Parameters:
options
- must not be null.- Returns:
- never null.
-
closeClient
protected void closeClient()Description copied from class:MongoDatabaseFactorySupport
Close the client instance.- Specified by:
closeClient
in classMongoDatabaseFactorySupport<com.mongodb.client.MongoClient>
-
doGetMongoDatabase
Description copied from class:MongoDatabaseFactorySupport
Get the actualMongoDatabase
from the client.- Specified by:
doGetMongoDatabase
in classMongoDatabaseFactorySupport<com.mongodb.client.MongoClient>
- Parameters:
dbName
- must not be null or empty.- Returns:
-