Class PostgresqlConnectionConfiguration.Builder
java.lang.Object
io.r2dbc.postgresql.PostgresqlConnectionConfiguration.Builder
- Enclosing class:
PostgresqlConnectionConfiguration
A builder for
PostgresqlConnectionConfiguration instances.
This class is not threadsafe
-
Method Summary
Modifier and TypeMethodDescriptionAdd host with default port to the hosts list.Add host to the hosts list.applicationName(String applicationName) Configure the application name.autodetectExtensions(boolean autodetectExtensions) Configures whether to useServiceLoaderto discover and register extensions.build()Returns a configuredPostgresqlConnectionConfiguration.codecRegistrar(CodecRegistrar codecRegistrar) Register aCodecRegistrarthat can contribute extensionCodecs.compatibilityMode(boolean compatibilityMode) Enables protocol compatibility mode for cursored query execution.connectTimeout(Duration connectTimeout) Configure the connection timeout.Configure the database.Enable SSL usage.errorResponseLogLevel(io.r2dbc.postgresql.util.LogLevel errorResponseLogLevel) Configure theLogLevelforerror responsesthat are part of a statement execution.extendWith(Extension extension) Registers aExtensionto extend driver functionality.fetchSize(int fetchSize) Set the default number of rows to return when fetching results from a query.fetchSize(ToIntFunction<String> fetchSizeFunction) Set a function that maps a SQL query to the number of rows to return when fetching results for that query.forceBinary(boolean forceBinary) Force binary results (Binary Transfer).Configure the host.hostRecheckTime(Duration hostRecheckTime) Controls how long the knowledge about a host state is cached connection factory.loadBalanceHosts(boolean loadBalanceHosts) In default mode (disabled) hosts are connected in the given order.lockWaitTimeout(Duration lockWaitTimeout) Configure the Lock wait timeout.loopResources(reactor.netty.resources.LoopResources loopResources) ConfigureLoopResources.noticeLogLevel(io.r2dbc.postgresql.util.LogLevel noticeLogLevel) Configure theLogLevelfornotice responses.Configure connection initialization parameters.password(CharSequence password) Configure the password.password(Supplier<CharSequence> password) Configure the password supplier.password(Publisher<CharSequence> password) Configure the password publisher.port(int port) Configure the port.preferAttachedBuffers(boolean preferAttachedBuffers) Configure whethercodecsshould prefer attached data buffers.preparedStatementCacheQueries(int preparedStatementCacheQueries) Configure the preparedStatementCacheQueries.Configure the schema.Configure the unix domain socket to connect to.Configure ssl cert for client certificate authentication.Configure ssl cert for client certificate authentication.sslContextBuilderCustomizer(Function<io.netty.handler.ssl.SslContextBuilder, io.netty.handler.ssl.SslContextBuilder> sslContextBuilderCustomizer) Configure aSslContextBuildercustomizer.sslEngineCustomizer(Function<SSLEngine, SSLEngine> sslEngineCustomizer) Configure aSSLEnginecustomizer.sslHostnameVerifier(HostnameVerifier sslHostnameVerifier) Configure ssl HostnameVerifier.Configure ssl key for client certificate authentication.Configure ssl key for client certificate authentication.sslMode(io.r2dbc.postgresql.client.SSLMode sslMode) Configure ssl mode.sslParameters(Function<SocketAddress, SSLParameters> sslParametersFactory) Configure aSSLParametersprovider for a givenSocketAddress.sslPassword(CharSequence sslPassword) Configure ssl password.sslRootCert(String sslRootCert) Configure ssl root cert for server certificate validation.sslRootCert(URL sslRootCert) Configure ssl root cert for server certificate validation.sslSni(boolean sslSni) Configure whether to indicate the hostname and port via SNI to the server.statementTimeout(Duration statementTimeout) Configure the Statement timeout.targetServerType(MultiHostConnectionStrategy.TargetServerType targetServerType) Allows opening connections to only servers with required state.tcpKeepAlive(boolean enabled) Configure TCP KeepAlive.tcpNoDelay(boolean enabled) Configure TCP NoDelay.Configure the session timezone.Configure the session timezone.toString()Configure the username.Configure the username supplier.Configure the username publisher.
-
Method Details
-
applicationName
Configure the application name. Defaults topostgresql-r2dbc.- Parameters:
applicationName- the application name- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifapplicationNameisnull
-
autodetectExtensions
Configures whether to useServiceLoaderto discover and register extensions. Defaults to true.- Parameters:
autodetectExtensions- to discover and register extensions- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
build
Returns a configuredPostgresqlConnectionConfiguration.- Returns:
- a configured
PostgresqlConnectionConfiguration
-
compatibilityMode
Enables protocol compatibility mode for cursored query execution. Cursored query execution applies when configuring a non-zero fetch size. Compatibility mode usesExecute+Syncmessages instead ofExecute+Flush. The default mode uses optimized fetching which does not work with newer pgpool versions.- Parameters:
compatibilityMode- whether to enable compatibility mode- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.8.7
-
connectTimeout
Configure the connection timeout. Default unconfigured.- Parameters:
connectTimeout- the connection timeout- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
codecRegistrar
Register aCodecRegistrarthat can contribute extensionCodecs. Calling this method adds aCodecRegistrarand does not replace existingExtensions.- Parameters:
codecRegistrar- registrar to contribute codecs- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
database
Configure the database.- Parameters:
database- the database- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
enableSsl
Enable SSL usage. This flag is also known as Use Encryption in other drivers.- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
extendWith
Registers aExtensionto extend driver functionality. Calling this method adds aExtensionand does not replace existingExtensions.- Parameters:
extension- extension to extend driver functionality- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
errorResponseLogLevel
public PostgresqlConnectionConfiguration.Builder errorResponseLogLevel(io.r2dbc.postgresql.util.LogLevel errorResponseLogLevel) Configure theLogLevelforerror responsesthat are part of a statement execution.- Parameters:
errorResponseLogLevel- the log level to use.- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.9
-
fetchSize
Set the default number of rows to return when fetching results from a query. If the value specified is zero, then the hint is ignored and queries request all rows when running a statement.- Parameters:
fetchSize- the number of rows to fetch- Returns:
- this
Builder - Throws:
IllegalArgumentException- iffetchSizeisnegative- Since:
- 0.9
-
fetchSize
Set a function that maps a SQL query to the number of rows to return when fetching results for that query.- Parameters:
fetchSizeFunction- a function that maps the number of rows to fetch- Returns:
- this
Builder - Throws:
IllegalArgumentException- iffetchSizeFunctionisnull- Since:
- 0.9
-
forceBinary
Force binary results (Binary Transfer). Defaults to false.- Parameters:
forceBinary- whether to force binary transfer- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
host
Configure the host. Calling this method prepares single-node configuration. This method can be only used if the builder was not configured with a multi-host configuration.- Parameters:
host- the host- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifhostisnullIllegalStateException- ifaddHost(String),targetServerType(MultiHostConnectionStrategy.TargetServerType)orhostRecheckTime(Duration)was configured earlier to ensure a consistent configuration state
-
addHost
Add host with default port to the hosts list. Calling this method prepares multi-node configuration. This method can be only used if the builder was not configured with a single-host configuration.- Parameters:
host- the host- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifhostisnullIllegalStateException- ifport(int),host(String)orsocket(String)was configured earlier to ensure a consistent configuration state- Since:
- 1.0
-
addHost
Add host to the hosts list. Calling this method prepares multi-node configuration. This method can be only used if the builder was not configured with a single-host configuration.- Parameters:
host- the hostport- the port- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifhostisnullIllegalStateException- ifport(int),host(String)orsocket(String)was configured earlier to ensure a consistent configuration state- Since:
- 1.0
-
hostRecheckTime
Controls how long the knowledge about a host state is cached connection factory. The default value is10 seconds. Calling this method prepares multi-node configuration. This method can be only used if the builder was not configured with a single-host configuration.- Parameters:
hostRecheckTime- host recheck time- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalStateException- ifport(int),host(String)orsocket(String)was configured earlier to ensure a consistent configuration state- Since:
- 1.0
-
loadBalanceHosts
In default mode (disabled) hosts are connected in the given order. If enabled hosts are chosen randomly from the set of suitable candidates. Calling this method prepares multi-node configuration. This method can be only used if the builder was not configured with a single-host configuration.- Parameters:
loadBalanceHosts- is load balance mode enabled- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalStateException- ifport(int),host(String)orsocket(String)was configured earlier to ensure a consistent configuration state- Since:
- 1.0
-
lockWaitTimeout
Configure the Lock wait timeout. Default unconfigured.This parameter is applied once after creating a new connection. If lockTimeout is already set using
options(Map), it will be overridden. Lock Timeout- Parameters:
lockWaitTimeout- the lock timeout- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.8.9
-
loopResources
public PostgresqlConnectionConfiguration.Builder loopResources(reactor.netty.resources.LoopResources loopResources) ConfigureLoopResources.- Parameters:
loopResources- theLoopResources- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.8.5
-
noticeLogLevel
public PostgresqlConnectionConfiguration.Builder noticeLogLevel(io.r2dbc.postgresql.util.LogLevel noticeLogLevel) Configure theLogLevelfornotice responses.- Parameters:
noticeLogLevel- the log level to use.- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.9
-
options
Configure connection initialization parameters.These parameters are applied once after creating a new connection. This is useful for setting up client-specific runtime parameters like statement timeouts, time zones etc.
- Parameters:
options- the options- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifoptionsor any key or value ofoptionsisnull
-
password
Configure the password.- Parameters:
password- the password- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
password
Configure the password publisher. The publisher is used on each authentication attempt.- Parameters:
password- the password- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 1.0.3
-
password
Configure the password supplier. The supplier is used on each authentication attempt.- Parameters:
password- the password- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 1.0.3
-
port
Configure the port. Defaults to5432. Calling this method prepares single-node configuration. This method can be only used if the builder was not configured with a multi-host configuration.- Parameters:
port- the port- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalStateException- ifaddHost(String),targetServerType(MultiHostConnectionStrategy.TargetServerType)orhostRecheckTime(Duration)was configured earlier to ensure a consistent configuration state
-
preferAttachedBuffers
public PostgresqlConnectionConfiguration.Builder preferAttachedBuffers(boolean preferAttachedBuffers) Configure whethercodecsshould prefer attached data buffers. The default isfalse, meaning that codecs will copy data from the input buffer into abyte[]or similar data structure that is enabled for garbage collection. Using attached buffers is more efficient but comes with the requirement that decoded values (such asJson) must be consumed to release attached buffers to avoid memory leaks.- Parameters:
preferAttachedBuffers- the flag whether to prefer attached buffers- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.8.5
-
preparedStatementCacheQueries
public PostgresqlConnectionConfiguration.Builder preparedStatementCacheQueries(int preparedStatementCacheQueries) Configure the preparedStatementCacheQueries. The default is-1, meaning there's no limit. The value of0disables the cache. Any other value specifies the cache size.- Parameters:
preparedStatementCacheQueries- the preparedStatementCacheQueries- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.8.1
-
schema
Configure the schema.- Parameters:
schema- the schema- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
socket
Configure the unix domain socket to connect to. Calling this method prepares single-node configuration. This method can be only used if the builder was not configured with a multi-host configuration.- Parameters:
socket- the socket path- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifsocketisnullIllegalStateException- ifaddHost(String),targetServerType(MultiHostConnectionStrategy.TargetServerType)orhostRecheckTime(Duration)was configured earlier to ensure a consistent configuration state
-
sslContextBuilderCustomizer
public PostgresqlConnectionConfiguration.Builder sslContextBuilderCustomizer(Function<io.netty.handler.ssl.SslContextBuilder, io.netty.handler.ssl.SslContextBuilder> sslContextBuilderCustomizer) Configure aSslContextBuildercustomizer. The customizer gets applied on each SSL connection attempt to allow for just-in-time configuration updates. TheFunctiongets called with the preparedSslContextBuilderthat 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.- Parameters:
sslContextBuilderCustomizer- customizer function- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifsslContextBuilderCustomizerisnull
-
sslEngineCustomizer
public PostgresqlConnectionConfiguration.Builder sslEngineCustomizer(Function<SSLEngine, SSLEngine> sslEngineCustomizer) Configure aSSLEnginecustomizer. The customizer gets applied on each SSL connection attempt to allow for just-in-time configuration updates. TheFunctiongets called with aSSLEngineinstance 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.- Parameters:
sslEngineCustomizer- customizer function- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifsslEngineCustomizerisnull
-
sslParameters
public PostgresqlConnectionConfiguration.Builder sslParameters(Function<SocketAddress, SSLParameters> sslParametersFactory) Configure aSSLParametersprovider for a givenSocketAddress. The provider gets applied on each SSL connection attempt to allow for just-in-time configuration updates. Typically used to configure SSL protocols- Parameters:
sslParametersFactory- customizer function- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifsslParametersFactoryisnull- Since:
- 1.0.5
-
sslSni
Configure whether to indicate the hostname and port via SNI to the server. Enabled by default.- Parameters:
sslSni- whether to indicate the hostname and port via SNI. SetsSSLParameters.setServerNames(List)on theSSLParametersinstance provided bysslParameters(Function).- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 1.0.5
-
sslCert
Configure ssl cert for client certificate authentication. Can point to either a resource within the classpath or a file.- Parameters:
sslCert- an X.509 certificate chain file in PEM format- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
sslCert
Configure ssl cert for client certificate authentication.- Parameters:
sslCert- an X.509 certificate chain file in PEM format- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.8.7
-
sslHostnameVerifier
public PostgresqlConnectionConfiguration.Builder sslHostnameVerifier(HostnameVerifier sslHostnameVerifier) Configure ssl HostnameVerifier.- Parameters:
sslHostnameVerifier-HostnameVerifier- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
sslKey
Configure ssl key for client certificate authentication. Can point to either a resource within the classpath or a file.- Parameters:
sslKey- a PKCS#8 private key file in PEM format- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
sslKey
Configure ssl key for client certificate authentication.- Parameters:
sslKey- a PKCS#8 private key file in PEM format- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.8.7
-
sslMode
public PostgresqlConnectionConfiguration.Builder sslMode(io.r2dbc.postgresql.client.SSLMode sslMode) Configure ssl mode.- Parameters:
sslMode- the SSL mode to use.- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
sslPassword
Configure ssl password.- Parameters:
sslPassword- the password of the sslKey, or null if it's not password-protected- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
sslRootCert
Configure ssl root cert for server certificate validation. Can point to either a resource within the classpath or a file.- Parameters:
sslRootCert- an X.509 certificate chain file in PEM format- Returns:
- this
PostgresqlConnectionConfiguration.Builder
-
sslRootCert
Configure ssl root cert for server certificate validation.- Parameters:
sslRootCert- an X.509 certificate chain file in PEM format- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.8.7
-
statementTimeout
Configure the Statement timeout. Default unconfigured.This parameter is applied once after creating a new connection. If statementTimeout is already set using
options(Map), it will be overridden. Statement Timeout- Parameters:
statementTimeout- the statement timeout- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.8.9
-
targetServerType
public PostgresqlConnectionConfiguration.Builder targetServerType(MultiHostConnectionStrategy.TargetServerType targetServerType) Allows opening connections to only servers with required state. The primary/secondary distinction is currently done by observing if the server allows writes. The valueMultiHostConnectionStrategy.TargetServerType.PREFER_SECONDARYtries to connect to a secondary if any are available, otherwise allows falls back to a primary. Default value isMultiHostConnectionStrategy.TargetServerType.ANY.- Parameters:
targetServerType- target server type- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- iftargetServerTypeisnull- Since:
- 1.0
-
tcpKeepAlive
Configure TCP KeepAlive.- Parameters:
enabled- whether to enable TCP KeepAlive- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.8.4
- See Also:
-
tcpNoDelay
Configure TCP NoDelay.- Parameters:
enabled- whether to enable TCP NoDelay- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Since:
- 0.8.4
- See Also:
-
timeZone
Configure the session timezone.- Parameters:
timeZone- the timeZone identifier- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- iftimeZoneis empty ornull- Since:
- 1.0
- See Also:
-
timeZone
Configure the session timezone.- Parameters:
timeZone- the timeZone identifier- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- iftimeZoneisnull- Since:
- 1.0
- See Also:
-
username
Configure the username.- Parameters:
username- the username- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifusernameisnull
-
username
Configure the username publisher. The publisher is used on each authentication attempt.- Parameters:
username- the username- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifusernameisnull
-
username
Configure the username supplier. The supplier is used on each authentication attempt.- Parameters:
username- the username- Returns:
- this
PostgresqlConnectionConfiguration.Builder - Throws:
IllegalArgumentException- ifusernameisnull
-
toString
-