update jdbcTaosdemo
This commit is contained in:
parent
4149545bc0
commit
a5a4f7026f
|
@ -1,2 +1,19 @@
|
||||||
out/
|
# custom
|
||||||
logs/
|
/out/
|
||||||
|
/logs/
|
||||||
|
*.jar
|
||||||
|
|
||||||
|
# Created by .ignore support plugin (hsz.mobi)
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# Build Artifacts
|
||||||
|
.gradle/*
|
||||||
|
build/*
|
||||||
|
target/*
|
||||||
|
bin/*
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
|
||||||
|
# Eclipse Project Files
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings/*
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.6</version>
|
<version>2.0.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
|
|
|
@ -11,7 +11,6 @@ public class JDBCConnectorChecker {
|
||||||
private static String tbName = "weather";
|
private static String tbName = "weather";
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get connection
|
* get connection
|
||||||
**/
|
**/
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.taosdata.example;
|
package com.taosdata.example.jdbcTaosdemo;
|
||||||
|
|
||||||
import com.taosdata.example.domain.JdbcTaosdemoConfig;
|
import com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig;
|
||||||
import com.taosdata.example.task.CreateTableTask;
|
import com.taosdata.example.jdbcTaosdemo.task.CreateTableTask;
|
||||||
import com.taosdata.example.task.InsertTableDatetimeTask;
|
import com.taosdata.example.jdbcTaosdemo.task.InsertTableDatetimeTask;
|
||||||
import com.taosdata.example.task.InsertTableTask;
|
import com.taosdata.example.jdbcTaosdemo.task.InsertTableTask;
|
||||||
import com.taosdata.example.utils.TimeStampUtil;
|
import com.taosdata.example.jdbcTaosdemo.utils.TimeStampUtil;
|
||||||
import com.taosdata.jdbc.TSDBDriver;
|
import com.taosdata.jdbc.TSDBDriver;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
@ -25,34 +25,20 @@ public class JdbcTaosdemo {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void printHelp() {
|
|
||||||
System.out.println("Usage: java -jar JDBCConnectorChecker.jar -h host [OPTION...]");
|
|
||||||
System.out.println("-p port The TCP/IP port number to use for the connection. Default is 6030");
|
|
||||||
System.out.println("-u user The TDengine user name to use when connecting to the server. Default is 'root'");
|
|
||||||
System.out.println("-P password The password to use when connecting to the server.Default is 'taosdata'");
|
|
||||||
System.out.println("-d database Destination database. Default is 'test'");
|
|
||||||
System.out.println("-m tablePrefix Table prefix name. Default is 'd'");
|
|
||||||
System.out.println("-T num_of_threads The number of threads. Default is 10");
|
|
||||||
System.out.println("-t num_of_tables The number of tables. Default is 10000");
|
|
||||||
System.out.println("-n num_of_records_per_table The number of records per table. Default is 100000");
|
|
||||||
System.out.println("-D delete table Delete data methods. Default is false");
|
|
||||||
System.out.println("--help Give this help list");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JdbcTaosdemoConfig config = JdbcTaosdemoConfig.build(args);
|
JdbcTaosdemoConfig config = JdbcTaosdemoConfig.build(args);
|
||||||
|
|
||||||
boolean isHelp = Arrays.asList(args).contains("--help");
|
boolean isHelp = Arrays.asList(args).contains("--help");
|
||||||
if (isHelp) {
|
if (isHelp) {
|
||||||
printHelp();
|
JdbcTaosdemoConfig.printHelp();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (config.getHost() == null) {
|
if (config.getHost() == null) {
|
||||||
printHelp();
|
JdbcTaosdemoConfig.printHelp();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean infinite = Arrays.asList().contains("--infinite");
|
|
||||||
JdbcTaosdemo taosdemo = new JdbcTaosdemo(config);
|
JdbcTaosdemo taosdemo = new JdbcTaosdemo(config);
|
||||||
taosdemo.init();
|
taosdemo.init();
|
||||||
taosdemo.dropDatabase();
|
taosdemo.dropDatabase();
|
||||||
|
@ -60,7 +46,10 @@ public class JdbcTaosdemo {
|
||||||
taosdemo.useDatabase();
|
taosdemo.useDatabase();
|
||||||
taosdemo.createSuperTable();
|
taosdemo.createSuperTable();
|
||||||
taosdemo.createTableMultiThreads();
|
taosdemo.createTableMultiThreads();
|
||||||
|
|
||||||
|
boolean infinite = Arrays.asList(args).contains("--infinite");
|
||||||
if (infinite) {
|
if (infinite) {
|
||||||
|
logger.info("!!! Infinite Insert Mode Started. !!!!");
|
||||||
taosdemo.insertInfinite();
|
taosdemo.insertInfinite();
|
||||||
} else {
|
} else {
|
||||||
taosdemo.insertMultiThreads();
|
taosdemo.insertMultiThreads();
|
||||||
|
@ -206,6 +195,17 @@ public class JdbcTaosdemo {
|
||||||
return sql;
|
return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String batchInsertSql(int tableIndex, long ts, int valueCnt, JdbcTaosdemoConfig config) {
|
||||||
|
float current = 10 + random.nextFloat();
|
||||||
|
int voltage = 200 + random.nextInt(20);
|
||||||
|
float phase = random.nextFloat();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("insert into " + config.getDbName() + "." + config.getTbPrefix() + "" + tableIndex + " " + "values");
|
||||||
|
for (int i = 0; i < valueCnt; i++) {
|
||||||
|
sb.append("(" + (ts + i) + ", " + current + ", " + voltage + ", " + phase + ") ");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static String createTableSql(int tableIndex, JdbcTaosdemoConfig config) {
|
public static String createTableSql(int tableIndex, JdbcTaosdemoConfig config) {
|
||||||
String location = locations[random.nextInt(locations.length)];
|
String location = locations[random.nextInt(locations.length)];
|
||||||
|
@ -252,7 +252,7 @@ public class JdbcTaosdemo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printSql(String sql, boolean succeed, long cost) {
|
private static void printSql(String sql, boolean succeed, long cost) {
|
||||||
logger.info("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql);
|
logger.info("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ public class JdbcTaosdemo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printResult(ResultSet resultSet) throws SQLException {
|
private static void printResult(ResultSet resultSet) throws SQLException {
|
||||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
|
@ -1,4 +1,4 @@
|
||||||
package com.taosdata.example.domain;
|
package com.taosdata.example.jdbcTaosdemo.domain;
|
||||||
|
|
||||||
public class JdbcTaosdemoConfig {
|
public class JdbcTaosdemoConfig {
|
||||||
|
|
||||||
|
@ -12,16 +12,12 @@ public class JdbcTaosdemoConfig {
|
||||||
private String password = "taosdata";
|
private String password = "taosdata";
|
||||||
//Destination database. Default is 'test'
|
//Destination database. Default is 'test'
|
||||||
private String dbName = "test";
|
private String dbName = "test";
|
||||||
|
//keep
|
||||||
//
|
|
||||||
private int keep = 365 * 20;
|
private int keep = 365 * 20;
|
||||||
|
//
|
||||||
private int days = 30;
|
private int days = 30;
|
||||||
|
|
||||||
//Super table Name. Default is 'meters'
|
//Super table Name. Default is 'meters'
|
||||||
private String stbName = "meters";
|
private String stbName = "meters";
|
||||||
|
|
||||||
|
|
||||||
//Table name prefix. Default is 'd'
|
//Table name prefix. Default is 'd'
|
||||||
private String tbPrefix = "d";
|
private String tbPrefix = "d";
|
||||||
//The number of threads. Default is 10.
|
//The number of threads. Default is 10.
|
||||||
|
@ -33,6 +29,20 @@ public class JdbcTaosdemoConfig {
|
||||||
//Delete data. Default is false
|
//Delete data. Default is false
|
||||||
private boolean deleteTable = true;
|
private boolean deleteTable = true;
|
||||||
|
|
||||||
|
public static void printHelp() {
|
||||||
|
System.out.println("Usage: java -jar JDBCConnectorChecker.jar -h host [OPTION...]");
|
||||||
|
System.out.println("-p port The TCP/IP port number to use for the connection. Default is 6030");
|
||||||
|
System.out.println("-u user The TDengine user name to use when connecting to the server. Default is 'root'");
|
||||||
|
System.out.println("-P password The password to use when connecting to the server.Default is 'taosdata'");
|
||||||
|
System.out.println("-d database Destination database. Default is 'test'");
|
||||||
|
System.out.println("-m tablePrefix Table prefix name. Default is 'd'");
|
||||||
|
System.out.println("-T num_of_threads The number of threads. Default is 10");
|
||||||
|
System.out.println("-t num_of_tables The number of tables. Default is 10000");
|
||||||
|
System.out.println("-n num_of_records_per_table The number of records per table. Default is 100000");
|
||||||
|
System.out.println("-D delete table Delete data methods. Default is false");
|
||||||
|
System.out.println("--help Give this help list");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parse args from command line
|
* parse args from command line
|
||||||
*
|
*
|
||||||
|
@ -40,6 +50,7 @@ public class JdbcTaosdemoConfig {
|
||||||
* @return JdbcTaosdemoConfig
|
* @return JdbcTaosdemoConfig
|
||||||
*/
|
*/
|
||||||
public static JdbcTaosdemoConfig build(String[] args) {
|
public static JdbcTaosdemoConfig build(String[] args) {
|
||||||
|
|
||||||
JdbcTaosdemoConfig config = new JdbcTaosdemoConfig();
|
JdbcTaosdemoConfig config = new JdbcTaosdemoConfig();
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
if ("-h".equals(args[i]) && i < args.length - 1) {
|
if ("-h".equals(args[i]) && i < args.length - 1) {
|
||||||
|
@ -72,8 +83,8 @@ public class JdbcTaosdemoConfig {
|
||||||
if ("-D".equals(args[i]) && i < args.length - 1) {
|
if ("-D".equals(args[i]) && i < args.length - 1) {
|
||||||
config.setDeleteTable(Boolean.parseBoolean(args[++i]));
|
config.setDeleteTable(Boolean.parseBoolean(args[++i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.taosdata.example.task;
|
package com.taosdata.example.jdbcTaosdemo.task;
|
||||||
|
|
||||||
import com.taosdata.example.JdbcTaosdemo;
|
import com.taosdata.example.jdbcTaosdemo.JdbcTaosdemo;
|
||||||
import com.taosdata.example.domain.JdbcTaosdemoConfig;
|
import com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
|
@ -1,7 +1,7 @@
|
||||||
package com.taosdata.example.task;
|
package com.taosdata.example.jdbcTaosdemo.task;
|
||||||
|
|
||||||
import com.taosdata.example.JdbcTaosdemo;
|
import com.taosdata.example.jdbcTaosdemo.JdbcTaosdemo;
|
||||||
import com.taosdata.example.domain.JdbcTaosdemoConfig;
|
import com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
@ -29,9 +29,12 @@ public class InsertTableDatetimeTask implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Connection connection = JdbcTaosdemo.getConnection(config);
|
Connection connection = JdbcTaosdemo.getConnection(config);
|
||||||
for (long ts = startDatetime; ts < finishedDatetime; ts++) {
|
int valueCnt = 100;
|
||||||
|
for (long ts = startDatetime; ts < finishedDatetime; ts+= valueCnt) {
|
||||||
for (int i = startTableIndex; i < startTableIndex + tableNumber; i++) {
|
for (int i = startTableIndex; i < startTableIndex + tableNumber; i++) {
|
||||||
String sql = JdbcTaosdemo.insertSql(i + 1, ts, config);
|
// String sql = JdbcTaosdemo.insertSql(i + 1, ts, config);
|
||||||
|
|
||||||
|
String sql = JdbcTaosdemo.batchInsertSql(i + 1, ts, valueCnt, config);
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
statement.execute(sql);
|
statement.execute(sql);
|
||||||
statement.close();
|
statement.close();
|
|
@ -1,7 +1,7 @@
|
||||||
package com.taosdata.example.task;
|
package com.taosdata.example.jdbcTaosdemo.task;
|
||||||
|
|
||||||
import com.taosdata.example.JdbcTaosdemo;
|
import com.taosdata.example.jdbcTaosdemo.JdbcTaosdemo;
|
||||||
import com.taosdata.example.domain.JdbcTaosdemoConfig;
|
import com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
@ -9,7 +9,7 @@ import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
|
||||||
public class InsertTableTask implements Runnable {
|
public class InsertTableTask implements Runnable {
|
||||||
private static Logger logger = Logger.getLogger(InsertTableTask.class);
|
private static final Logger logger = Logger.getLogger(InsertTableTask.class);
|
||||||
|
|
||||||
private final JdbcTaosdemoConfig config;
|
private final JdbcTaosdemoConfig config;
|
||||||
private final int startIndex;
|
private final int startIndex;
|
|
@ -1,4 +1,4 @@
|
||||||
package com.taosdata.example.utils;
|
package com.taosdata.example.jdbcTaosdemo.utils;
|
||||||
|
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
|
@ -1,10 +1,11 @@
|
||||||
### 设置###
|
### 设置###
|
||||||
log4j.rootLogger=debug,stdout,DebugLog,ErrorLog
|
#log4j.rootLogger=debug,stdout,DebugLog,ErrorLog
|
||||||
|
log4j.rootLogger=debug,DebugLog,ErrorLog
|
||||||
### 输出信息到控制抬 ###
|
### 输出信息到控制抬 ###
|
||||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||||
log4j.appender.stdout.Target=System.out
|
#log4j.appender.stdout.Target=System.out
|
||||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.stdout.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
|
#log4j.appender.stdout.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
|
||||||
### 输出DEBUG 级别以上的日志到=logs/error.log ###
|
### 输出DEBUG 级别以上的日志到=logs/error.log ###
|
||||||
log4j.appender.DebugLog=org.apache.log4j.DailyRollingFileAppender
|
log4j.appender.DebugLog=org.apache.log4j.DailyRollingFileAppender
|
||||||
log4j.appender.DebugLog.File=logs/debug.log
|
log4j.appender.DebugLog.File=logs/debug.log
|
||||||
|
|
Loading…
Reference in New Issue