Skip to content

Commit d0209e5

Browse files
committed
Nullability refinements and related polishing
1 parent 56c6618 commit d0209e5

File tree

15 files changed

+205
-349
lines changed

15 files changed

+205
-349
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
3939
* Particularly appropriate for waiting on a slowly starting Oracle database.
4040
*
4141
* @author Juergen Hoeller
42+
* @author Marten Deinum
4243
* @since 18.12.2003
4344
*/
4445
public class DatabaseStartupValidator implements InitializingBean {
@@ -59,12 +60,7 @@ public class DatabaseStartupValidator implements InitializingBean {
5960
@Nullable
6061
private DataSource dataSource;
6162

62-
/**
63-
* The query used to validate the connection
64-
* @deprecated in favor of JDBC 4.0 connection validation
65-
*/
6663
@Nullable
67-
@Deprecated
6864
private String validationQuery;
6965

7066
private int interval = DEFAULT_INTERVAL;
@@ -81,8 +77,7 @@ public void setDataSource(DataSource dataSource) {
8177

8278
/**
8379
* Set the SQL query string to use for validation.
84-
*
85-
* @deprecated in favor of the JDBC 4.0 connection validation
80+
* @deprecated as of 5.3, in favor of the JDBC 4.0 connection validation
8681
*/
8782
@Deprecated
8883
public void setValidationQuery(String validationQuery) {
@@ -148,10 +143,9 @@ public void afterPropertiesSet() {
148143
logger.debug("Validation query [" + this.validationQuery + "] threw exception", ex);
149144
}
150145
else {
151-
logger.debug(" Validation threw exception", ex);
146+
logger.debug("Validation check threw exception", ex);
152147
}
153148
}
154-
155149
if (logger.isInfoEnabled()) {
156150
float rest = ((float) (deadLine - System.currentTimeMillis())) / 1000;
157151
if (rest > this.interval) {

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ private ConnectionFactoryUtils() {}
8080
* Translates exceptions into the Spring hierarchy of unchecked generic
8181
* data access exceptions, simplifying calling code and making any
8282
* exception that is thrown more meaningful.
83-
*
8483
* <p>Is aware of a corresponding Connection bound to the current
8584
* {@link TransactionSynchronizationManager}. Will bind a Connection to the
8685
* {@link TransactionSynchronizationManager} if transaction synchronization is active.
@@ -99,7 +98,6 @@ public static Mono<Connection> getConnection(ConnectionFactory connectionFactory
9998
/**
10099
* Actually obtain a R2DBC Connection from the given {@link ConnectionFactory}.
101100
* Same as {@link #getConnection}, but preserving the original exceptions.
102-
*
103101
* <p>Is aware of a corresponding Connection bound to the current
104102
* {@link TransactionSynchronizationManager}. Will bind a Connection to the
105103
* {@link TransactionSynchronizationManager} if transaction synchronization is active
@@ -193,11 +191,9 @@ public static Mono<Void> releaseConnection(Connection con, ConnectionFactory con
193191
* @param connectionFactory the {@link ConnectionFactory} that the Connection was obtained from
194192
* @see #doGetConnection
195193
*/
196-
public static Mono<Void> doReleaseConnection(Connection connection,
197-
ConnectionFactory connectionFactory) {
194+
public static Mono<Void> doReleaseConnection(Connection connection, ConnectionFactory connectionFactory) {
198195
return TransactionSynchronizationManager.forCurrentTransaction()
199196
.flatMap(synchronizationManager -> {
200-
201197
ConnectionHolder conHolder = (ConnectionHolder) synchronizationManager.getResource(connectionFactory);
202198
if (conHolder != null && connectionEquals(conHolder, connection)) {
203199
// It's the transactional Connection: Don't close it.
@@ -235,7 +231,6 @@ public static Mono<ConnectionFactory> currentConnectionFactory(ConnectionFactory
235231
* @return the corresponding DataAccessException instance
236232
*/
237233
public static DataAccessException convertR2dbcException(String task, @Nullable String sql, R2dbcException ex) {
238-
239234
if (ex instanceof R2dbcTransientException) {
240235
if (ex instanceof R2dbcTransientResourceException) {
241236
return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
@@ -247,7 +242,6 @@ public static DataAccessException convertR2dbcException(String task, @Nullable S
247242
return new QueryTimeoutException(buildMessage(task, sql, ex), ex);
248243
}
249244
}
250-
251245
if (ex instanceof R2dbcNonTransientException) {
252246
if (ex instanceof R2dbcNonTransientResourceException) {
253247
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
@@ -262,7 +256,6 @@ public static DataAccessException convertR2dbcException(String task, @Nullable S
262256
return new BadSqlGrammarException(task, (sql != null ? sql : ""), ex);
263257
}
264258
}
265-
266259
return new UncategorizedR2dbcException(buildMessage(task, sql, ex), sql, ex);
267260
}
268261

@@ -326,7 +319,6 @@ public static Connection getTargetConnection(Connection con) {
326319
* @see #CONNECTION_SYNCHRONIZATION_ORDER
327320
*/
328321
private static int getConnectionSynchronizationOrder(ConnectionFactory connectionFactory) {
329-
330322
int order = CONNECTION_SYNCHRONIZATION_ORDER;
331323
ConnectionFactory current = connectionFactory;
332324
while (current instanceof DelegatingConnectionFactory) {
@@ -336,6 +328,7 @@ private static int getConnectionSynchronizationOrder(ConnectionFactory connectio
336328
return order;
337329
}
338330

331+
339332
/**
340333
* Callback for resource cleanup at the end of a non-native R2DBC transaction.
341334
*/
@@ -355,7 +348,6 @@ private static class ConnectionSynchronization implements TransactionSynchroniza
355348
this.order = getConnectionSynchronizationOrder(connectionFactory);
356349
}
357350

358-
359351
@Override
360352
public int getOrder() {
361353
return this.order;
@@ -387,7 +379,8 @@ public Mono<Void> suspend() {
387379
public Mono<Void> resume() {
388380
if (this.holderActive) {
389381
return TransactionSynchronizationManager.forCurrentTransaction()
390-
.doOnNext(synchronizationManager -> synchronizationManager.bindResource(this.connectionFactory, this.connectionHolder))
382+
.doOnNext(synchronizationManager ->
383+
synchronizationManager.bindResource(this.connectionFactory, this.connectionHolder))
391384
.then();
392385
}
393386
return Mono.empty();
@@ -401,8 +394,7 @@ public Mono<Void> beforeCompletion() {
401394
// to avoid issues with strict transaction implementations that expect
402395
// the close call before transaction completion.
403396
if (!this.connectionHolder.isOpen()) {
404-
return TransactionSynchronizationManager.forCurrentTransaction()
405-
.flatMap(synchronizationManager -> {
397+
return TransactionSynchronizationManager.forCurrentTransaction().flatMap(synchronizationManager -> {
406398
synchronizationManager.unbindResource(this.connectionFactory);
407399
this.holderActive = false;
408400
if (this.connectionHolder.hasConnection()) {
@@ -439,4 +431,5 @@ public Mono<Void> afterCompletion(int status) {
439431
return Mono.empty();
440432
}
441433
}
434+
442435
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public ConnectionHolder(Connection connection) {
6565
* in an ongoing transaction
6666
*/
6767
public ConnectionHolder(Connection connection, boolean transactionActive) {
68-
6968
this.currentConnection = connection;
7069
this.transactionActive = transactionActive;
7170
}
@@ -80,7 +79,6 @@ protected boolean hasConnection() {
8079

8180
/**
8281
* Set whether this holder represents an active, R2DBC-managed transaction.
83-
*
8482
* @see R2dbcTransactionManager
8583
*/
8684
protected void setTransactionActive(boolean transactionActive) {
@@ -111,7 +109,6 @@ protected void setConnection(@Nullable Connection connection) {
111109
* @see #released()
112110
*/
113111
public Connection getConnection() {
114-
115112
Assert.notNull(this.currentConnection, "Active Connection is required");
116113
return this.currentConnection;
117114
}

0 commit comments

Comments
 (0)