From b5c1f0029f47928a10a149d1d83db958da0ce7e6 Mon Sep 17 00:00:00 2001 From: zyyang Date: Wed, 23 Dec 2020 10:39:01 +0800 Subject: [PATCH] change --- src/connector/jdbc/pom.xml | 7 ++++ .../taosdata/jdbc/rs/RestfulConnection.java | 29 ++++++++++------ tests/examples/JDBC/taosdemo/pom.xml | 30 +++++++++++++--- .../taosdemo/TaosDemoApplication.java | 4 +-- .../components/JdbcTaosdemoConfig.java | 21 +++++++++--- .../taosdemo/dao/SubTableMapperImpl.java | 34 ++++++++++++++++--- .../src/main/resources/application.properties | 6 ++-- 7 files changed, 102 insertions(+), 29 deletions(-) diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 25a36e3a48..97bcdbb38c 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 6b0937a9b7..bbd7de3a3b 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 f63309962e..9b19ad9fb4 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 + 8 + org.apache.maven.plugins - maven-compiler-plugin + maven-assembly-plugin + 3.1.0 - 8 - 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 f6ae7b7ce8..200b17ec06 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 be19f1a211..1fb1c507b6 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 4720a7a70d..e3a6691430 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 4ff3dad78c..c85824d997 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 -- GitLab