Package com.clickhouse.jdbc.internal

# Class ClickHouseConnectionImpl

java.lang.Object
com.clickhouse.jdbc.JdbcWrapper
com.clickhouse.jdbc.internal.ClickHouseConnectionImpl

All Implemented Interfaces:
  `ClickHouseConnection`, `AutoCloseable`, `Connection`, `Wrapper`

public class ClickHouseConnectionImpl extends JdbcWrapper implements ClickHouseConnection

## Field Summary

### Fields inherited from interface com.clickhouse.jdbc.ClickHouseConnection

`COLUMN_ARRAY, COLUMN_ELEMENT, PROP_APPLICATION_NAME, PROP_CUSTOM_HTTP_HEADERS, PROP_CUSTOM_HTTP_PARAMS`

### Fields inherited from interface java.sql.Connection

`TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE`

## Constructor Summary

Constructors
Constructor
Description
`ClickHouseConnectionImpl(ClickHouseJdbcUrlParser.ConnectionInfo connInfo)`
`ClickHouseConnectionImpl(String url)`
`ClickHouseConnectionImpl(String url, Properties properties)`

## Method Summary

Modifier and Type
Method
Description
`void`
`abort(Executor executor)`
`boolean`
`allowCustomSetting()`
Checks whether custom setting is allowed or not.
`void`
`begin()`
Starts a new transaction.
`void`
`clearWarnings()`
`void`
`close()`
`void`
`commit()`
`NClob`
`createNClob()`
`protected JdbcSavepoint`
`createSavepoint()`
`ClickHouseStatement`
`createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)`
`protected JdbcTransaction`
`createTransaction()`
`protected void`
`ensureOpen()`
Checks if the connection is open or not.
`protected void`
`ensureSupport(String feature, boolean silent)`
Checks if a feature can be supported or not.
`protected void`
`ensureTransactionSupport()`
`boolean`
`getAutoCommit()`
`String`
`getCatalog()`
`Properties`
`getClientInfo()`
`String`
`getClientInfo(String name)`
`ClickHouseConfig`
`getConfig()`
Gets configuration tied to this connection.
`String`
`getCurrentDatabase()`
Gets current database.
`String`
`getCurrentUser()`
Gets current user.
`protected String`
`getDatabase()`
`Calendar`
`getDefaultCalendar()`
Gets default calendar which can be used to create timestamp.
`Optional<TimeZone>`
`getEffectiveTimeZone()`
Gets effective time zone.
`int`
`getHoldability()`
`JdbcConfig`
`getJdbcConfig()`
Gets JDBC-specific configuration.
`TimeZone`
`getJvmTimeZone()`
Gets cached value of `TimeZone.getDefault()`.
`long`
`getMaxInsertBlockSize()`
Gets max insert block size.
`DatabaseMetaData`
`getMetaData()`
`int`
`getNetworkTimeout()`
`String`
`getSchema()`
`protected static ClickHouseRecord`
`getServerInfo(ClickHouseNode node, ClickHouseRequest<?> request, boolean createDbIfNotExist)`
`TimeZone`
`getServerTimeZone()`
Gets server time zone, which is either same as result of `select timezone()`, or the overrided value from `ClickHouseConfig.getServerTimeZone()`.
`ClickHouseVersion`
`getServerVersion()`
Gets server version.
`protected List<ClickHouseColumn>`
`getTableColumns(String dbName, String tableName, String columns)`
`ClickHouseTransaction`
`getTransaction()`
Gets current transaction.
`int`
`getTransactionIsolation()`
`Map<String,Class<?>>`
`getTypeMap()`
`URI`
`getUri()`
Gets URI of the connection.
`SQLWarning`
`getWarnings()`
`boolean`
`isClosed()`
`boolean`
`isImplicitTransactionSupported()`
Checks whether implicit transaction is supported.
`boolean`
`isReadOnly()`
`boolean`
`isTransactionSupported()`
Checks whether transaction is supported.
`boolean`
`isValid(int timeout)`
`boolean`
`isWrapperFor(Class<?> iface)`
`String`
`nativeSQL(String sql)`
`String`
`newQueryId()`
Creates a new query ID.
`ClickHouseSqlStatement[]`
`parse(String sql, ClickHouseConfig config, Map<String,Serializable> settings)`
Parses the given sql.
`PreparedStatement`
`prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)`
`void`
`releaseSavepoint(Savepoint savepoint)`
`void`
`rollback()`
`void`
`rollback(Savepoint savepoint)`
`void`
`setAutoCommit(boolean autoCommit)`
`void`
`setCatalog(String catalog)`
`void`
`setClientInfo(String name, String value)`
`void`
`setClientInfo(Properties properties)`
`void`
`setCurrentDatabase(String db, boolean check)`
Sets current database.
`void`
`setHoldability(int holdability)`
`void`
`setNetworkTimeout(Executor executor, int milliseconds)`
`void`
`setReadOnly(boolean readOnly)`
`Savepoint`
`setSavepoint()`
`Savepoint`
`setSavepoint(String name)`
`void`
`setSchema(String schema)`
`void`
`setTransactionIsolation(int level)`
`void`
`setTypeMap(Map<String,Class<?>> map)`
`<T> T`
`unwrap(Class<T> iface)`

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

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

