Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0 #130

Merged
merged 40 commits into from
Oct 27, 2023
Merged

3.0 #130

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
608fc6e
Merge pull request #107 from taosdata/main
huolibo Jun 30, 2023
a78ee55
Merge branch 'main' into 3.0
huolibo Aug 28, 2023
711b17b
Merge branch 'main' into 3.0
huolibo Aug 28, 2023
a1de417
fix bug: need handle timezone in query result
sheyanjie-taos Sep 13, 2023
9a4f051
Merge branch 'main' into feat/TD-25872
sheyanjie-taos Sep 13, 2023
e525c59
add geometry support
sheyanjie-taos Sep 14, 2023
3d0ecec
Merge branch 'main' into feat/TD-25872
sheyanjie-taos Sep 14, 2023
3ca7b0a
support geometry data type
sheyanjie-taos Sep 19, 2023
5f96eac
fix test bugs
sheyanjie-taos Sep 19, 2023
7e5a368
add new endpoint ws, improve some code
sheyanjie-taos Sep 20, 2023
ea3f6ed
Merge pull request #122 from taosdata/feat/TD-25872
sheyanjie-qq Sep 20, 2023
1410980
remove maven.compiler.release, only jdk11 support it
sheyanjie-taos Sep 20, 2023
274c0e7
optimized code
sheyanjie-taos Sep 20, 2023
94faa33
add log to find interface called by BI
sheyanjie-taos Sep 25, 2023
65c1776
roll back ws new endpoint
sheyanjie-taos Sep 25, 2023
26d611d
support ws new endpoint
sheyanjie-taos Sep 25, 2023
271282c
Merge pull request #123 from taosdata/feat/TD-25872
sheyanjie-qq Sep 25, 2023
30fb506
fix TD-26619, TD-26567
sheyanjie-taos Oct 10, 2023
6f1b846
fix unit test bug
sheyanjie-taos Oct 10, 2023
5f518cf
fix unitest bug
sheyanjie-taos Oct 11, 2023
436cf10
mod test annotation
sheyanjie-taos Oct 11, 2023
f9e0d09
Merge pull request #125 from taosdata/fix/TS-4041-TS-4043
sheyanjie-qq Oct 11, 2023
d984425
update
sheyanjie-taos Oct 16, 2023
eddb888
update
sheyanjie-taos Oct 16, 2023
731b96e
remove snapshot.enable
sheyanjie-taos Oct 18, 2023
93f9c2b
fix unitest bug
sheyanjie-taos Oct 18, 2023
6c552b0
Merge pull request #126 from taosdata/fix/snapshot_enable
sheyanjie-qq Oct 18, 2023
96cb357
add websocket reconnect feature
sheyanjie-taos Oct 26, 2023
deed218
remove logback dependency
sheyanjie-taos Oct 26, 2023
057083b
del htmlreport
sheyanjie-taos Oct 26, 2023
47bcd22
mod git ignore
sheyanjie-taos Oct 26, 2023
b14f31a
remove logback xml
sheyanjie-taos Oct 26, 2023
e5e8136
update git ignore
sheyanjie-taos Oct 26, 2023
ca9f975
update
sheyanjie-taos Oct 26, 2023
3f4ce49
update MAX_CONNECT_RETRY_TIME
sheyanjie-taos Oct 26, 2023
06ca7cc
优化重试间隔处理
sheyanjie-taos Oct 27, 2023
e7331f7
update dependency
sheyanjie-taos Oct 27, 2023
1448f65
Merge branch 'main' into 3.0
sheyanjie-taos Oct 27, 2023
0b72d8d
Merge branch '3.0' into enh/TD-26708
sheyanjie-taos Oct 27, 2023
3eb0498
Merge pull request #128 from taosdata/enh/TD-26708
sheyanjie-qq Oct 27, 2023
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
target
.vscode
.DS_Store
*.iml
*.iml
htmlReport/
src/test/java/com/taosdata/jdbc/manual/
src/test/resources/logback.xml
9 changes: 5 additions & 4 deletions deploy-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.2.5</version>
<version>3.2.7</version>
<packaging>jar</packaging>

