public class BalancedClickhouseDataSource extends Object implements DataSource
Database for clickhouse jdbc connections.
It has list of database urls.
For every getConnection invocation, it returns connection to random host from the list.
Furthermore, this class has method scheduleActualization
which test hosts for availability. By default, this option is turned off.
The instances of BalancedClickhouseDataSource don't identify the master and replicas.
You should use it if you only read from database and don't have write operations.
| Constructor and Description |
|---|
BalancedClickhouseDataSource(String url)
create Datasource for clickhouse JDBC connections
|
BalancedClickhouseDataSource(String url,
ClickHouseProperties properties)
create Datasource for clickhouse JDBC connections
|
BalancedClickhouseDataSource(String url,
Properties properties)
create Datasource for clickhouse JDBC connections
|
| Modifier and Type | Method and Description |
|---|---|
Connection |
getConnection() |
Connection |
getConnection(String username,
String password) |
int |
getLoginTimeout() |
PrintWriter |
getLogWriter() |
Logger |
getParentLogger() |
boolean |
isWrapperFor(Class<?> iface) |
BalancedClickhouseDataSource |
scheduleActualization(int rate,
TimeUnit timeUnit)
set time period for checking availability connections
|
void |
setLoginTimeout(int seconds) |
void |
setLogWriter(PrintWriter printWriter) |
<T> T |
unwrap(Class<T> iface) |
BalancedClickhouseDataSource |
withConnectionsCleaning(int rate,
TimeUnit timeUnit)
set time period of removing connections
|
public BalancedClickhouseDataSource(String url)
url - address for connection to the database
must have the next format jdbc:clickhouse://<first-host>:<port>,<second-host>:<port>/<database>
for example, jdbc:clickhouse://localhost:8123,localhost:8123/database IllegalArgumentException - if param have not correct format, or error happens when checking host availabilitypublic BalancedClickhouseDataSource(String url, Properties properties)
url - address for connection to the databaseproperties - database propertiesBalancedClickhouseDataSource(String)public BalancedClickhouseDataSource(String url, ClickHouseProperties properties)
url - address for connection to the databaseproperties - database propertiesBalancedClickhouseDataSource(String)public Connection getConnection() throws SQLException
getConnection in interface DataSourceSQLExceptionpublic Connection getConnection(String username, String password) throws SQLException
getConnection in interface DataSourceSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap in interface WrapperSQLExceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic PrintWriter getLogWriter() throws SQLException
getLogWriter in interface CommonDataSourceSQLExceptionpublic void setLogWriter(PrintWriter printWriter) throws SQLException
setLogWriter in interface CommonDataSourceSQLExceptionpublic void setLoginTimeout(int seconds)
throws SQLException
setLoginTimeout in interface CommonDataSourceSQLExceptionpublic int getLoginTimeout()
throws SQLException
getLoginTimeout in interface CommonDataSourceSQLExceptionpublic Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger in interface CommonDataSourceSQLFeatureNotSupportedExceptionpublic BalancedClickhouseDataSource withConnectionsCleaning(int rate, TimeUnit timeUnit)
rate - value for time unittimeUnit - time unit for checkingClickHouseDriver.scheduleConnectionsCleaning(int, java.util.concurrent.TimeUnit)public BalancedClickhouseDataSource scheduleActualization(int rate, TimeUnit timeUnit)
rate - value for time unittimeUnit - time unit for checkingCopyright © 2017. All rights reserved.