Skip to content

Commit e15bd31

Browse files
committed
#124 - Polishing.
Tighten nullability constraints. Consistent Javadoc.
1 parent 5955270 commit e15bd31

File tree

10 files changed

+61
-71
lines changed

10 files changed

+61
-71
lines changed

src/main/java/org/springframework/data/r2dbc/connectionfactory/ConnectionFactoryUtils.java

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import io.r2dbc.spi.Connection;
1919
import io.r2dbc.spi.ConnectionFactory;
2020
import reactor.core.publisher.Mono;
21-
import reactor.util.function.Tuple2;
22-
import reactor.util.function.Tuples;
2321

2422
import org.apache.commons.logging.Log;
2523
import org.apache.commons.logging.LogFactory;
@@ -61,9 +59,10 @@ private ConnectionFactoryUtils() {}
6159
* Is aware of a corresponding Connection bound to the current {@link reactor.util.context.Context}. Will bind a
6260
* Connection to the {@link reactor.util.context.Context} if transaction synchronization is active.
6361
*
64-
* @param connectionFactory the {@link io.r2dbc.spi.ConnectionFactory} to obtain Connections from
62+
* @param connectionFactory the {@link io.r2dbc.spi.ConnectionFactory} to obtain {@link io.r2dbc.spi.Connection
63+
* Connections} from.
6564
* @return a R2DBC Connection from the given {@link io.r2dbc.spi.ConnectionFactory}.
66-
* @throws DataAccessResourceFailureException if the attempt to get a {@link io.r2dbc.spi.Connection} failed
65+
* @throws DataAccessResourceFailureException if the attempt to get a {@link io.r2dbc.spi.Connection} failed.
6766
* @see #releaseConnection
6867
*/
6968
public static Mono<Connection> getConnection(ConnectionFactory connectionFactory) {
@@ -72,14 +71,14 @@ public static Mono<Connection> getConnection(ConnectionFactory connectionFactory
7271
}
7372

7473
/**
75-
* Actually obtain a R2DBC Connection from the given {@link ConnectionFactory}. Same as {@link #getConnection}, but
76-
* preserving the original exceptions.
74+
* Actually obtain a R2DBC Connection from the given {@link io.r2dbc.spi.ConnectionFactory}. Same as
75+
* {@link #getConnection}, but preserving the original exceptions.
7776
* <p>
7877
* Is aware of a corresponding Connection bound to the current {@link reactor.util.context.Context}. Will bind a
7978
* Connection to the {@link reactor.util.context.Context} if transaction synchronization is active.
8079
*
81-
* @param connectionFactory the {@link ConnectionFactory} to obtain Connections from.
82-
* @return a R2DBC {@link io.r2dbc.spi.Connection} from the given {@link ConnectionFactory}.
80+
* @param connectionFactory the {@link io.r2dbc.spi.ConnectionFactory} to obtain Connections from.
81+
* @return a R2DBC {@link io.r2dbc.spi.Connection} from the given {@link io.r2dbc.spi.ConnectionFactory}.
8382
*/
8483
public static Mono<Connection> doGetConnection(ConnectionFactory connectionFactory) {
8584

@@ -143,45 +142,44 @@ public static Mono<Connection> doGetConnection(ConnectionFactory connectionFacto
143142
}
144143

145144
/**
146-
* Actually fetch a {@link Connection} from the given {@link ConnectionFactory}, defensively turning an unexpected
147-
* {@code null} return value from {@link ConnectionFactory#create()} into an {@link IllegalStateException}.
145+
* Actually fetch a {@link io.r2dbc.spi.Connection} from the given {@link io.r2dbc.spi.ConnectionFactory}, defensively
146+
* turning an unexpected {@literal null} return value from {@link io.r2dbc.spi.ConnectionFactory#create()} into an
147+
* {@link IllegalStateException}.
148148
*
149-
* @param connectionFactory the {@link ConnectionFactory} to obtain {@link Connection}s from
150-
* @return a R2DBC {@link Connection} from the given {@link ConnectionFactory} (never {@code null})
151-
* @throws IllegalStateException if the {@link ConnectionFactory} returned a {@literal null} value.
149+
* @param connectionFactory the {@link io.r2dbc.spi.ConnectionFactory} to obtain {@link io.r2dbc.spi.Connection}s from
150+
* @return a R2DBC {@link io.r2dbc.spi.Connection} from the given {@link io.r2dbc.spi.ConnectionFactory} (never
151+
* {@literal null}).
152+
* @throws IllegalStateException if the {@link io.r2dbc.spi.ConnectionFactory} returned a {@literal null} value.
152153
* @see ConnectionFactory#create()
153154
*/
154155
private static Mono<Connection> fetchConnection(ConnectionFactory connectionFactory) {
155156
return Mono.from(connectionFactory.create());
156157
}
157158

158159
/**
159-
* Close the given {@link io.r2dbc.spi.Connection}, obtained from the given {@link ConnectionFactory}, if it is not
160-
* managed externally (that is, not bound to the thread).
160+
* Close the given {@link io.r2dbc.spi.Connection}, obtained from the given {@link io.r2dbc.spi.ConnectionFactory}, if
161+
* it is not managed externally (that is, not bound to the thread).
161162
*
162163
* @param con the {@link io.r2dbc.spi.Connection} to close if necessary.
163-
* @param connectionFactory the {@link ConnectionFactory} that the Connection was obtained from (may be
164-
* {@literal null}).
164+
* @param connectionFactory the {@link io.r2dbc.spi.ConnectionFactory} that the Connection was obtained from.
165165
* @see #getConnection
166166
*/
167-
public static Mono<Void> releaseConnection(@Nullable io.r2dbc.spi.Connection con,
168-
@Nullable ConnectionFactory connectionFactory) {
167+
public static Mono<Void> releaseConnection(io.r2dbc.spi.Connection con, ConnectionFactory connectionFactory) {
169168

170169
return doReleaseConnection(con, connectionFactory)
171170
.onErrorMap(e -> new DataAccessResourceFailureException("Failed to close R2DBC Connection", e));
172171
}
173172

174173
/**
175-
* Actually close the given {@link io.r2dbc.spi.Connection}, obtained from the given {@link ConnectionFactory}. Same
176-
* as {@link #releaseConnection}, but preserving the original exception.
174+
* Actually close the given {@link io.r2dbc.spi.Connection}, obtained from the given
175+
* {@link io.r2dbc.spi.ConnectionFactory}. Same as {@link #releaseConnection}, but preserving the original exception.
177176
*
178177
* @param connection the {@link io.r2dbc.spi.Connection} to close if necessary.
179-
* @param connectionFactory the {@link ConnectionFactory} that the Connection was obtained from (may be
180-
* {@literal null}).
178+
* @param connectionFactory the {@link io.r2dbc.spi.ConnectionFactory} that the Connection was obtained from.
181179
* @see #doGetConnection
182180
*/
183-
public static Mono<Void> doReleaseConnection(@Nullable io.r2dbc.spi.Connection connection,
184-
@Nullable ConnectionFactory connectionFactory) {
181+
public static Mono<Void> doReleaseConnection(io.r2dbc.spi.Connection connection,
182+
ConnectionFactory connectionFactory) {
185183

186184
return TransactionSynchronizationManager.forCurrentTransaction().flatMap(it -> {
187185

@@ -200,12 +198,17 @@ public static Mono<Void> doReleaseConnection(@Nullable io.r2dbc.spi.Connection c
200198
* Close the {@link io.r2dbc.spi.Connection}. Translates exceptions into the Spring hierarchy of unchecked generic
201199
* data access exceptions, simplifying calling code and making any exception that is thrown more meaningful.
202200
*
203-
* @param connectionFactory the {@link io.r2dbc.spi.ConnectionFactory} to obtain Connections from
201+
* @param connection the {@link io.r2dbc.spi.Connection} to close.
202+
* @param connectionFactory the {@link io.r2dbc.spi.ConnectionFactory} that the {@link io.r2dbc.spi.Connection} was
203+
* obtained from.
204204
* @return a R2DBC Connection from the given {@link io.r2dbc.spi.ConnectionFactory}.
205205
* @throws DataAccessResourceFailureException if the attempt to get a {@link io.r2dbc.spi.Connection} failed
206206
*/
207207
public static Mono<Void> closeConnection(Connection connection, ConnectionFactory connectionFactory) {
208208

209+
Assert.notNull(connection, "Connection must not be null!");
210+
Assert.notNull(connectionFactory, "ConnectionFactory must not be null!");
211+
209212
return doCloseConnection(connection, connectionFactory)
210213
.onErrorMap(e -> new DataAccessResourceFailureException("Failed to obtain R2DBC Connection", e));
211214
}
@@ -214,7 +217,7 @@ public static Mono<Void> closeConnection(Connection connection, ConnectionFactor
214217
* Close the {@link io.r2dbc.spi.Connection}, unless a {@link SmartConnectionFactory} doesn't want us to.
215218
*
216219
* @param connection the {@link io.r2dbc.spi.Connection} to close if necessary.
217-
* @param connectionFactory the {@link ConnectionFactory} that the Connection was obtained from.
220+
* @param connectionFactory the {@link io.r2dbc.spi.ConnectionFactory} that the Connection was obtained from.
218221
* @see Connection#close()
219222
* @see SmartConnectionFactory#shouldClose(Connection)
220223
*/
@@ -236,6 +239,7 @@ public static Mono<Void> doCloseConnection(Connection connection, @Nullable Conn
236239
/**
237240
* Obtain the {@link io.r2dbc.spi.ConnectionFactory} from the current subscriber {@link reactor.util.context.Context}.
238241
*
242+
* @param connectionFactory the {@link io.r2dbc.spi.ConnectionFactory} that the Connection was obtained from.
239243
* @see TransactionSynchronizationManager
240244
*/
241245
public static Mono<ConnectionFactory> currentConnectionFactory(ConnectionFactory connectionFactory) {
@@ -252,12 +256,13 @@ public static Mono<ConnectionFactory> currentConnectionFactory(ConnectionFactory
252256
}
253257

254258
/**
255-
* Determine whether the given two {@link Connection}s are equal, asking the target {@link Connection} in case of a
256-
* proxy. Used to detect equality even if the user passed in a raw target Connection while the held one is a proxy.
259+
* Determine whether the given two {@link io.r2dbc.spi.Connection}s are equal, asking the target
260+
* {@link io.r2dbc.spi.Connection} in case of a proxy. Used to detect equality even if the user passed in a raw target
261+
* Connection while the held one is a proxy.
257262
*
258-
* @param conHolder the {@link ConnectionHolder} for the held Connection (potentially a proxy)
259-
* @param passedInCon the {@link Connection} passed-in by the user (potentially a target {@link Connection} without
260-
* proxy)
263+
* @param conHolder the {@link .ConnectionHolder} for the held {@link io.r2dbc.spi.Connection} (potentially a proxy).
264+
* @param passedInCon the {@link io.r2dbc.spi.Connection} passed-in by the user (potentially a target
265+
* {@link io.r2dbc.spi.Connection} without proxy).
261266
* @return whether the given Connections are equal
262267
* @see #getTargetConnection
263268
*/
@@ -273,11 +278,11 @@ private static boolean connectionEquals(ConnectionHolder conHolder, Connection p
273278
}
274279

275280
/**
276-
* Return the innermost target {@link Connection} of the given {@link Connection}. If the given {@link Connection} is
277-
* a proxy, it will be unwrapped until a non-proxy {@link Connection} is found. Otherwise, the passed-in Connection
278-
* will be returned as-is.
281+
* Return the innermost target {@link io.r2dbc.spi.Connection} of the given {@link io.r2dbc.spi.Connection}. If the
282+
* given {@link io.r2dbc.spi.Connection} is a proxy, it will be unwrapped until a non-proxy
283+
* {@link io.r2dbc.spi.Connection} is found. Otherwise, the passed-in Connection will be returned as-is.
279284
*
280-
* @param con the {@link Connection} proxy to unwrap
285+
* @param con the {@link io.r2dbc.spi.Connection} proxy to unwrap
281286
* @return the innermost target Connection, or the passed-in one if no proxy
282287
* @see ConnectionProxy#getTargetConnection()
283288
*/
@@ -291,11 +296,11 @@ public static Connection getTargetConnection(Connection con) {
291296
}
292297

293298
/**
294-
* Determine the connection synchronization order to use for the given {@link ConnectionFactory}. Decreased for every
295-
* level of nesting that a {@link ConnectionFactory} has, checked through the level of
296-
* {@link DelegatingConnectionFactory} nesting.
299+
* Determine the connection synchronization order to use for the given {@link io.r2dbc.spi.ConnectionFactory}.
300+
* Decreased for every level of nesting that a {@link io.r2dbc.spi.ConnectionFactory} has, checked through the level
301+
* of {@link DelegatingConnectionFactory} nesting.
297302
*
298-
* @param connectionFactory the {@link ConnectionFactory} to check.
303+
* @param connectionFactory the {@link io.r2dbc.spi.ConnectionFactory} to check.
299304
* @return the connection synchronization order to use.
300305
* @see #CONNECTION_SYNCHRONIZATION_ORDER
301306
*/
@@ -310,22 +315,6 @@ private static int getConnectionSynchronizationOrder(ConnectionFactory connectio
310315
return order;
311316
}
312317

313-
/**
314-
* Create a {@link Connection} via the given {@link ConnectionFactory#create() factory} and return a {@link Tuple2}
315-
* associating the {@link Connection} with its creating {@link ConnectionFactory}.
316-
*
317-
* @param factory must not be {@literal null}.
318-
* @return never {@literal null}
319-
*/
320-
private static Mono<Tuple2<Connection, ConnectionFactory>> createConnection(ConnectionFactory factory) {
321-
322-
if (logger.isDebugEnabled()) {
323-
logger.debug("Fetching resumed R2DBC Connection from ConnectionFactory");
324-
}
325-
326-
return Mono.from(factory.create()).map(connection -> Tuples.of(connection, factory));
327-
}
328-
329318
/**
330319
* Callback for resource cleanup at the end of a non-native R2DBC transaction.
331320
*/

src/main/java/org/springframework/data/r2dbc/connectionfactory/ConnectionHolder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ protected boolean isTransactionActive() {
100100
}
101101

102102
/**
103-
* Override the existing Connection handle with the given {@link Connection}. Reset the handle if given {@code null}.
103+
* Override the existing Connection handle with the given {@link Connection}. Reset the handle if given
104+
* {@literal null}.
104105
* <p>
105-
* Used for releasing the {@link Connection} on suspend (with a {@code null} argument) and setting a fresh
106+
* Used for releasing the {@link Connection} on suspend (with a {@literal null} argument) and setting a fresh
106107
* {@link Connection} on resume.
107108
*/
108109
protected void setConnection(@Nullable Connection connection) {

src/main/java/org/springframework/data/r2dbc/connectionfactory/DelegatingConnectionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public ConnectionFactory unwrap() {
7878
}
7979

8080
/**
81-
* Obtain the target {@link ConnectionFactory} for actual use (never {@code null}).
81+
* Obtain the target {@link ConnectionFactory} for actual use (never {@literal null}).
8282
*/
8383
protected ConnectionFactory obtainTargetConnectionFactory() {
8484
return getTargetConnectionFactory();

src/main/java/org/springframework/data/r2dbc/connectionfactory/R2dbcTransactionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public ConnectionFactory getConnectionFactory() {
127127
/**
128128
* Obtain the {@link ConnectionFactory} for actual use.
129129
*
130-
* @return the {@link ConnectionFactory} (never {@code null})
130+
* @return the {@link ConnectionFactory} (never {@literal null})
131131
* @throws IllegalStateException in case of no ConnectionFactory set
132132
*/
133133
protected ConnectionFactory obtainConnectionFactory() {

src/main/java/org/springframework/data/r2dbc/connectionfactory/lookup/MapConnectionFactoryLookup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public MapConnectionFactoryLookup(String connectionFactoryName, ConnectionFactor
6565
* Set the {@link Map} of {@link ConnectionFactory ConnectionFactories}. The keys are {@link String Strings}, the
6666
* values are actual {@link ConnectionFactory} instances.
6767
* <p>
68-
* If the supplied {@link Map} is {@code null}, then this method call effectively has no effect.
68+
* If the supplied {@link Map} is {@literal null}, then this method call effectively has no effect.
6969
*
7070
* @param connectionFactories said {@link Map} of {@link ConnectionFactory connectionFactories}
7171
*/

src/main/java/org/springframework/data/r2dbc/core/DatabaseClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public interface DatabaseClient {
5353
*
5454
* @param sql must not be {@literal null} or empty.
5555
* @return a new {@link GenericExecuteSpec}.
56-
* @see NamedParameterExpander * @see DatabaseClient.Builder#namedParameters(boolean)
56+
* @see NamedParameterExpander
57+
* @see DatabaseClient.Builder#namedParameters(boolean)
5758
*/
5859
GenericExecuteSpec execute(String sql);
5960

src/main/java/org/springframework/data/r2dbc/core/SqlProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ public interface SqlProvider {
3131
/**
3232
* Return the SQL string for this object, i.e. typically the SQL used for creating statements.
3333
*
34-
* @return the SQL string, or {@code null}.
34+
* @return the SQL string, or {@literal null}.
3535
*/
3636
@Nullable
3737
String getSql();
38-
3938
}

src/main/java/org/springframework/data/r2dbc/dialect/BindTarget.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ public interface BindTarget {
4444
void bind(int index, Object value);
4545

4646
/**
47-
* Bind a {@code null} value.
47+
* Bind a {@literal null} value.
4848
*
4949
* @param identifier the identifier to bind to.
5050
* @param type the type of {@literal null} value.
5151
*/
5252
void bindNull(Object identifier, Class<?> type);
5353

5454
/**
55-
* Bind a {@code null} value.
55+
* Bind a {@literal null} value.
5656
*
5757
* @param index the index to bind to.
5858
* @param type the type of {@literal null} value.

src/main/java/org/springframework/data/r2dbc/dialect/Bindings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
import org.springframework.util.Assert;
3333

3434
/**
35-
* Value object representing value and {@code null} bindings for a {@link Statement} using {@link BindMarkers}. Bindings
36-
* are typically immutable.
35+
* Value object representing value and {@literal null} bindings for a {@link Statement} using {@link BindMarkers}.
36+
* Bindings are typically immutable.
3737
*
3838
* @author Mark Paluch
3939
*/

src/main/java/org/springframework/data/r2dbc/dialect/MutableBindings.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.springframework.util.Assert;
2323

2424
/**
25-
* Mutable extension to {@link Bindings} for Value and {@code null} bindings for a {@link Statement} using
25+
* Mutable extension to {@link Bindings} for Value and {@literal null} bindings for a {@link Statement} using
2626
* {@link BindMarkers}.
2727
*
2828
* @author Mark Paluch
@@ -51,7 +51,7 @@ public MutableBindings(BindMarkers markers) {
5151
* @return the next {@link BindMarker}.
5252
*/
5353
public BindMarker nextMarker() {
54-
return markers.next();
54+
return this.markers.next();
5555
}
5656

5757
/**
@@ -61,7 +61,7 @@ public BindMarker nextMarker() {
6161
* @return the next {@link BindMarker}.
6262
*/
6363
public BindMarker nextMarker(String hint) {
64-
return markers.next(hint);
64+
return this.markers.next(hint);
6565
}
6666

6767
/**

0 commit comments

Comments
 (0)