@@ -119,13 +119,16 @@ public final class MssqlConnectionConfiguration {
119119
120120 private final String username ;
121121
122+ @ Nullable
123+ private final ConnectionProvider connectionProvider ;
124+
122125 private MssqlConnectionConfiguration (@ Nullable String applicationName , @ Nullable UUID connectionId , Duration connectTimeout , @ Nullable String database , String host , String hostNameInCertificate ,
123126 @ Nullable Duration lockWaitTimeout , CharSequence password , Predicate <String > preferCursoredExecution , int port , boolean sendStringParametersAsUnicode ,
124127 boolean ssl ,
125128 Function <SslContextBuilder , SslContextBuilder > sslContextBuilderCustomizer ,
126129 @ Nullable Function <SslContextBuilder , SslContextBuilder > sslTunnelSslContextBuilderCustomizer , boolean tcpKeepAlive , boolean tcpNoDelay ,
127130 boolean trustServerCertificate , @ Nullable File trustStore , @ Nullable String trustStoreType ,
128- @ Nullable char [] trustStorePassword , String username ) {
131+ @ Nullable char [] trustStorePassword , String username , @ Nullable ConnectionProvider connectionProvider ) {
129132
130133 this .applicationName = applicationName ;
131134 this .connectionId = connectionId ;
@@ -148,6 +151,7 @@ private MssqlConnectionConfiguration(@Nullable String applicationName, @Nullable
148151 this .trustStoreType = trustStoreType ;
149152 this .trustStorePassword = trustStorePassword ;
150153 this .username = Assert .requireNonNull (username , "username must not be null" );
154+ this .connectionProvider = connectionProvider ;
151155 }
152156
153157 /**
@@ -185,12 +189,14 @@ MssqlConnectionConfiguration withRedirect(Redirect redirect) {
185189 return new MssqlConnectionConfiguration (this .applicationName , this .connectionId , this .connectTimeout , this .database , redirectServerName , hostNameInCertificate , this .lockWaitTimeout ,
186190 this .password ,
187191 this .preferCursoredExecution , redirect .getPort (), this .sendStringParametersAsUnicode , this .ssl , this .sslContextBuilderCustomizer ,
188- this .sslTunnelSslContextBuilderCustomizer , this .tcpKeepAlive , this .tcpNoDelay , this .trustServerCertificate , this .trustStore , this .trustStoreType , this .trustStorePassword , this .username );
192+ this .sslTunnelSslContextBuilderCustomizer , this .tcpKeepAlive , this .tcpNoDelay , this .trustServerCertificate , this .trustStore , this .trustStoreType , this .trustStorePassword , this .username ,
193+ this .connectionProvider );
189194 }
190195
191196 ClientConfiguration toClientConfiguration () {
192197 return new DefaultClientConfiguration (this .connectTimeout , this .host , this .hostNameInCertificate , this .port , this .ssl , this .sslContextBuilderCustomizer ,
193- this .sslTunnelSslContextBuilderCustomizer , this .tcpKeepAlive , this .tcpNoDelay , this .trustServerCertificate , this .trustStore , this .trustStoreType , this .trustStorePassword );
198+ this .sslTunnelSslContextBuilderCustomizer , this .tcpKeepAlive , this .tcpNoDelay , this .trustServerCertificate , this .trustStore , this .trustStoreType , this .trustStorePassword ,
199+ this .connectionProvider );
194200 }
195201
196202 ConnectionOptions toConnectionOptions () {
@@ -387,6 +393,9 @@ public static final class Builder {
387393 @ Nullable
388394 private char [] trustStorePassword ;
389395
396+ @ Nullable
397+ private ConnectionProvider connectionProvider ;
398+
390399 private Builder () {
391400 }
392401
@@ -703,6 +712,18 @@ public Builder username(String username) {
703712 return this ;
704713 }
705714
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+
706727 /**
707728 * Returns a configured {@link MssqlConnectionConfiguration}.
708729 *
@@ -719,7 +740,7 @@ public MssqlConnectionConfiguration build() {
719740 this .preferCursoredExecution , this .port , this .sendStringParametersAsUnicode , this .ssl , this .sslContextBuilderCustomizer ,
720741 this .sslTunnelSslContextBuilderCustomizer , this .tcpKeepAlive ,
721742 this .tcpNoDelay , this .trustServerCertificate , this .trustStore ,
722- this .trustStoreType , this .trustStorePassword , this .username );
743+ this .trustStoreType , this .trustStorePassword , this .username , this . connectionProvider );
723744 }
724745
725746 }
@@ -756,10 +777,14 @@ static class DefaultClientConfiguration implements ClientConfiguration {
756777 @ Nullable
757778 private final char [] trustStorePassword ;
758779
780+ @ Nullable
781+ private final ConnectionProvider connectionProvider ;
782+
759783 DefaultClientConfiguration (Duration connectTimeout , String host , String hostNameInCertificate , int port , boolean ssl ,
760784 Function <SslContextBuilder , SslContextBuilder > sslContextBuilderCustomizer ,
761785 @ Nullable Function <SslContextBuilder , SslContextBuilder > sslTunnelSslContextBuilderCustomizer , boolean tcpKeepAlive , boolean tcpNoDelay ,
762- boolean trustServerCertificate , @ Nullable File trustStore , @ Nullable String trustStoreType , @ Nullable char [] trustStorePassword ) {
786+ boolean trustServerCertificate , @ Nullable File trustStore , @ Nullable String trustStoreType , @ Nullable char [] trustStorePassword ,
787+ ConnectionProvider connectionProvider ) {
763788
764789 this .connectTimeout = connectTimeout ;
765790 this .host = host ;
@@ -774,6 +799,7 @@ static class DefaultClientConfiguration implements ClientConfiguration {
774799 this .trustStore = trustStore ;
775800 this .trustStoreType = trustStoreType ;
776801 this .trustStorePassword = trustStorePassword ;
802+ this .connectionProvider = connectionProvider ;
777803 }
778804
779805 @ Override
@@ -803,7 +829,8 @@ public boolean isTcpNoDelay() {
803829
804830 @ Override
805831 public ConnectionProvider getConnectionProvider () {
806- return ConnectionProvider .newConnection ();
832+ return Optional .ofNullable (connectionProvider )
833+ .orElseGet (ConnectionProvider ::newConnection );
807834 }
808835
809836 @ Override
0 commit comments