@@ -86,6 +86,8 @@ public final class MssqlConnectionConfiguration {
86
86
87
87
private final Predicate <String > preferCursoredExecution ;
88
88
89
+ private final PreparedStatementCache preparedStatementCache ;
90
+
89
91
@ Nullable
90
92
private final Duration lockWaitTimeout ;
91
93
@@ -118,8 +120,8 @@ public final class MssqlConnectionConfiguration {
118
120
private final String username ;
119
121
120
122
private MssqlConnectionConfiguration (@ Nullable String applicationName , @ Nullable UUID connectionId , Duration connectTimeout , @ Nullable String database , String host , String hostNameInCertificate ,
121
- @ Nullable Duration lockWaitTimeout , CharSequence password , Predicate <String > preferCursoredExecution , int port , boolean sendStringParametersAsUnicode ,
122
- boolean ssl ,
123
+ @ Nullable Duration lockWaitTimeout , CharSequence password , Predicate <String > preferCursoredExecution , PreparedStatementCache preparedStatementCache ,
124
+ int port , boolean sendStringParametersAsUnicode , boolean ssl ,
123
125
Function <SslContextBuilder , SslContextBuilder > sslContextBuilderCustomizer ,
124
126
@ Nullable Function <SslContextBuilder , SslContextBuilder > sslTunnelSslContextBuilderCustomizer , boolean tcpKeepAlive , boolean tcpNoDelay ,
125
127
boolean trustServerCertificate , @ Nullable File trustStore , @ Nullable String trustStoreType ,
@@ -134,6 +136,7 @@ private MssqlConnectionConfiguration(@Nullable String applicationName, @Nullable
134
136
this .lockWaitTimeout = lockWaitTimeout ;
135
137
this .password = Assert .requireNonNull (password , "password must not be null" );
136
138
this .preferCursoredExecution = Assert .requireNonNull (preferCursoredExecution , "preferCursoredExecution must not be null" );
139
+ this .preparedStatementCache = Assert .requireNonNull (preparedStatementCache , "preparedStatementCache must not be null" );
137
140
this .port = port ;
138
141
this .sendStringParametersAsUnicode = sendStringParametersAsUnicode ;
139
142
this .ssl = ssl ;
@@ -182,7 +185,7 @@ MssqlConnectionConfiguration withRedirect(Redirect redirect) {
182
185
183
186
return new MssqlConnectionConfiguration (this .applicationName , this .connectionId , this .connectTimeout , this .database , redirectServerName , hostNameInCertificate , this .lockWaitTimeout ,
184
187
this .password ,
185
- this .preferCursoredExecution , redirect .getPort (), this .sendStringParametersAsUnicode , this .ssl , this .sslContextBuilderCustomizer ,
188
+ this .preferCursoredExecution , this . preparedStatementCache , redirect .getPort (), this .sendStringParametersAsUnicode , this .ssl , this .sslContextBuilderCustomizer ,
186
189
this .sslTunnelSslContextBuilderCustomizer , this .tcpKeepAlive , this .tcpNoDelay , this .trustServerCertificate , this .trustStore , this .trustStoreType , this .trustStorePassword , this .username );
187
190
}
188
191
@@ -192,7 +195,7 @@ ClientConfiguration toClientConfiguration() {
192
195
}
193
196
194
197
ConnectionOptions toConnectionOptions () {
195
- return new ConnectionOptions (this .preferCursoredExecution , new DefaultCodecs (), new IndefinitePreparedStatementCache () , this .sendStringParametersAsUnicode );
198
+ return new ConnectionOptions (this .preferCursoredExecution , new DefaultCodecs (), this . preparedStatementCache , this .sendStringParametersAsUnicode );
196
199
}
197
200
198
201
@ Override
@@ -355,6 +358,8 @@ public static final class Builder {
355
358
356
359
private Predicate <String > preferCursoredExecution = sql -> false ;
357
360
361
+ private PreparedStatementCache preparedStatementCache = new IndefinitePreparedStatementCache ();
362
+
358
363
private CharSequence password ;
359
364
360
365
private int port = DEFAULT_PORT ;
@@ -551,6 +556,17 @@ public Builder preferCursoredExecution(Predicate<String> preference) {
551
556
return this ;
552
557
}
553
558
559
+ /**
560
+ * Configures the {@link PreparedStatementCache}. By default, uses {@link IndefinitePreparedStatementCache}.
561
+ *
562
+ * @param cache the cache implementation to use (must not be null).
563
+ * @return this {@link Builder}
564
+ */
565
+ public Builder preparedStatementCache (PreparedStatementCache cache ) {
566
+ this .preparedStatementCache = Assert .requireNonNull (cache , "Prepared statement cache must not be null" );
567
+ return this ;
568
+ }
569
+
554
570
/**
555
571
* Configure the port. Defaults to {@code 5432}.
556
572
*
@@ -714,7 +730,7 @@ public MssqlConnectionConfiguration build() {
714
730
715
731
return new MssqlConnectionConfiguration (this .applicationName , this .connectionId , this .connectTimeout , this .database , this .host , this .hostNameInCertificate , this .lockWaitTimeout ,
716
732
this .password ,
717
- this .preferCursoredExecution , this .port , this .sendStringParametersAsUnicode , this .ssl , this .sslContextBuilderCustomizer ,
733
+ this .preferCursoredExecution , this .preparedStatementCache , this . port , this .sendStringParametersAsUnicode , this .ssl , this .sslContextBuilderCustomizer ,
718
734
this .sslTunnelSslContextBuilderCustomizer , this .tcpKeepAlive ,
719
735
this .tcpNoDelay , this .trustServerCertificate , this .trustStore ,
720
736
this .trustStoreType , this .trustStorePassword , this .username );
0 commit comments