Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
拾光师
TDengine
提交
a5a4f702
T
TDengine
项目概览
拾光师
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a5a4f702
编写于
9月 25, 2020
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update jdbcTaosdemo
上级
4149545b
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
85 addition
and
54 deletion
+85
-54
tests/examples/JDBC/JDBCDemo/.gitignore
tests/examples/JDBC/JDBCDemo/.gitignore
+19
-2
tests/examples/JDBC/JDBCDemo/pom.xml
tests/examples/JDBC/JDBCDemo/pom.xml
+1
-1
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCConnectorChecker.java
.../main/java/com/taosdata/example/JDBCConnectorChecker.java
+0
-1
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
.../java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
+24
-24
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java
...sdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java
+19
-8
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/CreateTableTask.java
...m/taosdata/example/jdbcTaosdemo/task/CreateTableTask.java
+3
-3
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableDatetimeTask.java
...ta/example/jdbcTaosdemo/task/InsertTableDatetimeTask.java
+8
-5
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java
...m/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java
+4
-4
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtil.java
...om/taosdata/example/jdbcTaosdemo/utils/TimeStampUtil.java
+1
-1
tests/examples/JDBC/JDBCDemo/src/main/resources/log4j.properties
...xamples/JDBC/JDBCDemo/src/main/resources/log4j.properties
+6
-5
未找到文件。
tests/examples/JDBC/JDBCDemo/.gitignore
浏览文件 @
a5a4f702
out/
logs/
# custom
/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/*
tests/examples/JDBC/JDBCDemo/pom.xml
浏览文件 @
a5a4f702
...
...
@@ -63,7 +63,7 @@
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.
6
</version>
<version>
2.0.
4
</version>
</dependency>
<dependency>
<groupId>
log4j
</groupId>
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCConnectorChecker.java
浏览文件 @
a5a4f702
...
...
@@ -11,7 +11,6 @@ public class JDBCConnectorChecker {
private
static
String
tbName
=
"weather"
;
private
Connection
connection
;
/**
* get connection
**/
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcTaosdemo.java
→
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/
jdbcTaosdemo/
JdbcTaosdemo.java
浏览文件 @
a5a4f702
package
com.taosdata.example
;
package
com.taosdata.example
.jdbcTaosdemo
;
import
com.taosdata.example.domain.JdbcTaosdemoConfig
;
import
com.taosdata.example.task.CreateTableTask
;
import
com.taosdata.example.task.InsertTableDatetimeTask
;
import
com.taosdata.example.task.InsertTableTask
;
import
com.taosdata.example.utils.TimeStampUtil
;
import
com.taosdata.example.
jdbcTaosdemo.
domain.JdbcTaosdemoConfig
;
import
com.taosdata.example.
jdbcTaosdemo.
task.CreateTableTask
;
import
com.taosdata.example.
jdbcTaosdemo.
task.InsertTableDatetimeTask
;
import
com.taosdata.example.
jdbcTaosdemo.
task.InsertTableTask
;
import
com.taosdata.example.
jdbcTaosdemo.
utils.TimeStampUtil
;
import
com.taosdata.jdbc.TSDBDriver
;
import
org.apache.log4j.Logger
;
...
...
@@ -25,34 +25,20 @@ public class JdbcTaosdemo {
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
)
{
JdbcTaosdemoConfig
config
=
JdbcTaosdemoConfig
.
build
(
args
);
boolean
isHelp
=
Arrays
.
asList
(
args
).
contains
(
"--help"
);
if
(
isHelp
)
{
printHelp
();
JdbcTaosdemoConfig
.
printHelp
();
return
;
}
if
(
config
.
getHost
()
==
null
)
{
printHelp
();
JdbcTaosdemoConfig
.
printHelp
();
return
;
}
boolean
infinite
=
Arrays
.
asList
().
contains
(
"--infinite"
);
JdbcTaosdemo
taosdemo
=
new
JdbcTaosdemo
(
config
);
taosdemo
.
init
();
taosdemo
.
dropDatabase
();
...
...
@@ -60,7 +46,10 @@ public class JdbcTaosdemo {
taosdemo
.
useDatabase
();
taosdemo
.
createSuperTable
();
taosdemo
.
createTableMultiThreads
();
boolean
infinite
=
Arrays
.
asList
(
args
).
contains
(
"--infinite"
);
if
(
infinite
)
{
logger
.
info
(
"!!! Infinite Insert Mode Started. !!!!"
);
taosdemo
.
insertInfinite
();
}
else
{
taosdemo
.
insertMultiThreads
();
...
...
@@ -206,6 +195,17 @@ public class JdbcTaosdemo {
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
)
{
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
);
}
...
...
@@ -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
();
while
(
resultSet
.
next
())
{
StringBuilder
sb
=
new
StringBuilder
();
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/domain/JdbcTaosdemoConfig.java
→
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/
jdbcTaosdemo/
domain/JdbcTaosdemoConfig.java
浏览文件 @
a5a4f702
package
com.taosdata.example.domain
;
package
com.taosdata.example.
jdbcTaosdemo.
domain
;
public
class
JdbcTaosdemoConfig
{
...
...
@@ -12,16 +12,12 @@ public class JdbcTaosdemoConfig {
private
String
password
=
"taosdata"
;
//Destination database. Default is 'test'
private
String
dbName
=
"test"
;
//
//keep
private
int
keep
=
365
*
20
;
//
private
int
days
=
30
;
//Super table Name. Default is 'meters'
private
String
stbName
=
"meters"
;
//Table name prefix. Default is 'd'
private
String
tbPrefix
=
"d"
;
//The number of threads. Default is 10.
...
...
@@ -33,6 +29,20 @@ public class JdbcTaosdemoConfig {
//Delete data. Default is false
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
*
...
...
@@ -40,6 +50,7 @@ public class JdbcTaosdemoConfig {
* @return JdbcTaosdemoConfig
*/
public
static
JdbcTaosdemoConfig
build
(
String
[]
args
)
{
JdbcTaosdemoConfig
config
=
new
JdbcTaosdemoConfig
();
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
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
)
{
config
.
setDeleteTable
(
Boolean
.
parseBoolean
(
args
[++
i
]));
}
}
return
config
;
}
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/CreateTableTask.java
→
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/
jdbcTaosdemo/
task/CreateTableTask.java
浏览文件 @
a5a4f702
package
com.taosdata.example.task
;
package
com.taosdata.example.
jdbcTaosdemo.
task
;
import
com.taosdata.example.JdbcTaosdemo
;
import
com.taosdata.example.domain.JdbcTaosdemoConfig
;
import
com.taosdata.example.
jdbcTaosdemo.
JdbcTaosdemo
;
import
com.taosdata.example.
jdbcTaosdemo.
domain.JdbcTaosdemoConfig
;
import
org.apache.log4j.Logger
;
import
java.sql.Connection
;
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/InsertTableDatetimeTask.java
→
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/
jdbcTaosdemo/
task/InsertTableDatetimeTask.java
浏览文件 @
a5a4f702
package
com.taosdata.example.task
;
package
com.taosdata.example.
jdbcTaosdemo.
task
;
import
com.taosdata.example.JdbcTaosdemo
;
import
com.taosdata.example.domain.JdbcTaosdemoConfig
;
import
com.taosdata.example.
jdbcTaosdemo.
JdbcTaosdemo
;
import
com.taosdata.example.
jdbcTaosdemo.
domain.JdbcTaosdemoConfig
;
import
org.apache.log4j.Logger
;
import
java.sql.Connection
;
...
...
@@ -29,9 +29,12 @@ public class InsertTableDatetimeTask implements Runnable {
public
void
run
()
{
try
{
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
++)
{
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
.
execute
(
sql
);
statement
.
close
();
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/InsertTableTask.java
→
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/
jdbcTaosdemo/
task/InsertTableTask.java
浏览文件 @
a5a4f702
package
com.taosdata.example.task
;
package
com.taosdata.example.
jdbcTaosdemo.
task
;
import
com.taosdata.example.JdbcTaosdemo
;
import
com.taosdata.example.domain.JdbcTaosdemoConfig
;
import
com.taosdata.example.
jdbcTaosdemo.
JdbcTaosdemo
;
import
com.taosdata.example.
jdbcTaosdemo.
domain.JdbcTaosdemoConfig
;
import
org.apache.log4j.Logger
;
import
java.sql.Connection
;
...
...
@@ -9,7 +9,7 @@ import java.sql.SQLException;
import
java.sql.Statement
;
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
int
startIndex
;
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/utils/TimeStampUtil.java
→
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/
jdbcTaosdemo/
utils/TimeStampUtil.java
浏览文件 @
a5a4f702
package
com.taosdata.example.utils
;
package
com.taosdata.example.
jdbcTaosdemo.
utils
;
import
java.sql.Date
;
import
java.text.ParseException
;
...
...
tests/examples/JDBC/JDBCDemo/src/main/resources/log4j.properties
浏览文件 @
a5a4f702
### 设置###
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.Target
=
System.out
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=org.apache.log4j.ConsoleAppender
#
log4j.appender.stdout.Target=System.out
#
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
### 输出DEBUG 级别以上的日志到=logs/error.log ###
log4j.appender.DebugLog
=
org.apache.log4j.DailyRollingFileAppender
log4j.appender.DebugLog.File
=
logs/debug.log
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录