Skip to content

Commit 10e96c9

Browse files
polish some stuff
1 parent 38a8b47 commit 10e96c9

32 files changed

+244
-207
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/BindableMongoExpression.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
* A {@link MongoExpression} using the {@link ParameterBindingDocumentCodec} for parsing a raw ({@literal json})
3232
* expression. The expression will be wrapped within <code>{ ... }</code> if necessary. The actual parsing and parameter
3333
* binding of placeholders like {@code ?0} is delayed upon first call on the target {@link Document} via
34-
* {@link #toDocument()}.
35-
* <br />
34+
* {@link #toDocument()}. <br />
3635
*
3736
* <pre class="code">
3837
* $toUpper : $name -> { '$toUpper' : '$name' }
@@ -55,17 +54,17 @@ public class BindableMongoExpression implements MongoExpression {
5554

5655
private final @Nullable CodecRegistryProvider codecRegistryProvider;
5756

58-
private final Object @Nullable[] args;
57+
private final Object @Nullable [] args;
5958

6059
private final Lazy<Document> target;
6160

6261
/**
6362
* Create a new instance of {@link BindableMongoExpression}.
6463
*
6564
* @param expression must not be {@literal null}.
66-
* @param args can be {@literal null}.
65+
* @param args must not be {@literal null} but may contain {@literal null} elements.
6766
*/
68-
public BindableMongoExpression(String expression, Object @Nullable[] args) {
67+
public BindableMongoExpression(String expression, Object @Nullable [] args) {
6968
this(expression, null, args);
7069
}
7170

@@ -74,10 +73,10 @@ public BindableMongoExpression(String expression, Object @Nullable[] args) {
7473
*
7574
* @param expression must not be {@literal null}.
7675
* @param codecRegistryProvider can be {@literal null}.
77-
* @param args can be {@literal null}.
76+
* @param args must not be {@literal null} but may contain {@literal null} elements.
7877
*/
7978
public BindableMongoExpression(String expression, @Nullable CodecRegistryProvider codecRegistryProvider,
80-
Object @Nullable[] args) {
79+
Object @Nullable [] args) {
8180

8281
Assert.notNull(expression, "Expression must not be null");
8382

@@ -139,7 +138,7 @@ private Document parse() {
139138

140139
private static String wrapJsonIfNecessary(String json) {
141140

142-
if(!StringUtils.hasText(json)) {
141+
if (!StringUtils.hasText(json)) {
143142
return json;
144143
}
145144

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/BulkOperationException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class BulkOperationException extends DataAccessException {
4141
/**
4242
* Creates a new {@link BulkOperationException} with the given message and source {@link MongoBulkWriteException}.
4343
*
44-
* @param message must not be {@literal null}.
44+
* @param message can be {@literal null}.
4545
* @param source must not be {@literal null}.
4646
*/
4747
public BulkOperationException(@Nullable String message, MongoBulkWriteException source) {

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/MongoDatabaseUtils.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
/**
3030
* Helper class for managing a {@link MongoDatabase} instances via {@link MongoDatabaseFactory}. Used for obtaining
3131
* {@link ClientSession session bound} resources, such as {@link MongoDatabase} and
32-
* {@link com.mongodb.client.MongoCollection} suitable for transactional usage.
33-
* <br />
32+
* {@link com.mongodb.client.MongoCollection} suitable for transactional usage. <br />
3433
* <strong>Note:</strong> Intended for internal usage only.
3534
*
3635
* @author Christoph Strobl
@@ -42,8 +41,7 @@ public class MongoDatabaseUtils {
4241

4342
/**
4443
* Obtain the default {@link MongoDatabase database} form the given {@link MongoDatabaseFactory factory} using
45-
* {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}.
46-
* <br />
44+
* {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}. <br />
4745
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the current
4846
* {@link Thread} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
4947
*
@@ -55,8 +53,7 @@ public static MongoDatabase getDatabase(MongoDatabaseFactory factory) {
5553
}
5654

5755
/**
58-
* Obtain the default {@link MongoDatabase database} form the given {@link MongoDatabaseFactory factory}.
59-
* <br />
56+
* Obtain the default {@link MongoDatabase database} form the given {@link MongoDatabaseFactory factory}. <br />
6057
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the current
6158
* {@link Thread} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
6259
*
@@ -70,8 +67,7 @@ public static MongoDatabase getDatabase(MongoDatabaseFactory factory, SessionSyn
7067

7168
/**
7269
* Obtain the {@link MongoDatabase database} with given name form the given {@link MongoDatabaseFactory factory} using
73-
* {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}.
74-
* <br />
70+
* {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}. <br />
7571
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the current
7672
* {@link Thread} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
7773
*

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/MongoResourceHolder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323

2424
/**
2525
* MongoDB specific {@link ResourceHolderSupport resource holder}, wrapping a {@link ClientSession}.
26-
* {@link MongoTransactionManager} binds instances of this class to the thread.
27-
* <br />
26+
* {@link MongoTransactionManager} binds instances of this class to the thread. <br />
2827
* <strong>Note:</strong> Intended for internal usage only.
2928
*
3029
* @author Christoph Strobl

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/MongoTransactionManager.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,15 @@
3636

3737
/**
3838
* A {@link org.springframework.transaction.PlatformTransactionManager} implementation that manages
39-
* {@link ClientSession} based transactions for a single {@link MongoDatabaseFactory}.
40-
* <br />
41-
* Binds a {@link ClientSession} from the specified {@link MongoDatabaseFactory} to the thread.
42-
* <br />
39+
* {@link ClientSession} based transactions for a single {@link MongoDatabaseFactory}. <br />
40+
* Binds a {@link ClientSession} from the specified {@link MongoDatabaseFactory} to the thread. <br />
4341
* {@link TransactionDefinition#isReadOnly() Readonly} transactions operate on a {@link ClientSession} and enable causal
4442
* consistency, and also {@link ClientSession#startTransaction() start}, {@link ClientSession#commitTransaction()
45-
* commit} or {@link ClientSession#abortTransaction() abort} a transaction.
46-
* <br />
43+
* commit} or {@link ClientSession#abortTransaction() abort} a transaction. <br />
4744
* Application code is required to retrieve the {@link com.mongodb.client.MongoDatabase} via
4845
* {@link MongoDatabaseUtils#getDatabase(MongoDatabaseFactory)} instead of a standard
4946
* {@link MongoDatabaseFactory#getMongoDatabase()} call. Spring classes such as
50-
* {@link org.springframework.data.mongodb.core.MongoTemplate} use this strategy implicitly.
51-
* <br />
47+
* {@link org.springframework.data.mongodb.core.MongoTemplate} use this strategy implicitly. <br />
5248
* By default failure of a {@literal commit} operation raises a {@link TransactionSystemException}. One may override
5349
* {@link #doCommit(MongoTransactionObject)} to implement the
5450
* <a href="https://docs.mongodb.com/manual/core/transactions/#retry-commit-operation">Retry Commit Operation</a>
@@ -153,7 +149,8 @@ protected void doBegin(Object transaction, TransactionDefinition definition) thr
153149
}
154150

155151
try {
156-
MongoTransactionOptions mongoTransactionOptions = transactionOptionsResolver.resolve(definition).mergeWith(options);
152+
MongoTransactionOptions mongoTransactionOptions = transactionOptionsResolver.resolve(definition)
153+
.mergeWith(options);
157154
mongoTransactionObject.startTransaction(mongoTransactionOptions.toDriverOptions());
158155
} catch (MongoException ex) {
159156
throw new TransactionSystemException(String.format("Could not start Mongo transaction for session %s.",
@@ -208,6 +205,7 @@ protected final void doCommit(DefaultTransactionStatus status) throws Transactio
208205
* By default those labels are ignored, nevertheless one might check for
209206
* {@link MongoException#UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL transient commit errors labels} and retry the the
210207
* commit. <br />
208+
*
211209
* <pre>
212210
* <code>
213211
* int retries = 3;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/MongoTransactionOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ default <T> T map(Function<MongoTransactionOptions, T> mappingFunction) {
149149
/**
150150
* Factory method to wrap given MongoDB driver native {@link TransactionOptions} into {@link MongoTransactionOptions}.
151151
*
152-
* @param options
152+
* @param options can be {@literal null}.
153153
* @return {@link MongoTransactionOptions#NONE} if given object is {@literal null}.
154154
*/
155155
static MongoTransactionOptions of(@Nullable TransactionOptions options) {

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/ReactiveMongoDatabaseUtils.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
package org.springframework.data.mongodb;
1717

1818
import reactor.core.publisher.Mono;
19-
20-
import org.jspecify.annotations.Nullable;
2119
import reactor.util.context.Context;
2220

21+
import org.jspecify.annotations.Nullable;
2322
import org.springframework.transaction.NoTransactionException;
2423
import org.springframework.transaction.reactive.ReactiveResourceSynchronization;
2524
import org.springframework.transaction.reactive.TransactionSynchronization;
@@ -36,8 +35,7 @@
3635
/**
3736
* Helper class for managing reactive {@link MongoDatabase} instances via {@link ReactiveMongoDatabaseFactory}. Used for
3837
* obtaining {@link ClientSession session bound} resources, such as {@link MongoDatabase} and {@link MongoCollection}
39-
* suitable for transactional usage.
40-
* <br />
38+
* suitable for transactional usage. <br />
4139
* <strong>Note:</strong> Intended for internal usage only.
4240
*
4341
* @author Mark Paluch
@@ -75,8 +73,7 @@ public static Mono<Boolean> isTransactionActive(ReactiveMongoDatabaseFactory dat
7573

7674
/**
7775
* Obtain the default {@link MongoDatabase database} form the given {@link ReactiveMongoDatabaseFactory factory} using
78-
* {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}.
79-
* <br />
76+
* {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}. <br />
8077
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the subscriber
8178
* {@link Context} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
8279
*
@@ -104,12 +101,12 @@ public static Mono<MongoDatabase> getDatabase(ReactiveMongoDatabaseFactory facto
104101

105102
/**
106103
* Obtain the {@link MongoDatabase database} with given name form the given {@link ReactiveMongoDatabaseFactory
107-
* factory} using {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}.
108-
* <br />
104+
* factory} using {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}. <br />
109105
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the subscriber
110106
* {@link Context} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
111107
*
112-
* @param dbName the name of the {@link MongoDatabase} to get.
108+
* @param dbName the name of the {@link MongoDatabase} to get. If {@literal null} the default database of the
109+
* {@link ReactiveMongoDatabaseFactory}.
113110
* @param factory the {@link ReactiveMongoDatabaseFactory} to get the {@link MongoDatabase} from.
114111
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
115112
*/
@@ -119,17 +116,17 @@ public static Mono<MongoDatabase> getDatabase(@Nullable String dbName, ReactiveM
119116

120117
/**
121118
* Obtain the {@link MongoDatabase database} with given name form the given {@link ReactiveMongoDatabaseFactory
122-
* factory}.
123-
* <br />
119+
* factory}. <br />
124120
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the subscriber
125121
* {@link Context} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
126122
*
127-
* @param dbName the name of the {@link MongoDatabase} to get.
123+
* @param dbName the name of the {@link MongoDatabase} to get. If {@literal null} the default database of the *
124+
* {@link ReactiveMongoDatabaseFactory}.
128125
* @param factory the {@link ReactiveMongoDatabaseFactory} to get the {@link MongoDatabase} from.
129126
* @param sessionSynchronization the synchronization to use. Must not be {@literal null}.
130127
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
131128
*/
132-
public static Mono<MongoDatabase> getDatabase(String dbName, ReactiveMongoDatabaseFactory factory,
129+
public static Mono<MongoDatabase> getDatabase(@Nullable String dbName, ReactiveMongoDatabaseFactory factory,
133130
SessionSynchronization sessionSynchronization) {
134131
return doGetMongoDatabase(dbName, factory, sessionSynchronization);
135132
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/ReactiveMongoResourceHolder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323

2424
/**
2525
* MongoDB specific resource holder, wrapping a {@link ClientSession}. {@link ReactiveMongoTransactionManager} binds
26-
* instances of this class to the subscriber context.
27-
* <br />
26+
* instances of this class to the subscriber context. <br />
2827
* <strong>Note:</strong> Intended for internal usage only.
2928
*
3029
* @author Mark Paluch

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/ReactiveMongoTransactionManager.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
public class ReactiveMongoTransactionManager extends AbstractReactiveTransactionManager implements InitializingBean {
6565

6666
private @Nullable ReactiveMongoDatabaseFactory databaseFactory;
67-
private @Nullable MongoTransactionOptions options;
67+
private MongoTransactionOptions options;
6868
private final MongoTransactionOptionsResolver transactionOptionsResolver;
6969

7070
/**
@@ -79,7 +79,9 @@ public class ReactiveMongoTransactionManager extends AbstractReactiveTransaction
7979
* @see #setDatabaseFactory(ReactiveMongoDatabaseFactory)
8080
*/
8181
public ReactiveMongoTransactionManager() {
82+
8283
this.transactionOptionsResolver = MongoTransactionOptionsResolver.defaultResolver();
84+
this.options = MongoTransactionOptions.NONE;
8385
}
8486

8587
/**
@@ -98,7 +100,7 @@ public ReactiveMongoTransactionManager(ReactiveMongoDatabaseFactory databaseFact
98100
* starting a new transaction.
99101
*
100102
* @param databaseFactory must not be {@literal null}.
101-
* @param options can be {@literal null}.
103+
* @param options can be {@literal null}. Will default {@link MongoTransactionOptions#NONE} if {@literal null}.
102104
*/
103105
public ReactiveMongoTransactionManager(ReactiveMongoDatabaseFactory databaseFactory,
104106
@Nullable TransactionOptions options) {
@@ -112,7 +114,8 @@ public ReactiveMongoTransactionManager(ReactiveMongoDatabaseFactory databaseFact
112114
*
113115
* @param databaseFactory must not be {@literal null}.
114116
* @param transactionOptionsResolver must not be {@literal null}.
115-
* @param defaultTransactionOptions can be {@literal null}.
117+
* @param defaultTransactionOptions can be {@literal null}. Will default {@link MongoTransactionOptions#NONE} if
118+
* {@literal null}.
116119
* @since 4.3
117120
*/
118121
public ReactiveMongoTransactionManager(ReactiveMongoDatabaseFactory databaseFactory,
@@ -124,7 +127,7 @@ public ReactiveMongoTransactionManager(ReactiveMongoDatabaseFactory databaseFact
124127

125128
this.databaseFactory = databaseFactory;
126129
this.transactionOptionsResolver = transactionOptionsResolver;
127-
this.options = defaultTransactionOptions;
130+
this.options = defaultTransactionOptions != null ? defaultTransactionOptions : MongoTransactionOptions.NONE;
128131
}
129132

130133
@Override

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/SessionAwareMethodInterceptor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434

3535
/**
3636
* {@link MethodInterceptor} implementation looking up and invoking an alternative target method having
37-
* {@link ClientSession} as its first argument. This allows seamless integration with the existing code base.
38-
* <br />
37+
* {@link ClientSession} as its first argument. This allows seamless integration with the existing code base. <br />
3938
* The {@link MethodInterceptor} is aware of methods on {@code MongoCollection} that my return new instances of itself
4039
* like (eg. {@link com.mongodb.reactivestreams.client.MongoCollection#withWriteConcern(WriteConcern)} and decorate them
4140
* if not already proxied.

0 commit comments

Comments
 (0)