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
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort(Executor executor)voidclearWarnings()voidclose()voidcommit()NClobcreateNClob()ClickHouseStatementcreateStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)protected voidensureOpen()Checks if the connection is open or not.protected voidensureSupport(String feature, boolean silent)Checks if a feature can be supported or not.protected voidensureTransactionSupport()booleangetAutoCommit()StringgetCatalog()PropertiesgetClientInfo()StringgetClientInfo(String name)ClickHouseConfiggetConfig()Gets configuration tied to this connection.StringgetCurrentDatabase()Gets current database.StringgetCurrentUser()Gets current user.CalendargetDefaultCalendar()Gets default calendar which can be used to create timestamp.Optional<TimeZone>getEffectiveTimeZone()Gets effective time zone.intgetHoldability()JdbcConfiggetJdbcConfig()Gets JDBC-specific configuration.TimeZonegetJvmTimeZone()Gets cached value ofTimeZone.getDefault().DatabaseMetaDatagetMetaData()intgetNetworkTimeout()StringgetSchema()TimeZonegetServerTimeZone()Gets server time zone, which is either same as result ofselect timezone(), or the overrided value fromClickHouseConfig.getServerTimeZone().ClickHouseVersiongetServerVersion()Gets server version.protected List<ClickHouseColumn>getTableColumns(String dbName, String tableName, String columns)intgetTransactionIsolation()Map<String,Class<?>>getTypeMap()URIgetUri()Gets URI of the connection.SQLWarninggetWarnings()booleanisClosed()booleanisReadOnly()booleanisValid(int timeout)booleanisWrapperFor(Class<?> iface)StringnativeSQL(String sql)StringnewQueryId()Creates a new query ID.ClickHouseSqlStatement[]parse(String sql, ClickHouseConfig config)Parses the given sql.PreparedStatementprepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)voidreleaseSavepoint(Savepoint savepoint)voidrollback()voidrollback(Savepoint savepoint)voidsetAutoCommit(boolean autoCommit)voidsetCatalog(String catalog)voidsetClientInfo(String name, String value)voidsetClientInfo(Properties properties)voidsetHoldability(int holdability)voidsetNetworkTimeout(Executor executor, int milliseconds)voidsetReadOnly(boolean readOnly)SavepointsetSavepoint()SavepointsetSavepoint(String name)voidsetSchema(String schema)voidsetTransactionIsolation(int level)voidsetTypeMap(Map<String,Class<?>> map)<T> Tunwrap(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, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement
-
Methods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
-
-
-
Constructor Detail
-
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 Detail
-
ensureOpen
protected void ensureOpen() throws SQLExceptionChecks 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 namesilent- whether to show warning in log or throw unsupported exception- Throws:
SQLException- when the feature is not supported and silent isfalse
-
ensureTransactionSupport
protected void ensureTransactionSupport() throws SQLException- Throws:
SQLException
-
getTableColumns
protected List<ClickHouseColumn> getTableColumns(String dbName, String tableName, String columns) throws SQLException
- Throws:
SQLException
-
nativeSQL
public String nativeSQL(String sql) throws SQLException
- Specified by:
nativeSQLin interfaceConnection- Throws:
SQLException
-
setAutoCommit
public void setAutoCommit(boolean autoCommit) throws SQLException- Specified by:
setAutoCommitin interfaceConnection- Throws:
SQLException
-
getAutoCommit
public boolean getAutoCommit() throws SQLException- Specified by:
getAutoCommitin interfaceConnection- Throws:
SQLException
-
commit
public void commit() throws SQLException- Specified by:
commitin interfaceConnection- Throws:
SQLException
-
rollback
public void rollback() throws SQLException- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
close
public void close() throws SQLException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
SQLException
-
isClosed
public boolean isClosed() throws SQLException- Specified by:
isClosedin interfaceConnection- Throws:
SQLException
-
getMetaData
public DatabaseMetaData getMetaData() throws SQLException
- Specified by:
getMetaDatain interfaceConnection- Throws:
SQLException
-
setReadOnly
public void setReadOnly(boolean readOnly) throws SQLException- Specified by:
setReadOnlyin interfaceConnection- Throws:
SQLException
-
isReadOnly
public boolean isReadOnly() throws SQLException- Specified by:
isReadOnlyin interfaceConnection- Throws:
SQLException
-
setCatalog
public void setCatalog(String catalog) throws SQLException
- Specified by:
setCatalogin interfaceConnection- Throws:
SQLException
-
getCatalog
public String getCatalog() throws SQLException
- Specified by:
getCatalogin interfaceConnection- Throws:
SQLException
-
setTransactionIsolation
public void setTransactionIsolation(int level) throws SQLException- Specified by:
setTransactionIsolationin interfaceConnection- Throws:
SQLException
-
getTransactionIsolation
public int getTransactionIsolation() throws SQLException- Specified by:
getTransactionIsolationin interfaceConnection- Throws:
SQLException
-
getWarnings
public SQLWarning getWarnings() throws SQLException
- Specified by:
getWarningsin interfaceConnection- Throws:
SQLException
-
clearWarnings
public void clearWarnings() throws SQLException- Specified by:
clearWarningsin interfaceConnection- Throws:
SQLException
-
getTypeMap
public Map<String,Class<?>> getTypeMap() throws SQLException
- Specified by:
getTypeMapin interfaceConnection- Throws:
SQLException
-
setTypeMap
public void setTypeMap(Map<String,Class<?>> map) throws SQLException
- Specified by:
setTypeMapin interfaceConnection- Throws:
SQLException
-
setHoldability
public void setHoldability(int holdability) throws SQLException- Specified by:
setHoldabilityin interfaceConnection- Throws:
SQLException
-
getHoldability
public int getHoldability() throws SQLException- Specified by:
getHoldabilityin interfaceConnection- Throws:
SQLException
-
setSavepoint
public Savepoint setSavepoint() throws SQLException
- Specified by:
setSavepointin interfaceConnection- Throws:
SQLException
-
setSavepoint
public Savepoint setSavepoint(String name) throws SQLException
- Specified by:
setSavepointin interfaceConnection- Throws:
SQLException
-
rollback
public void rollback(Savepoint savepoint) throws SQLException
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
releaseSavepoint
public void releaseSavepoint(Savepoint savepoint) throws SQLException
- Specified by:
releaseSavepointin interfaceConnection- Throws:
SQLException
-
createStatement
public ClickHouseStatement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
- Specified by:
createStatementin interfaceClickHouseConnection- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
createNClob
public NClob createNClob() throws SQLException
- Specified by:
createNClobin interfaceConnection- Throws:
SQLException
-
isValid
public boolean isValid(int timeout) throws SQLException- Specified by:
isValidin interfaceConnection- Throws:
SQLException
-
setClientInfo
public void setClientInfo(String name, String value) throws SQLClientInfoException
- Specified by:
setClientInfoin interfaceConnection- Throws:
SQLClientInfoException
-
setClientInfo
public void setClientInfo(Properties properties) throws SQLClientInfoException
- Specified by:
setClientInfoin interfaceConnection- Throws:
SQLClientInfoException
-
getClientInfo
public String getClientInfo(String name) throws SQLException
- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException
-
getClientInfo
public Properties getClientInfo() throws SQLException
- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException
-
setSchema
public void setSchema(String schema) throws SQLException
- Specified by:
setSchemain interfaceConnection- Throws:
SQLException
-
getSchema
public String getSchema() throws SQLException
- Specified by:
getSchemain interfaceConnection- Throws:
SQLException
-
abort
public void abort(Executor executor) throws SQLException
- Specified by:
abortin interfaceConnection- Throws:
SQLException
-
setNetworkTimeout
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException
- Specified by:
setNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
getNetworkTimeout
public int getNetworkTimeout() throws SQLException- Specified by:
getNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
getConfig
public ClickHouseConfig getConfig()
Description copied from interface:ClickHouseConnectionGets configuration tied to this connection.- Specified by:
getConfigin interfaceClickHouseConnection- Returns:
- non-null configuration
-
getCurrentDatabase
public String getCurrentDatabase()
Description copied from interface:ClickHouseConnectionGets current database.Connection.getSchema()is similar but it will check if connection is closed or not hence may throwSQLException.- Specified by:
getCurrentDatabasein interfaceClickHouseConnection- Returns:
- non-null database name
-
getCurrentUser
public String getCurrentUser()
Description copied from interface:ClickHouseConnectionGets current user.- Specified by:
getCurrentUserin interfaceClickHouseConnection- Returns:
- non-null user name
-
getDefaultCalendar
public Calendar getDefaultCalendar()
Description copied from interface:ClickHouseConnectionGets default calendar which can be used to create timestamp.- Specified by:
getDefaultCalendarin interfaceClickHouseConnection- Returns:
- non-null calendar
-
getEffectiveTimeZone
public Optional<TimeZone> getEffectiveTimeZone()
Description copied from interface:ClickHouseConnectionGets effective time zone. WhenClickHouseConfig.isUseServerTimeZone()returnsfalse,ClickHouseConfig.getUseTimeZone()will be used as effective time zone, which will be used for reading and writing timestamp values.- Specified by:
getEffectiveTimeZonein interfaceClickHouseConnection- Returns:
- effective time zone
-
getJvmTimeZone
public TimeZone getJvmTimeZone()
Description copied from interface:ClickHouseConnectionGets cached value ofTimeZone.getDefault().- Specified by:
getJvmTimeZonein interfaceClickHouseConnection- Returns:
- non-null cached JVM time zone
-
getServerTimeZone
public TimeZone getServerTimeZone()
Description copied from interface:ClickHouseConnectionGets server time zone, which is either same as result ofselect timezone(), or the overrided value fromClickHouseConfig.getServerTimeZone().- Specified by:
getServerTimeZonein interfaceClickHouseConnection- Returns:
- non-null server time zone
-
getServerVersion
public ClickHouseVersion getServerVersion()
Description copied from interface:ClickHouseConnectionGets server version.- Specified by:
getServerVersionin interfaceClickHouseConnection- Returns:
- non-null server version
-
getUri
public URI getUri()
Description copied from interface:ClickHouseConnectionGets URI of the connection.- Specified by:
getUriin interfaceClickHouseConnection- Returns:
- URI of the connection
-
getJdbcConfig
public JdbcConfig getJdbcConfig()
Description copied from interface:ClickHouseConnectionGets JDBC-specific configuration.- Specified by:
getJdbcConfigin interfaceClickHouseConnection- Returns:
- non-null JDBC-specific configuration
-
newQueryId
public String newQueryId()
Description copied from interface:ClickHouseConnectionCreates a new query ID.- Specified by:
newQueryIdin interfaceClickHouseConnection- Returns:
- universal unique query ID
-
parse
public ClickHouseSqlStatement[] parse(String sql, ClickHouseConfig config)
Description copied from interface:ClickHouseConnectionParses the given sql.- Specified by:
parsein interfaceClickHouseConnection- Parameters:
sql- sql to parseconfig- configuration which might be used for parsing, could be null- Returns:
- non-null parsed sql statements
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
- Specified by:
isWrapperForin interfaceWrapper- Overrides:
isWrapperForin classJdbcWrapper- Throws:
SQLException
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
- Specified by:
unwrapin interfaceWrapper- Overrides:
unwrapin classJdbcWrapper- Throws:
SQLException
-
-