Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions clickhouse-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@

<properties>
<httpclient.version>4.5.13</httpclient.version>
<guava.version>29.0-jre</guava.version>
<jaxb.version>2.3.1</jaxb.version>
<javacc-plugin.version>4.1.4</javacc-plugin.version>
<shade.base>ru.yandex.clickhouse.jdbc.internal</shade.base>
<spec.title>JDBC</spec.title>
Expand Down Expand Up @@ -74,20 +72,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -202,18 +190,10 @@
<pattern>com.fasterxml.jackson</pattern>
<shadedPattern>${shade.base}.jackson</shadedPattern>
</relocation>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>${shade.base}.google</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache</pattern>
<shadedPattern>${shade.base}.apache</shadedPattern>
</relocation>
<relocation>
<pattern>org.checkerframework</pattern>
<shadedPattern>${shade.base}.checker</shadedPattern>
</relocation>
<relocation>
<pattern>net.jpountz</pattern>
<shadedPattern>${shade.base}.jpountz</shadedPattern>
Expand Down Expand Up @@ -242,11 +222,10 @@
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>javax/**</exclude>
<exclude>mozilla/**</exclude>
<exclude>darwin/**</exclude>
<exclude>linux/**</exclude>
<exclude>win32/**</exclude>
<exclude>**/darwin/**</exclude>
<exclude>**/linux/**</exclude>
<exclude>**/win32/**</exclude>
<exclude>META-INF/maven/**</exclude>
<exclude>META-INF/native-image/**</exclude>
<exclude>META-INF/versions/**</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

import org.apache.http.HttpEntity;
import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.entity.StringEntity;

import ru.yandex.clickhouse.util.guava.StreamUtils;

/**
* Allow to inject sql query in the body, followed by row data
*/
Expand All @@ -18,7 +17,7 @@ public class BodyEntityWrapper extends AbstractHttpEntity {
private final HttpEntity delegate;

public BodyEntityWrapper(String sql, HttpEntity content) {
this.sql = new StringEntity(sql+"\n", StreamUtils.UTF_8);
this.sql = new StringEntity(sql+"\n", StandardCharsets.UTF_8);
this.delegate = content;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Strings;

import ru.yandex.clickhouse.domain.ClickHouseDataType;
import ru.yandex.clickhouse.except.ClickHouseUnknownException;
import ru.yandex.clickhouse.settings.ClickHouseConnectionSettings;
import ru.yandex.clickhouse.settings.ClickHouseProperties;
import ru.yandex.clickhouse.util.ClickHouseHttpClientBuilder;
import ru.yandex.clickhouse.util.LogProxy;
import ru.yandex.clickhouse.util.guava.StreamUtils;

import ru.yandex.clickhouse.util.Utils;

public class ClickHouseConnectionImpl implements ClickHouseConnection {

Expand Down Expand Up @@ -81,26 +78,22 @@ public ClickHouseConnectionImpl(String url, ClickHouseProperties properties) {
}

private void initTimeZone(ClickHouseProperties properties) {
if (properties.isUseServerTimeZone() && !Strings.isNullOrEmpty(properties.getUseTimeZone())) {
if (properties.isUseServerTimeZone() && !Utils.isNullOrEmptyString(properties.getUseTimeZone())) {
throw new IllegalArgumentException(String.format("only one of %s or %s must be enabled", ClickHouseConnectionSettings.USE_SERVER_TIME_ZONE.getKey(), ClickHouseConnectionSettings.USE_TIME_ZONE.getKey()));
}
if (!properties.isUseServerTimeZone() && Strings.isNullOrEmpty(properties.getUseTimeZone())) {
if (!properties.isUseServerTimeZone() && Utils.isNullOrEmptyString(properties.getUseTimeZone())) {
throw new IllegalArgumentException(String.format("one of %s or %s must be enabled", ClickHouseConnectionSettings.USE_SERVER_TIME_ZONE.getKey(), ClickHouseConnectionSettings.USE_TIME_ZONE.getKey()));
}
if (properties.isUseServerTimeZone()) {
ResultSet rs = null;
try {
timezone = TimeZone.getTimeZone("UTC"); // just for next query
rs = createStatement().executeQuery("select timezone()");
rs.next();
String timeZoneName = rs.getString(1);
timezone = TimeZone.getTimeZone(timeZoneName);
timezone = TimeZone.getTimeZone("UTC"); // just for next query
try (ResultSet rs = createStatement().executeQuery("select timezone()")) {
if (rs.next()) {
timezone = TimeZone.getTimeZone(rs.getString(1));
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
StreamUtils.close(rs);
}
} else if (!Strings.isNullOrEmpty(properties.getUseTimeZone())) {
} else if (!Utils.isNullOrEmptyString(properties.getUseTimeZone())) {
timezone = TimeZone.getTimeZone(properties.getUseTimeZone());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ru.yandex.clickhouse;

import com.google.common.collect.MapMaker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -9,10 +8,18 @@
import ru.yandex.clickhouse.settings.ClickHouseQueryParam;
import ru.yandex.clickhouse.settings.DriverPropertyCreator;
import ru.yandex.clickhouse.util.LogProxy;
import java.sql.*;

import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.WeakHashMap;
import java.util.concurrent.*;

/**
Expand All @@ -30,7 +37,7 @@ public class ClickHouseDriver implements Driver {

private static final Logger logger = LoggerFactory.getLogger(ClickHouseDriver.class);

private static final ConcurrentMap<ClickHouseConnectionImpl, Boolean> connections = new MapMaker().weakKeys().makeMap();
private static final Map<ClickHouseConnectionImpl, Boolean> connections = Collections.synchronizedMap(new WeakHashMap<>());

static {
ClickHouseDriver driver = new ClickHouseDriver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
Expand Down Expand Up @@ -44,7 +45,6 @@
import ru.yandex.clickhouse.settings.ClickHouseQueryParam;
import ru.yandex.clickhouse.util.ClickHouseArrayUtil;
import ru.yandex.clickhouse.util.ClickHouseValueFormatter;
import ru.yandex.clickhouse.util.guava.StreamUtils;

public class ClickHousePreparedStatementImpl extends ClickHouseStatementImpl implements ClickHousePreparedStatement {

Expand Down Expand Up @@ -339,7 +339,7 @@ private List<byte[]> buildBatch() throws SQLException {
}
sb.append(j < pList.size() - 1 ? "\t" : "\n");
}
newBatches.add(sb.toString().getBytes(StreamUtils.UTF_8));
newBatches.add(sb.toString().getBytes(StandardCharsets.UTF_8));
sb = new StringBuilder();
}
return newBatches;
Expand Down
Loading