public static final class MySqlConnectionConfiguration.Builder extends Object
MySqlConnectionConfiguration creation.| Modifier and Type | Method and Description |
|---|---|
MySqlConnectionConfiguration.Builder |
allowLoadLocalInfileInPath(@Nullable String path)
Configures to allow the
LOAD DATA LOCAL INFILE statement in the given path or
disallow the statement. |
MySqlConnectionConfiguration.Builder |
autodetectExtensions(boolean enabled)
Configures whether to use
ServiceLoader to discover and register extensions. |
MySqlConnectionConfiguration |
build()
Builds an immutable
MySqlConnectionConfiguration with current options. |
MySqlConnectionConfiguration.Builder |
compressionAlgorithms(CompressionAlgorithm... compressionAlgorithms)
Configures the compression algorithms.
|
MySqlConnectionConfiguration.Builder |
connectionTimeZone(String connectionTimeZone)
Configures the time zone of connection.
|
MySqlConnectionConfiguration.Builder |
connectTimeout(@Nullable Duration connectTimeout)
Configures the connection timeout.
|
MySqlConnectionConfiguration.Builder |
createDatabaseIfNotExist(boolean enabled)
Configures to create the database given in the configuration if it does not yet exist.
|
MySqlConnectionConfiguration.Builder |
database(@Nullable String database)
Configures the database.
|
MySqlConnectionConfiguration.Builder |
extendWith(Extension extension)
Registers a
Extension to extend driver functionality and manually. |
MySqlConnectionConfiguration.Builder |
forceConnectionTimeZoneToSession(boolean enabled)
Configures to force the connection time zone to session time zone.
|
MySqlConnectionConfiguration.Builder |
host(String host)
Configures the host.
|
MySqlConnectionConfiguration.Builder |
localInfileBufferSize(int localInfileBufferSize)
Configures the buffer size for
LOAD DATA LOCAL INFILE statement. |
MySqlConnectionConfiguration.Builder |
lockWaitTimeout(@Nullable Duration lockWaitTimeout)
Configures the lock wait timeout.
|
MySqlConnectionConfiguration.Builder |
loopResources(reactor.netty.resources.LoopResources loopResources)
Configures the
LoopResources for the driver. |
MySqlConnectionConfiguration.Builder |
password(@Nullable CharSequence password)
Configures the password.
|
MySqlConnectionConfiguration.Builder |
passwordPublisher(Publisher<String> passwordPublisher)
Registers a password publisher function.
|
MySqlConnectionConfiguration.Builder |
port(int port)
Configures the port.
|
MySqlConnectionConfiguration.Builder |
prepareCacheSize(int prepareCacheSize)
Configures the maximum size of the server-preparing cache.
|
MySqlConnectionConfiguration.Builder |
preserveInstants(boolean enabled)
Configures the time zone conversion.
|
MySqlConnectionConfiguration.Builder |
queryCacheSize(int queryCacheSize)
Configures the maximum size of the
Query parsing cache. |
MySqlConnectionConfiguration.Builder |
serverZoneId(@Nullable ZoneId serverZoneId)
Deprecated.
since 1.1.2, use
connectionTimeZone(String) instead. |
MySqlConnectionConfiguration.Builder |
sessionVariables(String... sessionVariables)
Configures the session variables, used to set session variables immediately after login.
|
MySqlConnectionConfiguration.Builder |
sslCa(@Nullable String sslCa)
Configures SSL root certification for server certificate validation.
|
MySqlConnectionConfiguration.Builder |
sslCert(@Nullable String sslCert)
Configures client SSL certificate for client authentication.
|
MySqlConnectionConfiguration.Builder |
sslContextBuilderCustomizer(Function<io.netty.handler.ssl.SslContextBuilder,io.netty.handler.ssl.SslContextBuilder> customizer)
Configures a
SslContextBuilder customizer. |
MySqlConnectionConfiguration.Builder |
sslHostnameVerifier(HostnameVerifier sslHostnameVerifier)
Configures SSL
HostnameVerifier, it is available only set sslMode(SslMode) as
SslMode.VERIFY_IDENTITY. |
MySqlConnectionConfiguration.Builder |
sslKey(@Nullable String sslKey)
Configures client SSL key for client authentication.
|
MySqlConnectionConfiguration.Builder |
sslKeyPassword(@Nullable CharSequence sslKeyPassword)
Configures the password of SSL key file for client certificate authentication.
|
MySqlConnectionConfiguration.Builder |
sslMode(SslMode sslMode)
Configures ssl mode.
|
MySqlConnectionConfiguration.Builder |
statementTimeout(@Nullable Duration statementTimeout)
Configures the statement timeout.
|
MySqlConnectionConfiguration.Builder |
tcpKeepAlive(boolean enabled)
Configures TCP KeepAlive.
|
MySqlConnectionConfiguration.Builder |
tcpNoDelay(boolean enabled)
Configures TCP NoDelay.
|
MySqlConnectionConfiguration.Builder |
tlsVersion(String... tlsVersion)
Configures TLS versions, see
TlsVersions. |
MySqlConnectionConfiguration.Builder |
unixSocket(String unixSocket)
Configures the Unix Domain Socket to connect to.
|
MySqlConnectionConfiguration.Builder |
useClientPrepareStatement()
Configures the protocol of parameterized statements to the text protocol.
|
MySqlConnectionConfiguration.Builder |
user(String user)
Configures the user for login the database.
|
MySqlConnectionConfiguration.Builder |
username(String user)
An alias of
user(String). |
MySqlConnectionConfiguration.Builder |
useServerPrepareStatement()
Configures the protocol of parameterized statements to the binary protocol.
|
MySqlConnectionConfiguration.Builder |
useServerPrepareStatement(Predicate<String> preferPrepareStatement)
Configures the protocol of parameterized statements and prepare-preferred simple statements to the
binary protocol.
|
MySqlConnectionConfiguration.Builder |
zeroDateOption(ZeroDateOption zeroDate)
Configures the
ZeroDateOption. |
MySqlConnectionConfiguration.Builder |
zstdCompressionLevel(int level)
Configures the zstd compression level.
|
public MySqlConnectionConfiguration build()
MySqlConnectionConfiguration with current options.MySqlConnectionConfiguration.public MySqlConnectionConfiguration.Builder database(@Nullable @Nullable String database)
database - the database, or null if no database want to be login.MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder createDatabaseIfNotExist(boolean enabled)
false.enabled - to discover and register extensions.MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder unixSocket(String unixSocket)
unixSocket - the socket file path.MySqlConnectionConfiguration.Builder.IllegalArgumentException - if unixSocket is null.public MySqlConnectionConfiguration.Builder host(String host)
host - the host.MySqlConnectionConfiguration.Builder.IllegalArgumentException - if host is null.public MySqlConnectionConfiguration.Builder password(@Nullable @Nullable CharSequence password)
Note: for memory security, should not use intern String for password.
password - the password, or null when user has no password.MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder port(int port)
3306.port - the port.MySqlConnectionConfiguration.Builder.IllegalArgumentException - if the port is negative or bigger than 65535.public MySqlConnectionConfiguration.Builder connectTimeout(@Nullable @Nullable Duration connectTimeout)
connectTimeout - the connection timeout, or null if no timeout.MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder user(String user)
user - the user.MySqlConnectionConfiguration.Builder.IllegalArgumentException - if user is null.public MySqlConnectionConfiguration.Builder username(String user)
user(String).user - the user.MySqlConnectionConfiguration.Builder.IllegalArgumentException - if user is null.public MySqlConnectionConfiguration.Builder preserveInstants(boolean enabled)
true means enable conversion between JVM
and connectionTimeZone(String).
Note: disable it will ignore the time zone of connection, and use the JVM local time zone.
enabled - true to preserve instants, or false to disable conversion.thispublic MySqlConnectionConfiguration.Builder connectionTimeZone(String connectionTimeZone)
LOCAL means use JVM local time zone.
"SERVER" means querying the server-side timezone during initialization.connectionTimeZone - "LOCAL", "SERVER", or a valid ID of ZoneId.thisIllegalArgumentException - if connectionTimeZone is null or empty.public MySqlConnectionConfiguration.Builder forceConnectionTimeZoneToSession(boolean enabled)
false. Used
only if the connectionTimeZone(String) is not "SERVER".
Note: alter the time zone of session will affect the results of MySQL date/time functions, e.g.
NOW([n]), CURRENT_TIME([n]), CURRENT_DATE(), etc. Please use with caution.
enabled - true to force the connection time zone to session time zone.this@Deprecated public MySqlConnectionConfiguration.Builder serverZoneId(@Nullable @Nullable ZoneId serverZoneId)
connectionTimeZone(String) instead.public MySqlConnectionConfiguration.Builder zeroDateOption(ZeroDateOption zeroDate)
ZeroDateOption. Default to ZeroDateOption.USE_NULL. It is a
behavior option when this driver receives a value of zero-date.zeroDate - the ZeroDateOption.MySqlConnectionConfiguration.Builder.IllegalArgumentException - if zeroDate is null.public MySqlConnectionConfiguration.Builder sslMode(SslMode sslMode)
SslMode.sslMode - the SSL mode to use.MySqlConnectionConfiguration.Builder.IllegalArgumentException - if sslMode is null.public MySqlConnectionConfiguration.Builder tlsVersion(String... tlsVersion)
TlsVersions.tlsVersion - TLS versions.MySqlConnectionConfiguration.Builder.IllegalArgumentException - if the array tlsVersion is null.public MySqlConnectionConfiguration.Builder sslHostnameVerifier(HostnameVerifier sslHostnameVerifier)
HostnameVerifier, it is available only set sslMode(SslMode) as
SslMode.VERIFY_IDENTITY. It is useful when server was using special Certificates or need
special verification.
Default is builtin HostnameVerifier which use RFC standards.
sslHostnameVerifier - the custom HostnameVerifier.MySqlConnectionConfiguration.BuilderIllegalArgumentException - if sslHostnameVerifier is nullpublic MySqlConnectionConfiguration.Builder sslCa(@Nullable @Nullable String sslCa)
sslMode(SslMode) is configured for verify server certification.
Default is null, which means that the default algorithm is used for the trust manager.
sslCa - an X.509 certificate chain file in PEM format.MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder sslCert(@Nullable @Nullable String sslCert)
sslCert - an X.509 certificate chain file in PEM format, or null if no SSL cert.MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder sslKey(@Nullable @Nullable String sslKey)
sslKey - a PKCS#8 private key file in PEM format, or null if no SSL key.MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder sslKeyPassword(@Nullable @Nullable CharSequence sslKeyPassword)
sslKeyPassword - the password of the sslKey, or null if it's not
password-protected.MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder sslContextBuilderCustomizer(Function<io.netty.handler.ssl.SslContextBuilder,io.netty.handler.ssl.SslContextBuilder> customizer)
SslContextBuilder customizer. The customizer gets applied on each SSL
connection attempt to allow for just-in-time configuration updates. The Function gets
called with the prepared SslContextBuilder that has all configuration options applied. The
customizer may return the same builder or return a new builder instance to be used to build the SSL
context.customizer - customizer functionMySqlConnectionConfiguration.BuilderIllegalArgumentException - if customizer is nullpublic MySqlConnectionConfiguration.Builder tcpKeepAlive(boolean enabled)
enabled - whether to enable TCP KeepAliveMySqlConnectionConfiguration.BuilderSocket.setKeepAlive(boolean)public MySqlConnectionConfiguration.Builder tcpNoDelay(boolean enabled)
enabled - whether to enable TCP NoDelayMySqlConnectionConfiguration.BuilderSocket.setTcpNoDelay(boolean)public MySqlConnectionConfiguration.Builder useClientPrepareStatement()
The text protocol is default protocol that's using client-preparing. See also MySQL documentations.
MySqlConnectionConfiguration.Builderpublic MySqlConnectionConfiguration.Builder useServerPrepareStatement()
The binary protocol is compact protocol that's using server-preparing. See also MySQL documentations.
MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder useServerPrepareStatement(Predicate<String> preferPrepareStatement)
The preferPrepareStatement configures whether to prefer prepare execution on a
statement-by-statement basis (simple statements). The Predicate accepts the simple SQL
query string and returns a boolean flag indicating preference. true prepare-preferred,
false prefers direct execution (text protocol). Defaults to direct execution.
The binary protocol is compact protocol that's using server-preparing. See also MySQL documentations.
preferPrepareStatement - the above Predicate.MySqlConnectionConfiguration.Builder.IllegalArgumentException - if preferPrepareStatement is null.public MySqlConnectionConfiguration.Builder sessionVariables(String... sessionVariables)
["sql_mode='ANSI_QUOTES,STRICT_TRANS_TABLES'", "time_zone=00:00"].sessionVariables - the session variables to set.thisIllegalArgumentException - if sessionVariables is null.public MySqlConnectionConfiguration.Builder lockWaitTimeout(@Nullable @Nullable Duration lockWaitTimeout)
lockWaitTimeout - the lock wait timeout, or null to use the server-side default value.thispublic MySqlConnectionConfiguration.Builder statementTimeout(@Nullable @Nullable Duration statementTimeout)
statementTimeout - the statement timeout, or null to use the server-side default value.thispublic MySqlConnectionConfiguration.Builder allowLoadLocalInfileInPath(@Nullable @Nullable String path)
LOAD DATA LOCAL INFILE statement in the given path or
disallow the statement. Default to null which means not allow the statement.path - which parent path are allowed to load file data, null means not be allowed.this.InvalidPathException - if the string cannot be converted to a Path.public MySqlConnectionConfiguration.Builder localInfileBufferSize(int localInfileBufferSize)
LOAD DATA LOCAL INFILE statement. Default to 8192.
It is used only if allowLoadLocalInfileInPath(String) is set.
localInfileBufferSize - the buffer size.this.IllegalArgumentException - if localInfileBufferSize is not positive.public MySqlConnectionConfiguration.Builder queryCacheSize(int queryCacheSize)
Query parsing cache. Usually it should be power of two.
Default to 0. Driver will use unbounded cache if size is less than 0.
Notice: the cache is using EL model (the PACELC theorem) which provider better performance. That means it is an elastic cache. So this size is not a hard-limit. It should be over 16 in average.
queryCacheSize - the above size, 0 means no cache, -1 means unbounded cache.MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder prepareCacheSize(int prepareCacheSize)
256. Driver will use unbounded cache if size is less than 0. It is used
only if using server-preparing parameterized statements, i.e. the useServerPrepareStatement()
is set.
Notice: the cache is using EC model (the PACELC theorem) for ensure consistency. Consistency is
very important because MySQL contains a hard limit of all server-prepared statements which has been
opened, see also max_prepared_stmt_count. And, the cache is one-to-one connection, which
means it will not work on thread-concurrency.
prepareCacheSize - the above size, 0 means no cache, -1 means unbounded
cache.MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder compressionAlgorithms(CompressionAlgorithm... compressionAlgorithms)
CompressionAlgorithm.UNCOMPRESSED].
It will auto choose an algorithm that's contained in the list and supported by the server,
preferring zstd, then zlib. If the list does not contain CompressionAlgorithm.UNCOMPRESSED
and the server does not support any algorithm in the list, an exception will be thrown when
connecting.
Note: zstd requires a dependency com.github.luben:zstd-jni.
compressionAlgorithms - the list of compression algorithms.this.IllegalArgumentException - if compressionAlgorithms is null or empty.public MySqlConnectionConfiguration.Builder zstdCompressionLevel(int level)
3.
It is only used if zstd is chosen for the connection.
Note: MySQL protocol does not allow to set the zlib compression level of the server, only zstd is configurable.
level - the compression level.this.IllegalArgumentException - if level is not between 1 and 22.public MySqlConnectionConfiguration.Builder loopResources(reactor.netty.resources.LoopResources loopResources)
LoopResources for the driver. Default to
global tcp resources.loopResources - the LoopResources.MySqlConnectionConfiguration.Builder.IllegalArgumentException - if loopResources is null.public MySqlConnectionConfiguration.Builder autodetectExtensions(boolean enabled)
ServiceLoader to discover and register extensions. Defaults to
true.enabled - to discover and register extensions.MySqlConnectionConfiguration.Builder.public MySqlConnectionConfiguration.Builder extendWith(Extension extension)
Extension to extend driver functionality and manually.
Notice: the driver will not deduplicate Extensions of autodetect discovered and manually
extended. So if a Extension is registered by this function and autodetect discovered, it
will get two Extension as same.
extension - extension to extend driver functionality.MySqlConnectionConfiguration.Builder.IllegalArgumentException - if extension is null.public MySqlConnectionConfiguration.Builder passwordPublisher(Publisher<String> passwordPublisher)
passwordPublisher - function to retrieve password before making connection.MySqlConnectionConfiguration.Builder.Copyright © 2018–2024 asyncer.io. All rights reserved.