diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml
index 25a36e3a4822bfbea0c7f07ff3a4a09032d44542..97bcdbb38c08439b88002fb671d79069320e3739 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
@@ -74,6 +80,7 @@
+
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..bbd7de3a3be8ed8bc3bbc6cf5dcca9371a31ce13 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
@@ -6,6 +6,7 @@ import java.sql.*;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicBoolean;
public class RestfulConnection implements Connection {
@@ -15,12 +16,18 @@ public class RestfulConnection implements Connection {
private final String database;
private final String url;
+ /**********************************************/
+ private volatile AtomicBoolean isClosed = new AtomicBoolean(false);
+ private DatabaseMetaData databaseMetaData;
+
public RestfulConnection(String host, String port, Properties props, String database, String url) {
this.host = host;
this.port = Integer.parseInt(port);
this.props = props;
this.database = database;
this.url = url;
+ //TODO
+ this.databaseMetaData = new RestfulDatabaseMetaData();
}
@Override
@@ -32,58 +39,58 @@ public class RestfulConnection implements Connection {
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
+ //TODO:
return null;
}
@Override
public CallableStatement prepareCall(String sql) throws SQLException {
- return null;
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public String nativeSQL(String sql) throws SQLException {
- return null;
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
-
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public boolean getAutoCommit() throws SQLException {
- return false;
+ return true;
}
@Override
public void commit() throws SQLException {
-
}
@Override
public void rollback() throws SQLException {
-
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
@Override
public void close() throws SQLException {
-
+ //TODO: check if resource need release
+ this.isClosed.set(true);
}
@Override
public boolean isClosed() throws SQLException {
- return false;
+ return this.isClosed.get();
}
@Override
public DatabaseMetaData getMetaData() throws SQLException {
- //TODO: RestfulDatabaseMetaData is not implemented
- return new RestfulDatabaseMetaData();
+ return this.databaseMetaData;
}
@Override
public void setReadOnly(boolean readOnly) throws SQLException {
-
+ throw new SQLFeatureNotSupportedException("transactions are not supported");
}
@Override
diff --git a/tests/examples/JDBC/taosdemo/pom.xml b/tests/examples/JDBC/taosdemo/pom.xml
index f63309962e67ab3ea80a341cfb0ee2df61d934c4..9b19ad9fb40873d5b0755cab043acd216647285d 100644
--- a/tests/examples/JDBC/taosdemo/pom.xml
+++ b/tests/examples/JDBC/taosdemo/pom.xml
@@ -126,17 +126,37 @@
org.apache.maven.plugins
- maven-assembly-plugin
- 3.0.0
+ maven-compiler-plugin
+
+
+ 8
+
org.apache.maven.plugins
- maven-compiler-plugin
+ maven-assembly-plugin
+ 3.1.0
-
- 8
+
+
+
+ com.taosdata.taosdemo.TaosDemoApplication
+
+
+
+ jar-with-dependencies
+
+
+
+ make-assembly
+ package
+
+ single
+
+
+
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 f6ae7b7ce8836ff2cb1ef885c3b35ac687b17ed6..200b17ec0651d5a6551815cbdb87165622c58157 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
@@ -43,7 +43,6 @@ public class TaosDemoApplication {
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();
@@ -68,6 +67,7 @@ public class TaosDemoApplication {
// 建表
start = System.currentTimeMillis();
if (config.doCreateTable) {
+ superTableService.drop(superTableMeta.getDatabase(), superTableMeta.getName());
superTableService.create(superTableMeta);
if (!config.autoCreateTable) {
// 批量建子表
@@ -101,7 +101,7 @@ public class TaosDemoApplication {
private static long getProperStartTime(long startTime, int keep) {
Instant now = Instant.now();
- long earliest = now.minus(Duration.ofDays(keep-1)).toEpochMilli();
+ long earliest = now.minus(Duration.ofDays(keep - 1)).toEpochMilli();
if (startTime == 0 || startTime < earliest) {
startTime = earliest;
}
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
index be19f1a2116ba5460bdae479ed147c0aacb6c32e..1fb1c507b63b4085a9e2c4e96266148992941e5d 100644
--- 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
@@ -13,6 +13,10 @@ public final class JdbcTaosdemoConfig {
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
@@ -54,6 +58,10 @@ public final class JdbcTaosdemoConfig {
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'");
@@ -121,6 +129,15 @@ public final class JdbcTaosdemoConfig {
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]);
@@ -198,8 +215,4 @@ public final class JdbcTaosdemoConfig {
}
}
- public static void main(String[] args) {
- JdbcTaosdemoConfig config = new JdbcTaosdemoConfig(args);
- }
-
}
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
index 4720a7a70d52b3d3beae386dea62d431d4976fb7..e3a6691430f8b5232660ed6edeab01318db30ef1 100644
--- 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
@@ -29,27 +29,53 @@ public class SubTableMapperImpl implements SubTableMapper {
public int insertOneTableMultiValues(SubTableValue subTableValue) {
String sql = SqlSpeller.insertOneTableMultiValues(subTableValue);
logger.info("SQL >>> " + sql);
- return jdbcTemplate.update(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);
- return jdbcTemplate.update(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);
- return jdbcTemplate.update(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);
- return jdbcTemplate.update(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/resources/application.properties b/tests/examples/JDBC/taosdemo/src/main/resources/application.properties
index 4ff3dad78c9d7f6b1b216ccf6447f82f04295024..c85824d9979d2be77b0b1e14ed9eefa83c5919b7 100644
--- a/tests/examples/JDBC/taosdemo/src/main/resources/application.properties
+++ b/tests/examples/JDBC/taosdemo/src/main/resources/application.properties
@@ -14,7 +14,7 @@ spring.datasource.password=taosdata
#spring.datasource.hikari.minimum-idle=1
#spring.datasource.hikari.max-lifetime=0
#logging.level.com.taosdata.taosdemo.dao=error
-jdbc.driver=com.taosdata.jdbc.rs.RestfulDriver
-hikari.maximum-pool-size=1
-hikari.minimum-idle=1
+jdbc.driver=com.taosdata.jdbc.TSDBDriver
+hikari.maximum-pool-size=500
+hikari.minimum-idle=100
hikari.max-lifetime=0
\ No newline at end of file