Package org.springframework.data.mongodb
Class MongoDatabaseUtils
java.lang.Object
org.springframework.data.mongodb.MongoDatabaseUtils
Helper class for managing a
Note: Intended for internal usage only.
MongoDatabase instances via MongoDatabaseFactory. Used for obtaining
session bound resources, such as MongoDatabase and
MongoCollection suitable for transactional usage.
Note: Intended for internal usage only.
- Since:
- 2.1
- Author:
- Christoph Strobl, Mark Paluch
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.mongodb.client.MongoDatabasegetDatabase(String dbName, MongoDatabaseFactory factory) static com.mongodb.client.MongoDatabasegetDatabase(String dbName, MongoDatabaseFactory factory, SessionSynchronization sessionSynchronization) Obtain thedatabasewith given name form the givenfactory.static com.mongodb.client.MongoDatabasegetDatabase(MongoDatabaseFactory factory) static com.mongodb.client.MongoDatabasegetDatabase(MongoDatabaseFactory factory, SessionSynchronization sessionSynchronization) Obtain the defaultdatabaseform the givenfactory.static booleanisTransactionActive(MongoDatabaseFactory dbFactory) Check if theMongoDatabaseFactoryis actually bound to aClientSessionthat has an active transaction, or if aTransactionSynchronizationhas been registered for theresourceand if the associatedClientSessionhas anactive transaction.
-
Constructor Details
-
MongoDatabaseUtils
public MongoDatabaseUtils()
-
-
Method Details
-
getDatabase
Obtain the defaultdatabaseform the givenfactoryusingnative session synchronization.
Registers aMongoDB specific transaction synchronizationwithin the currentThreadifsynchronization is active.- Parameters:
factory- theMongoDatabaseFactoryto get theMongoDatabasefrom.- Returns:
- the
MongoDatabasethat is potentially associated with a transactionalClientSession.
-
getDatabase
public static com.mongodb.client.MongoDatabase getDatabase(MongoDatabaseFactory factory, SessionSynchronization sessionSynchronization) Obtain the defaultdatabaseform the givenfactory.
Registers aMongoDB specific transaction synchronizationwithin the currentThreadifsynchronization is active.- Parameters:
factory- theMongoDatabaseFactoryto get theMongoDatabasefrom.sessionSynchronization- the synchronization to use. Must not be null.- Returns:
- the
MongoDatabasethat is potentially associated with a transactionalClientSession.
-
getDatabase
public static com.mongodb.client.MongoDatabase getDatabase(@Nullable String dbName, MongoDatabaseFactory factory) Obtain thedatabasewith given name form the givenfactoryusingnative session synchronization.
Registers aMongoDB specific transaction synchronizationwithin the currentThreadifsynchronization is active.- Parameters:
dbName- the name of theMongoDatabaseto get.factory- theMongoDatabaseFactoryto get theMongoDatabasefrom.- Returns:
- the
MongoDatabasethat is potentially associated with a transactionalClientSession.
-
getDatabase
public static com.mongodb.client.MongoDatabase getDatabase(@Nullable String dbName, MongoDatabaseFactory factory, SessionSynchronization sessionSynchronization) Obtain thedatabasewith given name form the givenfactory.
Registers aMongoDB specific transaction synchronizationwithin the currentThreadifsynchronization is active.- Parameters:
dbName- the name of theMongoDatabaseto get.factory- theMongoDatabaseFactoryto get theMongoDatabasefrom.sessionSynchronization- the synchronization to use. Must not be null.- Returns:
- the
MongoDatabasethat is potentially associated with a transactionalClientSession.
-
isTransactionActive
Check if theMongoDatabaseFactoryis actually bound to aClientSessionthat has an active transaction, or if aTransactionSynchronizationhas been registered for theresourceand if the associatedClientSessionhas anactive transaction.- Parameters:
dbFactory- the resource to check transactions for. Must not be null.- Returns:
- true if the factory has an ongoing transaction.
- Since:
- 2.1.3
-