ru.yandex.clickhouse

## Class BalancedClickhouseDataSource

- java.lang.Object
- - ru.yandex.clickhouse.BalancedClickhouseDataSource

All Implemented Interfaces:
  Wrapper, CommonDataSource, DataSource

    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.

### Constructor Summary

Constructors
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

### Method Summary

All Methods Instance Methods Concrete Methods
`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

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### BalancedClickhouseDataSource

    public BalancedClickhouseDataSource(String url)

create Datasource for clickhouse JDBC connections

Parameters:
  `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`
Throws:
  `IllegalArgumentException` - if param have not correct format, or error happens when checking host availability

#### BalancedClickhouseDataSource

    public BalancedClickhouseDataSource(String url,
                                        Properties properties)

create Datasource for clickhouse JDBC connections

Parameters:
  `url` - address for connection to the database
  `properties` - database properties
See Also:
  `BalancedClickhouseDataSource(String)`

#### BalancedClickhouseDataSource

    public BalancedClickhouseDataSource(String url,
                                        ClickHouseProperties properties)

create Datasource for clickhouse JDBC connections

Parameters:
  `url` - address for connection to the database
  `properties` - database properties
See Also:
  `BalancedClickhouseDataSource(String)`

### Method Detail

#### getConnection

    public Connection getConnection()
                             throws SQLException

Specified by:
  `getConnection` in interface `DataSource`
Throws:
  `SQLException`

#### getConnection

    public Connection getConnection(String username,
                                    String password)
                             throws SQLException

Specified by:
  `getConnection` in interface `DataSource`
Throws:
  `SQLException`

#### unwrap

    public <T> T unwrap(Class<T> iface)
                 throws SQLException

Specified by:
  `unwrap` in interface `Wrapper`
Throws:
  `SQLException`

#### isWrapperFor

    public boolean isWrapperFor(Class<?> iface)
                         throws SQLException

Specified by:
  `isWrapperFor` in interface `Wrapper`
Throws:
  `SQLException`

#### getLogWriter

    public PrintWriter getLogWriter()
                             throws SQLException

Specified by:
  `getLogWriter` in interface `CommonDataSource`
Throws:
  `SQLException`

#### setLogWriter

    public void setLogWriter(PrintWriter printWriter)
                      throws SQLException

Specified by:
  `setLogWriter` in interface `CommonDataSource`
Throws:
  `SQLException`

#### setLoginTimeout

    public void setLoginTimeout(int seconds)
                         throws SQLException

Specified by:
  `setLoginTimeout` in interface `CommonDataSource`
Throws:
  `SQLException`

#### getLoginTimeout

    public int getLoginTimeout()
                        throws SQLException

Specified by:
  `getLoginTimeout` in interface `CommonDataSource`
Throws:
  `SQLException`

#### getParentLogger

    public Logger getParentLogger()
                           throws SQLFeatureNotSupportedException

Specified by:
  `getParentLogger` in interface `CommonDataSource`
Throws:
  `SQLFeatureNotSupportedException`

#### withConnectionsCleaning

    public BalancedClickhouseDataSource withConnectionsCleaning(int rate,
                                                                TimeUnit timeUnit)

set time period of removing connections

Parameters:
  `rate` - value for time unit
  `timeUnit` - time unit for checking
Returns:
  this datasource with changed settings
See Also:
  `ClickHouseDriver.scheduleConnectionsCleaning(int, java.util.concurrent.TimeUnit)`

#### scheduleActualization

    public BalancedClickhouseDataSource scheduleActualization(int rate,
                                                              TimeUnit timeUnit)

set time period for checking availability connections

Parameters:
  `rate` - value for time unit
  `timeUnit` - time unit for checking
Returns:
  this datasource with changed settings