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 SummaryConstructors
- 
Method SummaryModifier 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- 
MongoDatabaseUtilspublic MongoDatabaseUtils()
 
- 
- 
Method Details- 
getDatabaseObtain the defaultdatabaseform the givenfactoryusingnative session synchronization.
 Registers aMongoDB specific transaction synchronizationwithin the currentThreadifsynchronization is active.- Parameters:
- factory- the- MongoDatabaseFactoryto get the- MongoDatabasefrom.
- Returns:
- the MongoDatabasethat is potentially associated with a transactionalClientSession.
 
- 
getDatabasepublic 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- the- MongoDatabaseFactoryto get the- MongoDatabasefrom.
- sessionSynchronization- the synchronization to use. Must not be null.
- Returns:
- the MongoDatabasethat is potentially associated with a transactionalClientSession.
 
- 
getDatabasepublic 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 the- MongoDatabaseto get.
- factory- the- MongoDatabaseFactoryto get the- MongoDatabasefrom.
- Returns:
- the MongoDatabasethat is potentially associated with a transactionalClientSession.
 
- 
getDatabasepublic 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 the- MongoDatabaseto get.
- factory- the- MongoDatabaseFactoryto get the- MongoDatabasefrom.
- sessionSynchronization- the synchronization to use. Must not be null.
- Returns:
- the MongoDatabasethat is potentially associated with a transactionalClientSession.
 
- 
isTransactionActiveCheck 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
 
 
-