Skip to content

Commit 05f724d

Browse files
committed
Polishing.
Reorder methods, reduce nullability, add author tags. [#291][resolves #292] Signed-off-by: Mark Paluch <[email protected]>
1 parent 162bce5 commit 05f724d

4 files changed

Lines changed: 73 additions & 81 deletions

File tree

README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,31 @@ Mono<Connection> connectionMono = Mono.from(connectionFactory.create());
6464

6565
**Supported ConnectionFactory Discovery Options**
6666

67-
| Option | Description
68-
| ----------------- | -----------
69-
| `ssl` | Whether to use transport-level encryption for the entire SQL server traffic.
70-
| `driver` | Must be `sqlserver`.
71-
| `host` | Server hostname to connect to.
72-
| `port` | Server port to connect to. Defaults to `1433`. _(Optional)_
73-
| `username` | Login username.
74-
| `password` | Login password.
75-
| `database` | Initial database to select. Defaults to SQL Server user profile settings. _(Optional)_
76-
| `applicationName` | Name of the application. Defaults to driver name and version. _(Optional)_
77-
| `connectionId` | Connection Id for tracing purposes. Defaults to a random Id. _(Optional)_
78-
| `connectTimeout` | Connection Id for tracing purposes. Defaults to 30 seconds. _(Optional)_
79-
| `hostNameInCertificate` | Expected hostname in SSL certificate. Supports wildcards (e.g. `*.database.windows.net`). _(Optional)_
80-
| `lockWaitTimeout` | Lock wait timeout using `SET LOCK_TIMEOUT …`. _(Optional)_
81-
| `preferCursoredExecution` | Whether to prefer cursors or direct execution for queries. Uses by default direct. Cursors require more round-trips but are more backpressure-friendly. Defaults to direct execution. Can be `boolean` or a `Predicate<String>` accepting the SQL query. _(Optional)_
82-
| `sendStringParametersAsUnicode` | Configure whether to send character data as unicode (NVARCHAR, NCHAR, NTEXT) or whether to use the database encoding, defaults to `true`. If disabled, `CharSequence` data is sent using the database-specific collation such as ASCII/MBCS instead of Unicode.
83-
| `sslTunnel` | Enables SSL tunnel usage when using a SSL tunnel or SSL terminator in front of SQL Server. Accepts `Function<SslContextBuilder, SslContextBuilder>` to customize the SSL tunnel settings. SSL tunneling is not related to SQL Server's built-in SSL support. _(Optional)_
84-
| `sslContextBuilderCustomizer` | SSL Context customizer to configure SQL Server's built-in SSL support (`Function<SslContextBuilder, SslContextBuilder>`) _(Optional)_
85-
| `tcpKeepAlive` | Enable/disable TCP KeepAlive. Disabled by default. _(Optional)_
86-
| `tcpNoDelay` | Enable/disable TCP NoDelay. Enabled by default. _(Optional)_
87-
| `trustServerCertificate` | Fully trust the server certificate bypassing X.509 certificate validation. Disabled by default. _(Optional)_
88-
| `trustStoreType` | Type of the TrustStore. Defaults to `KeyStore.getDefaultType()`. _(Optional)_
89-
| `trustStore` | Path to the certificate TrustStore file. _(Optional)_
90-
| `trustStorePassword` | Password used to check the integrity of the TrustStore data. _(Optional)_
91-
| `connectionProvider` | Set the `reactor.netty.resources.ConnectionProvider` to be used when creating the connection. Defaults to `ConnectionProvider.newConnection()`. _(Optional)_ |
67+
| Option | Description
68+
|---------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
69+
| `ssl` | Whether to use transport-level encryption for the entire SQL server traffic.
70+
| `driver` | Must be `sqlserver`.
71+
| `host` | Server hostname to connect to.
72+
| `port` | Server port to connect to. Defaults to `1433`. _(Optional)_
73+
| `username` | Login username.
74+
| `password` | Login password.
75+
| `database` | Initial database to select. Defaults to SQL Server user profile settings. _(Optional)_
76+
| `applicationName` | Name of the application. Defaults to driver name and version. _(Optional)_
77+
| `connectionId` | Connection Id for tracing purposes. Defaults to a random Id. _(Optional)_
78+
| `connectionProvider` | Set the `reactor.netty.resources.ConnectionProvider` to be used when creating the connection. Defaults to `ConnectionProvider.newConnection()`. _(Optional)_
79+
| `connectTimeout` | Connection Id for tracing purposes. Defaults to 30 seconds. _(Optional)_
80+
| `hostNameInCertificate` | Expected hostname in SSL certificate. Supports wildcards (e.g. `*.database.windows.net`). _(Optional)_
81+
| `lockWaitTimeout` | Lock wait timeout using `SET LOCK_TIMEOUT …`. _(Optional)_
82+
| `preferCursoredExecution` | Whether to prefer cursors or direct execution for queries. Uses by default direct. Cursors require more round-trips but are more backpressure-friendly. Defaults to direct execution. Can be `boolean` or a `Predicate<String>` accepting the SQL query. _(Optional)_
83+
| `sendStringParametersAsUnicode` | Configure whether to send character data as unicode (NVARCHAR, NCHAR, NTEXT) or whether to use the database encoding, defaults to `true`. If disabled, `CharSequence` data is sent using the database-specific collation such as ASCII/MBCS instead of Unicode.
84+
| `sslTunnel` | Enables SSL tunnel usage when using a SSL tunnel or SSL terminator in front of SQL Server. Accepts `Function<SslContextBuilder, SslContextBuilder>` to customize the SSL tunnel settings. SSL tunneling is not related to SQL Server's built-in SSL support. _(Optional)_
85+
| `sslContextBuilderCustomizer` | SSL Context customizer to configure SQL Server's built-in SSL support (`Function<SslContextBuilder, SslContextBuilder>`) _(Optional)_
86+
| `tcpKeepAlive` | Enable/disable TCP KeepAlive. Disabled by default. _(Optional)_
87+
| `tcpNoDelay` | Enable/disable TCP NoDelay. Enabled by default. _(Optional)_
88+
| `trustServerCertificate` | Fully trust the server certificate bypassing X.509 certificate validation. Disabled by default. _(Optional)_
89+
| `trustStoreType` | Type of the TrustStore. Defaults to `KeyStore.getDefaultType()`. _(Optional)_
90+
| `trustStore` | Path to the certificate TrustStore file. _(Optional)_
91+
| `trustStorePassword` | Password used to check the integrity of the TrustStore data. _(Optional)_
9292

9393

9494
**Programmatic Configuration**

src/main/java/io/r2dbc/mssql/MssqlConnectionConfiguration.java

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
*
5858
* @author Mark Paluch
5959
* @author Alex Stockinger
60+
* @author Paul Johe
6061
*/
6162
public final class MssqlConnectionConfiguration {
6263

@@ -73,6 +74,8 @@ public final class MssqlConnectionConfiguration {
7374
@Nullable
7475
private final String applicationName;
7576

77+
private final ConnectionProvider connectionProvider;
78+
7679
@Nullable
7780
private final UUID connectionId;
7881

@@ -119,19 +122,17 @@ public final class MssqlConnectionConfiguration {
119122

120123
private final String username;
121124

122-
@Nullable
123-
private final ConnectionProvider connectionProvider;
124-
125-
private MssqlConnectionConfiguration(@Nullable String applicationName, @Nullable UUID connectionId, Duration connectTimeout, @Nullable String database, String host, String hostNameInCertificate,
125+
private MssqlConnectionConfiguration(@Nullable String applicationName, @Nullable UUID connectionId, ConnectionProvider connectionProvider, Duration connectTimeout, @Nullable String database, String host, String hostNameInCertificate,
126126
@Nullable Duration lockWaitTimeout, CharSequence password, Predicate<String> preferCursoredExecution, int port, boolean sendStringParametersAsUnicode,
127127
boolean ssl,
128128
Function<SslContextBuilder, SslContextBuilder> sslContextBuilderCustomizer,
129129
@Nullable Function<SslContextBuilder, SslContextBuilder> sslTunnelSslContextBuilderCustomizer, boolean tcpKeepAlive, boolean tcpNoDelay,
130130
boolean trustServerCertificate, @Nullable File trustStore, @Nullable String trustStoreType,
131-
@Nullable char[] trustStorePassword, String username, @Nullable ConnectionProvider connectionProvider) {
131+
@Nullable char[] trustStorePassword, String username) {
132132

133133
this.applicationName = applicationName;
134134
this.connectionId = connectionId;
135+
this.connectionProvider = connectionProvider;
135136
this.connectTimeout = Assert.requireNonNull(connectTimeout, "connect timeout must not be null");
136137
this.database = database;
137138
this.host = Assert.requireNonNull(host, "host must not be null");
@@ -151,7 +152,6 @@ private MssqlConnectionConfiguration(@Nullable String applicationName, @Nullable
151152
this.trustStoreType = trustStoreType;
152153
this.trustStorePassword = trustStorePassword;
153154
this.username = Assert.requireNonNull(username, "username must not be null");
154-
this.connectionProvider = connectionProvider;
155155
}
156156

157157
/**
@@ -186,17 +186,17 @@ MssqlConnectionConfiguration withRedirect(Redirect redirect) {
186186
}
187187
}
188188

189-
return new MssqlConnectionConfiguration(this.applicationName, this.connectionId, this.connectTimeout, this.database, redirectServerName, hostNameInCertificate, this.lockWaitTimeout,
189+
return new MssqlConnectionConfiguration(this.applicationName, this.connectionId, this.connectionProvider, this.connectTimeout, this.database, redirectServerName, hostNameInCertificate, this.lockWaitTimeout,
190190
this.password,
191191
this.preferCursoredExecution, redirect.getPort(), this.sendStringParametersAsUnicode, this.ssl, this.sslContextBuilderCustomizer,
192-
this.sslTunnelSslContextBuilderCustomizer, this.tcpKeepAlive, this.tcpNoDelay, this.trustServerCertificate, this.trustStore, this.trustStoreType, this.trustStorePassword, this.username,
193-
this.connectionProvider);
192+
this.sslTunnelSslContextBuilderCustomizer, this.tcpKeepAlive, this.tcpNoDelay, this.trustServerCertificate, this.trustStore, this.trustStoreType, this.trustStorePassword, this.username
193+
);
194194
}
195195

196196
ClientConfiguration toClientConfiguration() {
197-
return new DefaultClientConfiguration(this.connectTimeout, this.host, this.hostNameInCertificate, this.port, this.ssl, this.sslContextBuilderCustomizer,
198-
this.sslTunnelSslContextBuilderCustomizer, this.tcpKeepAlive, this.tcpNoDelay, this.trustServerCertificate, this.trustStore, this.trustStoreType, this.trustStorePassword,
199-
this.connectionProvider);
197+
return new DefaultClientConfiguration(this.connectionProvider, this.connectTimeout, this.host, this.hostNameInCertificate, this.port, this.ssl, this.sslContextBuilderCustomizer,
198+
this.sslTunnelSslContextBuilderCustomizer, this.tcpKeepAlive, this.tcpNoDelay, this.trustServerCertificate, this.trustStore, this.trustStoreType, this.trustStorePassword
199+
);
200200
}
201201

202202
ConnectionOptions toConnectionOptions() {
@@ -348,6 +348,8 @@ public static final class Builder {
348348
@Nullable
349349
private String applicationName;
350350

351+
private ConnectionProvider connectionProvider = ConnectionProvider.newConnection();
352+
351353
private UUID connectionId = UUID.randomUUID();
352354

353355
private Duration connectTimeout = DEFAULT_CONNECT_TIMEOUT;
@@ -393,9 +395,6 @@ public static final class Builder {
393395
@Nullable
394396
private char[] trustStorePassword;
395397

396-
@Nullable
397-
private ConnectionProvider connectionProvider;
398-
399398
private Builder() {
400399
}
401400

@@ -423,6 +422,19 @@ public Builder connectionId(UUID connectionId) {
423422
return this;
424423
}
425424

425+
/**
426+
* Configure the {@link ConnectionProvider} to be used with Reactor Netty.
427+
* Defaults to {@link ConnectionProvider#newConnection()}.
428+
*
429+
* @param connectionProvider the connection provider
430+
* @return this {@link Builder}
431+
* @since 1.0.3
432+
*/
433+
public Builder connectionProvider(ConnectionProvider connectionProvider) {
434+
this.connectionProvider = Assert.requireNonNull(connectionProvider, "connectionProvider must not be null");
435+
return this;
436+
}
437+
426438
/**
427439
* Configure the connect timeout. Defaults to 30 seconds.
428440
*
@@ -712,18 +724,6 @@ public Builder username(String username) {
712724
return this;
713725
}
714726

715-
/**
716-
* Configure the {@link ConnectionProvider} to be used with Netty
717-
*
718-
* @param connectionProvider the connection provider
719-
* @return this {@link Builder}
720-
* @since 1.1.0
721-
*/
722-
public Builder connectionProvider(ConnectionProvider connectionProvider) {
723-
this.connectionProvider = connectionProvider;
724-
return this;
725-
}
726-
727727
/**
728728
* Returns a configured {@link MssqlConnectionConfiguration}.
729729
*
@@ -735,18 +735,20 @@ public MssqlConnectionConfiguration build() {
735735
this.hostNameInCertificate = this.host;
736736
}
737737

738-
return new MssqlConnectionConfiguration(this.applicationName, this.connectionId, this.connectTimeout, this.database, this.host, this.hostNameInCertificate, this.lockWaitTimeout,
738+
return new MssqlConnectionConfiguration(this.applicationName, this.connectionId, this.connectionProvider, this.connectTimeout, this.database, this.host, this.hostNameInCertificate, this.lockWaitTimeout,
739739
this.password,
740740
this.preferCursoredExecution, this.port, this.sendStringParametersAsUnicode, this.ssl, this.sslContextBuilderCustomizer,
741741
this.sslTunnelSslContextBuilderCustomizer, this.tcpKeepAlive,
742742
this.tcpNoDelay, this.trustServerCertificate, this.trustStore,
743-
this.trustStoreType, this.trustStorePassword, this.username, this.connectionProvider);
743+
this.trustStoreType, this.trustStorePassword, this.username);
744744
}
745745

746746
}
747747

748748
static class DefaultClientConfiguration implements ClientConfiguration {
749749

750+
private final ConnectionProvider connectionProvider;
751+
750752
private final Duration connectTimeout;
751753

752754
private final String host;
@@ -777,14 +779,10 @@ static class DefaultClientConfiguration implements ClientConfiguration {
777779
@Nullable
778780
private final char[] trustStorePassword;
779781

780-
@Nullable
781-
private final ConnectionProvider connectionProvider;
782-
783-
DefaultClientConfiguration(Duration connectTimeout, String host, String hostNameInCertificate, int port, boolean ssl,
782+
DefaultClientConfiguration(ConnectionProvider connectionProvider, Duration connectTimeout, String host, String hostNameInCertificate, int port, boolean ssl,
784783
Function<SslContextBuilder, SslContextBuilder> sslContextBuilderCustomizer,
785784
@Nullable Function<SslContextBuilder, SslContextBuilder> sslTunnelSslContextBuilderCustomizer, boolean tcpKeepAlive, boolean tcpNoDelay,
786-
boolean trustServerCertificate, @Nullable File trustStore, @Nullable String trustStoreType, @Nullable char[] trustStorePassword,
787-
ConnectionProvider connectionProvider) {
785+
boolean trustServerCertificate, @Nullable File trustStore, @Nullable String trustStoreType, @Nullable char[] trustStorePassword) {
788786

789787
this.connectTimeout = connectTimeout;
790788
this.host = host;
@@ -829,8 +827,7 @@ public boolean isTcpNoDelay() {
829827

830828
@Override
831829
public ConnectionProvider getConnectionProvider() {
832-
return Optional.ofNullable(connectionProvider)
833-
.orElseGet(ConnectionProvider::newConnection);
830+
return this.connectionProvider;
834831
}
835832

836833
@Override

0 commit comments

Comments
 (0)