mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add: Clickhouse 添加native驱动支持
This commit is contained in:
@@ -643,5 +643,30 @@
|
||||
<version>4.2.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.housepower</groupId>
|
||||
<artifactId>clickhouse-native-jdbc-shaded</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>nutz</id>
|
||||
<url>https://jfrog.nutz.cn/artifactory/libs-release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>nutz-snapshots</id>
|
||||
<url>https://jfrog.nutz.cn/artifactory/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.alibaba.druid.stat.JdbcDataSourceStat;
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
import com.alibaba.druid.stat.JdbcSqlStatValue;
|
||||
import com.alibaba.druid.support.clickhouse.BalancedClickhouseDriver;
|
||||
import com.alibaba.druid.support.clickhouse.BalancedClickhouseDriverNative;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
import com.alibaba.druid.util.*;
|
||||
@@ -1191,6 +1192,13 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
info.put("password", password);
|
||||
info.putAll(connectProperties);
|
||||
driver = new BalancedClickhouseDriver(jdbcUrl, info);
|
||||
}
|
||||
else if ("com.alibaba.druid.support.clickhouse.BalancedClickhouseDriverNative".equals(driverClass)) {
|
||||
Properties info = new Properties();
|
||||
info.put("user", username);
|
||||
info.put("password", password);
|
||||
info.putAll(connectProperties);
|
||||
driver = new BalancedClickhouseDriverNative(jdbcUrl, info);
|
||||
} else {
|
||||
if (jdbcUrl == null && (driverClass == null || driverClass.length() == 0)) {
|
||||
throw new SQLException("url not set");
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.alibaba.druid.support.clickhouse;
|
||||
|
||||
|
||||
|
||||
import com.github.housepower.jdbc.BalancedClickhouseDataSource;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverPropertyInfo;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class BalancedClickhouseDriverNative implements java.sql.Driver {
|
||||
private final String url;
|
||||
private BalancedClickhouseDataSource dataSource;
|
||||
|
||||
public BalancedClickhouseDriverNative(final String url, Properties properties) {
|
||||
this.url = url;
|
||||
this.dataSource = new BalancedClickhouseDataSource(url, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection connect(String url, Properties info) throws SQLException {
|
||||
if (!acceptsURL(url)) {
|
||||
throw new SQLException("TODO");
|
||||
}
|
||||
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsURL(String url) throws SQLException {
|
||||
return this.url.equals(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||
return new DriverPropertyInfo[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean jdbcCompliant() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user