Skip to content

Commit 37b64ae

Browse files
committed
Merge branch 'main' into v2_remove_old_project_dependencies
2 parents 99b7de5 + 90087f7 commit 37b64ae

File tree

33 files changed

+797
-384
lines changed

33 files changed

+797
-384
lines changed

clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,12 @@ public static boolean isCloud() {
324324

325325
@BeforeSuite(groups = {"integration"})
326326
public static void beforeSuite() {
327-
if (isCloud()) {
327+
if (isCloud) {
328328
if (!runQuery("CREATE DATABASE IF NOT EXISTS " + database)) {
329329
throw new IllegalStateException("Failed to create database for testing.");
330330
}
331+
332+
return;
331333
}
332334

333335
if (clickhouseContainer != null) {
@@ -337,6 +339,10 @@ public static void beforeSuite() {
337339

338340
try {
339341
clickhouseContainer.start();
342+
343+
if (clickhouseContainer.isRunning()) {
344+
runQuery("CREATE DATABASE IF NOT EXISTS " + database);
345+
}
340346
} catch (RuntimeException e) {
341347
throw new IllegalStateException(new StringBuilder()
342348
.append("Failed to start docker container for integration test.\r\n")
@@ -353,7 +359,7 @@ public static void afterSuite() {
353359
clickhouseContainer.stop();
354360
}
355361

356-
if (isCloud()) {
362+
if (isCloud) {
357363
if (!runQuery("DROP DATABASE IF EXISTS " + database)) {
358364
LOGGER.warn("Failed to drop database for testing.");
359365
}

clickhouse-jdbc/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
<artifactId>gson</artifactId>
5959
<optional>true</optional>
6060
</dependency>
61+
<dependency>
62+
<groupId>com.clickhouse</groupId>
63+
<artifactId>jdbc-v2</artifactId>
64+
<version>${revision}</version>
65+
</dependency>
6166
<dependency>
6267
<groupId>io.opencensus</groupId>
6368
<artifactId>opencensus-impl</artifactId>
@@ -303,6 +308,7 @@
303308
<include>org.apache.httpcomponents.client5:httpclient5</include>
304309
<include>org.apache.httpcomponents.core5:httpcore5</include>
305310
<include>org.apache.httpcomponents.core5:httpcore5-h2</include>
311+
<include>com.clickhouse:jdbc-v2</include>
306312
<include>org.lz4:lz4-pure-java</include>
307313
</includes>
308314
</artifactSet>
@@ -374,6 +380,7 @@
374380
<include>org.apache.httpcomponents.core5:httpcore5</include>
375381
<include>org.apache.httpcomponents.core5:httpcore5-h2</include>
376382
<include>org.lz4:lz4-pure-java</include>
383+
<include>com.clickhouse:jdbc-v2</include>
377384
</includes>
378385
</artifactSet>
379386
<relocations>
Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +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;
5+
import java.sql.Connection;
116
import java.sql.SQLException;
127
import java.sql.SQLFeatureNotSupportedException;
138
import java.util.Properties;
14-
import java.util.logging.Logger;
15-
16-
public class ClickHouseDataSource extends JdbcWrapper implements DataSource {
17-
private final String url;
18-
private final Properties props;
19-
20-
protected final ClickHouseDriver driver;
21-
protected final ConnectionInfo connInfo;
229

23-
protected PrintWriter printWriter;
24-
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;
2513

2614
public ClickHouseDataSource(String url) throws SQLException {
2715
this(url, new Properties());
2816
}
2917

3018
public ClickHouseDataSource(String url, Properties properties) throws SQLException {
31-
if (url == null) {
32-
throw new IllegalArgumentException("Incorrect ClickHouse jdbc url. It must be not null");
33-
}
34-
this.url = url;
35-
this.props = new Properties();
36-
if (properties != null && !properties.isEmpty()) {
37-
this.props.putAll(properties);
38-
}
39-
4019
this.driver = new ClickHouseDriver();
41-
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+
}
4228
}
4329

4430
@Override
45-
public ClickHouseConnection getConnection() throws SQLException {
46-
return new ClickHouseConnectionImpl(connInfo);
31+
public Connection getConnection() throws SQLException {
32+
return dataSource.getConnection();
4733
}
4834

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

7140
@Override
7241
public PrintWriter getLogWriter() throws SQLException {
73-
return printWriter;
42+
return dataSource.getLogWriter();
7443
}
7544

7645
@Override
7746
public void setLogWriter(PrintWriter out) throws SQLException {
78-
printWriter = out;
47+
dataSource.setLogWriter(out);
7948
}
8049

8150
@Override
8251
public void setLoginTimeout(int seconds) throws SQLException {
83-
loginTimeoutSeconds = seconds;
52+
dataSource.setLoginTimeout(seconds);
8453
}
8554

8655
@Override
8756
public int getLoginTimeout() throws SQLException {
88-
return loginTimeoutSeconds;
57+
return dataSource.getLoginTimeout();
8958
}
9059

91-
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
92-
return ClickHouseDriver.parentLogger;
60+
@Override
61+
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
62+
return dataSource.getParentLogger();
9363
}
9464
}

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)