Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
8877907e
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
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看板
提交
8877907e
编写于
12月 21, 2020
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
efa1709f
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
110 addition
and
23 deletion
+110
-23
tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/demo/ConnectionPoolDemo.java
...s/src/main/java/com/taosdata/demo/ConnectionPoolDemo.java
+20
-5
tests/examples/JDBC/taosdemo/pom.xml
tests/examples/JDBC/taosdemo/pom.xml
+7
-0
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
.../main/java/com/taosdata/taosdemo/TaosDemoApplication.java
+3
-3
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/DataSourceFactory.java
...a/com/taosdata/taosdemo/components/DataSourceFactory.java
+26
-5
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
.../com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
+3
-1
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JsonConfig.java
...ain/java/com/taosdata/taosdemo/components/JsonConfig.java
+39
-0
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/DatabaseMapperImpl.java
...in/java/com/taosdata/taosdemo/dao/DatabaseMapperImpl.java
+1
-1
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SubTableMapperImpl.java
...in/java/com/taosdata/taosdemo/dao/SubTableMapperImpl.java
+1
-1
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SuperTableMapperImpl.java
.../java/com/taosdata/taosdemo/dao/SuperTableMapperImpl.java
+1
-1
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/TableMapperImpl.java
.../main/java/com/taosdata/taosdemo/dao/TableMapperImpl.java
+1
-1
tests/examples/JDBC/taosdemo/src/main/resources/application.properties
...s/JDBC/taosdemo/src/main/resources/application.properties
+8
-5
未找到文件。
tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/demo/ConnectionPoolDemo.java
浏览文件 @
8877907e
...
...
@@ -82,12 +82,27 @@ public class ConnectionPoolDemo {
init
(
dataSource
);
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
threadCount
);
while
(
true
)
{
executor
.
execute
(
new
InsertTask
(
dataSource
,
dbName
,
tableSize
,
batchSize
));
if
(
sleep
>
0
)
TimeUnit
.
MILLISECONDS
.
sleep
(
sleep
);
try
{
Connection
connection
=
dataSource
.
getConnection
();
Statement
statement
=
connection
.
createStatement
();
String
sql
=
"insert into "
+
dbName
+
".t_1 values('2020-01-01 00:00:00.000',12.12,111)"
;
int
affectRows
=
statement
.
executeUpdate
(
sql
);
System
.
out
.
println
(
"affectRows >>> "
+
affectRows
);
affectRows
=
statement
.
executeUpdate
(
sql
);
System
.
out
.
println
(
"affectRows >>> "
+
affectRows
);
statement
.
close
();
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
// ExecutorService executor = Executors.newFixedThreadPool(threadCount);
// while (true) {
// executor.execute(new InsertTask(dataSource, dbName, tableSize, batchSize));
// if (sleep > 0)
// TimeUnit.MILLISECONDS.sleep(sleep);
// }
}
private
static
void
init
(
DataSource
dataSource
)
{
...
...
tests/examples/JDBC/taosdemo/pom.xml
浏览文件 @
8877907e
...
...
@@ -57,6 +57,13 @@
<version>
${spring.version}
</version>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.75
</version>
</dependency>
<!-- HikariCP -->
<dependency>
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
浏览文件 @
8877907e
...
...
@@ -8,10 +8,11 @@ import com.taosdata.taosdemo.service.DatabaseService;
import
com.taosdata.taosdemo.service.InsertTask
;
import
com.taosdata.taosdemo.service.SuperTableService
;
import
com.taosdata.taosdemo.service.data.SuperTableMetaGenerator
;
import
com.taosdata.taosdemo.
util
s.JdbcTaosdemoConfig
;
import
com.taosdata.taosdemo.
component
s.JdbcTaosdemoConfig
;
import
org.apache.log4j.Logger
;
import
javax.sql.DataSource
;
import
java.io.IOException
;
import
java.time.Duration
;
import
java.time.Instant
;
import
java.util.*
;
...
...
@@ -23,8 +24,7 @@ import java.util.stream.IntStream;
public
class
TaosDemoApplication
{
private
static
Logger
logger
=
Logger
.
getLogger
(
TaosDemoApplication
.
class
);
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
// 读配置参数
JdbcTaosdemoConfig
config
=
new
JdbcTaosdemoConfig
(
args
);
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/DataSourceFactory.java
浏览文件 @
8877907e
...
...
@@ -5,24 +5,45 @@ import com.zaxxer.hikari.HikariDataSource;
import
org.springframework.stereotype.Component
;
import
javax.sql.DataSource
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Properties
;
@Component
public
class
DataSourceFactory
{
private
static
DataSource
instance
;
public
static
DataSource
getInstance
(
String
host
,
int
port
,
String
user
,
String
password
)
{
public
static
DataSource
getInstance
(
String
host
,
int
port
,
String
user
,
String
password
)
throws
IOException
{
if
(
instance
==
null
)
{
synchronized
(
DataSourceFactory
.
class
)
{
if
(
instance
==
null
)
{
InputStream
is
=
DataSourceFactory
.
class
.
getClassLoader
().
getResourceAsStream
(
"application.properties"
);
Properties
properties
=
new
Properties
();
properties
.
load
(
is
);
HikariConfig
config
=
new
HikariConfig
();
config
.
setDriverClassName
(
"com.taosdata.jdbc.TSDBDriver"
);
config
.
setJdbcUrl
(
"jdbc:TAOS://"
+
host
+
":"
+
port
+
"/?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8"
);
if
(
properties
.
containsKey
(
"jdbc.driver"
))
config
.
setDriverClassName
(
properties
.
getProperty
(
"jdbc.driver"
));
else
config
.
setDriverClassName
(
"com.taosdata.jdbc.TSDBDriver"
);
if
(
"com.taosdata.jdbc.rs.RestfulDriver"
.
equalsIgnoreCase
(
properties
.
getProperty
(
"jdbc.driver"
)))
config
.
setJdbcUrl
(
"jdbc:TAOS-RS://"
+
host
+
":"
+
port
+
"/?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8"
);
else
config
.
setJdbcUrl
(
"jdbc:TAOS://"
+
host
+
":"
+
port
+
"/?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8"
);
config
.
setUsername
(
user
);
config
.
setPassword
(
password
);
// maximum-pool-size
if
(
properties
.
containsKey
(
"hikari.maximum-pool-size"
))
config
.
setMaximumPoolSize
(
Integer
.
parseInt
(
properties
.
getProperty
(
"hikari.maximum-pool-size"
)));
else
config
.
setMaximumPoolSize
(
500
);
// minimum-idle
if
(
properties
.
containsKey
(
"hikari.minimum-idle"
))
config
.
setMinimumIdle
(
Integer
.
parseInt
(
properties
.
getProperty
(
"hikari.minimum-idle"
)));
else
config
.
setMinimumIdle
(
100
);
config
.
setMaxLifetime
(
0
);
config
.
setMaximumPoolSize
(
500
);
config
.
setMinimumIdle
(
100
);
instance
=
new
HikariDataSource
(
config
);
}
}
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/
util
s/JdbcTaosdemoConfig.java
→
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/
component
s/JdbcTaosdemoConfig.java
浏览文件 @
8877907e
package
com.taosdata.taosdemo.utils
;
package
com.taosdata.taosdemo.components
;
import
com.taosdata.taosdemo.utils.TimeStampUtil
;
public
final
class
JdbcTaosdemoConfig
{
// instance
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JsonConfig.java
0 → 100644
浏览文件 @
8877907e
package
com.taosdata.taosdemo.components
;
import
com.alibaba.fastjson.JSONObject
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
public
class
JsonConfig
{
public
static
void
main
(
String
[]
args
)
{
JsonConfig
config
=
new
JsonConfig
();
String
str
=
config
.
read
(
"insert.json"
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
str
);
System
.
out
.
println
(
jsonObject
);
}
private
String
read
(
String
fileName
)
{
try
{
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
JsonConfig
.
class
.
getClassLoader
().
getResourceAsStream
(
fileName
))
);
StringBuilder
sb
=
new
StringBuilder
();
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
sb
.
append
(
line
);
}
return
sb
.
toString
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
fileName
;
}
}
\ No newline at end of file
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/
impl/
DatabaseMapperImpl.java
→
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/DatabaseMapperImpl.java
浏览文件 @
8877907e
package
com.taosdata.taosdemo.dao
.impl
;
package
com.taosdata.taosdemo.dao
;
import
com.taosdata.taosdemo.dao.DatabaseMapper
;
import
com.taosdata.taosdemo.utils.SqlSpeller
;
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/
impl/
SubTableMapperImpl.java
→
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SubTableMapperImpl.java
浏览文件 @
8877907e
package
com.taosdata.taosdemo.dao
.impl
;
package
com.taosdata.taosdemo.dao
;
import
com.taosdata.taosdemo.dao.SubTableMapper
;
import
com.taosdata.taosdemo.domain.SubTableMeta
;
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/
impl/
SuperTableMapperImpl.java
→
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SuperTableMapperImpl.java
浏览文件 @
8877907e
package
com.taosdata.taosdemo.dao
.impl
;
package
com.taosdata.taosdemo.dao
;
import
com.taosdata.taosdemo.dao.SuperTableMapper
;
import
com.taosdata.taosdemo.domain.SuperTableMeta
;
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/
impl/
TableMapperImpl.java
→
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/TableMapperImpl.java
浏览文件 @
8877907e
package
com.taosdata.taosdemo.dao
.impl
;
package
com.taosdata.taosdemo.dao
;
import
com.taosdata.taosdemo.dao.TableMapper
;
import
com.taosdata.taosdemo.domain.TableMeta
;
...
...
tests/examples/JDBC/taosdemo/src/main/resources/application.properties
浏览文件 @
8877907e
...
...
@@ -10,8 +10,11 @@ spring.datasource.password=taosdata
#spring.datasource.driver-class-name=com.taosdata.jdbc.rs.RestfulDriver
#spring.datasource.username=root
#spring.datasource.password=taosdata
spring.datasource.hikari.maximum-pool-size
=
1
spring.datasource.hikari.minimum-idle
=
1
spring.datasource.hikari.max-lifetime
=
0
logging.level.com.taosdata.taosdemo.dao
=
error
server.port
=
8888
\ No newline at end of file
#spring.datasource.hikari.maximum-pool-size=1
#spring.datasource.hikari.minimum-idle=1
#spring.datasource.hikari.max-lifetime=0
#logging.level.com.taosdata.taosdemo.dao=error
jdbc.driver
=
com.taosdata.jdbc.TSDBDriver
hikari.maximum-pool-size
=
1
hikari.minimum-idle
=
1
hikari.max-lifetime
=
0
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录