<name>JDBCDriver</name>
Expand Down Expand Up @@ -40,13 +40,14 @@
<product.name>TDengine</product.name>
<product.version>3.0.0.0</product.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

Expand All @@ -63,12 +64,12 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
<version>32.1.3-jre</version>
</dependency>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.5.2</version>
<version>1.5.4</version>
</dependency>
</dependencies>

Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.2.6</version>
<version>3.2.7</version>
<packaging>jar</packaging>
<name>JDBCDriver</name>
<url>https://github.com/taosdata/taos-connector-jdbc</url>
Expand Down Expand Up @@ -52,17 +52,17 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.0.0-jre</version>
<version>32.1.3-jre</version>
</dependency>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.5.2</version>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
36 changes: 31 additions & 5 deletions src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.taosdata.jdbc;

import com.taosdata.jdbc.enums.DataType;
import com.taosdata.jdbc.rs.ConnectionParam;
import com.taosdata.jdbc.utils.StringUtils;
import com.taosdata.jdbc.ws.WSConnection;

import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
Expand Down Expand Up @@ -35,7 +38,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da

private static InputStream loadProperties() throws IOException {
String currentJar = AbstractDatabaseMetaData.class.getProtectionDomain().getCodeSource().getLocation().getFile();
Enumeration<URL> urls = AbstractDatabaseMetaData.class.getClassLoader().getResources("version.properties");
Enumeration<URL> urls = AbstractDatabaseMetaData.class.getClassLoader().getResources("taos-jdbc-version.properties");
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
if (url.getFile().contains(currentJar)) {
Expand Down Expand Up @@ -599,8 +602,21 @@ private ColumnMetaData buildRefGenerationMeta(int colIndex) {
}

protected ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types, Connection connection) throws SQLException {
if (!StringUtils.isEmpty(catalog) && !isAvailableCatalog(connection, catalog))
String dbHelperStr = "";
String tableHelperStr = "";

if (connection instanceof WSConnection) {
WSConnection wsConnection = (WSConnection) connection;
//BI模式,只查询用户表,只查表,不查询子表
if (wsConnection.getParam().getConnectMode() == ConnectionParam.CONNECT_MODE_BI){
dbHelperStr = " user ";
tableHelperStr = " normal ";
}
}

if (!StringUtils.isEmpty(catalog) && !isAvailableCatalog(connection, catalog)){
return new EmptyResultSet();
}

DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
// set column metadata list
Expand All @@ -612,7 +628,7 @@ protected ResultSet getTables(String catalog, String schemaPattern, String table
if (!StringUtils.isEmpty(catalog)) {
dbs.add(catalog);
} else {
try (ResultSet dbRs = stmt.executeQuery("show databases")) {
try (ResultSet dbRs = stmt.executeQuery("show " + dbHelperStr + " databases")) {
while (dbRs.next()) {
dbs.add(dbRs.getString("name"));
}
Expand All @@ -622,7 +638,7 @@ protected ResultSet getTables(String catalog, String schemaPattern, String table
return new EmptyResultSet();
}
for (String db : dbs) {
StringBuilder sql = new StringBuilder().append("show ").append(db).append(".tables ");
StringBuilder sql = new StringBuilder().append("show ").append(tableHelperStr).append(db).append(".tables ");
StringBuilder Ssql = new StringBuilder().append("show ").append(db).append(".stables ");
if (!StringUtils.isEmpty(tableNamePattern)) {
sql.append("like '").append(tableNamePattern).append("'");
Expand Down Expand Up @@ -1514,8 +1530,18 @@ protected ResultSet getCatalogs(Connection conn) throws SQLException {
columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT
resultSet.setColumnMetaDataList(columnMetaDataList);

String dbHelperStr = "";

if (conn instanceof WSConnection) {
WSConnection wsConnection = (WSConnection) conn;
//BI模式,只查询用户表,只查表,不查询子表
if (wsConnection.getParam().getConnectMode() == 1){
dbHelperStr = " user ";
}
}

try (Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("show databases")) {
ResultSet rs = stmt.executeQuery("show " + dbHelperStr + " databases")) {
List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
while (rs.next()) {
TSDBResultSetRowData rowData = new TSDBResultSetRowData(1);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/taosdata/jdbc/TSDBConnection.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.taosdata.jdbc;

import java.sql.*;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

Expand All @@ -9,6 +10,7 @@ public class TSDBConnection extends AbstractConnection {
private TSDBJNIConnector connector;
private final TSDBDatabaseMetaData databaseMetaData;
private boolean batchFetch;

private CopyOnWriteArrayList<Statement> statements = new CopyOnWriteArrayList<>();

public Boolean getBatchFetch() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/taosdata/jdbc/TSDBConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public abstract class TSDBConstants {
public static final int TSDB_DATA_TYPE_UBIGINT = 14; //unsigned bigint
public static final int TSDB_DATA_TYPE_JSON = 15; //json
public static final int TSDB_DATA_TYPE_VARBINARY = 16; //varbinary
public static final int TSDB_DATA_TYPE_GEOMETRY = 20; //geometry

// nchar column max length
public static final int maxFieldSize = 16 * 1024;

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/taosdata/jdbc/TSDBDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public class TSDBDriver extends AbstractDriver {
*/
public static final String PROPERTY_KEY_MESSAGE_WAIT_TIMEOUT = "messageWaitTimeout";

/**
* connect mode
*/
public static final String PROPERTY_KEY_CONNECT_MODE = "conmode";

/**
* max message number send to server concurrently
*/
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
import java.nio.ByteBuffer;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.time.ZoneId;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.taosdata.jdbc.TSDBErrorNumbers.ERROR_INVALID_VARIABLE;

Expand Down Expand Up @@ -52,16 +57,64 @@ public static void init(Properties props) throws SQLWarning {
if (setOptions(1, charset) < 0) {
throw TSDBError.createSQLWarning("Failed to set charset: " + charset + ". System default will be used.");
}

String timezone = props.getProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE);
if (setOptions(2, timezone) < 0) {
throw TSDBError.createSQLWarning("Failed to set timezone: " + timezone + ". System default will be used.");
}

try{
handleTimeZone(timezone.trim());
} catch (Exception e){
}
isInitialized = true;
TaosGlobalConfig.setCharset(getTsCharset());
}
}
}


private static void handleTimeZone(String posixTimeZoneStr){
//争取向前兼容POSIX 接口规范,只处理能处理的情况
// 1. UTC 和 GMT,只处理小时情况,加号变减号,减号变加号
if (posixTimeZoneStr.startsWith("UTC") || posixTimeZoneStr.startsWith("GMT")){
if (posixTimeZoneStr.length() == 3){
//标准时间
TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("GMT")));
return;
}

// 只处理UTC-8,UTC+8, GMT+8, GMT-8这样的格式
String regex = "^(UTC|GMT)([+-])(\\d+)$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(posixTimeZoneStr);
if (matcher.matches()) {
String op = matcher.group(2);
String hourStr = matcher.group(3);
if (op.equals("+")){
op = "-";
}else{
op = "+";
}

//只处理java可以处理的情况
int hour = Integer.parseInt(hourStr);
if (hour > 18){
return;
}

String timezone = String.format("GMT%s%02d:00", op, hour);
TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of(timezone)));
return;
}
// 不支持的格式,不处理
}

// 2. 尝试处理Asia/Shanghai这种情况
if (posixTimeZoneStr.contains("/")){
TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of(posixTimeZoneStr)));
}
}
private static native void initImp(String configDir);

private static native int setOptions(int optionIndex, String optionValue);
Expand Down
Loading