Skip to content

Commit d348fd6

Browse files
authored
Merge pull request #240 from taosdata/fix/merge-main
Fix/merge main
2 parents dcfb754 + 837f28c commit d348fd6

5 files changed

Lines changed: 32 additions & 44 deletions

File tree

pom.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@
3838
<java.version>1.8</java.version>
3939
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
4040
<jackson.version>2.18.0</jackson.version>
41+
<httpclient.version>4.5.13</httpclient.version>
42+
<guava.version>32.1.3-jre</guava.version>
43+
<Java-WebSocket.version>1.5.4</Java-WebSocket.version>
44+
<junit.version>4.13.2</junit.version>
4145
</properties>
4246
<dependencies>
4347
<dependency>
4448
<groupId>org.apache.httpcomponents</groupId>
4549
<artifactId>httpclient</artifactId>
46-
<version>4.5.13</version>
50+
<version>${httpclient.version}</version>
4751
</dependency>
4852
<dependency>
4953
<groupId>com.fasterxml.jackson.core</groupId>
@@ -58,17 +62,17 @@
5862
<dependency>
5963
<groupId>com.google.guava</groupId>
6064
<artifactId>guava</artifactId>
61-
<version>32.1.3-jre</version>
65+
<version>${guava.version}</version>
6266
</dependency>
6367
<dependency>
6468
<groupId>org.java-websocket</groupId>
6569
<artifactId>Java-WebSocket</artifactId>
66-
<version>1.5.4</version>
70+
<version>${Java-WebSocket.version}</version>
6771
</dependency>
6872
<dependency>
6973
<groupId>junit</groupId>
7074
<artifactId>junit</artifactId>
71-
<version>4.13.2</version>
75+
<version>${junit.version}</version>
7276
<scope>test</scope>
7377
</dependency>
7478

src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.taosdata.jdbc;
22

