Skip to content

Commit a71d0c2

Browse files
christophstroblmp911de
authored andcommitted
polish some stuff
1 parent 754c183 commit a71d0c2

32 files changed

+242
-205
lines changed

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

+7-8
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

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

+1-1
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) {

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

+4-8
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
*

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

+1-2
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

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

+7-9
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;

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

+1-1
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) {

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

+10-13
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
}

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

+1-2
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

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

+7-4
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

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

+1-2
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.

Diff for: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/SimpleMongoTransactionOptions.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public String toString() {
115115
});
116116
}
117117

118-
private static <T> @Nullable T getValue(Map<String, String> options, OptionKey key, Function<String, T> convertFunction) {
118+
private static <T> @Nullable T getValue(Map<String, String> options, OptionKey key,
119+
Function<String, T> convertFunction) {
119120

120121
String value = options.get(key.getKey());
121122
return value != null ? convertFunction.apply(value) : null;

Diff for: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/aot/MongoRuntimeHints.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.mongodb.aot;
1717

18-
import static org.springframework.data.mongodb.aot.MongoAotPredicates.*;
18+
import static org.springframework.data.mongodb.aot.MongoAotPredicates.isReactorPresent;
1919

2020
import java.util.Arrays;
2121

Diff for: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoConfigurationSupport.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public abstract class MongoConfigurationSupport {
5353
/**
5454
* Return the name of the database to connect to.
5555
*
56-
* @return must not be {@literal null}.
56+
* @return never {@literal null}.
5757
*/
5858
protected abstract String getDatabaseName();
5959

@@ -77,7 +77,7 @@ protected Collection<String> getMappingBasePackages() {
7777
* Creates a {@link MongoMappingContext} equipped with entity classes scanned from the mapping base package.
7878
*
7979
* @see #getMappingBasePackages()
80-
* @return
80+
* @return never {@literal null}.
8181
*/
8282
@Bean
8383
public MongoMappingContext mongoMappingContext(MongoCustomConversions customConversions,
@@ -176,8 +176,7 @@ protected Set<Class<?>> scanForEntities(String basePackage) throws ClassNotFound
176176
String beanClassName = candidate.getBeanClassName();
177177
Assert.notNull(beanClassName, "BeanClassName cannot be null");
178178

179-
initialEntitySet
180-
.add(ClassUtils.forName(beanClassName, MongoConfigurationSupport.class.getClassLoader()));
179+
initialEntitySet.add(ClassUtils.forName(beanClassName, MongoConfigurationSupport.class.getClassLoader()));
181180
}
182181
}
183182

Diff for: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/ServerAddressPropertyEditor.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void setAsText(@Nullable String replicaSetString) {
8383
private @Nullable ServerAddress parseServerAddress(String source) {
8484

8585
if (!StringUtils.hasText(source)) {
86-
if(LOG.isWarnEnabled()) {
86+
if (LOG.isWarnEnabled()) {
8787
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "source", source));
8888
}
8989
return null;
@@ -92,7 +92,7 @@ public void setAsText(@Nullable String replicaSetString) {
9292
String[] hostAndPort = extractHostAddressAndPort(source.trim());
9393

9494
if (hostAndPort.length > 2) {
95-
if(LOG.isWarnEnabled()) {
95+
if (LOG.isWarnEnabled()) {
9696
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "source", source));
9797
}
9898
return null;
@@ -104,11 +104,11 @@ public void setAsText(@Nullable String replicaSetString) {
104104

105105
return port == null ? new ServerAddress(hostAddress) : new ServerAddress(hostAddress, port);
106106
} catch (UnknownHostException e) {
107-
if(LOG.isWarnEnabled()) {
107+
if (LOG.isWarnEnabled()) {
108108
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "host", hostAndPort[0]));
109109
}
110110
} catch (NumberFormatException e) {
111-
if(LOG.isWarnEnabled()) {
111+
if (LOG.isWarnEnabled()) {
112112
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "port", hostAndPort[1]));
113113
}
114114
}

0 commit comments

Comments
 (0)