Skip to content

Commit 4044f4c

Browse files
committed
Polishing
1 parent a2bb59f commit 4044f4c

9 files changed

+42
-59
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,43 @@
3434
*
3535
* @author Mark Paluch
3636
* @since 5.3
37-
* @see #create
37+
* @see #create()
3838
*/
3939
public class DelegatingConnectionFactory implements ConnectionFactory, Wrapped<ConnectionFactory> {
4040

4141
private final ConnectionFactory targetConnectionFactory;
4242

4343

44+
/**
45+
* Create a new DelegatingConnectionFactory.
46+
* @param targetConnectionFactory the target ConnectionFactory
47+
*/
4448
public DelegatingConnectionFactory(ConnectionFactory targetConnectionFactory) {
4549
Assert.notNull(targetConnectionFactory, "ConnectionFactory must not be null");
4650
this.targetConnectionFactory = targetConnectionFactory;
4751
}
4852

4953

54+
/**
55+
* Return the target ConnectionFactory that this ConnectionFactory delegates to.
56+
*/
57+
public ConnectionFactory getTargetConnectionFactory() {
58+
return this.targetConnectionFactory;
59+
}
60+
5061
@Override
5162
public Mono<? extends Connection> create() {
5263
return Mono.from(this.targetConnectionFactory.create());
5364
}
5465

55-
public ConnectionFactory getTargetConnectionFactory() {
56-
return this.targetConnectionFactory;
57-
}
58-
5966
@Override
6067
public ConnectionFactoryMetadata getMetadata() {
61-
return obtainTargetConnectionFactory().getMetadata();
68+
return this.targetConnectionFactory.getMetadata();
6269
}
6370

6471
@Override
6572
public ConnectionFactory unwrap() {
66-
return obtainTargetConnectionFactory();
67-
}
68-
69-
/**
70-
* Obtain the target {@link ConnectionFactory} for actual use (never {@code null}).
71-
*/
72-
protected ConnectionFactory obtainTargetConnectionFactory() {
73-
return getTargetConnectionFactory();
73+
return this.targetConnectionFactory;
7474
}
7575

7676
}

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

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@
5858
* {@link ConnectionFactory}, avoiding the need to define such a proxy in the first place.
5959
*
6060
* <p><b>NOTE:</b> This {@link ConnectionFactory} proxy needs to return wrapped
61-
* {@link Connection}s (which implement the {@link ConnectionProxy} interface) in order
62-
* to handle close calls properly. Use {@link Wrapped#unwrap()} to retrieve
63-
* the native R2DBC Connection.
61+
* {@link Connection}s in order to handle close calls properly.
62+
* Use {@link Wrapped#unwrap()} to retrieve the native R2DBC Connection.
6463
*
6564
* @author Mark Paluch
6665
* @author Christoph Strobl
@@ -74,35 +73,28 @@ public class TransactionAwareConnectionFactoryProxy extends DelegatingConnection
7473

7574
/**
7675
* Create a new {@link TransactionAwareConnectionFactoryProxy}.
77-
*
78-
* @param targetConnectionFactory the target {@link ConnectionFactory}.
79-
* @throws IllegalArgumentException if given {@link ConnectionFactory} is {@code null}.
76+
* @param targetConnectionFactory the target {@link ConnectionFactory}
8077
*/
8178
public TransactionAwareConnectionFactoryProxy(ConnectionFactory targetConnectionFactory) {
8279
super(targetConnectionFactory);
8380
}
8481

8582

8683
/**
87-
* Delegates to {@link ConnectionFactoryUtils} for automatically participating in Spring-managed transactions.
88-
* <p>
89-
* The returned {@link ConnectionFactory} handle implements the {@link ConnectionProxy} interface, allowing to
90-
* retrieve the underlying target {@link Connection}.
91-
*
84+
* Delegates to {@link ConnectionFactoryUtils} for automatically participating
85+
* in Spring-managed transactions.
9286
* @return a transactional {@link Connection} if any, a new one else.
9387
* @see ConnectionFactoryUtils#doGetConnection
94-
* @see ConnectionProxy#getTargetConnection
9588
*/
9689
@Override
9790
public Mono<Connection> create() {
98-
return getTransactionAwareConnectionProxy(obtainTargetConnectionFactory());
91+
return getTransactionAwareConnectionProxy(getTargetConnectionFactory());
9992
}
10093

10194
/**
102-
* Wraps the given {@link Connection} with a proxy that delegates every method call to it but delegates
103-
* {@code close()} calls to {@link ConnectionFactoryUtils}.
104-
*
105-
* @param targetConnectionFactory the {@link ConnectionFactory} that the {@link Connection} came from.
95+
* Wraps the given {@link Connection} with a proxy that delegates every method call
96+
* to it but delegates {@code close()} calls to {@link ConnectionFactoryUtils}.
97+
* @param targetConnectionFactory the {@link ConnectionFactory} that the {@link Connection} came from
10698
* @return the wrapped {@link Connection}.
10799
* @see Connection#close()
108100
* @see ConnectionFactoryUtils#doReleaseConnection
@@ -113,16 +105,15 @@ protected Mono<Connection> getTransactionAwareConnectionProxy(ConnectionFactory
113105
}
114106

115107
private static Connection proxyConnection(Connection connection, ConnectionFactory targetConnectionFactory) {
116-
117108
return (Connection) Proxy.newProxyInstance(TransactionAwareConnectionFactoryProxy.class.getClassLoader(),
118-
new Class<?>[] { Connection.class, Wrapped.class },
109+
new Class<?>[] {Connection.class, Wrapped.class},
119110
new TransactionAwareInvocationHandler(connection, targetConnectionFactory));
120111
}
121112

122113

123114
/**
124-
* Invocation handler that delegates close calls on R2DBC Connections to {@link ConnectionFactoryUtils} for being
125-
* aware of context-bound transactions.
115+
* Invocation handler that delegates close calls on R2DBC Connections to
116+
* {@link ConnectionFactoryUtils} for being aware of context-bound transactions.
126117
*/
127118
private static class TransactionAwareInvocationHandler implements InvocationHandler {
128119

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ public class ConnectionFactoryInitializer implements InitializingBean, Disposabl
4747

4848

4949
/**
50-
* The {@link ConnectionFactory} for the database to populate when this component is initialized and to clean up when
51-
* this component is shut down.
52-
* <p/>
53-
* This property is mandatory with no default provided.
54-
*
50+
* The {@link ConnectionFactory} for the database to populate when this
51+
* component is initialized and to clean up when this component is shut down.
52+
* <p>This property is mandatory with no default provided.
5553
* @param connectionFactory the R2DBC {@link ConnectionFactory}.
5654
*/
5755
public void setConnectionFactory(ConnectionFactory connectionFactory) {
@@ -60,7 +58,6 @@ public void setConnectionFactory(ConnectionFactory connectionFactory) {
6058

6159
/**
6260
* Set the {@link DatabasePopulator} to execute during the bean initialization phase.
63-
*
6461
* @param databasePopulator the {@link DatabasePopulator} to use during initialization
6562
* @see #setDatabaseCleaner
6663
*/
@@ -80,16 +77,16 @@ public void setDatabaseCleaner(DatabasePopulator databaseCleaner) {
8077
}
8178

8279
/**
83-
* Flag to explicitly enable or disable the {@link #setDatabasePopulator database populator} and
84-
* {@link #setDatabaseCleaner database cleaner}.
85-
*
86-
* @param enabled {@code true} if the database populator and database cleaner should be called on startup and
87-
* shutdown, respectively
80+
* Flag to explicitly enable or disable the {@link #setDatabasePopulator database populator}
81+
* and {@link #setDatabaseCleaner database cleaner}.
82+
* @param enabled {@code true} if the database populator and database cleaner
83+
* should be called on startup and shutdown, respectively
8884
*/
8985
public void setEnabled(boolean enabled) {
9086
this.enabled = enabled;
9187
}
9288

89+
9390
/**
9491
* Use the {@link #setDatabasePopulator database populator} to set up the database.
9592
*/

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public interface DatabasePopulator {
3838
/**
3939
* Populate, initialize, or clean up the database using the
4040
* provided R2DBC {@link Connection}.
41-
*
4241
* @param connection the R2DBC connection to use to populate the db;
4342
* already configured and ready to use, must not be {@code null}
4443
* @return {@link Mono} that initiates script execution and is
@@ -53,8 +52,7 @@ public interface DatabasePopulator {
5352
* @return {@link Mono} that initiates {@link DatabasePopulator#populate(Connection)}
5453
* and is notified upon completion
5554
*/
56-
default Mono<Void> populate(ConnectionFactory connectionFactory)
57-
throws DataAccessException {
55+
default Mono<Void> populate(ConnectionFactory connectionFactory) throws DataAccessException {
5856
Assert.notNull(connectionFactory, "ConnectionFactory must not be null");
5957
return Mono.usingWhen(ConnectionFactoryUtils.getConnection(connectionFactory), //
6058
this::populate, //

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public abstract class AbstractRoutingConnectionFactory implements ConnectionFact
7676
* with the lookup key as key. The mapped value can either be a corresponding
7777
* {@link ConnectionFactory} instance or a connection factory name String (to be
7878
* resolved via a {@link #setConnectionFactoryLookup ConnectionFactoryLookup}).
79-
*
8079
* <p>The key can be of arbitrary type; this class implements the generic lookup
8180
* process only. The concrete key representation will be handled by
8281
* {@link #resolveSpecifiedLookupKey(Object)} and {@link #determineCurrentLookupKey()}.
@@ -87,11 +86,9 @@ public void setTargetConnectionFactories(Map<?, ?> targetConnectionFactories) {
8786

8887
/**
8988
* Specify the default target {@link ConnectionFactory}, if any.
90-
*
9189
* <p>The mapped value can either be a corresponding {@link ConnectionFactory}
9290
* instance or a connection factory name {@link String} (to be resolved via a
9391
* {@link #setConnectionFactoryLookup ConnectionFactoryLookup}).
94-
*
9592
* <p>This {@link ConnectionFactory} will be used as target if none of the keyed
9693
* {@link #setTargetConnectionFactories targetConnectionFactories} match the
9794
* {@link #determineCurrentLookupKey() current lookup key}.
@@ -103,11 +100,9 @@ public void setDefaultTargetConnectionFactory(Object defaultTargetConnectionFact
103100
/**
104101
* Specify whether to apply a lenient fallback to the default {@link ConnectionFactory}
105102
* if no specific {@link ConnectionFactory} could be found for the current lookup key.
106-
*
107103
* <p>Default is {@code true}, accepting lookup keys without a corresponding entry
108104
* in the target {@link ConnectionFactory} map - simply falling back to the default
109105
* {@link ConnectionFactory} in that case.
110-
*
111106
* <p>Switch this flag to {@code false} if you would prefer the fallback to only
112107
* apply when no lookup key was emitted. Lookup keys without a {@link ConnectionFactory}
113108
* entry will then lead to an {@link IllegalStateException}.
@@ -234,7 +229,6 @@ protected Mono<ConnectionFactory> determineTargetConnectionFactory() {
234229
* Determine the current lookup key. This will typically be implemented to check a
235230
* subscriber context. Allows for arbitrary keys. The returned key needs to match the
236231
* stored lookup key type, as resolved by the {@link #resolveSpecifiedLookupKey} method.
237-
*
238232
* @return {@link Mono} emitting the lookup key. May complete without emitting a value
239233
* if no lookup key available
240234
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public void setBeanFactory(BeanFactory beanFactory) {
7272
@Override
7373
public ConnectionFactory getConnectionFactory(String connectionFactoryName)
7474
throws ConnectionFactoryLookupFailureException {
75+
7576
Assert.state(this.beanFactory != null, "BeanFactory is required");
7677
try {
7778
return this.beanFactory.getBean(connectionFactoryName, ConnectionFactory.class);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public interface ConnectionFactoryLookup {
3333
* @return the {@link ConnectionFactory} (never {@code null})
3434
* @throws ConnectionFactoryLookupFailureException if the lookup failed
3535
*/
36-
ConnectionFactory getConnectionFactory(String connectionFactoryName) throws ConnectionFactoryLookupFailureException;
36+
ConnectionFactory getConnectionFactory(String connectionFactoryName)
37+
throws ConnectionFactoryLookupFailureException;
3738

3839
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ public Map<String, ConnectionFactory> getConnectionFactories() {
8686
}
8787

8888
/**
89-
* Add the supplied {@link ConnectionFactory} to the map of {@link ConnectionFactory ConnectionFactorys} maintained by
90-
* this object.
91-
*
89+
* Add the supplied {@link ConnectionFactory} to the map of
90+
* {@link ConnectionFactory ConnectionFactory} instances maintained by this object.
9291
* @param connectionFactoryName the name under which the supplied {@link ConnectionFactory} is to be added
9392
* @param connectionFactory the {@link ConnectionFactory} to be so added
9493
*/
@@ -101,6 +100,7 @@ public void addConnectionFactory(String connectionFactoryName, ConnectionFactory
101100
@Override
102101
public ConnectionFactory getConnectionFactory(String connectionFactoryName)
103102
throws ConnectionFactoryLookupFailureException {
103+
104104
Assert.notNull(connectionFactoryName, "ConnectionFactory name must not be null");
105105
return this.connectionFactories.computeIfAbsent(connectionFactoryName, key -> {
106106
throw new ConnectionFactoryLookupFailureException(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public SingleConnectionFactoryLookup(ConnectionFactory connectionFactory) {
4646
@Override
4747
public ConnectionFactory getConnectionFactory(String connectionFactoryName)
4848
throws ConnectionFactoryLookupFailureException {
49+
4950
return this.connectionFactory;
5051
}
5152

0 commit comments

Comments
 (0)