### Methods inherited from interface com.clickhouse.jdbc.ClickHouseConnection

`createArrayOf, createBlob, createClob, createSQLXML, createStatement, createStatement, createStruct, getJdbcTypeMapping, parse, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement`

### Methods inherited from interface java.sql.Connection

`beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid`

## Constructor Details

### ClickHouseConnectionImpl

public ClickHouseConnectionImpl(String url) throws SQLException

Throws:
  `SQLException`

### ClickHouseConnectionImpl

public ClickHouseConnectionImpl(String url, Properties properties) throws SQLException

Throws:
  `SQLException`

### ClickHouseConnectionImpl

public ClickHouseConnectionImpl(ClickHouseJdbcUrlParser.ConnectionInfo connInfo) throws SQLException

Throws:
  `SQLException`

## Method Details

### getServerInfo

protected static ClickHouseRecord getServerInfo(ClickHouseNode node, ClickHouseRequest<?> request, boolean createDbIfNotExist) throws SQLException

Throws:
  `SQLException`

### createTransaction

protected JdbcTransaction createTransaction() throws SQLException

Throws:
  `SQLException`

### createSavepoint

protected JdbcSavepoint createSavepoint()

### ensureOpen

protected void ensureOpen() throws SQLException
Checks if the connection is open or not.

Throws:
  `SQLException` - when the connection is closed

### ensureSupport

protected void ensureSupport(String feature, boolean silent) throws SQLException
Checks if a feature can be supported or not.

Parameters:
  `feature` - non-empty feature name
  `silent` - whether to show warning in log or throw unsupported exception
Throws:
  `SQLException` - when the feature is not supported and silent is `false`

### ensureTransactionSupport

protected void ensureTransactionSupport() throws SQLException

Throws:
  `SQLException`

### getTableColumns

protected List<ClickHouseColumn> getTableColumns(String dbName, String tableName, String columns) throws SQLException

Throws:
  `SQLException`

### getDatabase

protected String getDatabase() throws SQLException

Throws:
  `SQLException`

### nativeSQL

public String nativeSQL(String sql) throws SQLException

Specified by:
  `nativeSQL` in interface `Connection`
Throws:
  `SQLException`

### setAutoCommit

public void setAutoCommit(boolean autoCommit) throws SQLException

Specified by:
  `setAutoCommit` in interface `Connection`
Throws:
  `SQLException`

### getAutoCommit

public boolean getAutoCommit() throws SQLException

Specified by:
  `getAutoCommit` in interface `Connection`
Throws:
  `SQLException`

### begin

public void begin() throws SQLException
Description copied from interface: `ClickHouseConnection`
Starts a new transaction. It's no-op for a newly started transaction.

Specified by:
  `begin` in interface `ClickHouseConnection`
Throws:
  `SQLException` - when current transaction is active state or not able to start new transaction

### commit

public void commit() throws SQLException

Specified by:
  `commit` in interface `Connection`
Throws:
  `SQLException`

### rollback

public void rollback() throws SQLException

Specified by:
  `rollback` in interface `Connection`
Throws:
  `SQLException`

### close

