|
45 | 45 | import java.security.KeyStore;
|
46 | 46 | import java.time.Duration;
|
47 | 47 | import java.util.Arrays;
|
| 48 | +import java.util.Locale; |
48 | 49 | import java.util.Optional;
|
49 | 50 | import java.util.UUID;
|
50 | 51 | import java.util.function.Function;
|
@@ -182,14 +183,14 @@ MssqlConnectionConfiguration withRedirect(Redirect redirect) {
|
182 | 183 | }
|
183 | 184 |
|
184 | 185 | return new MssqlConnectionConfiguration(this.applicationName, this.connectionId, this.connectTimeout, this.database, redirectServerName, hostNameInCertificate, this.lockWaitTimeout,
|
185 |
| - this.password, |
186 |
| - this.preferCursoredExecution, redirect.getPort(), this.sendStringParametersAsUnicode, this.ssl, this.sslContextBuilderCustomizer, |
187 |
| - this.sslTunnelSslContextBuilderCustomizer, this.tcpKeepAlive, this.tcpNoDelay, this.trustServerCertificate, this.trustStore, this.trustStoreType, this.trustStorePassword, this.username); |
| 186 | + this.password, |
| 187 | + 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); |
188 | 189 | }
|
189 | 190 |
|
190 | 191 | ClientConfiguration toClientConfiguration() {
|
191 | 192 | return new DefaultClientConfiguration(this.connectTimeout, this.host, this.hostNameInCertificate, this.port, this.ssl, this.sslContextBuilderCustomizer,
|
192 |
| - this.sslTunnelSslContextBuilderCustomizer, this.tcpKeepAlive, this.tcpNoDelay, this.trustServerCertificate, this.trustStore, this.trustStoreType, this.trustStorePassword); |
| 193 | + this.sslTunnelSslContextBuilderCustomizer, this.tcpKeepAlive, this.tcpNoDelay, this.trustServerCertificate, this.trustStore, this.trustStoreType, this.trustStorePassword); |
193 | 194 | }
|
194 | 195 |
|
195 | 196 | ConnectionOptions toConnectionOptions() {
|
@@ -354,7 +355,7 @@ public static final class Builder {
|
354 | 355 | @Nullable
|
355 | 356 | private Duration lockWaitTimeout;
|
356 | 357 |
|
357 |
| - private Predicate<String> preferCursoredExecution = sql -> false; |
| 358 | + private Predicate<String> preferCursoredExecution = DefaultCursorPreference.INSTANCE; |
358 | 359 |
|
359 | 360 | private CharSequence password;
|
360 | 361 |
|
@@ -714,11 +715,11 @@ public MssqlConnectionConfiguration build() {
|
714 | 715 | }
|
715 | 716 |
|
716 | 717 | return new MssqlConnectionConfiguration(this.applicationName, this.connectionId, this.connectTimeout, this.database, this.host, this.hostNameInCertificate, this.lockWaitTimeout,
|
717 |
| - this.password, |
718 |
| - this.preferCursoredExecution, this.port, this.sendStringParametersAsUnicode, this.ssl, this.sslContextBuilderCustomizer, |
719 |
| - this.sslTunnelSslContextBuilderCustomizer, this.tcpKeepAlive, |
720 |
| - this.tcpNoDelay, this.trustServerCertificate, this.trustStore, |
721 |
| - this.trustStoreType, this.trustStorePassword, this.username); |
| 718 | + this.password, |
| 719 | + this.preferCursoredExecution, this.port, this.sendStringParametersAsUnicode, this.ssl, this.sslContextBuilderCustomizer, |
| 720 | + this.sslTunnelSslContextBuilderCustomizer, this.tcpKeepAlive, |
| 721 | + this.tcpNoDelay, this.trustServerCertificate, this.trustStore, |
| 722 | + this.trustStoreType, this.trustStorePassword, this.username); |
722 | 723 | }
|
723 | 724 |
|
724 | 725 | }
|
@@ -887,12 +888,35 @@ public SslContext getSslContext() throws GeneralSecurityException {
|
887 | 888 | private static SslContextBuilder createSslContextBuilder() {
|
888 | 889 | SslContextBuilder sslContextBuilder = SslContextBuilder.forClient();
|
889 | 890 | sslContextBuilder.sslProvider(
|
890 |
| - OpenSsl.isAvailable() ? |
891 |
| - io.netty.handler.ssl.SslProvider.OPENSSL : |
892 |
| - io.netty.handler.ssl.SslProvider.JDK) |
893 |
| - .ciphers(null, IdentityCipherSuiteFilter.INSTANCE) |
894 |
| - .applicationProtocolConfig(null); |
| 891 | + OpenSsl.isAvailable() ? |
| 892 | + io.netty.handler.ssl.SslProvider.OPENSSL : |
| 893 | + io.netty.handler.ssl.SslProvider.JDK) |
| 894 | + .ciphers(null, IdentityCipherSuiteFilter.INSTANCE) |
| 895 | + .applicationProtocolConfig(null); |
895 | 896 | return sslContextBuilder;
|
896 | 897 | }
|
897 | 898 |
|
| 899 | + |
| 900 | + static class DefaultCursorPreference implements Predicate<String> { |
| 901 | + |
| 902 | + static final DefaultCursorPreference INSTANCE = new DefaultCursorPreference(); |
| 903 | + |
| 904 | + @Override |
| 905 | + public boolean test(String sql) { |
| 906 | + |
| 907 | + if (sql.isEmpty()) { |
| 908 | + return false; |
| 909 | + } |
| 910 | + |
| 911 | + String lc = sql.trim().toLowerCase(Locale.ENGLISH); |
| 912 | + if (lc.contains("for xml") || lc.contains("for json")) { |
| 913 | + return false; |
| 914 | + } |
| 915 | + |
| 916 | + char c = sql.charAt(0); |
| 917 | + |
| 918 | + return (c == 's' || c == 'S') && lc.startsWith("select"); |
| 919 | + } |
| 920 | + } |
| 921 | + |
898 | 922 | }
|
0 commit comments