Skip to content

Commit 7660894

Browse files
author
Paultagoras
committed
Updating where the proxy happens
1 parent d9cbaba commit 7660894

File tree

13 files changed

+452
-427
lines changed

13 files changed

+452
-427
lines changed
Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,64 @@
11
package com.clickhouse.jdbc;
22

33
import javax.sql.DataSource;
4-
5-
import com.clickhouse.client.config.ClickHouseDefaults;
6-
import com.clickhouse.jdbc.internal.ClickHouseConnectionImpl;
7-
import com.clickhouse.jdbc.internal.ClickHouseJdbcUrlParser;
8-
import com.clickhouse.jdbc.internal.ClickHouseJdbcUrlParser.ConnectionInfo;
9-
104
import java.io.PrintWriter;
115
import java.sql.Connection;
12-
import java.sql.DriverManager;
136
import java.sql.SQLException;
147
import java.sql.SQLFeatureNotSupportedException;
158
import java.util.Properties;
16-
import java.util.logging.Logger;
17-
18-
public class ClickHouseDataSource extends JdbcWrapper implements DataSource {
19-
private final String url;
20-
private final Properties props;
21-
22-
protected final ClickHouseDriver driver;
23-
protected final ConnectionInfo connInfo;
249

25-
protected PrintWriter printWriter;
26-
protected int loginTimeoutSeconds = 0;
10+
public class ClickHouseDataSource implements javax.sql.DataSource, com.clickhouse.jdbc.JdbcV2Wrapper {
11+
private final DataSource dataSource;
12+
private final ClickHouseDriver driver;
2713

2814
public ClickHouseDataSource(String url) throws SQLException {
2915
this(url, new Properties());
3016
}
3117

3218
public ClickHouseDataSource(String url, Properties properties) throws SQLException {
33-
if (url == null) {
34-
throw new IllegalArgumentException("Incorrect ClickHouse jdbc url. It must be not null");
35-
}
36-
this.url = url;
37-
this.props = new Properties();
38-
if (properties != null && !properties.isEmpty()) {
39-
this.props.putAll(properties);
40-
}
41-
4219
this.driver = new ClickHouseDriver();
43-
new VersionSelectingDriver();//This is a workaround to make sure the driver is loaded
44-
this.connInfo = ClickHouseJdbcUrlParser.parse(url, properties);
20+
21+
if (driver.isV2(url)) {
22+
//v2
23+
this.dataSource = new com.clickhouse.jdbc.DataSourceImpl(url, properties);
24+
} else {
25+
//v1
26+
this.dataSource = new DataSourceV1(url, properties);
27+
}
4528
}
4629

4730
@Override
48-
public ClickHouseConnection getConnection() throws SQLException {
49-
return new ClickHouseConnectionImpl(connInfo);
31+
public Connection getConnection() throws SQLException {
32+
return dataSource.getConnection();
5033
}
5134

5235
@Override
53-
public ClickHouseConnection getConnection(String username, String password) throws SQLException {
54-
if (username == null || username.isEmpty()) {
55-
throw SqlExceptionUtils.clientError("Non-empty user name is required");
56-
}
57-
58-
if (password == null) {
59-
password = "";
60-
}
61-
62-
if (username.equals(props.getProperty(ClickHouseDefaults.USER.getKey()))
63-
&& password.equals(props.getProperty(ClickHouseDefaults.PASSWORD.getKey()))) {
64-
return new ClickHouseConnectionImpl(connInfo);
65-
}
66-
67-
Properties properties = new Properties();
68-
properties.putAll(this.props);
69-
properties.setProperty(ClickHouseDefaults.USER.getKey(), username);
70-
properties.setProperty(ClickHouseDefaults.PASSWORD.getKey(), password);
71-
return new ClickHouseConnectionImpl(url, properties);
36+
public Connection getConnection(String username, String password) throws SQLException {
37+
return dataSource.getConnection(username, password);
7238
}
7339

7440
@Override
7541
public PrintWriter getLogWriter() throws SQLException {
76-
return printWriter;
42+
return dataSource.getLogWriter();
7743
}
7844

7945
@Override
8046
public void setLogWriter(PrintWriter out) throws SQLException {
81-
printWriter = out;
47+
dataSource.setLogWriter(out);
8248
}
8349

8450
@Override
8551
public void setLoginTimeout(int seconds) throws SQLException {
86-
loginTimeoutSeconds = seconds;
52+
dataSource.setLoginTimeout(seconds);
8753
}
8854

8955
@Override
9056
public int getLoginTimeout() throws SQLException {
91-
return loginTimeoutSeconds;
57+
return dataSource.getLoginTimeout();
9258
}
9359

94-
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
95-
return ClickHouseDriver.parentLogger;
60+
@Override
61+
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
62+
return dataSource.getParentLogger();
9663
}
9764
}

clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaData.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,17 @@ public String getDriverName() throws SQLException {
149149

150150
@Override
151151
public String getDriverVersion() throws SQLException {
152-
return ClickHouseDriver.driverVersionString;
152+
return DriverV1.driverVersionString;
153153
}
154154

155155
@Override
156156
public int getDriverMajorVersion() {
157-
return ClickHouseDriver.driverVersion.getMajorVersion();
157+
return DriverV1.driverVersion.getMajorVersion();
158158
}
159159

160160
@Override
161161
public int getDriverMinorVersion() {
162-
return ClickHouseDriver.driverVersion.getMinorVersion();
162+
return DriverV1.driverVersion.getMinorVersion();
163163
}
164164

165165
@Override
@@ -1217,12 +1217,12 @@ public int getDatabaseMinorVersion() throws SQLException {
12171217

12181218
@Override
12191219
public int getJDBCMajorVersion() throws SQLException {
1220-
return ClickHouseDriver.specVersion.getMajorVersion();
1220+
return DriverV1.specVersion.getMajorVersion();
12211221
}
12221222

12231223
@Override
12241224
public int getJDBCMinorVersion() throws SQLException {
1225-
return ClickHouseDriver.specVersion.getMinorVersion();
1225+
return DriverV1.specVersion.getMinorVersion();
12261226
}
12271227

12281228
@Override

0 commit comments

Comments
 (0)