public void close() throws SQLException

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Connection`
Throws:
  `SQLException`

### isClosed

public boolean isClosed() throws SQLException

Specified by:
  `isClosed` in interface `Connection`
Throws:
  `SQLException`

### getMetaData

public DatabaseMetaData getMetaData() throws SQLException

Specified by:
  `getMetaData` in interface `Connection`
Throws:
  `SQLException`

### setReadOnly

public void setReadOnly(boolean readOnly) throws SQLException

Specified by:
  `setReadOnly` in interface `Connection`
Throws:
  `SQLException`

### isReadOnly

public boolean isReadOnly() throws SQLException

Specified by:
  `isReadOnly` in interface `Connection`
Throws:
  `SQLException`

### setCatalog

public void setCatalog(String catalog) throws SQLException

Specified by:
  `setCatalog` in interface `Connection`
Throws:
  `SQLException`

### getCatalog

public String getCatalog() throws SQLException

Specified by:
  `getCatalog` in interface `Connection`
Throws:
  `SQLException`

### setTransactionIsolation

public void setTransactionIsolation(int level) throws SQLException

Specified by:
  `setTransactionIsolation` in interface `Connection`
Throws:
  `SQLException`

### getTransactionIsolation

public int getTransactionIsolation() throws SQLException

Specified by:
  `getTransactionIsolation` in interface `Connection`
Throws:
  `SQLException`

### getWarnings

public SQLWarning getWarnings() throws SQLException

Specified by:
  `getWarnings` in interface `Connection`
Throws:
  `SQLException`

### clearWarnings

public void clearWarnings() throws SQLException

Specified by:
  `clearWarnings` in interface `Connection`
Throws:
  `SQLException`

### getTypeMap

public Map<String,Class<?>> getTypeMap() throws SQLException

Specified by:
  `getTypeMap` in interface `Connection`
Throws:
  `SQLException`

### setTypeMap

public void setTypeMap(Map<String,Class<?>> map) throws SQLException

Specified by:
  `setTypeMap` in interface `Connection`
Throws:
  `SQLException`

### setHoldability

public void setHoldability(int holdability) throws SQLException

Specified by:
  `setHoldability` in interface `Connection`
Throws:
  `SQLException`

### getHoldability

public int getHoldability() throws SQLException

Specified by:
  `getHoldability` in interface `Connection`
Throws:
  `SQLException`

### setSavepoint

public Savepoint setSavepoint() throws SQLException

Specified by:
  `setSavepoint` in interface `Connection`
Throws:
  `SQLException`

### setSavepoint

public Savepoint setSavepoint(String name) throws SQLException

Specified by:
  `setSavepoint` in interface `Connection`
Throws:
  `SQLException`

### rollback

public void rollback(Savepoint savepoint) throws SQLException

Specified by:
  `rollback` in interface `Connection`
Throws:
  `SQLException`

### releaseSavepoint

public void releaseSavepoint(Savepoint savepoint) throws SQLException

Specified by:
  `releaseSavepoint` in interface `Connection`
Throws:
  `SQLException`

### createStatement

public ClickHouseStatement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException

Specified by:
  `createStatement` in interface `ClickHouseConnection`
Specified by:
  `createStatement` in interface `Connection`
Throws:
  `SQLException`

### prepareStatement

public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

### createNClob

public NClob createNClob() throws SQLException

Specified by:
  `createNClob` in interface `Connection`
Throws:
  `SQLException`

### isValid

public boolean isValid(int timeout) throws SQLException

Specified by:
  `isValid` in interface `Connection`
Throws:
  `SQLException`

### setClientInfo

public void setClientInfo(String name, String value) throws SQLClientInfoException

Specified by:
  `setClientInfo` in interface `Connection`
Throws:
  `SQLClientInfoException`

### setClientInfo

public void setClientInfo(Properties properties) throws SQLClientInfoException

Specified by:
  `setClientInfo` in interface `Connection`
Throws:
  `SQLClientInfoException`

### getClientInfo

public String getClientInfo(String name) throws SQLException

Specified by:
  `getClientInfo` in interface `Connection`
Throws:
  `SQLException`

### getClientInfo

public Properties getClientInfo() throws SQLException

Specified by:
  `getClientInfo` in interface `Connection`
Throws:
  `SQLException`

### setSchema

public void setSchema(String schema) throws SQLException

Specified by:
  `setSchema` in interface `Connection`
Throws:
  `SQLException`

### getSchema

public String getSchema() throws SQLException

Specified by:
  `getSchema` in interface `Connection`
Throws:
  `SQLException`

### abort

public void abort(Executor executor) throws SQLException

Specified by:
  `abort` in interface `Connection`
Throws:
  `SQLException`

### setNetworkTimeout

public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException

Specified by:
  `setNetworkTimeout` in interface `Connection`
Throws:
  `SQLException`

### getNetworkTimeout

public int getNetworkTimeout() throws SQLException

Specified by:
  `getNetworkTimeout` in interface `Connection`
Throws:
  `SQLException`

### getConfig

public ClickHouseConfig getConfig()
Description copied from interface: `ClickHouseConnection`
Gets configuration tied to this connection.

Specified by:
  `getConfig` in interface `ClickHouseConnection`
Returns:
  non-null configuration

### allowCustomSetting

public boolean allowCustomSetting()
Description copied from interface: `ClickHouseConnection`
Checks whether custom setting is allowed or not.

Specified by:
  `allowCustomSetting` in interface `ClickHouseConnection`
Returns:
  true if custom setting is allowed; false otherwise

### getCurrentDatabase

public String getCurrentDatabase()
Description copied from interface: `ClickHouseConnection`
Gets current database. `Connection.getSchema()` is similar but it will check if connection is closed or not hence may throw `SQLException`.

Specified by:
  `getCurrentDatabase` in interface `ClickHouseConnection`
Returns:
  non-null database name

### setCurrentDatabase

public void setCurrentDatabase(String db, boolean check) throws SQLException
Description copied from interface: `ClickHouseConnection`
Sets current database.

Specified by:
  `setCurrentDatabase` in interface `ClickHouseConnection`
Parameters:
  `db` - non-empty database name
  `check` - whether to check if the database exists or not
Throws:
  `SQLException` - when failed to change current database

### getCurrentUser

public String getCurrentUser()
Description copied from interface: `ClickHouseConnection`
Gets current user.

Specified by:
  `getCurrentUser` in interface `ClickHouseConnection`
Returns:
  non-null user name

### getDefaultCalendar

public Calendar getDefaultCalendar()
Description copied from interface: `ClickHouseConnection`
Gets default calendar which can be used to create timestamp.

Specified by:
  `getDefaultCalendar` in interface `ClickHouseConnection`
Returns:
  non-null calendar

### getEffectiveTimeZone

public Optional<TimeZone> getEffectiveTimeZone()
Description copied from interface: `ClickHouseConnection`
Gets effective time zone. When `ClickHouseConfig.isUseServerTimeZone()` returns `false`, `ClickHouseConfig.getUseTimeZone()` will be used as effective time zone, which will be used for reading and writing timestamp values.

Specified by:
  `getEffectiveTimeZone` in interface `ClickHouseConnection`
Returns:
  effective time zone

### getJvmTimeZone

public TimeZone getJvmTimeZone()
Description copied from interface: `ClickHouseConnection`
Gets cached value of `TimeZone.getDefault()`.

Specified by:
  `getJvmTimeZone` in interface `ClickHouseConnection`
Returns:
  non-null cached JVM time zone

### getServerTimeZone

public TimeZone getServerTimeZone()
Description copied from interface: `ClickHouseConnection`
Gets server time zone, which is either same as result of `select timezone()`, or the overrided value from `ClickHouseConfig.getServerTimeZone()`.

Specified by:
  `getServerTimeZone` in interface `ClickHouseConnection`
Returns:
  non-null server time zone

### getServerVersion

public ClickHouseVersion getServerVersion()
Description copied from interface: `ClickHouseConnection`
Gets server version.

Specified by:
  `getServerVersion` in interface `ClickHouseConnection`
Returns:
  non-null server version

### getTransaction

public ClickHouseTransaction getTransaction()
Description copied from interface: `ClickHouseConnection`
Gets current transaction.

Specified by:
  `getTransaction` in interface `ClickHouseConnection`
Returns:
  current transaction, which could be null

### getUri

public URI getUri()
Description copied from interface: `ClickHouseConnection`
Gets URI of the connection.

Specified by:
  `getUri` in interface `ClickHouseConnection`
Returns:
  URI of the connection

### getJdbcConfig

public JdbcConfig getJdbcConfig()
Description copied from interface: `ClickHouseConnection`
Gets JDBC-specific configuration.

Specified by:
  `getJdbcConfig` in interface `ClickHouseConnection`
Returns:
  non-null JDBC-specific configuration

### getMaxInsertBlockSize

public long getMaxInsertBlockSize()
Description copied from interface: `ClickHouseConnection`
Gets max insert block size. Pay attention that INSERT into one partition in one table of MergeTree family up to max_insert_block_size rows is transactional.

Specified by:
  `getMaxInsertBlockSize` in interface `ClickHouseConnection`
Returns:
  value of max_insert_block_size

### isTransactionSupported

public boolean isTransactionSupported()
Description copied from interface: `ClickHouseConnection`
Checks whether transaction is supported.

Specified by:
  `isTransactionSupported` in interface `ClickHouseConnection`
Returns:
  true if transaction is supported; false otherwise

### isImplicitTransactionSupported

public boolean isImplicitTransactionSupported()
Description copied from interface: `ClickHouseConnection`
Checks whether implicit transaction is supported.

Specified by:
  `isImplicitTransactionSupported` in interface `ClickHouseConnection`
Returns:
  true if implicit transaction is supported; false otherwise

### newQueryId

public String newQueryId()
Description copied from interface: `ClickHouseConnection`
Creates a new query ID.

Specified by:
  `newQueryId` in interface `ClickHouseConnection`
Returns:
  universal unique query ID

### parse

public ClickHouseSqlStatement[] parse(String sql, ClickHouseConfig config, Map<String,Serializable> settings)
Description copied from interface: `ClickHouseConnection`
Parses the given sql.

Specified by:
  `parse` in interface `ClickHouseConnection`
Parameters:
  `sql` - sql to parse
  `config` - configuration which might be used for parsing, could be null
  `settings` - server settings
Returns:
  non-null parsed sql statements

### isWrapperFor

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

Specified by:
  `isWrapperFor` in interface `Wrapper`
Overrides:
  `isWrapperFor` in class `JdbcWrapper`
Throws:
  `SQLException`

### unwrap

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

Specified by:
  `unwrap` in interface `Wrapper`
Overrides:
  `unwrap` in class `JdbcWrapper`
Throws:
  `SQLException`