Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e3b2d4e9
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e3b2d4e9
编写于
8月 24, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
cd2fc0f4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
32 deletion
+44
-32
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java
...ctor/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java
+2
-2
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+19
-3
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SetConfigurationInJNITest.java
...est/java/com/taosdata/jdbc/SetConfigurationInJNITest.java
+8
-14
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
...src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
+15
-13
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java
浏览文件 @
e3b2d4e9
...
...
@@ -132,8 +132,7 @@ public class TSDBDriver extends AbstractDriver {
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_PASSWORD_IS_REQUIRED
);
try
{
TSDBJNIConnector
.
init
((
String
)
props
.
get
(
PROPERTY_KEY_CONFIG_DIR
),
(
String
)
props
.
get
(
PROPERTY_KEY_LOCALE
),
(
String
)
props
.
get
(
PROPERTY_KEY_CHARSET
),
(
String
)
props
.
get
(
PROPERTY_KEY_TIME_ZONE
));
TSDBJNIConnector
.
init
(
props
);
return
new
TSDBConnection
(
props
,
this
.
dbMetaData
);
}
catch
(
SQLWarning
sqlWarning
)
{
sqlWarning
.
printStackTrace
();
...
...
@@ -202,6 +201,7 @@ public class TSDBDriver extends AbstractDriver {
String
dbProductName
=
url
.
substring
(
0
,
beginningOfSlashes
);
dbProductName
=
dbProductName
.
substring
(
dbProductName
.
indexOf
(
":"
)
+
1
);
dbProductName
=
dbProductName
.
substring
(
0
,
dbProductName
.
indexOf
(
":"
));
urlProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_PRODUCT_NAME
,
dbProductName
);
// parse database name
url
=
url
.
substring
(
beginningOfSlashes
+
2
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
浏览文件 @
e3b2d4e9
...
...
@@ -16,18 +16,21 @@
*/
package
com.taosdata.jdbc
;
import
com.alibaba.fastjson.JSONObject
;
import
com.taosdata.jdbc.utils.TaosInfo
;
import
java.nio.ByteBuffer
;
import
java.sql.SQLException
;
import
java.sql.SQLWarning
;
import
java.util.List
;
import
java.util.Properties
;
/**
* JNI connector
*/
public
class
TSDBJNIConnector
{
private
static
volatile
Boolean
isInitialized
=
false
;
private
static
final
Object
LOCK
=
new
Object
();
private
static
volatile
boolean
isInitialized
;
private
final
TaosInfo
taosInfo
=
TaosInfo
.
getInstance
();
private
long
taos
=
TSDBConstants
.
JNI_NULL_POINTER
;
// Connection pointer used in C
...
...
@@ -38,10 +41,23 @@ public class TSDBJNIConnector {
System
.
loadLibrary
(
"taos"
);
}
public
static
void
init
(
String
configDir
,
String
locale
,
String
charset
,
String
timezone
)
throws
SQLWarning
{
synchronized
(
isInitialized
)
{
public
static
void
init
(
Properties
props
)
throws
SQLWarning
{
synchronized
(
LOCK
)
{
if
(!
isInitialized
)
{
JSONObject
configJSON
=
new
JSONObject
();
for
(
String
key
:
props
.
stringPropertyNames
())
{
configJSON
.
put
(
key
,
props
.
getProperty
(
key
));
}
setConfig
(
configJSON
.
toJSONString
());
String
configDir
=
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_CONFIG_DIR
);
initImp
(
configDir
);
String
locale
=
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
);
String
charset
=
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
);
String
timezone
=
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
);
if
(
setOptions
(
0
,
locale
)
<
0
)
{
throw
TSDBError
.
createSQLWarning
(
"Failed to set locale: "
+
locale
+
". System default will be used."
);
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SetConfigurationInJNITest.java
浏览文件 @
e3b2d4e9
package
com.taosdata.jdbc
;
import
org.junit.After
;
import
org.junit.Test
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Properties
;
public
class
SetConfigurationInJNITest
{
private
String
host
=
"127.0.0.1"
;
private
String
dbname
=
"test_jni"
;
private
String
debugFlagJSON
=
"{ \"debugFlag\": \"135\"}"
;
private
long
maxSQLLength
=
1024000
;
private
String
maxSqlLengthJSON
=
"{ \"maxSQLLength\": "
+
maxSQLLength
+
"}"
;
private
String
dbname
=
"test_set_config"
;
@Test
public
void
setConfig
BeforeConnectIsValid
()
{
public
void
setConfig
InUrl
()
{
try
{
TSDBJNIConnector
.
setConfig
(
debugFlagJSON
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/?user=root&password=taosdata"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/?user=root&password=taosdata&debugFlag=135"
);
Statement
stmt
=
conn
.
createStatement
();
stmt
.
execute
(
"drop database if exists "
+
dbname
);
...
...
@@ -40,13 +34,13 @@ public class SetConfigurationInJNITest {
}
@Test
public
void
setConfig
AfterConnectIsInvalid
()
{
public
void
setConfig
InProperties
()
{
try
{
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/?user=root&password=taosdata"
);
Properties
props
=
new
Properties
();
props
.
setProperty
(
"debugFlag"
,
"135"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/?user=root&password=taosdata"
,
props
);
TSDBJNIConnector
.
setConfig
(
debugFlagJSON
);
Statement
stmt
=
conn
.
createStatement
();
stmt
.
execute
(
"drop database if exists "
+
dbname
);
stmt
.
execute
(
"create database if not exists "
+
dbname
);
stmt
.
execute
(
"use "
+
dbname
);
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
浏览文件 @
e3b2d4e9
...
...
@@ -7,6 +7,7 @@ import java.lang.management.RuntimeMXBean;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
...
...
@@ -21,21 +22,22 @@ public class TSDBJNIConnectorTest {
try
{
//change sleepSeconds when debugging with attach to process to find PID
int
sleepSeconds
=
-
1
;
if
(
sleepSeconds
>
0
)
{
if
(
sleepSeconds
>
0
)
{
RuntimeMXBean
runtimeBean
=
ManagementFactory
.
getRuntimeMXBean
();
String
jvmName
=
runtimeBean
.
getName
();
long
pid
=
Long
.
valueOf
(
jvmName
.
split
(
"@"
)[
0
]);
System
.
out
.
println
(
"JVM PID = "
+
pid
);
Thread
.
sleep
(
sleepSeconds
*
1000
);
Thread
.
sleep
(
sleepSeconds
*
1000
);
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
// init
TSDBJNIConnector
.
init
(
"/etc/taos"
,
null
,
null
,
null
);
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CONFIG_DIR
,
"/etc/taos"
);
TSDBJNIConnector
.
init
(
properties
);
// connect
TSDBJNIConnector
connector
=
new
TSDBJNIConnector
();
...
...
@@ -43,12 +45,12 @@ public class TSDBJNIConnectorTest {
// setup
String
setupSqlStrs
[]
=
{
"create database if not exists d precision \"us\""
,
"create table if not exists d.t(ts timestamp, f int)"
,
"create database if not exists d2"
,
"create table if not exists d2.t2(ts timestamp, f int)"
,
"insert into d.t values(now+100s, 100)"
,
"insert into d2.t2 values(now+200s, 200)"
};
"create table if not exists d.t(ts timestamp, f int)"
,
"create database if not exists d2"
,
"create table if not exists d2.t2(ts timestamp, f int)"
,
"insert into d.t values(now+100s, 100)"
,
"insert into d2.t2 values(now+200s, 200)"
};
for
(
String
setupSqlStr
:
setupSqlStrs
)
{
long
setupSql
=
connector
.
executeQuery
(
setupSqlStr
);
...
...
@@ -113,8 +115,8 @@ public class TSDBJNIConnectorTest {
}
// close statement
connector
.
executeQuery
(
"use d"
);
String
[]
lines
=
new
String
[]
{
"st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns"
,
"st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns"
};
String
[]
lines
=
new
String
[]{
"st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns"
,
"st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns"
};
connector
.
insertLines
(
lines
);
// close connection
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录