Skip to content

Commit 41247d4

Browse files
committed
R2DBC javadoc and code style revision
See gh-25065
1 parent 16c8676 commit 41247d4

32 files changed

+219
-375
lines changed

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java

+25-52
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import io.r2dbc.spi.R2dbcTransientException;
3030
import io.r2dbc.spi.R2dbcTransientResourceException;
3131
import io.r2dbc.spi.Wrapped;
32-
import org.apache.commons.logging.Log;
33-
import org.apache.commons.logging.LogFactory;
3432
import reactor.core.publisher.Mono;
3533

3634
import org.springframework.core.Ordered;
@@ -69,11 +67,6 @@ public abstract class ConnectionFactoryUtils {
6967
*/
7068
public static final int CONNECTION_SYNCHRONIZATION_ORDER = 1000;
7169

72-
private static final Log logger = LogFactory.getLog(ConnectionFactoryUtils.class);
73-
74-
75-
private ConnectionFactoryUtils() {}
76-
7770

7871
/**
7972
* Obtain a {@link Connection} from the given {@link ConnectionFactory}.
@@ -112,48 +105,34 @@ public static Mono<Connection> doGetConnection(ConnectionFactory connectionFacto
112105
if (conHolder != null && (conHolder.hasConnection() || conHolder.isSynchronizedWithTransaction())) {
113106
conHolder.requested();
114107
if (!conHolder.hasConnection()) {
115-
116-
if (logger.isDebugEnabled()) {
117-
logger.debug("Fetching resumed R2DBC Connection from ConnectionFactory");
118-
}
119108
return fetchConnection(connectionFactory).doOnNext(conHolder::setConnection);
120109
}
121110
return Mono.just(conHolder.getConnection());
122111
}
123112
// Else we either got no holder or an empty thread-bound holder here.
124113

125-
if (logger.isDebugEnabled()) {
126-
logger.debug("Fetching R2DBC Connection from ConnectionFactory");
127-
}
128-
129114
Mono<Connection> con = fetchConnection(connectionFactory);
130-
131115
if (synchronizationManager.isSynchronizationActive()) {
132-
133-
return con.flatMap(connection -> {
134-
return Mono.just(connection).doOnNext(conn -> {
135-
136-
// Use same Connection for further R2DBC actions within the transaction.
137-
// Thread-bound object will get removed by synchronization at transaction completion.
138-
ConnectionHolder holderToUse = conHolder;
139-
if (holderToUse == null) {
140-
holderToUse = new ConnectionHolder(conn);
141-
}
142-
else {
143-
holderToUse.setConnection(conn);
144-
}
145-
holderToUse.requested();
146-
synchronizationManager
147-
.registerSynchronization(new ConnectionSynchronization(holderToUse, connectionFactory));
148-
holderToUse.setSynchronizedWithTransaction(true);
149-
if (holderToUse != conHolder) {
150-
synchronizationManager.bindResource(connectionFactory, holderToUse);
151-
}
152-
}) // Unexpected exception from external delegation call -> close Connection and rethrow.
153-
.onErrorResume(e -> releaseConnection(connection, connectionFactory).then(Mono.error(e)));
154-
});
116+
return con.flatMap(connection -> Mono.just(connection).doOnNext(conn -> {
117+
// Use same Connection for further R2DBC actions within the transaction.
118+
// Thread-bound object will get removed by synchronization at transaction completion.
119+
ConnectionHolder holderToUse = conHolder;
120+
if (holderToUse == null) {
121+
holderToUse = new ConnectionHolder(conn);
122+
}
123+
else {
124+
holderToUse.setConnection(conn);
125+
}
126+
holderToUse.requested();
127+
synchronizationManager
128+
.registerSynchronization(new ConnectionSynchronization(holderToUse, connectionFactory));
129+
holderToUse.setSynchronizedWithTransaction(true);
130+
if (holderToUse != conHolder) {
131+
synchronizationManager.bindResource(connectionFactory, holderToUse);
132+
}
133+
}) // Unexpected exception from external delegation call -> close Connection and rethrow.
134+
.onErrorResume(e -> releaseConnection(connection, connectionFactory).then(Mono.error(e))));
155135
}
156-
157136
return con;
158137
}).onErrorResume(NoTransactionException.class, e -> Mono.from(connectionFactory.create()));
159138
}
@@ -356,9 +335,7 @@ public int getOrder() {
356335
@Override
357336
public Mono<Void> suspend() {
358337
if (this.holderActive) {
359-
return TransactionSynchronizationManager.forCurrentTransaction()
360-
.flatMap(synchronizationManager -> {
361-
338+
return TransactionSynchronizationManager.forCurrentTransaction().flatMap(synchronizationManager -> {
362339
synchronizationManager.unbindResource(this.connectionFactory);
363340
if (this.connectionHolder.hasConnection() && !this.connectionHolder.isOpen()) {
364341
// Release Connection on suspend if the application doesn't keep
@@ -371,7 +348,6 @@ public Mono<Void> suspend() {
371348
return Mono.empty();
372349
});
373350
}
374-
375351
return Mono.empty();
376352
}
377353

@@ -388,11 +364,10 @@ public Mono<Void> resume() {
388364

389365
@Override
390366
public Mono<Void> beforeCompletion() {
391-
// Release Connection early if the holder is not open anymore
392-
// (that is, not used by another resource
393-
// that has its own cleanup via transaction synchronization),
394-
// to avoid issues with strict transaction implementations that expect
395-
// the close call before transaction completion.
367+
// Release Connection early if the holder is not open anymore (that is,
368+
// not used by another resource that has its own cleanup via transaction
369+
// synchronization), to avoid issues with strict transaction implementations
370+
// that expect the close call before transaction completion.
396371
if (!this.connectionHolder.isOpen()) {
397372
return TransactionSynchronizationManager.forCurrentTransaction().flatMap(synchronizationManager -> {
398373
synchronizationManager.unbindResource(this.connectionFactory);
@@ -414,8 +389,7 @@ public Mono<Void> afterCompletion(int status) {
414389
if (this.holderActive) {
415390
// The bound ConnectionHolder might not be available anymore,
416391
// since afterCompletion might get called from a different thread.
417-
return TransactionSynchronizationManager.forCurrentTransaction()
418-
.flatMap(synchronizationManager -> {
392+
return TransactionSynchronizationManager.forCurrentTransaction().flatMap(synchronizationManager -> {
419393
synchronizationManager.unbindResourceIfPossible(this.connectionFactory);
420394
this.holderActive = false;
421395
if (this.connectionHolder.hasConnection()) {
@@ -426,7 +400,6 @@ public Mono<Void> afterCompletion(int status) {
426400
return Mono.empty();
427401
});
428402
}
429-
430403
this.connectionHolder.reset();
431404
return Mono.empty();
432405
}

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java

+15-23
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ public abstract class ScriptUtils {
107107

108108
private static final Log logger = LogFactory.getLog(ScriptUtils.class);
109109

110-
// utility constructor
111-
private ScriptUtils() {}
112110

113111
/**
114112
* Split an SQL script into separate statements delimited by the provided
@@ -335,14 +333,11 @@ private static Mono<String> readScript(EncodedResource resource, DataBufferFacto
335333

336334
return DataBufferUtils.join(DataBufferUtils.read(resource.getResource(), dataBufferFactory, 8192))
337335
.handle((it, sink) -> {
338-
339336
try (InputStream is = it.asInputStream()) {
340-
341-
InputStreamReader in = resource.getCharset() != null ? new InputStreamReader(is, resource.getCharset())
342-
: new InputStreamReader(is);
337+
InputStreamReader in = (resource.getCharset() != null ?
338+
new InputStreamReader(is, resource.getCharset()) : new InputStreamReader(is));
343339
LineNumberReader lnr = new LineNumberReader(in);
344340
String script = readScript(lnr, commentPrefixes, separator, blockCommentEndDelimiter);
345-
346341
sink.next(script);
347342
sink.complete();
348343
}
@@ -548,9 +543,9 @@ public static Mono<Void> executeSqlScript(Connection connection, EncodedResource
548543
* @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#releaseConnection
549544
*/
550545
public static Mono<Void> executeSqlScript(Connection connection, EncodedResource resource,
551-
DataBufferFactory dataBufferFactory, boolean continueOnError, boolean ignoreFailedDrops, String commentPrefix,
552-
@Nullable String separator, String blockCommentStartDelimiter, String blockCommentEndDelimiter)
553-
throws ScriptException {
546+
DataBufferFactory dataBufferFactory, boolean continueOnError, boolean ignoreFailedDrops,
547+
String commentPrefix, @Nullable String separator, String blockCommentStartDelimiter,
548+
String blockCommentEndDelimiter) throws ScriptException {
554549

555550
return executeSqlScript(connection, resource, dataBufferFactory, continueOnError,
556551
ignoreFailedDrops, new String[] { commentPrefix }, separator,
@@ -587,10 +582,10 @@ public static Mono<Void> executeSqlScript(Connection connection, EncodedResource
587582
* @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#getConnection
588583
* @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#releaseConnection
589584
*/
590-
public static Mono<Void> executeSqlScript(Connection connection, EncodedResource resource, DataBufferFactory dataBufferFactory,
591-
boolean continueOnError,
592-
boolean ignoreFailedDrops, String[] commentPrefixes, @Nullable String separator,
593-
String blockCommentStartDelimiter, String blockCommentEndDelimiter) throws ScriptException {
585+
public static Mono<Void> executeSqlScript(Connection connection, EncodedResource resource,
586+
DataBufferFactory dataBufferFactory, boolean continueOnError, boolean ignoreFailedDrops,
587+
String[] commentPrefixes, @Nullable String separator, String blockCommentStartDelimiter,
588+
String blockCommentEndDelimiter) throws ScriptException {
594589

595590
if (logger.isDebugEnabled()) {
596591
logger.debug("Executing SQL script from " + resource);
@@ -622,17 +617,15 @@ public static Mono<Void> executeSqlScript(Connection connection, EncodedResource
622617
});
623618

624619
if (logger.isDebugEnabled()) {
625-
626620
executeScript = executeScript.doOnComplete(() -> {
627-
628621
long elapsedTime = System.currentTimeMillis() - startTime;
629622
logger.debug("Executed SQL script from " + resource + " in " + elapsedTime + " ms.");
630623
});
631624
}
632625

633626
return executeScript.onErrorMap(ex -> !(ex instanceof ScriptException),
634-
ex -> new UncategorizedScriptException("Failed to execute database script from resource [" + resource + "]",
635-
ex))
627+
ex -> new UncategorizedScriptException(
628+
"Failed to execute database script from resource [" + resource + "]", ex))
636629
.then();
637630
}
638631

@@ -644,22 +637,21 @@ private static Publisher<? extends Void> runStatement(String statement, Connecti
644637
.collect(Collectors.summingLong(count -> count));
645638

646639
if (logger.isDebugEnabled()) {
647-
execution = execution.doOnNext(rowsAffected -> logger.debug(rowsAffected + " returned as update count for SQL: " + statement));
640+
execution = execution.doOnNext(rowsAffected ->
641+
logger.debug(rowsAffected + " returned as update count for SQL: " + statement));
648642
}
649643

650644
return execution.onErrorResume(ex -> {
651-
652645
boolean dropStatement = StringUtils.startsWithIgnoreCase(statement.trim(), "drop");
653646
if (continueOnError || (dropStatement && ignoreFailedDrops)) {
654647
if (logger.isDebugEnabled()) {
655-
logger.debug(ScriptStatementFailedException.buildErrorMessage(statement, statementNumber.get(), resource),
656-
ex);
648+
logger.debug(ScriptStatementFailedException.buildErrorMessage(
649+
statement, statementNumber.get(), resource), ex);
657650
}
658651
}
659652
else {
660653
return Mono.error(new ScriptStatementFailedException(statement, statementNumber.get(), resource, ex));
661654
}
662-
663655
return Mono.empty();
664656
}).then();
665657
}

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactory.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,22 @@ protected Object resolveSpecifiedLookupKey(Object lookupKey) {
167167
*/
168168
protected ConnectionFactory resolveSpecifiedConnectionFactory(Object connectionFactory)
169169
throws IllegalArgumentException {
170+
170171
if (connectionFactory instanceof ConnectionFactory) {
171172
return (ConnectionFactory) connectionFactory;
172173
}
173174
else if (connectionFactory instanceof String) {
174175
return this.connectionFactoryLookup.getConnectionFactory((String) connectionFactory);
175176
}
176177
else {
177-
throw new IllegalArgumentException(
178-
"Illegal connection factory value - only 'io.r2dbc.spi.ConnectionFactory' and 'String' supported: "
179-
+ connectionFactory);
178+
throw new IllegalArgumentException("Illegal connection factory value - " +
179+
"only 'io.r2dbc.spi.ConnectionFactory' and 'String' supported: " + connectionFactory);
180180
}
181181
}
182182

183183
@Override
184184
public Mono<Connection> create() {
185-
return determineTargetConnectionFactory() //
186-
.map(ConnectionFactory::create) //
187-
.flatMap(Mono::from);
185+
return determineTargetConnectionFactory().map(ConnectionFactory::create).flatMap(Mono::from);
188186
}
189187

190188
@Override

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/MapConnectionFactoryLookup.java

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public MapConnectionFactoryLookup(Map<String, ConnectionFactory> connectionFacto
5656

5757
/**
5858
* Create a new instance of the {@link MapConnectionFactoryLookup} class.
59-
*
6059
* @param connectionFactoryName the name under which the supplied {@link ConnectionFactory} is to be added
6160
* @param connectionFactory the {@link ConnectionFactory} to be added
6261
*/

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/BindParameterSource.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface BindParameterSource {
4646
/**
4747
* Return the parameter value for the requested named parameter.
4848
* @param paramName the name of the parameter
49-
* @return the value of the specified parameter, can be {@code null}
49+
* @return the value of the specified parameter (can be {@code null})
5050
* @throws IllegalArgumentException if there is no value
5151
* for the requested parameter
5252
*/
@@ -64,8 +64,8 @@ default Class<?> getType(String paramName) {
6464
}
6565

6666
/**
67-
* Return parameter names of the underlying parameter source.
68-
* @return parameter names of the underlying parameter source.
67+
* Return the parameter names of the underlying parameter source.
68+
* @return an iterator over the parameter names
6969
*/
7070
Iterable<String> getParameterNames();
7171

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ColumnMapRowMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*/
4949
public class ColumnMapRowMapper implements BiFunction<Row, RowMetadata, Map<String, Object>> {
5050

51-
/** Default instance. */
51+
/** A default {@code ColumnMapRowMapper} instance. */
5252
public final static ColumnMapRowMapper INSTANCE = new ColumnMapRowMapper();
5353

5454

0 commit comments

Comments
 (0)