Skip to content

Commit 02eaa4c

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 7429503 commit 02eaa4c

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;
@@ -3454,7 +3453,20 @@ public void close() {
34543453
}
34553454
}
34563455

3456+
/**
3457+
* @deprecated since 3.1.4. Use {@link #getMongoDatabaseFactory()} instead.
3458+
* @return the {@link MongoDatabaseFactory} in use.
3459+
*/
3460+
@Deprecated
34573461
public MongoDatabaseFactory getMongoDbFactory() {
3462+
return getMongoDatabaseFactory();
3463+
}
3464+
3465+
/**
3466+
* @return the {@link MongoDatabaseFactory} in use.
3467+
* @since 3.1.4
3468+
*/
3469+
public MongoDatabaseFactory getMongoDatabaseFactory() {
34583470
return mongoDbFactory;
34593471
}
34603472

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

+8
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,14 @@ protected WriteConcern prepareWriteConcern(MongoAction mongoAction) {
27302730
return potentiallyForceAcknowledgedWrite(wc);
27312731
}
27322732

2733+
/**
2734+
* @return the {@link MongoDatabaseFactory} in use.
2735+
* @since 3.1.4
2736+
*/
2737+
public ReactiveMongoDatabaseFactory getMongoDatabaseFactory() {
2738+
return mongoDatabaseFactory;
2739+
}
2740+
27332741
@Nullable
27342742
private WriteConcern potentiallyForceAcknowledgedWrite(@Nullable WriteConcern wc) {
27352743

0 commit comments

Comments
 (0)