change
This commit is contained in:
parent
1e578c399c
commit
b5c1f0029f
|
@ -56,6 +56,12 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.47</version>
|
||||
</dependency>
|
||||
|
||||
<!-- for restful -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
|
@ -74,6 +80,7 @@
|
|||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -124,12 +124,6 @@
|
|||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
@ -138,6 +132,32 @@
|
|||
<target>8</target>
|
||||
</configuration>
|
||||
</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>
|
||||
|
||||
</build>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<SubTableValue> 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<SubTableValue> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue