Skip to content

Commit a33aece

Browse files
christophstroblmp911de
authored andcommitted
Allow access to mongoDatabaseFactory used in ReactiveMongoTemplate.
By offering a getter method for the ReactiveMongoDatabaseFactory users subclassing ReactiveMongoTemplate could evaluate the current transaction state via ReactiveMongoDatabaseUtils.isTransactionActive(getDatabaseFactory()). This change also aligns the reactive and imperative template implementation in that regard. Closes #3540 Original pull request: #3541.
1 parent 076d334 commit a33aece

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.bson.conversions.Bson;
2929
import org.slf4j.Logger;
3030
import org.slf4j.LoggerFactory;
31-
3231
import org.springframework.beans.BeansException;
3332
import org.springframework.context.ApplicationContext;
3433
import org.springframework.context.ApplicationContextAware;
@@ -3463,7 +3462,20 @@ public void close() {
34633462
}
34643463
}
34653464

3465+
/**
3466+
* @deprecated since 3.1.4. Use {@link #getMongoDatabaseFactory()} instead.
3467+
* @return the {@link MongoDatabaseFactory} in use.
3468+
*/
3469+
@Deprecated
34663470
public MongoDatabaseFactory getMongoDbFactory() {
3471+
return getMongoDatabaseFactory();
3472+
}
3473+
3474+
/**
3475+
* @return the {@link MongoDatabaseFactory} in use.
3476+
* @since 3.1.4
3477+
*/
3478+
public MongoDatabaseFactory getMongoDatabaseFactory() {
34673479
return mongoDbFactory;
34683480
}
34693481

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java

+8
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,14 @@ protected WriteConcern prepareWriteConcern(MongoAction mongoAction) {
27162716
return potentiallyForceAcknowledgedWrite(wc);
27172717
}
27182718

2719+
/**
2720+
* @return the {@link MongoDatabaseFactory} in use.
2721+
* @since 3.1.4
2722+
*/
2723+
public ReactiveMongoDatabaseFactory getMongoDatabaseFactory() {
2724+
return mongoDatabaseFactory;
2725+
}
2726+
27192727
@Nullable
27202728
private WriteConcern potentiallyForceAcknowledgedWrite(@Nullable WriteConcern wc) {
27212729

0 commit comments

Comments
 (0)