Package com.clickhouse.client.api
Class Client.Builder
java.lang.Object
com.clickhouse.client.api.Client.Builder
- Enclosing class:
- Client
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddEndpoint(Protocol protocol, String host, int port, boolean secure) Server address to which client may connect.addEndpoint(String endpoint) Server address to which client may connect.build()compressClientRequest(boolean enabled) Client request compression.compressServerResponse(boolean enabled) Server response compression.enableConnectionPool(boolean enable) Configures client to use build-in connection poolsetAccessToken(String accessToken) Access token for authentication with server.setClientCertificate(String path) Client certificate for mTLS.setClientKey(String path) Client key for mTLS.setConnectionRequestTimeout(long timeout, ChronoUnit unit) Set timeout for waiting a free connection from a pool when all connections are leased.Sets strategy of how connections are reuse.setConnectionTTL(long timeout, ChronoUnit unit) Sets how long any connection would be considered as active and able for a lease.setConnectTimeout(long timeout) Default connection timeout in milliseconds.setConnectTimeout(long timeout, ChronoUnit unit) Default connection timeout in milliseconds.setDefaultDatabase(String database) Sets the default database name that will be used by operations if not specified.setExecutionTimeout(long timeout, ChronoUnit timeUnit) Sets the maximum time for operation to complete.setHttpCookiesEnabled(boolean enabled) setKeepAliveTimeout(long timeout, ChronoUnit unit) Sets keep alive timeout for a connection to override server value.setLZ4UncompressedBufferSize(int size) Sets buffer size for uncompressed data in LZ4 compression.setMaxConnections(int maxConnections) Sets the maximum number of connections that can be opened at the same time to a single server.Sets a configuration option.setPassword(String password) Password for authentication with server.setProxyCredentials(String user, String pass) setRootCertificate(String path) Defines path to the key store file.setServerTimeZone(String timeZone) Specify server timezone to use.setSharedOperationExecutor(ExecutorService executorService) Sets an executor for running operations.setSocketKeepAlive(boolean value) Default socket keep alive option.If set to true socket will be kept alive until terminated by one of the parties.setSocketLinger(int secondsToWait) Default socket linger option.setSocketRcvbuf(long size) Default socket receive buffer size in bytes.setSocketReuseAddress(boolean value) Default socket reuse address option.setSocketSndbuf(long size) Default socket send buffer size in bytes.setSocketTcpNodelay(boolean value) Default socket tcp_no_delay option.setSocketTimeout(long timeout) Default socket timeout in milliseconds.setSocketTimeout(long timeout, ChronoUnit unit) Default socket timeout in milliseconds.setSSLTrustStore(String path) Defines path to the trust store file.setSSLTrustStorePassword(String password) Password for the SSL Trust Store.setSSLTrustStoreType(String type) Type of the SSL Trust Store.setUsername(String username) Username for authentication with server.useAsyncRequests(boolean async) Configures client to execute requests in a separate thread.useHttpCompression(boolean enabled) Configures the client to use HTTP compression.useNewImplementation(boolean useNewImplementation) Deprecated.- do not use - it is only for developmentuseServerTimeZone(boolean useServerTimeZone) Configure client to use server timezone for date/datetime columns.useTimeZone(String timeZone) Configure client to use specified timezone.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
addEndpoint
Server address to which client may connect. If there are multiple endpoints then client will connect to one of them. Acceptable formats are:http://localhost:8123https://localhost:8443
- Parameters:
endpoint- - URL formatted string with protocol, host and port.
-
addEndpoint
Server address to which client may connect. If there are multiple endpoints then client will connect to one of them.- Parameters:
protocol- - Endpoint protocolhost- - Endpoint hostport- - Endpoint port
-
setOption
Sets a configuration option. This method can be used to set any configuration option. There is no specific validation is done on the key or value.- Parameters:
key- - configuration option namevalue- - configuration option value
-
setUsername
Username for authentication with server. Required for all operations. Same username will be used for all endpoints.- Parameters:
username- - a valid username
-
setPassword
Password for authentication with server. Required for all operations. Same password will be used for all endpoints.- Parameters:
password- - plain text password
-
setAccessToken
Access token for authentication with server. Required for all operations. Same access token will be used for all endpoints.- Parameters:
accessToken- - plain text access token
-
enableConnectionPool
Configures client to use build-in connection pool- Parameters:
enable- - if connection pool should be enabled- Returns:
-
setConnectTimeout
Default connection timeout in milliseconds. Timeout is applied to establish a connection.- Parameters:
timeout- - connection timeout in milliseconds
-
setConnectTimeout
Default connection timeout in milliseconds. Timeout is applied to establish a connection.- Parameters:
timeout- - connection timeout valueunit- - time unit
-
setConnectionRequestTimeout
Set timeout for waiting a free connection from a pool when all connections are leased. This configuration is important when need to fail fast in high concurrent scenarios. Default is 10 s.- Parameters:
timeout- - connection timeout in millisecondsunit- - time unit
-
setMaxConnections
Sets the maximum number of connections that can be opened at the same time to a single server. Limit is not a hard stop. It is done to prevent threads stuck inside a connection pool waiting for a connection. Default is 10. It is recommended to set a higher value for a high concurrent applications. It will let more threads to get a connection and execute a query.- Parameters:
maxConnections- - maximum number of connections
-
setConnectionTTL
Sets how long any connection would be considered as active and able for a lease. After this time connection will be marked for sweep and will not be returned from a pool. Has more effect than keep-alive timeout.- Parameters:
timeout- - time in unitunit- - time unit- Returns:
-
setKeepAliveTimeout
Sets keep alive timeout for a connection to override server value. If set to -1 then server value will be used. Default is -1. Doesn't override connection TTL value.- Parameters:
timeout- - time in unitunit- - time unit- Returns:
-
setConnectionReuseStrategy
Sets strategy of how connections are reuse. Default isConnectionReuseStrategy.FIFOto evenly distribute load between them.- Parameters:
strategy- - strategy for connection reuse- Returns:
-
setSocketTimeout
Default socket timeout in milliseconds. Timeout is applied to read and write operations.- Parameters:
timeout- - socket timeout in milliseconds
-
setSocketTimeout
Default socket timeout in milliseconds. Timeout is applied to read and write operations.- Parameters:
timeout- - socket timeout valueunit- - time unit
-
setSocketRcvbuf
Default socket receive buffer size in bytes.- Parameters:
size- - socket receive buffer size in bytes
-
setSocketSndbuf
Default socket send buffer size in bytes.- Parameters:
size- - socket send buffer size in bytes
-
setSocketReuseAddress
Default socket reuse address option.- Parameters:
value- - socket reuse address option
-
setSocketKeepAlive
Default socket keep alive option.If set to true socket will be kept alive until terminated by one of the parties.- Parameters:
value- - socket keep alive option
-
setSocketTcpNodelay
Default socket tcp_no_delay option. If set to true, disables Nagle's algorithm.- Parameters:
value- - socket tcp no delay option
-
setSocketLinger
Default socket linger option. If set to true, socket will linger for the specified time.- Parameters:
secondsToWait- - socket linger time in seconds
-
compressServerResponse
Server response compression. If set to true server will compress the response. Has most effect for read operations.- Parameters:
enabled- - indicates if server response compression is enabled
-
compressClientRequest
Client request compression. If set to true client will compress the request. Has most effect for write operations.- Parameters:
enabled- - indicates if client request compression is enabled
-
useHttpCompression
Configures the client to use HTTP compression. In this case compression is controlled by http headers. Client compression will setContent-Encoding: lz4header and server compression will setAccept-Encoding: lz4header.- Parameters:
enabled- - indicates if http compression is enabled- Returns:
-
setLZ4UncompressedBufferSize
Sets buffer size for uncompressed data in LZ4 compression. For outgoing data it is the size of a buffer that will be compressed. For incoming data it is the size of a buffer that will be decompressed.- Parameters:
size- - size of the buffer in bytes- Returns:
-
setDefaultDatabase
Sets the default database name that will be used by operations if not specified.- Parameters:
database- - actual default database name.
-
addProxy
-
setProxyCredentials
-
setExecutionTimeout
Sets the maximum time for operation to complete. By default, it is set to 3 hours.- Parameters:
timeout-timeUnit-- Returns:
-
useNewImplementation
Deprecated.- do not use - it is only for developmentSwitches to new implementation of the client. -
setHttpCookiesEnabled
-
setSSLTrustStore
Defines path to the trust store file. It cannot be combined with certificates. Either trust store or certificates should be used. and- Parameters:
path-- Returns:
-
setSSLTrustStorePassword
Password for the SSL Trust Store.- Parameters:
password-- Returns:
-
setSSLTrustStoreType
Type of the SSL Trust Store. Usually JKS- Parameters:
type-- Returns:
-
setRootCertificate
Defines path to the key store file. It cannot be combined with certificates. Either key store or certificates should be used. and- Parameters:
path-- Returns:
-
setClientCertificate
Client certificate for mTLS.- Parameters:
path-- Returns:
-
setClientKey
Client key for mTLS.- Parameters:
path-- Returns:
-
useServerTimeZone
Configure client to use server timezone for date/datetime columns. Default is true. If this options is selected then server timezone should be set as well.- Parameters:
useServerTimeZone- - if to use server timezone- Returns:
-
useTimeZone
Configure client to use specified timezone. If set using server TimeZone should be set to false- Parameters:
timeZone-- Returns:
-
setServerTimeZone
Specify server timezone to use. If not set then UTC will be used.- Parameters:
timeZone- - server timezone- Returns:
-
useAsyncRequests
Configures client to execute requests in a separate thread. By default, operations (query, insert) are executed in the same thread as the caller. It is possible to set a shared executor for all operations. SeesetSharedOperationExecutor(ExecutorService)Note: Async operations a using executor what expects having a queue of tasks for a pool of executors. The queue size limit is small it may quickly become a problem for scheduling new tasks.- Parameters:
async- - if to use async requests- Returns:
-
build
-