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
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.mongodb.client.MongoDatabase
getDatabase
(String dbName, MongoDatabaseFactory factory) static com.mongodb.client.MongoDatabase
getDatabase
(String dbName, MongoDatabaseFactory factory, SessionSynchronization sessionSynchronization) Obtain thedatabase
with given name form the givenfactory
.static com.mongodb.client.MongoDatabase
getDatabase
(MongoDatabaseFactory factory) static com.mongodb.client.MongoDatabase
getDatabase
(MongoDatabaseFactory factory, SessionSynchronization sessionSynchronization) Obtain the defaultdatabase
form the givenfactory
.static boolean
isTransactionActive
(MongoDatabaseFactory dbFactory) Check if theMongoDatabaseFactory
is actually bound to aClientSession
that has an active transaction, or if aTransactionSynchronization
has been registered for theresource
and if the associatedClientSession
has anactive transaction
.
-
Constructor Details
-
MongoDatabaseUtils
public MongoDatabaseUtils()
-
-
Method Details
-
getDatabase
Obtain the defaultdatabase
form the givenfactory
usingnative session synchronization
.
Registers aMongoDB specific transaction synchronization
within the currentThread
ifsynchronization is active
.- Parameters:
factory
- theMongoDatabaseFactory
to get theMongoDatabase
from.- Returns:
- the
MongoDatabase
that is potentially associated with a transactionalClientSession
.
-
getDatabase
public static com.mongodb.client.MongoDatabase getDatabase(MongoDatabaseFactory factory, SessionSynchronization sessionSynchronization) Obtain the defaultdatabase
form the givenfactory
.
Registers aMongoDB specific transaction synchronization
within the currentThread
ifsynchronization is active
.- Parameters:
factory
- theMongoDatabaseFactory
to get theMongoDatabase
from.sessionSynchronization
- the synchronization to use. Must not be null.- Returns:
- the
MongoDatabase
that is potentially associated with a transactionalClientSession
.
-
getDatabase
public static com.mongodb.client.MongoDatabase getDatabase(@Nullable String dbName, MongoDatabaseFactory factory) Obtain thedatabase
with given name form the givenfactory
usingnative session synchronization
.
Registers aMongoDB specific transaction synchronization
within the currentThread
ifsynchronization is active
.- Parameters:
dbName
- the name of theMongoDatabase
to get.factory
- theMongoDatabaseFactory
to get theMongoDatabase
from.- Returns:
- the
MongoDatabase
that is potentially associated with a transactionalClientSession
.
-
getDatabase
public static com.mongodb.client.MongoDatabase getDatabase(@Nullable String dbName, MongoDatabaseFactory factory, SessionSynchronization sessionSynchronization) Obtain thedatabase
with given name form the givenfactory
.
Registers aMongoDB specific transaction synchronization
within the currentThread
ifsynchronization is active
.- Parameters:
dbName
- the name of theMongoDatabase
to get.factory
- theMongoDatabaseFactory
to get theMongoDatabase
from.sessionSynchronization
- the synchronization to use. Must not be null.- Returns:
- the
MongoDatabase
that is potentially associated with a transactionalClientSession
.
-
isTransactionActive
Check if theMongoDatabaseFactory
is actually bound to aClientSession
that has an active transaction, or if aTransactionSynchronization
has been registered for theresource
and if the associatedClientSession
has 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
-