Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
b5c1f002
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看板
提交
b5c1f002
编写于
12月 23, 2020
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
1e578c39
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
102 addition
and
29 deletion
+102
-29
src/connector/jdbc/pom.xml
src/connector/jdbc/pom.xml
+7
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
...src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
+18
-11
tests/examples/JDBC/taosdemo/pom.xml
tests/examples/JDBC/taosdemo/pom.xml
+25
-5
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
.../main/java/com/taosdata/taosdemo/TaosDemoApplication.java
+2
-2
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
.../com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
+17
-4
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SubTableMapperImpl.java
...in/java/com/taosdata/taosdemo/dao/SubTableMapperImpl.java
+30
-4
tests/examples/JDBC/taosdemo/src/main/resources/application.properties
...s/JDBC/taosdemo/src/main/resources/application.properties
+3
-3
未找到文件。
src/connector/jdbc/pom.xml
浏览文件 @
b5c1f002
...
@@ -56,6 +56,12 @@
...
@@ -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 @@
...
@@ -74,6 +80,7 @@
</dependency>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<plugins>
<plugins>
<plugin>
<plugin>
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
浏览文件 @
b5c1f002
...
@@ -6,6 +6,7 @@ import java.sql.*;
...
@@ -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 {
...
@@ -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 {
...
@@ -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
fals
e
;
return
tru
e
;
}
}
@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
...
...
tests/examples/JDBC/taosdemo/pom.xml
浏览文件 @
b5c1f002
...
@@ -126,17 +126,37 @@
...
@@ -126,17 +126,37 @@
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-assembly-plugin
</artifactId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.0.0
</version>
<configuration>
<source>
8
</source>
<target>
8
</target>
</configuration>
</plugin>
</plugin>
<plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<artifactId>
maven-assembly-plugin
</artifactId>
<version>
3.1.0
</version>
<configuration>
<configuration>
<source>
8
</source>
<archive>
<target>
8
</target>
<manifest>
<!-- 指定JdbcChecker为mainClass -->
<mainClass>
com.taosdata.taosdemo.TaosDemoApplication
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
</configuration>
</configuration>
<executions>
<execution>
<id>
make-assembly
</id>
<phase>
package
</phase>
<goals>
<goal>
single
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugin>
</plugins>
</plugins>
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
浏览文件 @
b5c1f002
...
@@ -43,7 +43,6 @@ public class TaosDemoApplication {
...
@@ -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 {
...
@@ -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 {
...
@@ -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
;
}
}
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
浏览文件 @
b5c1f002
...
@@ -13,6 +13,10 @@ public final class JdbcTaosdemoConfig {
...
@@ -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 {
...
@@ -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 {
...
@@ -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 {
...
@@ -198,8 +215,4 @@ public final class JdbcTaosdemoConfig {
}
}
}
}
public
static
void
main
(
String
[]
args
)
{
JdbcTaosdemoConfig
config
=
new
JdbcTaosdemoConfig
(
args
);
}
}
}
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/dao/SubTableMapperImpl.java
浏览文件 @
b5c1f002
...
@@ -29,27 +29,53 @@ public class SubTableMapperImpl implements SubTableMapper {
...
@@ -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
;
}
}
}
}
tests/examples/JDBC/taosdemo/src/main/resources/application.properties
浏览文件 @
b5c1f002
...
@@ -14,7 +14,7 @@ spring.datasource.password=taosdata
...
@@ -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.Restful
Driver
jdbc.driver
=
com.taosdata.jdbc.
TSDB
Driver
hikari.maximum-pool-size
=
1
hikari.maximum-pool-size
=
500
hikari.minimum-idle
=
1
hikari.minimum-idle
=
1
00
hikari.max-lifetime
=
0
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录