3+
import com.google.common.collect.Lists;
34
import com.taosdata.jdbc.enums.DataType;
45
import com.taosdata.jdbc.rs.ConnectionParam;
56
import com.taosdata.jdbc.utils.StringUtils;
@@ -616,13 +617,13 @@ protected ResultSet getTables(String catalog, String schemaPattern, String table
616617
if (connection instanceof WSConnection) {
617618
WSConnection wsConnection = (WSConnection) connection;
618619
//BI模式,只查询用户表,只查表,不查询子表
619-
if (wsConnection.getParam().getConnectMode() == ConnectionParam.CONNECT_MODE_BI){
620+
if (wsConnection.getParam().getConnectMode() == ConnectionParam.CONNECT_MODE_BI) {
620621
dbHelperStr = "user";
621622
tableHelperStr = "normal ";
622623
}
623624
}
624625

625-
if (!StringUtils.isEmpty(catalog) && !isAvailableCatalog(connection, catalog)){
626+
if (!StringUtils.isEmpty(catalog) && !isAvailableCatalog(connection, catalog)) {
626627
return new EmptyResultSet();
627628
}
628629

@@ -733,8 +734,8 @@ public ResultSet getTableTypes() throws SQLException {
733734
resultSet.setColumnMetaDataList(buildTableTypesColumnMetadataList());
734735

735736
// set up rowDataList
736-
List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
737-
for (String tableType : tableTypeSet){
737+
List<TSDBResultSetRowData> rowDataList = Lists.newArrayListWithExpectedSize(tableTypeSet.size());
738+
for (String tableType : tableTypeSet) {
738739
TSDBResultSetRowData rowData = new TSDBResultSetRowData(1);
739740
rowData.setStringValue(1, tableType);
740741
rowDataList.add(rowData);
@@ -777,13 +778,7 @@ private Map<String, Set<String>> getSTableMate(Connection connection, String sTa
777778
while (databases.next()) {
778779
String name = databases.getString("stable_name");
779780
String dbName = databases.getString("db_name");
780-
Set<String> stables;
781-
if (result.containsKey(dbName)) {
782-
stables = result.get(dbName);
783-
} else {
784-
stables = new HashSet<>();
785-
result.put(dbName, stables);
786-
}
781+
Set<String> stables = result.computeIfAbsent(dbName, k -> new HashSet<>());
787782
stables.add(name);
788783
}
789784
}
@@ -802,14 +797,8 @@ private Map<String, Set<String>> getTableMate(Connection connection, String tabl
802797
while (tables.next()) {
803798
String name = tables.getString("table_name");
804799
String dbName = tables.getString("db_name");
805-
if (result.containsKey(dbName)) {
806-
Set<String> set = result.get(dbName);
807-
set.add(name);
808-
} else {
809-
Set<String> set = new HashSet<>();
810-
set.add(name);
811-
result.put(dbName, set);
812-
}
800+
Set<String> set = result.computeIfAbsent(dbName, k -> new HashSet<>());
801+
set.add(name);
813802
}
814803
}
815804
return result;
@@ -827,13 +816,7 @@ private Map<String, Set<String>> getViewMate(Connection connection, String viewN
827816
while (databases.next()) {
828817
String name = databases.getString("view_name");
829818
String dbName = databases.getString("db_name");
830-
Set<String> views;
831-
if (result.containsKey(dbName)) {
832-
views = result.get(dbName);
833-
} else {
834-
views = new HashSet<>();
835-
result.put(dbName, views);
836-
}
819+
Set<String> views = result.computeIfAbsent(dbName, k -> new HashSet<>());
837820
views.add(name);
838821
}
839822
}
@@ -894,6 +877,7 @@ private void show2RowData(ResultSet rs, List<TSDBResultSetRowData> rowDataList,
894877
}
895878

896879
Pattern pattern = Pattern.compile("\\((\\d+)\\)");
880+
897881
// normal table or child table
898882
private void colResultSet2RowData(ResultSet rs, List<TSDBResultSetRowData> rowDataList, Map<String, String> precision) throws SQLException {
899883
int rowIndex = 0;
@@ -989,7 +973,7 @@ private void tagResultSet2RowData(ResultSet rs, List<TSDBResultSetRowData> rowDa
989973
length = Integer.parseInt(matcher.group(1));
990974
}
991975
typeName = "NCHAR";
992-
}else {
976+
} else {
993977
rowData.setIntValue(5, DataType.getDataType(typeName).getJdbcTypeValue());
994978
length = 0;
995979
}
@@ -1146,7 +1130,7 @@ protected ResultSet getColumns(String catalog, String schemaPattern, String tabl
11461130

11471131
List<Map<String, Set<String>>> mapList = new ArrayList<>(Arrays.asList(sTableMate, tableMate, viewMate));
11481132

1149-
for (Map<String, Set<String>> tmpMap : mapList){
1133+
for (Map<String, Set<String>> tmpMap : mapList) {
11501134
for (Map.Entry<String, Set<String>> dbs : tmpMap.entrySet()) {
11511135
for (String table : dbs.getValue()) {
11521136
try (Statement stmt = conn.createStatement();
@@ -1591,7 +1575,7 @@ protected ResultSet getCatalogs(Connection conn) throws SQLException {
15911575
if (conn instanceof WSConnection) {
15921576
WSConnection wsConnection = (WSConnection) conn;
15931577
//BI模式,只查询用户表,只查表,不查询子表
1594-
if (wsConnection.getParam().getConnectMode() == 1){
1578+
if (wsConnection.getParam().getConnectMode() == 1) {
15951579
dbHelperStr = "user";
15961580
}
15971581
}
@@ -1725,7 +1709,7 @@ private ColumnMetaData buildSuperTableNameMeta(int colIndex) {
17251709
return col4;
17261710
}
17271711

1728-
private String generateDescribeSql(String dbName, String tableName) throws SQLException{
1712+
private String generateDescribeSql(String dbName, String tableName) throws SQLException {
17291713
return "describe " + dbName + "." + getIdentifierQuoteString() + tableName + getIdentifierQuoteString();
17301714
}
17311715
}

src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.JsonNode;
55
import com.fasterxml.jackson.databind.ObjectWriter;
6+
import com.google.common.collect.Lists;
67
import com.google.common.primitives.Ints;
78
import com.google.common.primitives.Longs;
89
import com.google.common.primitives.Shorts;
@@ -14,7 +15,6 @@
1415
import com.taosdata.jdbc.enums.TimestampPrecision;
1516
import com.taosdata.jdbc.utils.DateTimeUtils;
1617
import com.taosdata.jdbc.utils.JsonUtil;
17-
import com.taosdata.jdbc.utils.Utils;
1818

1919
import java.math.BigDecimal;
2020
import java.sql.*;
@@ -88,7 +88,7 @@ public RestfulResultSet(String database, Statement statement, JsonNode resultJso
8888
return;
8989
// parse row data
9090
for (JsonNode jsonRow : data) {
91-
List<Object> row = new ArrayList<>();
91+
List<Object> row = Lists.newArrayListWithExpectedSize(this.metaData.getColumnCount());
9292
for (int colIndex = 0; colIndex < this.metaData.getColumnCount(); colIndex++) {
9393
row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex)));
9494
}
@@ -117,7 +117,7 @@ private void parseColumnMeta_new(JsonNode columnMeta) {
117117

118118
private Object parseColumnData(JsonNode row, int colIndex, Field field) throws SQLException {
119119
int taosType = field.taos_type;
120-
if (row.get(colIndex).isNull()){
120+
if (row.get(colIndex).isNull()) {
121121
return null;
122122
}
123123

@@ -155,7 +155,7 @@ private Object parseColumnData(JsonNode row, int colIndex, Field field) throws S
155155
ObjectWriter objectWriter = JsonUtil.getObjectWriter(JsonNode.class);
156156
JsonNode jsonNode = row.get(colIndex);
157157
if (jsonNode != null && !jsonNode.isNull() && (jsonNode.isTextual() || jsonNode.isObject())) {
158-
try{
158+
try {
159159
return objectWriter.writeValueAsString(jsonNode);
160160
} catch (JsonProcessingException e) {
161161
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, e.getMessage());

src/main/java/com/taosdata/jdbc/tmq/ReferenceDeserializer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.taosdata.jdbc.tmq;
22

3+
import com.google.common.collect.Lists;
34
import com.taosdata.jdbc.TaosGlobalConfig;
45
import com.taosdata.jdbc.utils.Utils;
56

@@ -16,7 +17,6 @@
1617
import java.sql.ResultSet;
1718
import java.sql.SQLException;
1819
import java.sql.Timestamp;
19-
import java.util.ArrayList;
2020
import java.util.List;
2121
import java.util.Map;
2222

@@ -38,8 +38,8 @@ public V deserialize(ResultSet data, String topic, String dbName) throws Deseria
3838
try {
3939
t = Utils.newInstance(clazz);
4040
if (params == null) {
41-
List<Param> lists = new ArrayList<>();
4241
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
42+
List<Param> lists = Lists.newArrayListWithExpectedSize(beanInfo.getPropertyDescriptors().length);
4343
for (PropertyDescriptor property : beanInfo.getPropertyDescriptors()) {
4444
String name = property.getName();
4545
if ("class".equals(name))
@@ -134,17 +134,17 @@ public V deserialize(ResultSet data, String topic, String dbName) throws Deseria
134134
|| param.clazz.isAssignableFrom(byte[].class)) {
135135
byte[] bytes = data.getBytes(param.name);
136136
param.method.invoke(t, data.wasNull() ? null : bytes);
137-
} else if (param.clazz.isAssignableFrom(BigDecimal.class)){
137+
} else if (param.clazz.isAssignableFrom(BigDecimal.class)) {
138138
BigDecimal bigDecimal = data.getBigDecimal(param.name);
139139
param.method.invoke(t, data.wasNull() ? null : bigDecimal);
140-
} else if (param.clazz.isAssignableFrom(BigInteger.class)){
140+
} else if (param.clazz.isAssignableFrom(BigInteger.class)) {
141141
BigInteger bigInteger = (BigInteger) data.getObject(param.name);
142142
param.method.invoke(t, data.wasNull() ? null : bigInteger);
143143
}
144144

145145
} catch (IllegalAccessException | InvocationTargetException e) {
146146
throw new SQLException(this.getClass().getSimpleName() + ": " + param.name
147-
+ " through method:" + param.method.getName() +" get Data error: ", e);
147+
+ " through method:" + param.method.getName() + " get Data error: ", e);
148148
}
149149
}
150150
return t;

src/main/java/com/taosdata/jdbc/ws/TSWSPreparedStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.taosdata.jdbc.ws;
22

3+
34
import com.taosdata.jdbc.AbstractConnection;
45
import com.taosdata.jdbc.rs.ConnectionParam;
56
import com.taosdata.jdbc.ws.stmt2.entity.Stmt2PrepareResp;
67

78
import java.sql.SQLException;
8-
99
public class TSWSPreparedStatement extends AbsWSPreparedStatement {
1010
public TSWSPreparedStatement(Transport transport,
1111
ConnectionParam param,

0 commit comments

Comments
 (0)