Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
16069460
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看板
提交
16069460
编写于
1月 26, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-2672]<test>: optimized the JDBC test cases
上级
c3755720
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
217 addition
and
39 deletion
+217
-39
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
...rc/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
+1
-3
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
+8
-2
src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java
...rc/test/java/com/taosdata/jdbc/PreparedStatementTest.java
+19
-31
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
+3
-3
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
...est/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
+186
-0
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
浏览文件 @
16069460
...
...
@@ -100,7 +100,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
* order to process those supported SQLs.
*/
private
void
preprocessSql
()
{
/***** For processing some of Spark SQLs*****/
// should replace it first
this
.
rawSql
=
this
.
rawSql
.
replaceAll
(
"or (.*) is null"
,
""
);
...
...
@@ -149,7 +148,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
rawSql
=
rawSql
.
replace
(
matcher
.
group
(
1
),
tableFullName
);
}
/***** for inner queries *****/
}
/**
...
...
@@ -196,7 +194,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override
public
void
setNull
(
int
parameterIndex
,
int
sqlType
)
throws
SQLException
{
setObject
(
parameterIndex
,
new
String
(
"NULL"
)
);
setObject
(
parameterIndex
,
"NULL"
);
}
@Override
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
浏览文件 @
16069460
...
...
@@ -52,12 +52,18 @@ public class TSDBStatement implements Statement {
this
.
isClosed
=
false
;
}
@Override
public
<
T
>
T
unwrap
(
Class
<
T
>
iface
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORT_METHOD_EXCEPTIONZ_MSG
);
try
{
return
iface
.
cast
(
this
);
}
catch
(
ClassCastException
cce
)
{
throw
new
SQLException
(
"Unable to unwrap to "
+
iface
.
toString
());
}
}
@Override
public
boolean
isWrapperFor
(
Class
<?>
iface
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORT_METHOD_EXCEPTIONZ_MSG
);
return
iface
.
isInstance
(
this
);
}
public
ResultSet
executeQuery
(
String
sql
)
throws
SQLException
{
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java
浏览文件 @
16069460
package
com.taosdata.jdbc
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.FixMethodOrder
;
import
org.junit.Test
;
import
org.junit.*
;
import
org.junit.runners.MethodSorters
;
import
java.sql.*
;
import
java.util.Properties
;
...
...
@@ -11,14 +9,13 @@ import java.util.Properties;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@FixMethodOrder
()
public
class
PreparedStatementTest
extends
BaseTest
{
static
Connection
connection
=
null
;
static
PreparedStatement
statement
=
null
;
@FixMethodOrder
(
value
=
MethodSorters
.
NAME_ASCENDING
)
public
class
PreparedStatementTest
{
static
Connection
connection
;
static
TSDBPreparedStatement
statement
;
static
String
dbName
=
"test"
;
static
String
tName
=
"t0"
;
static
String
host
=
"localhost"
;
static
ResultSet
resSet
=
null
;
@BeforeClass
public
static
void
createConnection
()
throws
SQLException
{
...
...
@@ -28,19 +25,16 @@ public class PreparedStatementTest extends BaseTest {
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
,
properties
);
String
sql
=
"drop database if exists "
+
dbName
;
statement
=
(
TSDBPreparedStatement
)
connection
.
prepareStatement
(
sql
);
}
@Test
public
void
createTableAndQuery
()
throws
SQLException
{
public
void
c
ase001_c
reateTableAndQuery
()
throws
SQLException
{
long
ts
=
System
.
currentTimeMillis
();
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
...
...
@@ -48,47 +42,40 @@ public class PreparedStatementTest extends BaseTest {
statement
.
executeUpdate
(
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", 1)"
);
PreparedStatement
selectStatement
=
connection
.
prepareStatement
(
"select * from "
+
dbName
+
"."
+
tName
);
ResultSet
resultSet
=
selectStatement
.
executeQuery
();
assertTrue
(
null
!=
resultSet
);
boolean
isClosed
=
statement
.
isClosed
();
assertEquals
(
false
,
isClosed
);
selectStatement
.
close
();
}
@Test
public
void
testPreparedStatement
()
throws
SQLException
{
public
void
case002_
testPreparedStatement
()
throws
SQLException
{
long
ts
=
System
.
currentTimeMillis
()
+
20000
;
PreparedStatement
saveStatement
=
connection
.
prepareStatement
(
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", 1)"
);
PreparedStatement
saveStatement
=
connection
.
prepareStatement
(
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", 1)"
);
int
affectedRows
=
saveStatement
.
executeUpdate
();
assertTrue
(
1
==
affectedRows
);
saveStatement
.
close
();
}
@Test
public
void
testSavedPreparedStatement
()
throws
SQLException
{
public
void
case003_
testSavedPreparedStatement
()
throws
SQLException
{
long
ts
=
System
.
currentTimeMillis
();
TSDBPreparedStatement
saveStatement
=
(
TSDBPreparedStatement
)
connection
.
prepareStatement
(
"insert into "
+
dbName
+
"."
+
tName
+
" values (?, ?)"
);
TSDBPreparedStatement
saveStatement
=
(
TSDBPreparedStatement
)
connection
.
prepareStatement
(
"insert into "
+
dbName
+
"."
+
tName
+
" values (?, ?)"
);
saveStatement
.
setObject
(
1
,
ts
+
10000
);
saveStatement
.
setObject
(
2
,
3
);
int
rows
=
saveStatement
.
executeUpdate
();
assertEquals
(
1
,
rows
);
saveStatement
.
close
();
}
@Test
public
void
testUnsupport
()
{
// if(null == resSet) {
// return;
// }
TSDBPreparedStatement
tsdbStatement
=
(
TSDBPreparedStatement
)
statement
;
try
{
tsdbStatement
.
unwrap
(
null
);
}
catch
(
SQLException
e
)
{
}
public
void
case004_testUnsupport
()
throws
SQLException
{
TSDBPreparedStatement
tsdbStatement
=
statement
;
Assert
.
assertNotNull
(
tsdbStatement
.
unwrap
(
TSDBPreparedStatement
.
class
));
try
{
tsdbStatement
.
isWrapperFor
(
null
);
}
catch
(
SQLException
e
)
{
...
...
@@ -180,6 +167,7 @@ public class PreparedStatementTest extends BaseTest {
try
{
tsdbStatement
.
closeOnCompletion
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
isCloseOnCompletion
();
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
浏览文件 @
16069460
...
...
@@ -10,9 +10,9 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.util.Properties
;
public
class
SubscribeTest
extends
BaseTest
{
Connection
connection
=
null
;
Statement
statement
=
null
;
public
class
SubscribeTest
{
Connection
connection
;
Statement
statement
;
String
dbName
=
"test"
;
String
tName
=
"t0"
;
String
host
=
"localhost"
;
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
0 → 100644
浏览文件 @
16069460
package
com.taosdata.jdbc
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
public
class
TSDBPreparedStatementTest
{
private
static
final
String
host
=
"127.0.0.1"
;
private
static
Connection
conn
;
@Test
public
void
executeQuery
()
{
}
@Test
public
void
executeUpdate
()
{
}
@Test
public
void
setNull
()
{
}
@Test
public
void
setBoolean
()
{
}
@Test
public
void
setByte
()
{
}
@Test
public
void
setShort
()
{
}
@Test
public
void
setInt
()
{
}
@Test
public
void
setLong
()
{
}
@Test
public
void
setFloat
()
{
}
@Test
public
void
setDouble
()
{
}
@Test
public
void
setBigDecimal
()
{
}
@Test
public
void
setString
()
{
}
@Test
public
void
setBytes
()
{
}
@Test
public
void
setDate
()
{
}
@Test
public
void
setTime
()
{
}
@Test
public
void
setTimestamp
()
{
}
@Test
public
void
setAsciiStream
()
{
}
@Test
public
void
setUnicodeStream
()
{
}
@Test
public
void
setBinaryStream
()
{
}
@Test
public
void
clearParameters
()
{
}
@Test
public
void
setObject
()
{
}
@Test
public
void
execute
()
{
}
@Test
public
void
addBatch
()
{
}
@Test
public
void
setCharacterStream
()
{
}
@Test
public
void
setRef
()
{
}
@Test
public
void
setBlob
()
{
}
@Test
public
void
setClob
()
{
}
@Test
public
void
setArray
()
{
}
@Test
public
void
getMetaData
()
{
}
@Test
public
void
setURL
()
{
}
@Test
public
void
getParameterMetaData
()
{
}
@Test
public
void
setRowId
()
{
}
@Test
public
void
setNString
()
{
}
@Test
public
void
setNCharacterStream
()
{
}
@Test
public
void
setNClob
()
{
}
@Test
public
void
setSQLXML
()
{
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.rs.RestfulDriver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":6030/jdbc_test?user=root&password=taosdata"
);
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@AfterClass
public
static
void
afterClass
()
{
try
{
if
(
conn
!=
null
)
conn
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录