change
This commit is contained in:
parent
1e578c399c
commit
b5c1f0029f
|
@ -56,6 +56,12 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>5.1.47</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- for restful -->
|
<!-- for restful -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
@ -74,6 +80,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.sql.*;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class RestfulConnection implements Connection {
|
public class RestfulConnection implements Connection {
|
||||||
|
|
||||||
|
@ -15,12 +16,18 @@ public class RestfulConnection implements Connection {
|
||||||
private final String database;
|
private final String database;
|
||||||
private final String url;
|
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) {
|
public RestfulConnection(String host, String port, Properties props, String database, String url) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = Integer.parseInt(port);
|
this.port = Integer.parseInt(port);
|
||||||
this.props = props;
|
this.props = props;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
//TODO
|
||||||
|
this.databaseMetaData = new RestfulDatabaseMetaData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,58 +39,58 @@ public class RestfulConnection implements Connection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||||
|
//TODO:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallableStatement prepareCall(String sql) throws SQLException {
|
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||||
return null;
|
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String nativeSQL(String sql) throws SQLException {
|
public String nativeSQL(String sql) throws SQLException {
|
||||||
return null;
|
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||||
|
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getAutoCommit() throws SQLException {
|
public boolean getAutoCommit() throws SQLException {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void commit() throws SQLException {
|
public void commit() throws SQLException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void rollback() throws SQLException {
|
public void rollback() throws SQLException {
|
||||||
|
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws SQLException {
|
public void close() throws SQLException {
|
||||||
|
//TODO: check if resource need release
|
||||||
|
this.isClosed.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClosed() throws SQLException {
|
public boolean isClosed() throws SQLException {
|
||||||
return false;
|
return this.isClosed.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseMetaData getMetaData() throws SQLException {
|
public DatabaseMetaData getMetaData() throws SQLException {
|
||||||
//TODO: RestfulDatabaseMetaData is not implemented
|
return this.databaseMetaData;
|
||||||
return new RestfulDatabaseMetaData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||||
|
throw new SQLFeatureNotSupportedException("transactions are not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -124,12 +124,6 @@
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<version>3.0.0</version>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
@ -138,6 +132,32 @@
|
||||||
<target>8</target>
|
<target>8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<!-- 指定JdbcChecker为mainClass -->
|
||||||
|
<mainClass>com.taosdata.taosdemo.TaosDemoApplication</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
</build>
|
</build>
|
||||||
|
|
|
@ -43,7 +43,6 @@ public class TaosDemoApplication {
|
||||||
databaseParam.put("days", Integer.toString(config.days));
|
databaseParam.put("days", Integer.toString(config.days));
|
||||||
databaseParam.put("replica", Integer.toString(config.replica));
|
databaseParam.put("replica", Integer.toString(config.replica));
|
||||||
//TODO: other database parameters
|
//TODO: other database parameters
|
||||||
databaseService.dropDatabase(config.database);
|
|
||||||
databaseService.createDatabase(databaseParam);
|
databaseService.createDatabase(databaseParam);
|
||||||
databaseService.useDatabase(config.database);
|
databaseService.useDatabase(config.database);
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
|
@ -68,6 +67,7 @@ public class TaosDemoApplication {
|
||||||
// 建表
|
// 建表
|
||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
if (config.doCreateTable) {
|
if (config.doCreateTable) {
|
||||||
|
superTableService.drop(superTableMeta.getDatabase(), superTableMeta.getName());
|
||||||
superTableService.create(superTableMeta);
|
superTableService.create(superTableMeta);
|
||||||
if (!config.autoCreateTable) {
|
if (!config.autoCreateTable) {
|
||||||
// 批量建子表
|
// 批量建子表
|
||||||
|
@ -101,7 +101,7 @@ public class TaosDemoApplication {
|
||||||
|
|
||||||
private static long getProperStartTime(long startTime, int keep) {
|
private static long getProperStartTime(long startTime, int keep) {
|
||||||
Instant now = Instant.now();
|
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) {
|
if (startTime == 0 || startTime < earliest) {
|
||||||
startTime = earliest;
|
startTime = earliest;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,10 @@ public final class JdbcTaosdemoConfig {
|
||||||
public int keep = 3650; //keep
|
public int keep = 3650; //keep
|
||||||
public int days = 30; //days
|
public int days = 30; //days
|
||||||
public int replica = 1; //replica
|
public int replica = 1; //replica
|
||||||
|
public int blocks = 16;
|
||||||
|
public int cache = 8;
|
||||||
|
public String precision = "ms";
|
||||||
|
|
||||||
//super table
|
//super table
|
||||||
public boolean doCreateTable = true;
|
public boolean doCreateTable = true;
|
||||||
public String superTable = "weather"; //super table name
|
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("-keep database keep parameter. Default is 3650");
|
||||||
System.out.println("-days database days parameter. Default is 30");
|
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("-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
|
// super table
|
||||||
System.out.println("-doCreateTable do create super table and sub table, true or false, Default true");
|
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("-superTable super table name. Default 'weather'");
|
||||||
|
@ -121,6 +129,15 @@ public final class JdbcTaosdemoConfig {
|
||||||
if ("-replica".equals(args[i]) && i < args.length - 1) {
|
if ("-replica".equals(args[i]) && i < args.length - 1) {
|
||||||
replica = Integer.parseInt(args[++i]);
|
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
|
// super table
|
||||||
if ("-doCreateTable".equals(args[i]) && i < args.length - 1) {
|
if ("-doCreateTable".equals(args[i]) && i < args.length - 1) {
|
||||||
doCreateTable = Boolean.parseBoolean(args[++i]);
|
doCreateTable = Boolean.parseBoolean(args[++i]);
|
||||||
|
@ -198,8 +215,4 @@ public final class JdbcTaosdemoConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
JdbcTaosdemoConfig config = new JdbcTaosdemoConfig(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,27 +29,53 @@ public class SubTableMapperImpl implements SubTableMapper {
|
||||||
public int insertOneTableMultiValues(SubTableValue subTableValue) {
|
public int insertOneTableMultiValues(SubTableValue subTableValue) {
|
||||||
String sql = SqlSpeller.insertOneTableMultiValues(subTableValue);
|
String sql = SqlSpeller.insertOneTableMultiValues(subTableValue);
|
||||||
logger.info("SQL >>> " + sql);
|
logger.info("SQL >>> " + sql);
|
||||||
return jdbcTemplate.update(sql);
|
|
||||||
|
int affectRows = 0;
|
||||||
|
try {
|
||||||
|
affectRows = jdbcTemplate.update(sql);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return affectRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insertOneTableMultiValuesUsingSuperTable(SubTableValue subTableValue) {
|
public int insertOneTableMultiValuesUsingSuperTable(SubTableValue subTableValue) {
|
||||||
String sql = SqlSpeller.insertOneTableMultiValuesUsingSuperTable(subTableValue);
|
String sql = SqlSpeller.insertOneTableMultiValuesUsingSuperTable(subTableValue);
|
||||||
logger.info("SQL >>> " + sql);
|
logger.info("SQL >>> " + sql);
|
||||||
return jdbcTemplate.update(sql);
|
|
||||||
|
int affectRows = 0;
|
||||||
|
try {
|
||||||
|
affectRows = jdbcTemplate.update(sql);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return affectRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insertMultiTableMultiValues(List<SubTableValue> tables) {
|
public int insertMultiTableMultiValues(List<SubTableValue> tables) {
|
||||||
String sql = SqlSpeller.insertMultiSubTableMultiValues(tables);
|
String sql = SqlSpeller.insertMultiSubTableMultiValues(tables);
|
||||||
logger.info("SQL >>> " + sql);
|
logger.info("SQL >>> " + sql);
|
||||||
return jdbcTemplate.update(sql);
|
int affectRows = 0;
|
||||||
|
try {
|
||||||
|
affectRows = jdbcTemplate.update(sql);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return affectRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insertMultiTableMultiValuesUsingSuperTable(List<SubTableValue> tables) {
|
public int insertMultiTableMultiValuesUsingSuperTable(List<SubTableValue> tables) {
|
||||||
String sql = SqlSpeller.insertMultiTableMultiValuesUsingSuperTable(tables);
|
String sql = SqlSpeller.insertMultiTableMultiValuesUsingSuperTable(tables);
|
||||||
logger.info("SQL >>> " + sql);
|
logger.info("SQL >>> " + sql);
|
||||||
return jdbcTemplate.update(sql);
|
int affectRows = 0;
|
||||||
|
try {
|
||||||
|
affectRows = jdbcTemplate.update(sql);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return affectRows;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ spring.datasource.password=taosdata
|
||||||
#spring.datasource.hikari.minimum-idle=1
|
#spring.datasource.hikari.minimum-idle=1
|
||||||
#spring.datasource.hikari.max-lifetime=0
|
#spring.datasource.hikari.max-lifetime=0
|
||||||
#logging.level.com.taosdata.taosdemo.dao=error
|
#logging.level.com.taosdata.taosdemo.dao=error
|
||||||
jdbc.driver=com.taosdata.jdbc.rs.RestfulDriver
|
jdbc.driver=com.taosdata.jdbc.TSDBDriver
|
||||||
hikari.maximum-pool-size=1
|
hikari.maximum-pool-size=500
|
||||||
hikari.minimum-idle=1
|
hikari.minimum-idle=100
|
||||||
hikari.max-lifetime=0
|
hikari.max-lifetime=0
|
Loading…
Reference in New Issue