2525
2626import javax .net .ssl .HostnameVerifier ;
2727import java .net .Socket ;
28+ import java .nio .file .Path ;
29+ import java .nio .file .Paths ;
2830import java .time .Duration ;
2931import java .time .ZoneId ;
3032import java .util .ArrayList ;
@@ -89,6 +91,11 @@ public final class MySqlConnectionConfiguration {
8991 @ Nullable
9092 private final Predicate <String > preferPrepareStatement ;
9193
94+ @ Nullable
95+ private final Path loadLocalInfilePath ;
96+
97+ private final int localInfileBufferSize ;
98+
9299 private final int queryCacheSize ;
93100
94101 private final int prepareCacheSize ;
@@ -104,6 +111,7 @@ private MySqlConnectionConfiguration(
104111 @ Nullable Duration socketTimeout , ZeroDateOption zeroDateOption , @ Nullable ZoneId serverZoneId ,
105112 String user , @ Nullable CharSequence password , @ Nullable String database ,
106113 boolean createDatabaseIfNotExist , @ Nullable Predicate <String > preferPrepareStatement ,
114+ @ Nullable Path loadLocalInfilePath , int localInfileBufferSize ,
107115 int queryCacheSize , int prepareCacheSize , Extensions extensions ,
108116 @ Nullable Publisher <String > passwordPublisher
109117 ) {
@@ -122,6 +130,8 @@ private MySqlConnectionConfiguration(
122130 this .database = database == null || database .isEmpty () ? "" : database ;
123131 this .createDatabaseIfNotExist = createDatabaseIfNotExist ;
124132 this .preferPrepareStatement = preferPrepareStatement ;
133+ this .loadLocalInfilePath = loadLocalInfilePath ;
134+ this .localInfileBufferSize = localInfileBufferSize ;
125135 this .queryCacheSize = queryCacheSize ;
126136 this .prepareCacheSize = prepareCacheSize ;
127137 this .extensions = extensions ;
@@ -207,6 +217,15 @@ Predicate<String> getPreferPrepareStatement() {
207217 return preferPrepareStatement ;
208218 }
209219
220+ @ Nullable
221+ Path getLoadLocalInfilePath () {
222+ return loadLocalInfilePath ;
223+ }
224+
225+ int getLocalInfileBufferSize () {
226+ return localInfileBufferSize ;
227+ }
228+
210229 int getQueryCacheSize () {
211230 return queryCacheSize ;
212231 }
@@ -248,6 +267,8 @@ public boolean equals(Object o) {
248267 database .equals (that .database ) &&
249268 createDatabaseIfNotExist == that .createDatabaseIfNotExist &&
250269 Objects .equals (preferPrepareStatement , that .preferPrepareStatement ) &&
270+ Objects .equals (loadLocalInfilePath , that .loadLocalInfilePath ) &&
271+ localInfileBufferSize == that .localInfileBufferSize &&
251272 queryCacheSize == that .queryCacheSize &&
252273 prepareCacheSize == that .prepareCacheSize &&
253274 extensions .equals (that .extensions ) &&
@@ -258,7 +279,8 @@ public boolean equals(Object o) {
258279 public int hashCode () {
259280 return Objects .hash (isHost , domain , port , ssl , tcpKeepAlive , tcpNoDelay , connectTimeout ,
260281 socketTimeout , serverZoneId , zeroDateOption , user , password , database , createDatabaseIfNotExist ,
261- preferPrepareStatement , queryCacheSize , prepareCacheSize , extensions , passwordPublisher );
282+ preferPrepareStatement , loadLocalInfilePath , localInfileBufferSize , queryCacheSize ,
283+ prepareCacheSize , extensions , passwordPublisher );
262284 }
263285
264286 @ Override
@@ -269,16 +291,21 @@ public String toString() {
269291 connectTimeout + ", socketTimeout=" + socketTimeout + ", serverZoneId=" + serverZoneId +
270292 ", zeroDateOption=" + zeroDateOption + ", user='" + user + "', password=" + password +
271293 ", database='" + database + "', createDatabaseIfNotExist=" + createDatabaseIfNotExist +
272- ", preferPrepareStatement=" + preferPrepareStatement + ", queryCacheSize=" + queryCacheSize +
273- ", prepareCacheSize=" + prepareCacheSize + ", extensions=" + extensions +
274- ", passwordPublisher=" + passwordPublisher + '}' ;
294+ ", preferPrepareStatement=" + preferPrepareStatement +
295+ ", loadLocalInfilePath=" + loadLocalInfilePath +
296+ ", localInfileBufferSize=" + localInfileBufferSize +
297+ ", queryCacheSize=" + queryCacheSize + ", prepareCacheSize=" + prepareCacheSize +
298+ ", extensions=" + extensions + ", passwordPublisher=" + passwordPublisher + '}' ;
275299 }
276300
277301 return "MySqlConnectionConfiguration{unixSocket='" + domain + "', connectTimeout=" +
278302 connectTimeout + ", socketTimeout=" + socketTimeout + ", serverZoneId=" + serverZoneId +
279303 ", zeroDateOption=" + zeroDateOption + ", user='" + user + "', password=" + password +
280304 ", database='" + database + "', createDatabaseIfNotExist=" + createDatabaseIfNotExist +
281- ", preferPrepareStatement=" + preferPrepareStatement + ", queryCacheSize=" + queryCacheSize +
305+ ", preferPrepareStatement=" + preferPrepareStatement +
306+ ", loadLocalInfilePath=" + loadLocalInfilePath +
307+ ", localInfileBufferSize=" + localInfileBufferSize +
308+ ", queryCacheSize=" + queryCacheSize +
282309 ", prepareCacheSize=" + prepareCacheSize + ", extensions=" + extensions +
283310 ", passwordPublisher=" + passwordPublisher + '}' ;
284311 }
@@ -345,6 +372,11 @@ public static final class Builder {
345372 @ Nullable
346373 private Predicate <String > preferPrepareStatement ;
347374
375+ @ Nullable
376+ private Path loadLocalInfilePath ;
377+
378+ private int localInfileBufferSize = 8192 ;
379+
348380 private int queryCacheSize = 0 ;
349381
350382 private int prepareCacheSize = 256 ;
@@ -379,7 +411,8 @@ public MySqlConnectionConfiguration build() {
379411 sslCa , sslKey , sslKeyPassword , sslCert , sslContextBuilderCustomizer );
380412 return new MySqlConnectionConfiguration (isHost , domain , port , ssl , tcpKeepAlive , tcpNoDelay ,
381413 connectTimeout , socketTimeout , zeroDateOption , serverZoneId , user , password , database ,
382- createDatabaseIfNotExist , preferPrepareStatement , queryCacheSize , prepareCacheSize ,
414+ createDatabaseIfNotExist , preferPrepareStatement , loadLocalInfilePath ,
415+ localInfileBufferSize , queryCacheSize , prepareCacheSize ,
383416 Extensions .from (extensions , autodetectExtensions ), passwordPublisher );
384417 }
385418
@@ -754,6 +787,38 @@ public Builder useServerPrepareStatement(Predicate<String> preferPrepareStatemen
754787 return this ;
755788 }
756789
790+ /**
791+ * Configures to allow the {@code LOAD DATA LOCAL INFILE} statement in the given {@code path} or
792+ * disallow the statement. Default to {@code null} which means not allow the statement.
793+ *
794+ * @param path which parent path are allowed to load file data, {@code null} means not be allowed.
795+ * @return {@link Builder this}.
796+ * @throws java.nio.file.InvalidPathException if the string cannot be converted to a {@link Path}.
797+ * @since 1.1.0
798+ */
799+ public Builder allowLoadLocalInfileInPath (@ Nullable String path ) {
800+ this .loadLocalInfilePath = path == null ? null : Paths .get (path );
801+
802+ return this ;
803+ }
804+
805+ /**
806+ * Configures the buffer size for {@code LOAD DATA LOCAL INFILE} statement. Default to {@code 8192}.
807+ * <p>
808+ * It is used only if {@link #allowLoadLocalInfileInPath(String)} is set.
809+ *
810+ * @param localInfileBufferSize the buffer size.
811+ * @return {@link Builder this}.
812+ * @throws IllegalArgumentException if {@code localInfileBufferSize} is not positive.
813+ * @since 1.1.0
814+ */
815+ public Builder localInfileBufferSize (int localInfileBufferSize ) {
816+ require (localInfileBufferSize > 0 , "localInfileBufferSize must be positive" );
817+
818+ this .localInfileBufferSize = localInfileBufferSize ;
819+ return this ;
820+ }
821+
757822 /**
758823 * Configures the maximum size of the {@link Query} parsing cache. Usually it should be power of two.
759824 * Default to {@code 0}. Driver will use unbounded cache if size is less than {@code 0}.
@@ -823,6 +888,7 @@ public Builder extendWith(Extension extension) {
823888
824889 /**
825890 * Registers a password publisher function.
891+ *
826892 * @param passwordPublisher function to retrieve password before making connection.
827893 * @return this {@link Builder}.
828894 */
0 commit comments