diff --git a/tests/examples/JDBC/taosdemo/pom.xml b/tests/examples/JDBC/taosdemo/pom.xml
index 74e311951bceac2a0433eadf6ba5ae618b1cceaa..5cbf6cb7004566e8d6ea6e16e8b70f289ac2941d 100644
--- a/tests/examples/JDBC/taosdemo/pom.xml
+++ b/tests/examples/JDBC/taosdemo/pom.xml
@@ -19,6 +19,33 @@
+
+
+
+ com.taosdata.jdbc
+ taos-jdbcdriver
+ 2.0.14
+
+
+
+ mysql
+ mysql-connector-java
+ 5.1.47
+
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.1.2
+
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+
org.springframework.boot
spring-boot-starter-jdbc
@@ -36,7 +63,12 @@
mybatis-spring-boot-starter
2.1.4
-
+
+ junit
+ junit
+ 4.12
+ test
+
org.springframework.boot
spring-boot-devtools
@@ -56,6 +88,24 @@
+
+
+ src/main/resources
+
+ **/*.properties
+ **/*.xml
+
+ true
+
+
+ src/main/java
+
+ **/*.properties
+ **/*.xml
+
+
+
+
org.springframework.boot
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
index 78af6421f6c19c3106087b6012a80f852dc712a3..db1b20527d88f5bca24ed5c6a3b477fa3a71bdf1 100644
--- 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
@@ -1,8 +1,10 @@
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 {
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
new file mode 100644
index 0000000000000000000000000000000000000000..432a20a4f980038ba194ebd5c085a0f94fcf5658
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/TaosDemoCommandLineRunner.java
@@ -0,0 +1,154 @@
+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();
+ }
+ // 准备数据
+ prepareData(config);
+
+ // 创建数据库
+ 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);
+
+ // 建表
+ // 建超级表,三种方式:1. 指定SQL,2. 指定field和tags的个数,3. 默认
+ if (config.doCreateTable) {
+ superTableService.create(superTableMeta);
+ // 批量建子表
+ subTableService.createSubTable(subTableMetaList, config.numOfThreadsForCreate);
+ }
+
+ // 插入
+ int numOfThreadsForInsert = 1;
+ int sleep = 0;
+ if (config.autoCreateTable) {
+ // 批量插入,自动建表
+ dataList.stream().forEach(subTableValues -> {
+ subTableService.insertAutoCreateTable(subTableValues, numOfThreadsForInsert);
+ sleep(sleep);
+ });
+ } else {
+ dataList.stream().forEach(subTableValues -> {
+ subTableService.insert(subTableValues, numOfThreadsForInsert);
+ sleep(sleep);
+ });
+ }
+ // 批量插入,不使用自动建表
+
+ // 查询
+ // 1. 生成查询语句
+ // 2. 执行查询
+
+ // 删除表
+ if (config.dropTable) {
+ superTableService.drop(config.database, config.superTable);
+ }
+
+ System.exit(0);
+ }
+
+ private void prepareData(JdbcTaosdemoConfig config) {
+ // 超级表的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);
+ }
+
+ 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
new file mode 100644
index 0000000000000000000000000000000000000000..1cf1463f0ab4f2a8c67258f512e407d54c1d869e
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/DatabaseController.java
@@ -0,0 +1,40 @@
+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
new file mode 100644
index 0000000000000000000000000000000000000000..788f68a30af5ac7dd4c8c27f4cfe5f1a6f2b440b
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/InsertController.java
@@ -0,0 +1,17 @@
+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
new file mode 100644
index 0000000000000000000000000000000000000000..797c3708d3357c19bf5f64046bb794b66786e080
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/SubTableController.java
@@ -0,0 +1,45 @@
+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
new file mode 100644
index 0000000000000000000000000000000000000000..cf53c1440fa710c3bea510973ca2efecb0705828
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/SuperTableController.java
@@ -0,0 +1,26 @@
+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
new file mode 100644
index 0000000000000000000000000000000000000000..dbdd978e746eb89d8927617ae4026cdcf544559b
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/controller/TableController.java
@@ -0,0 +1,11 @@
+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/domain/FieldMeta.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/FieldMeta.java
new file mode 100644
index 0000000000000000000000000000000000000000..8a45e99989821562fdf9333b90a2972388cf6003
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/FieldMeta.java
@@ -0,0 +1,17 @@
+package com.taosdata.taosdemo.domain;
+
+import lombok.Data;
+
+@Data
+public class FieldMeta {
+ private String name;
+ private String type;
+
+ public FieldMeta() {
+ }
+
+ public FieldMeta(String name, String type) {
+ this.name = name;
+ this.type = type;
+ }
+}
\ No newline at end of file
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/FieldValue.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/FieldValue.java
new file mode 100644
index 0000000000000000000000000000000000000000..44805c0d7c2f4e0df60d723afd598f2aa788ee65
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/FieldValue.java
@@ -0,0 +1,17 @@
+package com.taosdata.taosdemo.domain;
+
+import lombok.Data;
+
+@Data
+public class FieldValue {
+ private String name;
+ private T value;
+
+ public FieldValue() {
+ }
+
+ public FieldValue(String name, T value) {
+ this.name = name;
+ this.value = value;
+ }
+}
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
new file mode 100644
index 0000000000000000000000000000000000000000..a9f216f6792820931af4570450318ddc53e3c8b7
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/RowValue.java
@@ -0,0 +1,15 @@
+package com.taosdata.taosdemo.domain;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class RowValue {
+ private List fields;
+
+
+ public RowValue(List fields) {
+ this.fields = fields;
+ }
+}
\ No newline at end of file
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/SubTableMeta.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/SubTableMeta.java
new file mode 100644
index 0000000000000000000000000000000000000000..81de882448121532a3c840296702d1fb24c37326
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/SubTableMeta.java
@@ -0,0 +1,15 @@
+package com.taosdata.taosdemo.domain;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class SubTableMeta {
+
+ private String database;
+ private String supertable;
+ private String name;
+ private List tags;
+ private List fields;
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/SubTableValue.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/SubTableValue.java
new file mode 100644
index 0000000000000000000000000000000000000000..74fb9598bc8e920123180f948b88fb98baf9218e
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/SubTableValue.java
@@ -0,0 +1,15 @@
+package com.taosdata.taosdemo.domain;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class SubTableValue {
+
+ private String database;
+ private String supertable;
+ private String name;
+ private List tags;
+ private List values;
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/SuperTableMeta.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/SuperTableMeta.java
new file mode 100644
index 0000000000000000000000000000000000000000..c5c65a4599b776faeead19ffbf065361b293b44b
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/SuperTableMeta.java
@@ -0,0 +1,14 @@
+package com.taosdata.taosdemo.domain;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class SuperTableMeta {
+
+ private String database;
+ private String name;
+ private List fields;
+ private List tags;
+}
\ No newline at end of file
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TableMeta.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TableMeta.java
new file mode 100644
index 0000000000000000000000000000000000000000..3ab0a75c0b8ddda46f016c93e0a4893ff1ef21fa
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TableMeta.java
@@ -0,0 +1,13 @@
+package com.taosdata.taosdemo.domain;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class TableMeta {
+
+ private String database;
+ private String name;
+ private List fields;
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TableValue.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TableValue.java
new file mode 100644
index 0000000000000000000000000000000000000000..d5502aa46f3508d2f6dcc3668e741adde5b0a4f0
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TableValue.java
@@ -0,0 +1,15 @@
+package com.taosdata.taosdemo.domain;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class TableValue {
+
+ private String database;
+ private String name;
+ private List columns;
+ private List values;
+
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TagMeta.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TagMeta.java
new file mode 100644
index 0000000000000000000000000000000000000000..a385bb4e125e46fe37c1f9542817a4d81301d72f
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TagMeta.java
@@ -0,0 +1,18 @@
+package com.taosdata.taosdemo.domain;
+
+import lombok.Data;
+
+@Data
+public class TagMeta {
+ private String name;
+ private String type;
+
+ public TagMeta() {
+
+ }
+
+ public TagMeta(String name, String type) {
+ this.name = name;
+ this.type = type;
+ }
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TagValue.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TagValue.java
new file mode 100644
index 0000000000000000000000000000000000000000..98ea8c0dc97ebfd330c57f8852eaf2fa379aef50
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/domain/TagValue.java
@@ -0,0 +1,17 @@
+package com.taosdata.taosdemo.domain;
+
+import lombok.Data;
+
+@Data
+public class TagValue {
+ private String name;
+ private T value;
+
+ public TagValue() {
+ }
+
+ public TagValue(String name, T value) {
+ this.name = name;
+ this.value = value;
+ }
+}
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
new file mode 100644
index 0000000000000000000000000000000000000000..062346c274b1dfa7be50b1a0a0f804ba36b31a8a
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/DatabaseMapper.java
@@ -0,0 +1,27 @@
+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("dbname") String dbname);
+
+ // drop database if exists XXX
+ int dropDatabase(@Param("dbname") String dbname);
+
+ // create database if not exists XXX keep XX days XX replica XX
+ int createDatabaseWithParameters(Map map);
+
+ // use XXX
+ int useDatabase(@Param("dbname") 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
new file mode 100644
index 0000000000000000000000000000000000000000..8f421e935b4138ddd57d7d51abe14c26fe6c2990
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/DatabaseMapper.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+ create database if not exists ${dbname}
+
+
+
+ DROP database if exists ${dbname}
+
+
+
+ CREATE database if not exists ${dbname}
+
+ KEEP ${keep}
+
+
+ DAYS ${days}
+
+
+ REPLICA ${replica}
+
+
+ cache ${cache}
+
+
+ blocks ${blocks}
+
+
+ minrows ${minrows}
+
+
+ maxrows ${maxrows}
+
+
+
+
+ use ${dbname}
+
+
+
+
+
+
+
\ No newline at end of file
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/mapper/SubTableMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..d23473ba313899eee04f07f5c06177a2d55f6295
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SubTableMapper.java
@@ -0,0 +1,30 @@
+package com.taosdata.taosdemo.mapper;
+
+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;
+
+@Repository
+public interface SubTableMapper {
+
+ // 创建:子表
+ int createUsingSuperTable(SubTableMeta subTableMeta);
+
+ // 插入:一张子表多个values
+ int insertOneTableMultiValues(SubTableValue subTableValue);
+
+ // 插入:一张子表多个values, 自动建表
+ int insertOneTableMultiValuesUsingSuperTable(SubTableValue subTableValue);
+
+ // 插入:多张表多个values
+ int insertMultiTableMultiValues(@Param("tables") List tables);
+
+ // 插入:多张表多个values,自动建表
+ int insertMultiTableMultiValuesUsingSuperTable(@Param("tables") List tables);
+
+ //
+
+}
\ 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
new file mode 100644
index 0000000000000000000000000000000000000000..fd275bf216de4d832ec5ce3e7c2961444566c13a
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SubTableMapper.xml
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+ 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.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SuperTableMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..c8610fac901efa907971d700bd9956cac264236f
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SuperTableMapper.java
@@ -0,0 +1,33 @@
+package com.taosdata.taosdemo.mapper;
+
+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);
+
+ // 删除超级表 drop table if exists xxx;
+ int dropSuperTable(@Param("database") String database, @Param("name") String name);
+
+ //
+
+ //
+
+ //
+
+ //
+
+ //
+
+ //
+
+ //
+
+}
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
new file mode 100644
index 0000000000000000000000000000000000000000..8b83d57a4bcbf7a2a6b3f69911b3accc61064480
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/SuperTableMapper.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+ ${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.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/TableMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..f00f6c96941d47258d91a34ffeb1de99c4c8435e
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/TableMapper.java
@@ -0,0 +1,28 @@
+package com.taosdata.taosdemo.mapper;
+
+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;
+
+@Repository
+public interface TableMapper {
+
+ // 创建:普通表
+ int create(TableMeta tableMeta);
+
+ // 插入:一张表多个value
+ int insertOneTableMultiValues(TableValue values);
+
+ // 插入: 一张表多个value,指定的列
+ int insertOneTableMultiValuesWithColumns(TableValue values);
+
+ // 插入:多个表多个value
+ int insertMultiTableMultiValues(@Param("tables") List tables);
+
+ // 插入:多个表多个value, 指定的列
+ int insertMultiTableMultiValuesWithColumns(@Param("tables") List tables);
+
+}
\ 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
new file mode 100644
index 0000000000000000000000000000000000000000..e2e7cbb30def21f88ec7615b7a6dd4a769cb643a
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/mapper/TableMapper.xml
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+ 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/AbstractService.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/AbstractService.java
new file mode 100644
index 0000000000000000000000000000000000000000..4afbe9dae82516e050eb7d729d6ecb8eb1e59d6b
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/AbstractService.java
@@ -0,0 +1,35 @@
+package com.taosdata.taosdemo.service;
+
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+public class AbstractService {
+
+ protected int getAffectRows(List> futureList) {
+ int count = 0;
+ for (Future future : futureList) {
+ try {
+ count += future.get();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ }
+ return count;
+ }
+
+ protected int getAffectRows(Future future) {
+ int count = 0;
+ try {
+ count += future.get();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ return count;
+ }
+
+}
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
new file mode 100644
index 0000000000000000000000000000000000000000..e9aa2727a06ade0ff3d7661f84977c64f64ea9af
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/DatabaseService.java
@@ -0,0 +1,38 @@
+package com.taosdata.taosdemo.service;
+
+import com.taosdata.taosdemo.mapper.DatabaseMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Map;
+
+@Service
+public class DatabaseService {
+
+ @Autowired
+ private DatabaseMapper databaseMapper;
+
+ // 建库,指定 name
+ public int createDatabase(String database) {
+ return databaseMapper.createDatabase(database);
+ }
+
+ // 建库,指定参数 keep,days,replica等
+ public int 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);
+ }
+
+ // drop database
+ public int dropDatabase(String dbname) {
+ return databaseMapper.dropDatabase(dbname);
+ }
+
+ // use database
+ public int useDatabase(String dbname) {
+ return 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
new file mode 100644
index 0000000000000000000000000000000000000000..07c315b65a9e07222fe85066c3f1f3b1edb107fe
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SubTableService.java
@@ -0,0 +1,118 @@
+package com.taosdata.taosdemo.service;
+
+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 java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+@Service
+public class SubTableService extends AbstractService {
+
+ @Autowired
+ private SubTableMapper mapper;
+
+ /**
+ * 1. 选择database,找到所有supertable
+ * 2. 选择supertable,可以拿到表结构,包括field和tag
+ * 3. 指定子表的前缀和个数
+ * 4. 指定创建子表的线程数
+ */
+ //TODO:指定database、supertable、子表前缀、子表个数、线程数
+
+ // 多线程创建表,指定线程个数
+ 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);
+ }
+ executor.shutdown();
+ return getAffectRows(futureList);
+ }
+
+
+ // 创建一张子表,可以指定database,supertable,tablename,tag值
+ public int createSubTable(SubTableMeta subTableMeta) {
+ return mapper.createUsingSuperTable(subTableMeta);
+ }
+
+ // 单线程创建多张子表,每张子表分别可以指定自己的database,supertable,tablename,tag值
+ public int createSubTable(List subTables) {
+ return createSubTable(subTables, 1);
+ }
+
+ /*************************************************************************************************************************/
+ // 插入:多线程,多表
+ public int insert(List subTableValues, int threadSize) {
+ 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();
+ return getAffectRows(future);
+ }
+
+ // 插入:单表,insert into xxx values(),()...
+ public int insert(SubTableValue subTableValue) {
+ return mapper.insertOneTableMultiValues(subTableValue);
+ }
+
+ // 插入: 多表,insert into xxx values(),()... xxx values(),()...
+ public int insert(List subTableValues) {
+ return mapper.insertMultiTableMultiValuesUsingSuperTable(subTableValues);
+ }
+
+ // 插入:单表,自动建表, insert into xxx using xxx tags(...) values(),()...
+ public int insertAutoCreateTable(SubTableValue subTableValue) {
+ return mapper.insertOneTableMultiValuesUsingSuperTable(subTableValue);
+ }
+
+ // 插入:多表,自动建表, insert into xxx using XXX tags(...) values(),()... xxx using XXX tags(...) values(),()...
+ public int insertAutoCreateTable(List subTableValues) {
+ return mapper.insertMultiTableMultiValuesUsingSuperTable(subTableValues);
+ }
+
+
+// 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