diff --git a/cmake/version.inc b/cmake/version.inc
index 7d0ad0585f67921c8c2ddbcf47ba08f803cc375a..49f01d00bc18ef4f0e1d87ac06b4b1bf09784268 100644
--- a/cmake/version.inc
+++ b/cmake/version.inc
@@ -4,7 +4,7 @@ PROJECT(TDengine)
IF (DEFINED VERNUMBER)
SET(TD_VER_NUMBER ${VERNUMBER})
ELSE ()
- SET(TD_VER_NUMBER "2.0.12.0")
+ SET(TD_VER_NUMBER "2.0.13.0")
ENDIF ()
IF (DEFINED VERCOMPATIBLE)
diff --git a/documentation20/webdocs/markdowndocs/Model-ch.md b/documentation20/webdocs/markdowndocs/Model-ch.md
index dce7819423661a3748c4c5cd4402777e21b16a89..ea1be899a85fe6bb31ab03674ab496d7b301432f 100644
--- a/documentation20/webdocs/markdowndocs/Model-ch.md
+++ b/documentation20/webdocs/markdowndocs/Model-ch.md
@@ -4,6 +4,8 @@
TDengine采用关系型数据模型,需要建库、建表。因此对于一个具体的应用场景,需要考虑库的设计,超级表和普通表的设计。本节不讨论细致的语法规则,只介绍概念。
+关于数据建模请参考视频教程。
+
## 创建库
不同类型的数据采集点往往具有不同的数据特征,包括数据采集频率的高低,数据保留时间的长短,副本的数目,数据块的大小,是否允许更新数据等等。为让各种场景下TDengine都能最大效率的工作,TDengine建议将不同数据特征的表创建在不同的库里,因为每个库可以配置不同的存储策略。创建一个库时,除SQL标准的选项外,应用还可以指定保留时长、副本数、内存块个数、时间精度、文件块里最大最小记录条数、是否压缩、一个数据文件覆盖的天数等多种参数。比如:
@@ -60,4 +62,3 @@ TDengine支持多列模型,只要物理量是一个数据采集点同时采集
TDengine建议尽可能采用多列模型,因为插入效率以及存储效率更高。但对于有些场景,一个采集点的采集量的种类经常变化,这个时候,如果采用多列模型,就需要频繁修改超级表的结构定义,让应用变的复杂,这个时候,采用单列模型会显得简单。
-关于数据建模请参考视频教程。
diff --git a/documentation20/webdocs/markdowndocs/cluster-ch.md b/documentation20/webdocs/markdowndocs/cluster-ch.md
index f1c275ab0c4c986766fa8d33c71fe65777c90848..89f6a64f192c65ae422c6fc52600040d439456a7 100644
--- a/documentation20/webdocs/markdowndocs/cluster-ch.md
+++ b/documentation20/webdocs/markdowndocs/cluster-ch.md
@@ -6,6 +6,8 @@
TDengine的集群管理极其简单,除添加和删除节点需要人工干预之外,其他全部是自动完成,最大程度的降低了运维的工作量。本章对集群管理的操作做详细的描述。
+关于集群搭建请参考视频教程。
+
## 准备工作
**第零步**:规划集群所有物理节点的FQDN,将规划好的FQDN分别添加到每个物理节点的/etc/hostname;修改每个物理节点的/etc/hosts,将所有集群物理节点的IP与FQDN的对应添加好。【如部署了DNS,请联系网络管理员在DNS上做好相关配置】
@@ -227,4 +229,3 @@ SHOW MNODES;
TDengine提供一个执行程序tarbitrator, 找任何一台Linux服务器运行它即可。请点击[安装包下载](https://www.taosdata.com/cn/all-downloads/),在TDengine Arbitrator Linux一节中,选择适合的版本下载并安装。该程序对系统资源几乎没有要求,只需要保证有网络连接即可。该应用的命令行参数`-p`可以指定其对外服务的端口号,缺省是6042。配置每个taosd实例时,可以在配置文件taos.cfg里将参数arbitrator设置为arbitrator的End Point。如果该参数配置了,当副本数为偶数数,系统将自动连接配置的arbitrator。如果副本数为奇数,即使配置了arbitrator, 系统也不会去建立连接。
-关于集群搭建请参考视频教程。
diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
index d1a334664e17c89dc3f55849f8ceb203e5026fe6..c4b2039737723ca7704cb8a40a3f8d1e128df008 100644
--- a/snap/snapcraft.yaml
+++ b/snap/snapcraft.yaml
@@ -1,6 +1,6 @@
name: tdengine
base: core18
-version: '2.0.12.0'
+version: '2.0.13.0'
icon: snap/gui/t-dengine.svg
summary: an open-source big data platform designed and optimized for IoT.
description: |
@@ -72,7 +72,7 @@ parts:
- usr/bin/taosd
- usr/bin/taos
- usr/bin/taosdemo
- - usr/lib/libtaos.so.2.0.12.0
+ - usr/lib/libtaos.so.2.0.13.0
- usr/lib/libtaos.so.1
- usr/lib/libtaos.so
diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c
index 4a5a7b09a2013fe76cd4abcbc2f0fb903758d935..6479a7ecba505c90025b66c41f8740651132cb66 100644
--- a/src/client/src/tscSQLParser.c
+++ b/src/client/src/tscSQLParser.c
@@ -75,11 +75,11 @@ static int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SC
static int32_t convertFunctionId(int32_t optr, int16_t* functionId);
static uint8_t convertOptr(SStrToken *pToken);
-static int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable, bool joinQuery);
+static int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable, bool joinQuery, bool intervalQuery);
static bool validateIpAddress(const char* ip, size_t size);
static bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
-static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery);
+static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool intervalQuery);
static int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd);
@@ -1475,7 +1475,7 @@ static void addPrimaryTsColIntoResult(SQueryInfo* pQueryInfo) {
pQueryInfo->type |= TSDB_QUERY_TYPE_PROJECTION_QUERY;
}
-int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable, bool joinQuery) {
+int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable, bool joinQuery, bool intervalQuery) {
assert(pSelection != NULL && pCmd != NULL);
const char* msg2 = "functions can not be mixed up";
@@ -1531,7 +1531,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
addPrimaryTsColIntoResult(pQueryInfo);
}
- if (!functionCompatibleCheck(pQueryInfo, joinQuery)) {
+ if (!functionCompatibleCheck(pQueryInfo, joinQuery, intervalQuery)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
@@ -2810,7 +2810,7 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo)
return false;
}
-static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery) {
+static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool intervalQuery) {
int32_t startIdx = 0;
size_t numOfExpr = tscSqlExprNumOfExprs(pQueryInfo);
@@ -2826,6 +2826,10 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery) {
int32_t factor = functionCompatList[tscSqlExprGet(pQueryInfo, startIdx)->functionId];
+ if (tscSqlExprGet(pQueryInfo, 0)->functionId == TSDB_FUNC_LAST_ROW && (joinQuery || intervalQuery)) {
+ return false;
+ }
+
// diff function cannot be executed with other function
// arithmetic function can be executed with other arithmetic functions
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
@@ -2850,7 +2854,7 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery) {
}
}
- if (functionId == TSDB_FUNC_LAST_ROW && joinQuery) {
+ if (functionId == TSDB_FUNC_LAST_ROW && (joinQuery || intervalQuery)) {
return false;
}
}
@@ -6320,7 +6324,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
}
bool isSTable = UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo);
- if (parseSelectClause(&pSql->cmd, 0, pQuerySql->pSelection, isSTable, false) != TSDB_CODE_SUCCESS) {
+ if (parseSelectClause(&pSql->cmd, 0, pQuerySql->pSelection, isSTable, false, false) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
@@ -6565,7 +6569,9 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
int32_t joinQuery = (pQuerySql->from != NULL && taosArrayGetSize(pQuerySql->from) > 2);
- if (parseSelectClause(pCmd, index, pQuerySql->pSelection, isSTable, joinQuery) != TSDB_CODE_SUCCESS) {
+ int32_t intervalQuery = !(pQuerySql->interval.type == 0 || pQuerySql->interval.n == 0);
+
+ if (parseSelectClause(pCmd, index, pQuerySql->pSelection, isSTable, joinQuery, intervalQuery) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c
index a6e33778cde0a43f4cdd003e718ef49b89a41866..5d818692ed90480c4b461c1fe8aba9d785dee694 100644
--- a/src/client/src/tscUtil.c
+++ b/src/client/src/tscUtil.c
@@ -458,12 +458,13 @@ void tscFreeRegisteredSqlObj(void *pSql) {
assert(RID_VALID(p->self));
- tscFreeSqlObj(p);
- taosReleaseRef(tscRefId, pTscObj->rid);
-
int32_t num = atomic_sub_fetch_32(&pTscObj->numOfObj, 1);
int32_t total = atomic_sub_fetch_32(&tscNumOfObj, 1);
+
tscDebug("%p free SqlObj, total in tscObj:%d, total:%d", pSql, num, total);
+ tscFreeSqlObj(p);
+ taosReleaseRef(tscRefId, pTscObj->rid);
+
}
void tscFreeSqlObj(SSqlObj* pSql) {
diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml
index 25a36e3a4822bfbea0c7f07ff3a4a09032d44542..9865fc7127b39debc965f6be9bad6e8485169416 100755
--- a/src/connector/jdbc/pom.xml
+++ b/src/connector/jdbc/pom.xml
@@ -56,6 +56,12 @@
test
+
+ mysql
+ mysql-connector-java
+ 5.1.47
+
+
org.apache.httpcomponents
@@ -73,7 +79,14 @@
1.2.58
+
+ mysql
+ mysql-connector-java
+ 5.1.49
+
+
+
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
new file mode 100644
index 0000000000000000000000000000000000000000..1445be18654ff3e73b74484b47e09856ddc94b01
--- /dev/null
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
@@ -0,0 +1,808 @@
+/***************************************************************************
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *****************************************************************************/
+package com.taosdata.jdbc;
+
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
+
+ private final static String PRODUCT_NAME = "TDengine";
+ private final static String PRODUCT_VESION = "2.0.x.x";
+ private final static String DRIVER_NAME = "taos-jdbcdriver";
+ private final static String DRIVER_VERSION = "2.0.x";
+ private final static int DRIVER_MAJAR_VERSION = 2;
+ private final static int DRIVER_MINOR_VERSION = 0;
+
+ public boolean allProceduresAreCallable() throws SQLException {
+ return false;
+ }
+
+ public boolean allTablesAreSelectable() throws SQLException {
+ return false;
+ }
+
+ public abstract String getURL() throws SQLException;
+
+ public abstract String getUserName() throws SQLException;
+
+ public boolean isReadOnly() throws SQLException {
+ return false;
+ }
+
+ public boolean nullsAreSortedHigh() throws SQLException {
+ return false;
+ }
+
+ public boolean nullsAreSortedLow() throws SQLException {
+ return !nullsAreSortedHigh();
+ }
+
+ public boolean nullsAreSortedAtStart() throws SQLException {
+ return true;
+ }
+
+ public boolean nullsAreSortedAtEnd() throws SQLException {
+ return !nullsAreSortedAtStart();
+ }
+
+ public String getDatabaseProductName() throws SQLException {
+ return PRODUCT_NAME;
+ }
+
+ public String getDatabaseProductVersion() throws SQLException {
+ return PRODUCT_VESION;
+ }
+
+ public String getDriverName() throws SQLException {
+ return DRIVER_NAME;
+ }
+
+ public String getDriverVersion() throws SQLException {
+ return DRIVER_VERSION;
+ }
+
+ public int getDriverMajorVersion() {
+ return DRIVER_MAJAR_VERSION;
+ }
+
+ public int getDriverMinorVersion() {
+ return DRIVER_MINOR_VERSION;
+ }
+
+ public boolean usesLocalFiles() throws SQLException {
+ return false;
+ }
+
+ public boolean usesLocalFilePerTable() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsMixedCaseIdentifiers() throws SQLException {
+ return false;
+ }
+
+ public boolean storesUpperCaseIdentifiers() throws SQLException {
+ return false;
+ }
+
+ public boolean storesLowerCaseIdentifiers() throws SQLException {
+ return false;
+ }
+
+ public boolean storesMixedCaseIdentifiers() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
+ return false;
+ }
+
+ public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
+ return false;
+ }
+
+ public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
+ return false;
+ }
+
+ public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
+ return false;
+ }
+
+ public String getIdentifierQuoteString() throws SQLException {
+ return " ";
+ }
+
+ public String getSQLKeywords() throws SQLException {
+ return null;
+ }
+
+ public String getNumericFunctions() throws SQLException {
+ return null;
+ }
+
+ public String getStringFunctions() throws SQLException {
+ return null;
+ }
+
+ public String getSystemFunctions() throws SQLException {
+ return null;
+ }
+
+ public String getTimeDateFunctions() throws SQLException {
+ return null;
+ }
+
+ public String getSearchStringEscape() throws SQLException {
+ return null;
+ }
+
+ public String getExtraNameCharacters() throws SQLException {
+ return null;
+ }
+
+ public boolean supportsAlterTableWithAddColumn() throws SQLException {
+ return true;
+ }
+
+ public boolean supportsAlterTableWithDropColumn() throws SQLException {
+ return true;
+ }
+
+ public boolean supportsColumnAliasing() throws SQLException {
+ return true;
+ }
+
+ public boolean nullPlusNonNullIsNull() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsConvert() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsConvert(int fromType, int toType) throws SQLException {
+ return false;
+ }
+
+ public boolean supportsTableCorrelationNames() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsDifferentTableCorrelationNames() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsExpressionsInOrderBy() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsOrderByUnrelated() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsGroupBy() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsGroupByUnrelated() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsGroupByBeyondSelect() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsLikeEscapeClause() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsMultipleResultSets() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsMultipleTransactions() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsNonNullableColumns() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsMinimumSQLGrammar() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsCoreSQLGrammar() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsExtendedSQLGrammar() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsANSI92EntryLevelSQL() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsANSI92IntermediateSQL() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsANSI92FullSQL() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsIntegrityEnhancementFacility() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsOuterJoins() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsFullOuterJoins() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsLimitedOuterJoins() throws SQLException {
+ return false;
+ }
+
+ public String getSchemaTerm() throws SQLException {
+ return null;
+ }
+
+ public String getProcedureTerm() throws SQLException {
+ return null;
+ }
+
+ public String getCatalogTerm() throws SQLException {
+ return "database";
+ }
+
+ public boolean isCatalogAtStart() throws SQLException {
+ return true;
+ }
+
+ public String getCatalogSeparator() throws SQLException {
+ return ".";
+ }
+
+ public boolean supportsSchemasInDataManipulation() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsSchemasInProcedureCalls() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsSchemasInTableDefinitions() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsSchemasInIndexDefinitions() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsCatalogsInDataManipulation() throws SQLException {
+ return true;
+ }
+
+ public boolean supportsCatalogsInProcedureCalls() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsCatalogsInTableDefinitions() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsPositionedDelete() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsPositionedUpdate() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsSelectForUpdate() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsStoredProcedures() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsSubqueriesInComparisons() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsSubqueriesInExists() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsSubqueriesInIns() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsSubqueriesInQuantifieds() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsCorrelatedSubqueries() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsUnion() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsUnionAll() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
+ return false;
+ }
+
+ public int getMaxBinaryLiteralLength() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxCharLiteralLength() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxColumnNameLength() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxColumnsInGroupBy() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxColumnsInIndex() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxColumnsInOrderBy() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxColumnsInSelect() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxColumnsInTable() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxConnections() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxCursorNameLength() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxIndexLength() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxSchemaNameLength() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxProcedureNameLength() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxCatalogNameLength() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxRowSize() throws SQLException {
+ return 0;
+ }
+
+ public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
+ return false;
+ }
+
+ public int getMaxStatementLength() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxStatements() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxTableNameLength() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxTablesInSelect() throws SQLException {
+ return 0;
+ }
+
+ public int getMaxUserNameLength() throws SQLException {
+ return 0;
+ }
+
+ public int getDefaultTransactionIsolation() throws SQLException {
+ return 0;
+ }
+
+ public boolean supportsTransactions() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
+ return false;
+ }
+
+ public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsDataManipulationTransactionsOnly() throws SQLException {
+ return false;
+ }
+
+ public boolean dataDefinitionCausesTransactionCommit() throws SQLException {
+ return false;
+ }
+
+ public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
+ return false;
+ }
+
+ public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern)
+ throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern,
+ String columnNamePattern) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public abstract ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)
+ throws SQLException;
+
+ public ResultSet getSchemas() throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public abstract ResultSet getCatalogs() throws SQLException;
+
+ public ResultSet getTableTypes() throws SQLException {
+ DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
+
+ // set up ColumnMetaDataList
+ List columnMetaDataList = new ArrayList(1);
+ ColumnMetaData colMetaData = new ColumnMetaData();
+ colMetaData.setColIndex(0);
+ colMetaData.setColName("TABLE_TYPE");
+ colMetaData.setColSize(10);
+ colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY);
+ columnMetaDataList.add(colMetaData);
+
+ // set up rowDataList
+ List rowDataList = new ArrayList(2);
+ TSDBResultSetRowData rowData = new TSDBResultSetRowData();
+ rowData.setString(0, "TABLE");
+ rowDataList.add(rowData);
+ rowData = new TSDBResultSetRowData();
+ rowData.setString(0, "STABLE");
+ rowDataList.add(rowData);
+
+ resultSet.setColumnMetaDataList(columnMetaDataList);
+ resultSet.setRowDataList(rowDataList);
+ return resultSet;
+ }
+
+ public abstract ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException;
+
+ protected int getNullable(int index, String typeName) {
+ if (index == 0 && "TIMESTAMP".equals(typeName))
+ return DatabaseMetaData.columnNoNulls;
+ return DatabaseMetaData.columnNullable;
+ }
+
+ protected int getColumnSize(String typeName, int length) {
+ switch (typeName) {
+ case "TIMESTAMP":
+ return 23;
+
+ default:
+ return 0;
+ }
+ }
+
+ protected int getDecimalDigits(String typeName) {
+ switch (typeName) {
+ case "FLOAT":
+ return 5;
+ case "DOUBLE":
+ return 9;
+ default:
+ return 0;
+ }
+ }
+
+ protected int getDataType(String typeName) {
+ switch (typeName) {
+ case "TIMESTAMP":
+ return Types.TIMESTAMP;
+ case "INT":
+ return Types.INTEGER;
+ case "BIGINT":
+ return Types.BIGINT;
+ case "FLOAT":
+ return Types.FLOAT;
+ case "DOUBLE":
+ return Types.DOUBLE;
+ case "BINARY":
+ return Types.BINARY;
+ case "SMALLINT":
+ return Types.SMALLINT;
+ case "TINYINT":
+ return Types.TINYINT;
+ case "BOOL":
+ return Types.BOOLEAN;
+ case "NCHAR":
+ return Types.NCHAR;
+ default:
+ return Types.NULL;
+ }
+ }
+
+ public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern)
+ throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern)
+ throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable)
+ throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable,
+ String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getTypeInfo() throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate)
+ throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public boolean supportsResultSetType(int type) throws SQLException {
+ return false;
+ }
+
+ public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException {
+ return false;
+ }
+
+ public boolean ownUpdatesAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ public boolean ownDeletesAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ public boolean ownInsertsAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ public boolean othersUpdatesAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ public boolean othersDeletesAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ public boolean othersInsertsAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ public boolean updatesAreDetected(int type) throws SQLException {
+ return false;
+ }
+
+ public boolean deletesAreDetected(int type) throws SQLException {
+ return false;
+ }
+
+ public boolean insertsAreDetected(int type) throws SQLException {
+ return false;
+ }
+
+ public boolean supportsBatchUpdates() throws SQLException {
+ return false;
+ }
+
+ public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types)
+ throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public Connection getConnection() throws SQLException {
+ return null;
+ }
+
+ public boolean supportsSavepoints() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsNamedParameters() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsMultipleOpenResults() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsGetGeneratedKeys() throws SQLException {
+ return false;
+ }
+
+ public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern,
+ String attributeNamePattern) throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public boolean supportsResultSetHoldability(int holdability) throws SQLException {
+ return false;
+ }
+
+ public int getResultSetHoldability() throws SQLException {
+ return 0;
+ }
+
+ public int getDatabaseMajorVersion() throws SQLException {
+ return 0;
+ }
+
+ public int getDatabaseMinorVersion() throws SQLException {
+ return 0;
+ }
+
+ public int getJDBCMajorVersion() throws SQLException {
+ return 0;
+ }
+
+ public int getJDBCMinorVersion() throws SQLException {
+ return 0;
+ }
+
+ public int getSQLStateType() throws SQLException {
+ return 0;
+ }
+
+ public boolean locatorsUpdateCopy() throws SQLException {
+ return false;
+ }
+
+ public boolean supportsStatementPooling() throws SQLException {
+ return false;
+ }
+
+ public RowIdLifetime getRowIdLifetime() throws SQLException {
+ return null;
+ }
+
+ public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
+ return null;
+ }
+
+ public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
+ return false;
+ }
+
+ public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
+ return false;
+ }
+
+ public ResultSet getClientInfoProperties() throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern)
+ throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern,
+ String columnNamePattern) throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern,
+ String columnNamePattern) throws SQLException {
+ return getEmptyResultSet();
+ }
+
+ public boolean generatedKeyAlwaysReturned() throws SQLException {
+ return false;
+ }
+
+ private ResultSet getEmptyResultSet() {
+ return new EmptyResultSet();
+ }
+}
\ No newline at end of file
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
index 3940e809300b7d8e0b6c79038afaa6ff76f81bf0..4f4911aad9c138eb13fffdd698b794a03222160f 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
@@ -19,68 +19,71 @@ import java.util.Map;
public abstract class TSDBConstants {
- public static final String DEFAULT_PORT = "6200";
- public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!";
- public static final String INVALID_VARIABLES = "invalid variables";
- public static Map DATATYPE_MAP = null;
+ public static final String DEFAULT_PORT = "6200";
+ public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!";
+ public static final String INVALID_VARIABLES = "invalid variables";
+ public static Map DATATYPE_MAP = null;
- public static final long JNI_NULL_POINTER = 0L;
+ public static final long JNI_NULL_POINTER = 0L;
- public static final int JNI_SUCCESS = 0;
- public static final int JNI_TDENGINE_ERROR = -1;
- public static final int JNI_CONNECTION_NULL = -2;
- public static final int JNI_RESULT_SET_NULL = -3;
- public static final int JNI_NUM_OF_FIELDS_0 = -4;
- public static final int JNI_SQL_NULL = -5;
- public static final int JNI_FETCH_END = -6;
-
- public static final int TSDB_DATA_TYPE_NULL = 0;
- public static final int TSDB_DATA_TYPE_BOOL = 1;
- public static final int TSDB_DATA_TYPE_TINYINT = 2;
- public static final int TSDB_DATA_TYPE_SMALLINT = 3;
- public static final int TSDB_DATA_TYPE_INT = 4;
- public static final int TSDB_DATA_TYPE_BIGINT = 5;
- public static final int TSDB_DATA_TYPE_FLOAT = 6;
- public static final int TSDB_DATA_TYPE_DOUBLE = 7;
- public static final int TSDB_DATA_TYPE_BINARY = 8;
- public static final int TSDB_DATA_TYPE_TIMESTAMP = 9;
- public static final int TSDB_DATA_TYPE_NCHAR = 10;
-
- public static String WrapErrMsg(String msg) {
- return "TDengine Error: " + msg;
- }
+ public static final int JNI_SUCCESS = 0;
+ public static final int JNI_TDENGINE_ERROR = -1;
+ public static final int JNI_CONNECTION_NULL = -2;
+ public static final int JNI_RESULT_SET_NULL = -3;
+ public static final int JNI_NUM_OF_FIELDS_0 = -4;
+ public static final int JNI_SQL_NULL = -5;
+ public static final int JNI_FETCH_END = -6;
- public static String FixErrMsg(int code) {
- switch (code) {
- case JNI_TDENGINE_ERROR:
- return WrapErrMsg("internal error of database!");
- case JNI_CONNECTION_NULL:
- return WrapErrMsg("invalid tdengine connection!");
- case JNI_RESULT_SET_NULL:
- return WrapErrMsg("invalid resultset pointer!");
- case JNI_NUM_OF_FIELDS_0:
- return WrapErrMsg("invalid num of fields!");
- case JNI_SQL_NULL:
- return WrapErrMsg("can't execute empty sql!");
- case JNI_FETCH_END:
- return WrapErrMsg("fetch to the end of resultset");
- default:
- break;
- }
- return WrapErrMsg("unkown error!");
- }
+ public static final int TSDB_DATA_TYPE_NULL = 0;
+ public static final int TSDB_DATA_TYPE_BOOL = 1;
+ public static final int TSDB_DATA_TYPE_TINYINT = 2;
+ public static final int TSDB_DATA_TYPE_SMALLINT = 3;
+ public static final int TSDB_DATA_TYPE_INT = 4;
+ public static final int TSDB_DATA_TYPE_BIGINT = 5;
+ public static final int TSDB_DATA_TYPE_FLOAT = 6;
+ public static final int TSDB_DATA_TYPE_DOUBLE = 7;
+ public static final int TSDB_DATA_TYPE_BINARY = 8;
+ public static final int TSDB_DATA_TYPE_TIMESTAMP = 9;
+ public static final int TSDB_DATA_TYPE_NCHAR = 10;
- static {
- DATATYPE_MAP = new HashMap();
- DATATYPE_MAP.put(1, "BOOL");
- DATATYPE_MAP.put(2, "TINYINT");
- DATATYPE_MAP.put(3, "SMALLINT");
- DATATYPE_MAP.put(4, "INT");
- DATATYPE_MAP.put(5, "BIGINT");
- DATATYPE_MAP.put(6, "FLOAT");
- DATATYPE_MAP.put(7, "DOUBLE");
- DATATYPE_MAP.put(8, "BINARY");
- DATATYPE_MAP.put(9, "TIMESTAMP");
- DATATYPE_MAP.put(10, "NCHAR");
- }
+ // nchar field's max length
+ public static final int maxFieldSize = 16 * 1024;
+
+ public static String WrapErrMsg(String msg) {
+ return "TDengine Error: " + msg;
+ }
+
+ public static String FixErrMsg(int code) {
+ switch (code) {
+ case JNI_TDENGINE_ERROR:
+ return WrapErrMsg("internal error of database!");
+ case JNI_CONNECTION_NULL:
+ return WrapErrMsg("invalid tdengine connection!");
+ case JNI_RESULT_SET_NULL:
+ return WrapErrMsg("invalid resultset pointer!");
+ case JNI_NUM_OF_FIELDS_0:
+ return WrapErrMsg("invalid num of fields!");
+ case JNI_SQL_NULL:
+ return WrapErrMsg("can't execute empty sql!");
+ case JNI_FETCH_END:
+ return WrapErrMsg("fetch to the end of resultset");
+ default:
+ break;
+ }
+ return WrapErrMsg("unkown error!");
+ }
+
+ static {
+ DATATYPE_MAP = new HashMap();
+ DATATYPE_MAP.put(1, "BOOL");
+ DATATYPE_MAP.put(2, "TINYINT");
+ DATATYPE_MAP.put(3, "SMALLINT");
+ DATATYPE_MAP.put(4, "INT");
+ DATATYPE_MAP.put(5, "BIGINT");
+ DATATYPE_MAP.put(6, "FLOAT");
+ DATATYPE_MAP.put(7, "DOUBLE");
+ DATATYPE_MAP.put(8, "BINARY");
+ DATATYPE_MAP.put(9, "TIMESTAMP");
+ DATATYPE_MAP.put(10, "NCHAR");
+ }
}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
index 6b0937a9b7c50c25d03459d18e01b807b5c00c3c..5260b780bd510edad6ef8ea9a481fa334cca50f6 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
@@ -1,19 +1,29 @@
package com.taosdata.jdbc.rs;
import com.taosdata.jdbc.TSDBConstants;
+import com.taosdata.jdbc.TSDBDriver;
import java.sql.*;
+import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
public class RestfulConnection implements Connection {
+ private static final String CONNECTION_IS_CLOSED = "connection is closed.";
+ private static final String AUTO_COMMIT_IS_TRUE = "auto commit is true";
private final String host;
private final int port;
private final Properties props;
- private final String database;
+ private volatile String database;
private final String url;
+ /******************************************************/
+ private boolean isClosed;
+ private DatabaseMetaData metadata;
+ private Map> typeMap;
+ private Properties clientInfoProps = new Properties();
public RestfulConnection(String host, String port, Properties props, String database, String url) {
this.host = host;
@@ -21,280 +31,424 @@ public class RestfulConnection implements Connection {
this.props = props;
this.database = database;
this.url = url;
+ this.metadata = new RestfulDatabaseMetaData(url, props.getProperty(TSDBDriver.PROPERTY_KEY_USER), this);
}
@Override
public Statement createStatement() throws SQLException {
if (isClosed())
- throw new SQLException(TSDBConstants.WrapErrMsg("restful TDengine connection is closed."));
+ throw new SQLException(CONNECTION_IS_CLOSED);
+
return new RestfulStatement(this, database);
}
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
- return null;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ //TODO: prepareStatement
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public CallableStatement prepareCall(String sql) throws SQLException {
- return null;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public String nativeSQL(String sql) throws SQLException {
- return null;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+
+ //nothing did
+ return sql;
}
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
-
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ if (!autoCommit)
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public boolean getAutoCommit() throws SQLException {
- return false;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ return true;
}
@Override
public void commit() throws SQLException {
-
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ if (getAutoCommit())
+ throw new SQLException(AUTO_COMMIT_IS_TRUE);
+ //nothing to do
}
@Override
public void rollback() throws SQLException {
-
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ if (getAutoCommit())
+ throw new SQLException(AUTO_COMMIT_IS_TRUE);
+ //nothing to do
}
@Override
public void close() throws SQLException {
-
+ if (isClosed)
+ return;
+ //TODO: release all resources
+ isClosed = true;
}
@Override
public boolean isClosed() throws SQLException {
- return false;
+ return isClosed;
}
@Override
public DatabaseMetaData getMetaData() throws SQLException {
- //TODO: RestfulDatabaseMetaData is not implemented
- return new RestfulDatabaseMetaData();
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+
+ return this.metadata;
}
@Override
public void setReadOnly(boolean readOnly) throws SQLException {
-
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ // nothing to do
}
@Override
public boolean isReadOnly() throws SQLException {
- return false;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ return true;
}
@Override
public void setCatalog(String catalog) throws SQLException {
-
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ synchronized (RestfulConnection.class) {
+ this.database = catalog;
+ }
}
@Override
public String getCatalog() throws SQLException {
- return null;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ return this.database;
}
@Override
public void setTransactionIsolation(int level) throws SQLException {
- //transaction is not supported
- throw new SQLFeatureNotSupportedException("transactions are not supported");
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ switch (level) {
+ case Connection.TRANSACTION_NONE:
+ break;
+ case Connection.TRANSACTION_READ_UNCOMMITTED:
+ case Connection.TRANSACTION_READ_COMMITTED:
+ case Connection.TRANSACTION_REPEATABLE_READ:
+ case Connection.TRANSACTION_SERIALIZABLE:
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ default:
+ throw new SQLException(TSDBConstants.INVALID_VARIABLES);
+ }
}
- /**
- *
- */
@Override
public int getTransactionIsolation() throws SQLException {
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
//Connection.TRANSACTION_NONE specifies that transactions are not supported.
return Connection.TRANSACTION_NONE;
}
@Override
public SQLWarning getWarnings() throws SQLException {
- //TODO: getWarnings not implemented
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+
return null;
}
@Override
public void clearWarnings() throws SQLException {
- throw new SQLFeatureNotSupportedException("clearWarnings not supported.");
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ //nothing to do
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
- return null;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+
+ if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+ if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ return createStatement();
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
- return null;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
+ throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES);
+
+ return this.prepareStatement(sql);
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
- return null;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
+ throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES);
+
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public Map> getTypeMap() throws SQLException {
- return null;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+
+ synchronized (RestfulConnection.class) {
+ if (this.typeMap == null) {
+ this.typeMap = new HashMap<>();
+ }
+ return this.typeMap;
+ }
}
@Override
public void setTypeMap(Map> map) throws SQLException {
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ synchronized (RestfulConnection.class) {
+ this.typeMap = map;
+ }
}
@Override
public void setHoldability(int holdability) throws SQLException {
-
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ if (holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT)
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public int getHoldability() throws SQLException {
- return 0;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ return ResultSet.HOLD_CURSORS_OVER_COMMIT;
}
@Override
public Savepoint setSavepoint() throws SQLException {
- return null;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ if (getAutoCommit())
+ throw new SQLException(TSDBConstants.INVALID_VARIABLES);
+ //nothing to do
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public Savepoint setSavepoint(String name) throws SQLException {
- return null;
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ if (getAutoCommit())
+ throw new SQLException(TSDBConstants.INVALID_VARIABLES);
+ //nothing to do
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public void rollback(Savepoint savepoint) throws SQLException {
-
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ if (getAutoCommit())
+ throw new SQLException(TSDBConstants.INVALID_VARIABLES);
+ //nothing to do
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
-
+ if (isClosed())
+ throw new SQLException(CONNECTION_IS_CLOSED);
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
- return null;
+ if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT)
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ return createStatement(resultSetType, resultSetConcurrency);
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
- return null;
+ if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT)
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ return prepareStatement(sql, resultSetType, resultSetConcurrency);
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
- return null;
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
- return null;
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
- return null;
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
- return null;
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public Clob createClob() throws SQLException {
- //TODO: not supported
- throw new SQLFeatureNotSupportedException();
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public Blob createBlob() throws SQLException {
- //TODO: not supported
- throw new SQLFeatureNotSupportedException();
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public NClob createNClob() throws SQLException {
- //TODO: not supported
- throw new SQLFeatureNotSupportedException();
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public SQLXML createSQLXML() throws SQLException {
- //TODO: not supported
- throw new SQLFeatureNotSupportedException();
+ throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public boolean isValid(int timeout) throws SQLException {
- return false;
+ if (timeout < 0)
+ throw new SQLException(TSDBConstants.INVALID_VARIABLES);
+ // TODO:
+ /* The driver shall submit a query on the connection or use some other mechanism that positively verifies
+ the connection is still valid when this method is called.*/
+ return !isClosed();
}
@Override
public void setClientInfo(String name, String value) throws SQLClientInfoException {
-
+ if (isClosed)
+ throw new SQLClientInfoException();
+ clientInfoProps.setProperty(name, value);
}
@Override
public void setClientInfo(Properties properties) throws SQLClientInfoException {
+ if (isClosed)
+ throw new SQLClientInfoException();
+ for (Enumeration
diff --git a/tests/examples/JDBC/taosdemo/readme.md b/tests/examples/JDBC/taosdemo/readme.md
new file mode 100644
index 0000000000000000000000000000000000000000..a4b6e297691c4981fc36a06679d085c183e890a1
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/readme.md
@@ -0,0 +1,3 @@
+需求:
+1. 可以读lowa的配置文件
+2. 支持对JNI方式和Restful方式的taos-driver
\ No newline at end of file
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
new file mode 100644
index 0000000000000000000000000000000000000000..b9a22a1ef75962159bd33a8e525898a69b67a911
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
@@ -0,0 +1,112 @@
+package com.taosdata.taosdemo;
+
+import com.taosdata.taosdemo.components.DataSourceFactory;
+import com.taosdata.taosdemo.components.JdbcTaosdemoConfig;
+import com.taosdata.taosdemo.domain.SuperTableMeta;
+import com.taosdata.taosdemo.service.DatabaseService;
+import com.taosdata.taosdemo.service.SubTableService;
+import com.taosdata.taosdemo.service.SuperTableService;
+import com.taosdata.taosdemo.service.data.SuperTableMetaGenerator;
+import org.apache.log4j.Logger;
+
+import javax.sql.DataSource;
+import java.io.IOException;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+public class TaosDemoApplication {
+
+ private static Logger logger = Logger.getLogger(TaosDemoApplication.class);
+
+ public static void main(String[] args) throws IOException {
+ // 读配置参数
+ JdbcTaosdemoConfig config = new JdbcTaosdemoConfig(args);
+ boolean isHelp = Arrays.asList(args).contains("--help");
+ if (isHelp || config.host == null || config.host.isEmpty()) {
+// if (isHelp) {
+ JdbcTaosdemoConfig.printHelp();
+ System.exit(0);
+ }
+ // 初始化
+ final DataSource dataSource = DataSourceFactory.getInstance(config.host, config.port, config.user, config.password);
+ final DatabaseService databaseService = new DatabaseService(dataSource);
+ final SuperTableService superTableService = new SuperTableService(dataSource);
+ final SubTableService subTableService = new SubTableService(dataSource);
+ // 创建数据库
+ long start = System.currentTimeMillis();
+ Map databaseParam = new HashMap<>();
+ databaseParam.put("database", config.database);
+ databaseParam.put("keep", Integer.toString(config.keep));
+ databaseParam.put("days", Integer.toString(config.days));
+ databaseParam.put("replica", Integer.toString(config.replica));
+ //TODO: other database parameters
+ databaseService.createDatabase(databaseParam);
+ databaseService.useDatabase(config.database);
+ long end = System.currentTimeMillis();
+ logger.info(">>> create database time cost : " + (end - start) + " ms.");
+ /**********************************************************************************/
+ // 构造超级表的meta
+ SuperTableMeta superTableMeta;
+ // create super table
+ if (config.superTableSQL != null) {
+ // use a sql to create super table
+ superTableMeta = SuperTableMetaGenerator.generate(config.superTableSQL);
+ if (config.database != null && !config.database.isEmpty())
+ superTableMeta.setDatabase(config.database);
+ } else if (config.numOfFields == 0) {
+ String sql = "create table " + config.database + "." + config.superTable + " (ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int)";
+ superTableMeta = SuperTableMetaGenerator.generate(sql);
+ } else {
+ // create super table with specified field size and tag size
+ superTableMeta = SuperTableMetaGenerator.generate(config.database, config.superTable, config.numOfFields, config.prefixOfFields, config.numOfTags, config.prefixOfTags);
+ }
+ /**********************************************************************************/
+ // 建表
+ start = System.currentTimeMillis();
+ if (config.doCreateTable) {
+ superTableService.drop(superTableMeta.getDatabase(), superTableMeta.getName());
+ superTableService.create(superTableMeta);
+ if (!config.autoCreateTable) {
+ // 批量建子表
+ subTableService.createSubTable(superTableMeta, config.numOfTables, config.prefixOfTable, config.numOfThreadsForCreate);
+ }
+ }
+ end = System.currentTimeMillis();
+ logger.error(">>> create table time cost : " + (end - start) + " ms.");
+ /**********************************************************************************/
+ // 插入
+ long tableSize = config.numOfTables;
+ int threadSize = config.numOfThreadsForInsert;
+ long startTime = getProperStartTime(config.startTime, config.keep);
+
+ if (tableSize < threadSize)
+ threadSize = (int) tableSize;
+ long gap = (long) Math.ceil((0.0d + tableSize) / threadSize);
+
+ start = System.currentTimeMillis();
+ // multi threads to insert
+ int affectedRows = subTableService.insertMultiThreads(superTableMeta, threadSize, tableSize, startTime, gap, config);
+ end = System.currentTimeMillis();
+ logger.error("insert " + affectedRows + " rows, time cost: " + (end - start) + " ms");
+ /**********************************************************************************/
+ // 删除表
+ if (config.dropTable) {
+ superTableService.drop(config.database, config.superTable);
+ }
+ System.exit(0);
+ }
+
+ private static long getProperStartTime(long startTime, int keep) {
+ Instant now = Instant.now();
+ long earliest = now.minus(Duration.ofDays(keep - 1)).toEpochMilli();
+ if (startTime == 0 || startTime < earliest) {
+ startTime = earliest;
+ }
+ return startTime;
+ }
+
+
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosdemoApplication.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosdemoApplication.java
deleted file mode 100644
index db1b20527d88f5bca24ed5c6a3b477fa3a71bdf1..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosdemoApplication.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.taosdata.taosdemo;
-
-import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-@MapperScan(basePackages = {"com.taosdata.taosdemo.mapper"})
-@SpringBootApplication
-public class TaosdemoApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(TaosdemoApplication.class, args);
- }
-
-}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/DataSourceFactory.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/DataSourceFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..c96d6f8bed68e9bb67d959ddb1d7531b4cbadeb3
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/DataSourceFactory.java
@@ -0,0 +1,63 @@
+package com.taosdata.taosdemo.components;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+import org.springframework.stereotype.Component;
+
+import javax.sql.DataSource;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+@Component
+public class DataSourceFactory {
+
+ private static DataSource instance;
+
+ public static DataSource getInstance(String host, int port, String user, String password) throws IOException {
+ if (instance == null) {
+ synchronized (DataSourceFactory.class) {
+ if (instance == null) {
+ InputStream is = DataSourceFactory.class.getClassLoader().getResourceAsStream("application.properties");
+ Properties properties = new Properties();
+ properties.load(is);
+
+ HikariConfig config = new HikariConfig();
+
+ if (properties.containsKey("jdbc.driver")) {
+// String driverName = properties.getProperty("jdbc.driver");
+// System.out.println(">>> load driver : " + driverName);
+// try {
+// Class.forName(driverName);
+// } catch (ClassNotFoundException e) {
+// e.printStackTrace();
+// }
+ config.setDriverClassName(properties.getProperty("jdbc.driver"));
+ } else {
+ config.setDriverClassName("com.taosdata.jdbc.TSDBDriver");
+ }
+ if ("com.taosdata.jdbc.rs.RestfulDriver".equalsIgnoreCase(properties.getProperty("jdbc.driver")))
+ config.setJdbcUrl("jdbc:TAOS-RS://" + host + ":6041/?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8");
+ else
+ config.setJdbcUrl("jdbc:TAOS://" + host + ":" + port + "/?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8");
+ config.setUsername(user);
+ config.setPassword(password);
+ // maximum-pool-size
+ if (properties.containsKey("hikari.maximum-pool-size"))
+ config.setMaximumPoolSize(Integer.parseInt(properties.getProperty("hikari.maximum-pool-size")));
+ else
+ config.setMaximumPoolSize(500);
+ // minimum-idle
+ if (properties.containsKey("hikari.minimum-idle"))
+ config.setMinimumIdle(Integer.parseInt(properties.getProperty("hikari.minimum-idle")));
+ else
+ config.setMinimumIdle(100);
+ config.setMaxLifetime(0);
+ instance = new HikariDataSource(config);
+ }
+ }
+ }
+ return instance;
+ }
+
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..971c10dee2889543e95a70b244ea3cda462df3a6
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
@@ -0,0 +1,218 @@
+package com.taosdata.taosdemo.components;
+
+import com.taosdata.taosdemo.utils.TimeStampUtil;
+
+public final class JdbcTaosdemoConfig {
+ // instance
+ public String host; //host
+ public int port = 6030; //port
+ public String user = "root"; //user
+ public String password = "taosdata"; //password
+ // database
+ public String database = "jdbcdb"; //database
+ public int keep = 3650; //keep
+ public int days = 30; //days
+ public int replica = 1; //replica
+ public int blocks = 16;
+ public int cache = 8;
+ public String precision = "ms";
+
+ //super table
+ public boolean doCreateTable = true;
+ public String superTable = "weather"; //super table name
+ public String prefixOfFields = "col";
+ public int numOfFields;
+ public String prefixOfTags = "tag";
+ public int numOfTags;
+ public String superTableSQL;
+ //sub table
+ public String prefixOfTable = "t";
+ // insert task
+ public boolean autoCreateTable;
+ public long numOfTables = 10;
+ public long numOfRowsPerTable = 10;
+ public int numOfTablesPerSQL = 1;
+ public int numOfValuesPerSQL = 1;
+ public int numOfThreadsForCreate = 1;
+ public int numOfThreadsForInsert = 1;
+ public long startTime;
+ public long timeGap = 1;
+ public int frequency;
+ public int order;
+ public int rate = 10;
+ public long range = 1000l;
+ // select task
+
+ // drop task
+ public boolean dropTable = false;
+
+ public static void printHelp() {
+ System.out.println("Usage: java -jar jdbc-taosdemo-2.0.jar [OPTION...]");
+ // instance
+ System.out.println("-host The host to connect to TDengine which you must specify");
+ System.out.println("-port The TCP/IP port number to use for the connection. Default is 6030");
+ System.out.println("-user The TDengine user name to use when connecting to the server. Default is 'root'");
+ System.out.println("-password The password to use when connecting to the server.Default is 'taosdata'");
+ // database
+ System.out.println("-database Destination database. Default is 'jdbcdb'");
+ System.out.println("-keep database keep parameter. Default is 3650");
+ System.out.println("-days database days parameter. Default is 30");
+ System.out.println("-replica database replica parameter. Default 1, min: 1, max: 3");
+ System.out.println("-blocks database blocks parameter. Default is 16");
+ System.out.println("-cache database cache parameter. Default is 8");
+ System.out.println("-precision database precision parameter. Default is ms");
+
+ // super table
+ System.out.println("-doCreateTable do create super table and sub table, true or false, Default true");
+ System.out.println("-superTable super table name. Default 'weather'");
+ System.out.println("-prefixOfFields The prefix of field in super table. Default is 'col'");
+ System.out.println("-numOfFields The number of field in super table. Default is (ts timestamp, temperature float, humidity int).");
+ System.out.println("-prefixOfTags The prefix of tag in super table. Default is 'tag'");
+ System.out.println("-numOfTags The number of tag in super table. Default is (location nchar(64), groupId int).");
+ System.out.println("-superTableSQL specify a sql statement for the super table.\n" +
+ " Default is 'create table weather(ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int). \n" +
+ " if you use this parameter, the numOfFields and numOfTags will be invalid'");
+ // sub table
+ System.out.println("-prefixOfTable The prefix of sub tables. Default is 't'");
+ System.out.println("-numOfTables The number of tables. Default is 1");
+ System.out.println("-numOfThreadsForCreate The number of thread during create sub table. Default is 1");
+ // insert task
+ System.out.println("-autoCreateTable Use auto Create sub tables SQL. Default is false");
+ System.out.println("-numOfRowsPerTable The number of records per table. Default is 1");
+ System.out.println("-numOfThreadsForInsert The number of threads during insert row. Default is 1");
+ System.out.println("-numOfTablesPerSQL The number of table per SQL. Default is 1");
+ System.out.println("-numOfValuesPerSQL The number of value per SQL. Default is 1");
+ System.out.println("-startTime start time for insert task, The format is \"yyyy-MM-dd HH:mm:ss.SSS\".");
+ System.out.println("-timeGap the number of time gap. Default is 1000 ms");
+ System.out.println("-frequency the number of records per second inserted into one table. default is 0, do not control frequency");
+ System.out.println("-order Insert mode--0: In order, 1: Out of order. Default is in order");
+ System.out.println("-rate The proportion of data out of order. effective only if order is 1. min 0, max 100, default is 10");
+ System.out.println("-range The range of data out of order. effective only if order is 1. default is 1000 ms");
+ // query task
+// System.out.println("-sqlFile The select sql file");
+ // drop task
+ System.out.println("-dropTable Drop data before quit. Default is false");
+ System.out.println("--help Give this help list");
+ }
+
+ /**
+ * parse args from command line
+ *
+ * @param args command line args
+ * @return JdbcTaosdemoConfig
+ */
+ public JdbcTaosdemoConfig(String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ // instance
+ if ("-host".equals(args[i]) && i < args.length - 1) {
+ host = args[++i];
+ }
+ if ("-port".equals(args[i]) && i < args.length - 1) {
+ port = Integer.parseInt(args[++i]);
+ }
+ if ("-user".equals(args[i]) && i < args.length - 1) {
+ user = args[++i];
+ }
+ if ("-password".equals(args[i]) && i < args.length - 1) {
+ password = args[++i];
+ }
+ // database
+ if ("-database".equals(args[i]) && i < args.length - 1) {
+ database = args[++i];
+ }
+ if ("-keep".equals(args[i]) && i < args.length - 1) {
+ keep = Integer.parseInt(args[++i]);
+ }
+ if ("-days".equals(args[i]) && i < args.length - 1) {
+ days = Integer.parseInt(args[++i]);
+ }
+ if ("-replica".equals(args[i]) && i < args.length - 1) {
+ replica = Integer.parseInt(args[++i]);
+ }
+ if ("-blocks".equals(args[i]) && i < args.length - 1) {
+ blocks = Integer.parseInt(args[++i]);
+ }
+ if ("-cache".equals(args[i]) && i < args.length - 1) {
+ cache = Integer.parseInt(args[++i]);
+ }
+ if ("-precision".equals(args[i]) && i < args.length - 1) {
+ precision = args[++i];
+ }
+ // super table
+ if ("-doCreateTable".equals(args[i]) && i < args.length - 1) {
+ doCreateTable = Boolean.parseBoolean(args[++i]);
+ }
+ if ("-superTable".equals(args[i]) && i < args.length - 1) {
+ superTable = args[++i];
+ }
+ if ("-prefixOfFields".equals(args[i]) && i < args.length - 1) {
+ prefixOfFields = args[++i];
+ }
+ if ("-numOfFields".equals(args[i]) && i < args.length - 1) {
+ numOfFields = Integer.parseInt(args[++i]);
+ }
+ if ("-prefixOfTags".equals(args[i]) && i < args.length - 1) {
+ prefixOfTags = args[++i];
+ }
+ if ("-numOfTags".equals(args[i]) && i < args.length - 1) {
+ numOfTags = Integer.parseInt(args[++i]);
+ }
+ if ("-superTableSQL".equals(args[i]) && i < args.length - 1) {
+ superTableSQL = args[++i];
+ }
+ // sub table
+ if ("-prefixOfTable".equals(args[i]) && i < args.length - 1) {
+ prefixOfTable = args[++i];
+ }
+ if ("-numOfTables".equals(args[i]) && i < args.length - 1) {
+ numOfTables = Long.parseLong(args[++i]);
+ }
+ if ("-autoCreateTable".equals(args[i]) && i < args.length - 1) {
+ autoCreateTable = Boolean.parseBoolean(args[++i]);
+ }
+ if ("-numOfThreadsForCreate".equals(args[i]) && i < args.length - 1) {
+ numOfThreadsForCreate = Integer.parseInt(args[++i]);
+ }
+ // insert task
+ if ("-numOfRowsPerTable".equals(args[i]) && i < args.length - 1) {
+ numOfRowsPerTable = Long.parseLong(args[++i]);
+ }
+ if ("-numOfThreadsForInsert".equals(args[i]) && i < args.length - 1) {
+ numOfThreadsForInsert = Integer.parseInt(args[++i]);
+ }
+ if ("-numOfTablesPerSQL".equals(args[i]) && i < args.length - 1) {
+ numOfTablesPerSQL = Integer.parseInt(args[++i]);
+ }
+ if ("-numOfValuesPerSQL".equals(args[i]) && i < args.length - 1) {
+ numOfValuesPerSQL = Integer.parseInt(args[++i]);
+ }
+ if ("-startTime".equals(args[i]) && i < args.length - 1) {
+ startTime = TimeStampUtil.datetimeToLong(args[++i]);
+ }
+ if ("-timeGap".equals(args[i]) && i < args.length - 1) {
+ timeGap = Long.parseLong(args[++i]);
+ }
+ if ("-frequency".equals(args[i]) && i < args.length - 1) {
+ frequency = Integer.parseInt(args[++i]);
+ }
+ if ("-order".equals(args[i]) && i < args.length - 1) {
+ order = Integer.parseInt(args[++i]);
+ }
+ if ("-rate".equals(args[i]) && i < args.length - 1) {
+ rate = Integer.parseInt(args[++i]);
+ if (rate < 0 || rate > 100)
+ throw new IllegalArgumentException("rate must between 0 and 100");
+ }
+ if ("-range".equals(args[i]) && i < args.length - 1) {
+ range = Integer.parseInt(args[++i]);
+ }
+ // select task
+
+ // drop task
+ if ("-dropTable".equals(args[i]) && i < args.length - 1) {
+ dropTable = Boolean.parseBoolean(args[++i]);
+ }
+ }
+ }
+
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JsonConfig.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JsonConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..1c44610095f4b383f82a74dfdc11030a28afb246
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JsonConfig.java
@@ -0,0 +1,39 @@
+package com.taosdata.taosdemo.components;
+
+import com.alibaba.fastjson.JSONObject;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+public class JsonConfig {
+
+ public static void main(String[] args) {
+
+ JsonConfig config = new JsonConfig();
+ String str = config.read("insert.json");
+ JSONObject jsonObject = JSONObject.parseObject(str);
+ System.out.println(jsonObject);
+
+ }
+
+ private String read(String fileName) {
+ try {
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(JsonConfig.class.getClassLoader().getResourceAsStream(fileName))
+ );
+ StringBuilder sb = new StringBuilder();
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ sb.append(line);
+ }
+ return sb.toString();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return fileName;
+ }
+
+
+}
\ No newline at end of file
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/TaosDemoCommandLineRunner.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/TaosDemoCommandLineRunner.java
deleted file mode 100644
index e58c68f7a5f60b57f064075c4004267918526b15..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/TaosDemoCommandLineRunner.java
+++ /dev/null
@@ -1,174 +0,0 @@
-package com.taosdata.taosdemo.components;
-
-import com.taosdata.taosdemo.domain.*;
-import com.taosdata.taosdemo.service.DatabaseService;
-import com.taosdata.taosdemo.service.SubTableService;
-import com.taosdata.taosdemo.service.SuperTableService;
-import com.taosdata.taosdemo.service.data.SubTableMetaGenerator;
-import com.taosdata.taosdemo.service.data.SubTableValueGenerator;
-import com.taosdata.taosdemo.service.data.SuperTableMetaGenerator;
-import com.taosdata.taosdemo.utils.JdbcTaosdemoConfig;
-import org.apache.log4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.CommandLineRunner;
-import org.springframework.stereotype.Component;
-
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-
-
-@Component
-public class TaosDemoCommandLineRunner implements CommandLineRunner {
-
- private static Logger logger = Logger.getLogger(TaosDemoCommandLineRunner.class);
- @Autowired
- private DatabaseService databaseService;
- @Autowired
- private SuperTableService superTableService;
- @Autowired
- private SubTableService subTableService;
-
- private SuperTableMeta superTableMeta;
- private List subTableMetaList;
- private List subTableValueList;
- private List> dataList;
-
-
- @Override
- public void run(String... args) throws Exception {
- // 读配置参数
- JdbcTaosdemoConfig config = new JdbcTaosdemoConfig(args);
- boolean isHelp = Arrays.asList(args).contains("--help");
- if (isHelp) {
- JdbcTaosdemoConfig.printHelp();
- System.exit(0);
- }
- // 准备数据
- prepareData(config);
- // 创建数据库
- createDatabaseTask(config);
- // 建表
- createTableTask(config);
- // 插入
- insertTask(config);
- // 查询: 1. 生成查询语句, 2. 执行查询
- // 删除表
- if (config.dropTable) {
- superTableService.drop(config.database, config.superTable);
- }
-
- System.exit(0);
- }
-
- private void createDatabaseTask(JdbcTaosdemoConfig config) {
- long start = System.currentTimeMillis();
-
- Map databaseParam = new HashMap<>();
- databaseParam.put("database", config.database);
- databaseParam.put("keep", Integer.toString(config.keep));
- databaseParam.put("days", Integer.toString(config.days));
- databaseParam.put("replica", Integer.toString(config.replica));
- //TODO: other database parameters
- databaseService.dropDatabase(config.database);
- databaseService.createDatabase(databaseParam);
- databaseService.useDatabase(config.database);
-
- long end = System.currentTimeMillis();
- logger.info(">>> insert time cost : " + (end - start) + " ms.");
- }
-
- // 建超级表,三种方式:1. 指定SQL,2. 指定field和tags的个数,3. 默认
- private void createTableTask(JdbcTaosdemoConfig config) {
- long start = System.currentTimeMillis();
- if (config.doCreateTable) {
- superTableService.create(superTableMeta);
- // 批量建子表
- subTableService.createSubTable(subTableMetaList, config.numOfThreadsForCreate);
- }
- long end = System.currentTimeMillis();
- logger.info(">>> create table time cost : " + (end - start) + " ms.");
- }
-
- private void insertTask(JdbcTaosdemoConfig config) {
- long start = System.currentTimeMillis();
-
- int numOfThreadsForInsert = config.numOfThreadsForInsert;
- int sleep = config.sleep;
- if (config.autoCreateTable) {
- // 批量插入,自动建表
- dataList.stream().forEach(subTableValues -> {
- subTableService.insertAutoCreateTable(subTableValues, numOfThreadsForInsert);
- sleep(sleep);
- });
- } else {
- dataList.stream().forEach(subTableValues -> {
- subTableService.insert(subTableValues, numOfThreadsForInsert);
- sleep(sleep);
- });
- }
- long end = System.currentTimeMillis();
- logger.info(">>> insert time cost : " + (end - start) + " ms.");
- }
-
- private void prepareData(JdbcTaosdemoConfig config) {
- long start = System.currentTimeMillis();
- // 超级表的meta
- superTableMeta = createSupertable(config);
- // 子表的meta
- subTableMetaList = SubTableMetaGenerator.generate(superTableMeta, config.numOfTables, config.tablePrefix);
- // 子表的data
- subTableValueList = SubTableValueGenerator.generate(subTableMetaList, config.numOfRowsPerTable, config.startTime, config.timeGap);
- // 如果有乱序,给数据搞乱
- if (config.order != 0) {
- SubTableValueGenerator.disrupt(subTableValueList, config.rate, config.range);
- }
- // 分割数据
- int numOfTables = config.numOfTables;
- int numOfTablesPerSQL = config.numOfTablesPerSQL;
- int numOfRowsPerTable = config.numOfRowsPerTable;
- int numOfValuesPerSQL = config.numOfValuesPerSQL;
- dataList = SubTableValueGenerator.split(subTableValueList, numOfTables, numOfTablesPerSQL, numOfRowsPerTable, numOfValuesPerSQL);
- long end = System.currentTimeMillis();
- logger.info(">>> prepare data time cost : " + (end - start) + " ms.");
- }
-
- private SuperTableMeta createSupertable(JdbcTaosdemoConfig config) {
- SuperTableMeta tableMeta;
- // create super table
- logger.info(">>> create super table <<<");
- if (config.superTableSQL != null) {
- // use a sql to create super table
- tableMeta = SuperTableMetaGenerator.generate(config.superTableSQL);
- } else if (config.numOfFields == 0) {
- // default sql = "create table test.weather (ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int)";
- SuperTableMeta superTableMeta = new SuperTableMeta();
- superTableMeta.setDatabase(config.database);
- superTableMeta.setName(config.superTable);
- List fields = new ArrayList<>();
- fields.add(new FieldMeta("ts", "timestamp"));
- fields.add(new FieldMeta("temperature", "float"));
- fields.add(new FieldMeta("humidity", "int"));
- superTableMeta.setFields(fields);
- List tags = new ArrayList<>();
- tags.add(new TagMeta("location", "nchar(64)"));
- tags.add(new TagMeta("groupId", "int"));
- superTableMeta.setTags(tags);
- return superTableMeta;
- } else {
- // create super table with specified field size and tag size
- tableMeta = SuperTableMetaGenerator.generate(config.database, config.superTable, config.numOfFields, config.prefixOfFields, config.numOfTags, config.prefixOfTags);
- }
- return tableMeta;
- }
-
- private static void sleep(int sleep) {
- if (sleep <= 0)
- return;
- try {
- TimeUnit.MILLISECONDS.sleep(sleep);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
-}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/DatabaseController.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/DatabaseController.java
deleted file mode 100644
index 1cf1463f0ab4f2a8c67258f512e407d54c1d869e..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/DatabaseController.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.taosdata.taosdemo.controller;
-
-import com.taosdata.taosdemo.service.DatabaseService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.Map;
-
-@RestController
-@RequestMapping
-public class DatabaseController {
-
- @Autowired
- private DatabaseService databaseService;
-
- /**
- * create database
- ***/
- @PostMapping
- public int create(@RequestBody Map map) {
- return databaseService.createDatabase(map);
- }
-
-
- /**
- * drop database
- **/
- @DeleteMapping("/{dbname}")
- public int delete(@PathVariable("dbname") String dbname) {
- return databaseService.dropDatabase(dbname);
- }
-
- /**
- * use database
- **/
- @GetMapping("/{dbname}")
- public int use(@PathVariable("dbname") String dbname) {
- return databaseService.useDatabase(dbname);
- }
-}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/InsertController.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/InsertController.java
deleted file mode 100644
index 788f68a30af5ac7dd4c8c27f4cfe5f1a6f2b440b..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/InsertController.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.taosdata.taosdemo.controller;
-
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-public class InsertController {
-
- //TODO:多线程写一张表, thread = 10, table = 1
- //TODO:一个批次写多张表, insert into t1 using weather values() t2 using weather values()
- //TODO:插入的频率,
- //TODO:指定一张表内的records数量
- //TODO:是否乱序,
- //TODO:乱序的比例,乱序的范围
- //TODO:先建表,自动建表
- //TODO:一个批次写多张表
-
-}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/SubTableController.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/SubTableController.java
deleted file mode 100644
index 797c3708d3357c19bf5f64046bb794b66786e080..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/SubTableController.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.taosdata.taosdemo.controller;
-
-import com.taosdata.taosdemo.domain.TableValue;
-import com.taosdata.taosdemo.service.SuperTableService;
-import com.taosdata.taosdemo.service.TableService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-public class SubTableController {
-
- @Autowired
- private TableService tableService;
- @Autowired
- private SuperTableService superTableService;
-
- //TODO: 使用supertable创建一个子表
-
- //TODO:使用supertable创建多个子表
-
- //TODO:使用supertable多线程创建子表
-
- //TODO:使用supertable多线程创建子表,指定子表的name_prefix,子表的数量,使用线程的个数
-
- /**
- * 创建表,超级表或者普通表
- **/
-
-
- /**
- * 创建超级表的子表
- **/
- @PostMapping("/{database}/{superTable}")
- public int createTable(@PathVariable("database") String database,
- @PathVariable("superTable") String superTable,
- @RequestBody TableValue tableMetadta) {
- tableMetadta.setDatabase(database);
- return 0;
- }
-
-
-}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/SuperTableController.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/SuperTableController.java
deleted file mode 100644
index cf53c1440fa710c3bea510973ca2efecb0705828..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/SuperTableController.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.taosdata.taosdemo.controller;
-
-import com.taosdata.taosdemo.domain.SuperTableMeta;
-import com.taosdata.taosdemo.service.SuperTableService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-
-public class SuperTableController {
- @Autowired
- private SuperTableService superTableService;
-
-
- @PostMapping("/{database}")
- public int createTable(@PathVariable("database") String database, @RequestBody SuperTableMeta tableMetadta) {
- tableMetadta.setDatabase(database);
- return superTableService.create(tableMetadta);
- }
-
- //TODO: 删除超级表
-
- //TODO:查询超级表
-
- //TODO:统计查询表
-}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/TableController.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/TableController.java
deleted file mode 100644
index dbdd978e746eb89d8927617ae4026cdcf544559b..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/TableController.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.taosdata.taosdemo.controller;
-
-public class TableController {
-
- //TODO:创建普通表,create table(ts timestamp, temperature float)
-
- //TODO:创建普通表,指定表的列数,包括第一列timestamp
-
- //TODO:创建普通表,指定表每列的name和type
-
-}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/DatabaseMapper.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/DatabaseMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..56e38d2bfce8ba5801d0f8dc48093d198852fbca
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/DatabaseMapper.java
@@ -0,0 +1,23 @@
+package com.taosdata.taosdemo.dao;
+
+import java.util.Map;
+
+public interface DatabaseMapper {
+
+ // create database if not exists XXX
+ void createDatabase(String dbname);
+
+ // drop database if exists XXX
+ void dropDatabase(String dbname);
+
+ // create database if not exists XXX keep XX days XX replica XX
+ void createDatabaseWithParameters(Map map);
+
+ // use XXX
+ void useDatabase(String dbname);
+
+ //TODO: alter database
+
+ //TODO: show database
+
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/DatabaseMapperImpl.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/DatabaseMapperImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..69bae160f6285bb9d1a94357cc2279ebfca22eca
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/DatabaseMapperImpl.java
@@ -0,0 +1,47 @@
+package com.taosdata.taosdemo.dao;
+
+import com.taosdata.taosdemo.utils.SqlSpeller;
+import org.apache.log4j.Logger;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.sql.DataSource;
+import java.util.Map;
+
+public class DatabaseMapperImpl implements DatabaseMapper {
+ private static final Logger logger = Logger.getLogger(DatabaseMapperImpl.class);
+
+ private final JdbcTemplate jdbcTemplate;
+
+ public DatabaseMapperImpl(DataSource dataSource) {
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ }
+
+
+ @Override
+ public void createDatabase(String dbname) {
+ String sql = "create database if not exists " + dbname;
+ jdbcTemplate.execute(sql);
+ logger.info("SQL >>> " + sql);
+ }
+
+ @Override
+ public void dropDatabase(String dbname) {
+ String sql = "drop database if exists " + dbname;
+ jdbcTemplate.update(sql);
+ logger.info("SQL >>> " + sql);
+ }
+
+ @Override
+ public void createDatabaseWithParameters(Map map) {
+ String sql = SqlSpeller.createDatabase(map);
+ jdbcTemplate.execute(sql);
+ logger.info("SQL >>> " + sql);
+ }
+
+ @Override
+ public void useDatabase(String dbname) {
+ String sql = "use " + dbname;
+ jdbcTemplate.execute(sql);
+ logger.info("SQL >>> " + sql);
+ }
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SubTableMapper.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SubTableMapper.java
similarity index 67%
rename from tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SubTableMapper.java
rename to tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SubTableMapper.java
index d23473ba313899eee04f07f5c06177a2d55f6295..e0ddd220c19066afd1cc332f007a82e2fdab2b07 100644
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SubTableMapper.java
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SubTableMapper.java
@@ -1,8 +1,7 @@
-package com.taosdata.taosdemo.mapper;
+package com.taosdata.taosdemo.dao;
import com.taosdata.taosdemo.domain.SubTableMeta;
import com.taosdata.taosdemo.domain.SubTableValue;
-import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@@ -11,7 +10,7 @@ import java.util.List;
public interface SubTableMapper {
// 创建:子表
- int createUsingSuperTable(SubTableMeta subTableMeta);
+ void createUsingSuperTable(SubTableMeta subTableMeta);
// 插入:一张子表多个values
int insertOneTableMultiValues(SubTableValue subTableValue);
@@ -20,10 +19,10 @@ public interface SubTableMapper {
int insertOneTableMultiValuesUsingSuperTable(SubTableValue subTableValue);
// 插入:多张表多个values
- int insertMultiTableMultiValues(@Param("tables") List tables);
+ int insertMultiTableMultiValues(List tables);
// 插入:多张表多个values,自动建表
- int insertMultiTableMultiValuesUsingSuperTable(@Param("tables") List tables);
+ int insertMultiTableMultiValuesUsingSuperTable(List tables);
//
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SubTableMapperImpl.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SubTableMapperImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..e3a6691430f8b5232660ed6edeab01318db30ef1
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SubTableMapperImpl.java
@@ -0,0 +1,81 @@
+package com.taosdata.taosdemo.dao;
+
+import com.taosdata.taosdemo.domain.SubTableMeta;
+import com.taosdata.taosdemo.domain.SubTableValue;
+import com.taosdata.taosdemo.utils.SqlSpeller;
+import org.apache.log4j.Logger;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.sql.DataSource;
+import java.util.List;
+
+public class SubTableMapperImpl implements SubTableMapper {
+
+ private static final Logger logger = Logger.getLogger(SubTableMapperImpl.class);
+ private final JdbcTemplate jdbcTemplate;
+
+ public SubTableMapperImpl(DataSource dataSource) {
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ }
+
+ @Override
+ public void createUsingSuperTable(SubTableMeta subTableMeta) {
+ String sql = SqlSpeller.createTableUsingSuperTable(subTableMeta);
+ logger.info("SQL >>> " + sql);
+ jdbcTemplate.execute(sql);
+ }
+
+ @Override
+ public int insertOneTableMultiValues(SubTableValue subTableValue) {
+ String sql = SqlSpeller.insertOneTableMultiValues(subTableValue);
+ logger.info("SQL >>> " + sql);
+
+ int affectRows = 0;
+ try {
+ affectRows = jdbcTemplate.update(sql);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return affectRows;
+ }
+
+ @Override
+ public int insertOneTableMultiValuesUsingSuperTable(SubTableValue subTableValue) {
+ String sql = SqlSpeller.insertOneTableMultiValuesUsingSuperTable(subTableValue);
+ logger.info("SQL >>> " + sql);
+
+ int affectRows = 0;
+ try {
+ affectRows = jdbcTemplate.update(sql);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return affectRows;
+ }
+
+ @Override
+ public int insertMultiTableMultiValues(List tables) {
+ String sql = SqlSpeller.insertMultiSubTableMultiValues(tables);
+ logger.info("SQL >>> " + sql);
+ int affectRows = 0;
+ try {
+ affectRows = jdbcTemplate.update(sql);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return affectRows;
+ }
+
+ @Override
+ public int insertMultiTableMultiValuesUsingSuperTable(List tables) {
+ String sql = SqlSpeller.insertMultiTableMultiValuesUsingSuperTable(tables);
+ logger.info("SQL >>> " + sql);
+ int affectRows = 0;
+ try {
+ affectRows = jdbcTemplate.update(sql);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return affectRows;
+ }
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SuperTableMapper.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SuperTableMapper.java
similarity index 70%
rename from tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SuperTableMapper.java
rename to tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SuperTableMapper.java
index c8610fac901efa907971d700bd9956cac264236f..9f8cec9e8fa5af8741d9efbdce72f240aa7a09aa 100644
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SuperTableMapper.java
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SuperTableMapper.java
@@ -1,20 +1,16 @@
-package com.taosdata.taosdemo.mapper;
+package com.taosdata.taosdemo.dao;
import com.taosdata.taosdemo.domain.SuperTableMeta;
-import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface SuperTableMapper {
- // 创建超级表,使用自己定义的SQL语句
- int createSuperTableUsingSQL(@Param("createSuperTableSQL") String sql);
-
// 创建超级表 create table if not exists xxx.xxx (f1 type1, f2 type2, ... ) tags( t1 type1, t2 type2 ...)
- int createSuperTable(SuperTableMeta tableMetadata);
+ void createSuperTable(SuperTableMeta tableMetadata);
// 删除超级表 drop table if exists xxx;
- int dropSuperTable(@Param("database") String database, @Param("name") String name);
+ void dropSuperTable(String database, String name);
//
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SuperTableMapperImpl.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SuperTableMapperImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..a293de5100d9af33bc88ad5f02ae632333a5b5b8
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SuperTableMapperImpl.java
@@ -0,0 +1,31 @@
+package com.taosdata.taosdemo.dao;
+
+import com.taosdata.taosdemo.domain.SuperTableMeta;
+import com.taosdata.taosdemo.utils.SqlSpeller;
+import org.apache.log4j.Logger;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.sql.DataSource;
+
+public class SuperTableMapperImpl implements SuperTableMapper {
+ private static final Logger logger = Logger.getLogger(SuperTableMapperImpl.class);
+ private JdbcTemplate jdbcTemplate;
+
+ public SuperTableMapperImpl(DataSource dataSource) {
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ }
+
+ @Override
+ public void createSuperTable(SuperTableMeta tableMetadata) {
+ String sql = SqlSpeller.createSuperTable(tableMetadata);
+ logger.info("SQL >>> " + sql);
+ jdbcTemplate.execute(sql);
+ }
+
+ @Override
+ public void dropSuperTable(String database, String name) {
+ String sql = "drop table if exists " + database + "." + name;
+ logger.info("SQL >>> " + sql);
+ jdbcTemplate.execute(sql);
+ }
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/TableMapper.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/TableMapper.java
similarity index 65%
rename from tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/TableMapper.java
rename to tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/TableMapper.java
index f00f6c96941d47258d91a34ffeb1de99c4c8435e..32d1875e4d1a82f7dfb658d68ed0e63a5cbfa040 100644
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/TableMapper.java
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/TableMapper.java
@@ -1,8 +1,7 @@
-package com.taosdata.taosdemo.mapper;
+package com.taosdata.taosdemo.dao;
import com.taosdata.taosdemo.domain.TableMeta;
import com.taosdata.taosdemo.domain.TableValue;
-import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@@ -11,7 +10,7 @@ import java.util.List;
public interface TableMapper {
// 创建:普通表
- int create(TableMeta tableMeta);
+ void create(TableMeta tableMeta);
// 插入:一张表多个value
int insertOneTableMultiValues(TableValue values);
@@ -20,9 +19,9 @@ public interface TableMapper {
int insertOneTableMultiValuesWithColumns(TableValue values);
// 插入:多个表多个value
- int insertMultiTableMultiValues(@Param("tables") List tables);
+ int insertMultiTableMultiValues(List tables);
// 插入:多个表多个value, 指定的列
- int insertMultiTableMultiValuesWithColumns(@Param("tables") List tables);
+ int insertMultiTableMultiValuesWithColumns(List tables);
}
\ No newline at end of file
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/TableMapperImpl.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/TableMapperImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..77415619f02a1a0650448e9a8856fcb8d33e4921
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/TableMapperImpl.java
@@ -0,0 +1,43 @@
+package com.taosdata.taosdemo.dao;
+
+import com.taosdata.taosdemo.dao.TableMapper;
+import com.taosdata.taosdemo.domain.TableMeta;
+import com.taosdata.taosdemo.domain.TableValue;
+import com.taosdata.taosdemo.utils.SqlSpeller;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.util.List;
+
+public class TableMapperImpl implements TableMapper {
+ private JdbcTemplate template;
+
+ @Override
+ public void create(TableMeta tableMeta) {
+ String sql = SqlSpeller.createTable(tableMeta);
+ template.execute(sql);
+ }
+
+ @Override
+ public int insertOneTableMultiValues(TableValue values) {
+ String sql = SqlSpeller.insertOneTableMultiValues(values);
+ return template.update(sql);
+ }
+
+ @Override
+ public int insertOneTableMultiValuesWithColumns(TableValue values) {
+ String sql = SqlSpeller.insertOneTableMultiValuesWithColumns(values);
+ return template.update(sql);
+ }
+
+ @Override
+ public int insertMultiTableMultiValues(List tables) {
+ String sql = SqlSpeller.insertMultiTableMultiValues(tables);
+ return template.update(sql);
+ }
+
+ @Override
+ public int insertMultiTableMultiValuesWithColumns(List tables) {
+ String sql = SqlSpeller.insertMultiTableMultiValuesWithColumns(tables);
+ return template.update(sql);
+ }
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/RowValue.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/RowValue.java
index a9f216f6792820931af4570450318ddc53e3c8b7..a444fa78dcdeb8f1bb76974a29051c98348a055b 100644
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/RowValue.java
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/RowValue.java
@@ -8,7 +8,6 @@ import java.util.List;
public class RowValue {
private List fields;
-
public RowValue(List fields) {
this.fields = fields;
}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/DatabaseMapper.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/DatabaseMapper.java
deleted file mode 100644
index e535ed1f985d37688c8461e1f0bef3a803f541d4..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/DatabaseMapper.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.taosdata.taosdemo.mapper;
-
-import org.apache.ibatis.annotations.Param;
-import org.springframework.stereotype.Repository;
-
-import java.util.Map;
-
-@Repository
-public interface DatabaseMapper {
-
- // create database if not exists XXX
- int createDatabase(@Param("database") String dbname);
-
- // drop database if exists XXX
- int dropDatabase(@Param("database") String dbname);
-
- // create database if not exists XXX keep XX days XX replica XX
- int createDatabaseWithParameters(Map map);
-
- // use XXX
- int useDatabase(@Param("database") String dbname);
-
- //TODO: alter database
-
- //TODO: show database
-
-}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/DatabaseMapper.xml b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/DatabaseMapper.xml
deleted file mode 100644
index 1a1de348428ae63ad16f9988f535f339f61d8c25..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/DatabaseMapper.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-
-
-
-
-
- create database if not exists ${database}
-
-
-
- DROP database if exists ${database}
-
-
-
- CREATE database if not exists ${database}
-
- KEEP ${keep}
-
-
- DAYS ${days}
-
-
- REPLICA ${replica}
-
-
- cache ${cache}
-
-
- blocks ${blocks}
-
-
- minrows ${minrows}
-
-
- maxrows ${maxrows}
-
-
-
-
- use ${database}
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SubTableMapper.xml b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SubTableMapper.xml
deleted file mode 100644
index 2fb94e99b77623ab8731c03f398058dbdc459d07..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SubTableMapper.xml
+++ /dev/null
@@ -1,81 +0,0 @@
-
-
-
-
-
-
-
- CREATE table IF NOT EXISTS ${database}.${name} USING ${supertable} TAGS
-
- #{tag.value}
-
-
-
-
-
- INSERT INTO ${database}.${name}
- VALUES
-
-
- #{field.value}
-
-
-
-
-
-
- INSERT INTO ${database}.${name} USING ${supertable} TAGS
-
- #{tag.value}
-
- VALUES
-
-
- #{field.value}
-
-
-
-
-
-
-
-
-
-
- INSERT INTO
-
- ${table.database}.${table.name}
- VALUES
-
-
- #{field.value}
-
-
-
-
-
-
-
- INSERT INTO
-
- ${table.database}.${table.name} USING ${table.supertable} TAGS
-
- #{tag.value}
-
- VALUES
-
-
- #{field.value}
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SuperTableMapper.xml b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SuperTableMapper.xml
deleted file mode 100644
index 8b83d57a4bcbf7a2a6b3f69911b3accc61064480..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SuperTableMapper.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
-
- ${createSuperTableSQL}
-
-
-
-
- create table if not exists ${database}.${name}
-
- ${field.name} ${field.type}
-
- tags
-
- ${tag.name} ${tag.type}
-
-
-
-
-
- drop table if exists ${database}.${name}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/TableMapper.xml b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/TableMapper.xml
deleted file mode 100644
index e2e7cbb30def21f88ec7615b7a6dd4a769cb643a..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/TableMapper.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-
-
-
-
-
-
-
- create table if not exists ${database}.${name}
-
- ${field.name} ${field.type}
-
-
-
-
-
- insert into ${database}.${name} values
-
-
- ${field.value}
-
-
-
-
-
-
- insert into ${database}.${name}
-
- ${column.name}
-
- values
-
-
- ${field.value}
-
-
-
-
-
-
- insert into
-
- ${table.database}.${table.name} values
-
-
- ${field.value}
-
-
-
-
-
-
-
- insert into
-
- ${table.database}.${table.name}
-
- ${column.name}
-
- values
-
-
- ${field.value}
-
-
-
-
-
-
\ No newline at end of file
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/DatabaseService.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/DatabaseService.java
index e9aa2727a06ade0ff3d7661f84977c64f64ea9af..3c8e9624066bf629a74ebcaa3959a2e15338c363 100644
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/DatabaseService.java
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/DatabaseService.java
@@ -1,38 +1,42 @@
package com.taosdata.taosdemo.service;
-import com.taosdata.taosdemo.mapper.DatabaseMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
+import com.taosdata.taosdemo.dao.DatabaseMapper;
+import com.taosdata.taosdemo.dao.DatabaseMapperImpl;
+import javax.sql.DataSource;
import java.util.Map;
-@Service
public class DatabaseService {
- @Autowired
- private DatabaseMapper databaseMapper;
+ private final DatabaseMapper databaseMapper;
+
+ public DatabaseService(DataSource dataSource) {
+ this.databaseMapper = new DatabaseMapperImpl(dataSource);
+ }
// 建库,指定 name
- public int createDatabase(String database) {
- return databaseMapper.createDatabase(database);
+ public void createDatabase(String database) {
+ databaseMapper.createDatabase(database);
}
// 建库,指定参数 keep,days,replica等
- public int createDatabase(Map map) {
+ public void createDatabase(Map map) {
if (map.isEmpty())
- return 0;
- if (map.containsKey("database") && map.size() == 1)
- return databaseMapper.createDatabase(map.get("database"));
- return databaseMapper.createDatabaseWithParameters(map);
+ return;
+ if (map.containsKey("database") && map.size() == 1) {
+ createDatabase(map.get("database"));
+ return;
+ }
+ databaseMapper.createDatabaseWithParameters(map);
}
// drop database
- public int dropDatabase(String dbname) {
- return databaseMapper.dropDatabase(dbname);
+ public void dropDatabase(String dbname) {
+ databaseMapper.dropDatabase(dbname);
}
// use database
- public int useDatabase(String dbname) {
- return databaseMapper.useDatabase(dbname);
+ public void useDatabase(String dbname) {
+ databaseMapper.useDatabase(dbname);
}
}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SubTableService.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SubTableService.java
index 07c315b65a9e07222fe85066c3f1f3b1edb107fe..cea98a1c5d350ed22ed5d26c72fedb212dcb7f26 100644
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SubTableService.java
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SubTableService.java
@@ -1,68 +1,63 @@
package com.taosdata.taosdemo.service;
+import com.taosdata.taosdemo.components.JdbcTaosdemoConfig;
+import com.taosdata.taosdemo.dao.SubTableMapper;
+import com.taosdata.taosdemo.dao.SubTableMapperImpl;
import com.taosdata.taosdemo.domain.SubTableMeta;
import com.taosdata.taosdemo.domain.SubTableValue;
-import com.taosdata.taosdemo.mapper.SubTableMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
+import com.taosdata.taosdemo.domain.SuperTableMeta;
+import com.taosdata.taosdemo.service.data.SubTableMetaGenerator;
+import com.taosdata.taosdemo.service.data.SubTableValueGenerator;
+import org.apache.log4j.Logger;
+import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
+import java.util.concurrent.*;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
-@Service
public class SubTableService extends AbstractService {
- @Autowired
private SubTableMapper mapper;
+ private static final Logger logger = Logger.getLogger(SubTableService.class);
- /**
- * 1. 选择database,找到所有supertable
- * 2. 选择supertable,可以拿到表结构,包括field和tag
- * 3. 指定子表的前缀和个数
- * 4. 指定创建子表的线程数
- */
- //TODO:指定database、supertable、子表前缀、子表个数、线程数
+ public SubTableService(DataSource datasource) {
+ this.mapper = new SubTableMapperImpl(datasource);
+ }
- // 多线程创建表,指定线程个数
- public int createSubTable(List subTables, int threadSize) {
- ExecutorService executor = Executors.newFixedThreadPool(threadSize);
- List> futureList = new ArrayList<>();
- for (SubTableMeta subTableMeta : subTables) {
- Future future = executor.submit(() -> createSubTable(subTableMeta));
- futureList.add(future);
+ public void createSubTable(SuperTableMeta superTableMeta, long numOfTables, String prefixOfTable, int numOfThreadsForCreate) {
+ ExecutorService executor = Executors.newFixedThreadPool(numOfThreadsForCreate);
+ for (long i = 0; i < numOfTables; i++) {
+ long tableIndex = i;
+ executor.execute(() -> createSubTable(superTableMeta, prefixOfTable + (tableIndex + 1)));
}
executor.shutdown();
- return getAffectRows(futureList);
+ try {
+ executor.awaitTermination(Long.MAX_VALUE,TimeUnit.NANOSECONDS);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
-
- // 创建一张子表,可以指定database,supertable,tablename,tag值
- public int createSubTable(SubTableMeta subTableMeta) {
- return mapper.createUsingSuperTable(subTableMeta);
+ public void createSubTable(SuperTableMeta superTableMeta, String tableName) {
+ // 构造数据
+ SubTableMeta meta = SubTableMetaGenerator.generate(superTableMeta, tableName);
+ createSubTable(meta);
}
- // 单线程创建多张子表,每张子表分别可以指定自己的database,supertable,tablename,tag值
- public int createSubTable(List subTables) {
- return createSubTable(subTables, 1);
+ // 创建一张子表,可以指定database,supertable,tablename,tag值
+ public void createSubTable(SubTableMeta subTableMeta) {
+ mapper.createUsingSuperTable(subTableMeta);
}
/*************************************************************************************************************************/
// 插入:多线程,多表
- public int insert(List subTableValues, int threadSize) {
+ public int insert(List subTableValues, int threadSize, int frequency) {
ExecutorService executor = Executors.newFixedThreadPool(threadSize);
Future future = executor.submit(() -> insert(subTableValues));
executor.shutdown();
- return getAffectRows(future);
- }
-
- // 插入:多线程,多表, 自动建表
- public int insertAutoCreateTable(List subTableValues, int threadSize) {
- ExecutorService executor = Executors.newFixedThreadPool(threadSize);
- Future future = executor.submit(() -> insertAutoCreateTable(subTableValues));
- executor.shutdown();
+ //TODO:frequency
return getAffectRows(future);
}
@@ -73,7 +68,7 @@ public class SubTableService extends AbstractService {
// 插入: 多表,insert into xxx values(),()... xxx values(),()...
public int insert(List subTableValues) {
- return mapper.insertMultiTableMultiValuesUsingSuperTable(subTableValues);
+ return mapper.insertMultiTableMultiValues(subTableValues);
}
// 插入:单表,自动建表, insert into xxx using xxx tags(...) values(),()...
@@ -86,33 +81,128 @@ public class SubTableService extends AbstractService {
return mapper.insertMultiTableMultiValuesUsingSuperTable(subTableValues);
}
+ public int insertMultiThreads(SuperTableMeta superTableMeta, int threadSize, long tableSize, long startTime, long gap, JdbcTaosdemoConfig config) {
+ List taskList = new ArrayList<>();
+ List threads = IntStream.range(0, threadSize)
+ .mapToObj(i -> {
+ long startInd = i * gap;
+ long endInd = (i + 1) * gap < tableSize ? (i + 1) * gap : tableSize;
+ FutureTask task = new FutureTask<>(
+ new InsertTask(superTableMeta,
+ startInd, endInd,
+ startTime, config.timeGap,
+ config.numOfRowsPerTable, config.numOfTablesPerSQL, config.numOfValuesPerSQL,
+ config.order, config.rate, config.range,
+ config.prefixOfTable, config.autoCreateTable)
+ );
+ taskList.add(task);
+ return new Thread(task, "InsertThread-" + i);
+ }).collect(Collectors.toList());
+
+ threads.stream().forEach(Thread::start);
+ for (Thread thread : threads) {
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ int affectedRows = 0;
+ for (FutureTask task : taskList) {
+ try {
+ affectedRows += task.get();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return affectedRows;
+ }
-// ExecutorService executors = Executors.newFixedThreadPool(threadSize);
-// int count = 0;
-//
-// //
-// List subTableValues = new ArrayList<>();
-// for (int tableIndex = 1; tableIndex <= numOfTablesPerSQL; tableIndex++) {
-// // each table
-// SubTableValue subTableValue = new SubTableValue();
-// subTableValue.setDatabase();
-// subTableValue.setName();
-// subTableValue.setSupertable();
-//
-// List values = new ArrayList<>();
-// for (int valueCnt = 0; valueCnt < numOfValuesPerSQL; valueCnt++) {
-// List fields = new ArrayList<>();
-// for (int fieldInd = 0; fieldInd <; fieldInd++) {
-// FieldValue