Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
55729a6e
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看板
提交
55729a6e
编写于
2月 23, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add unit test cases for TSDBStatement
上级
2cdcfcf5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
240 addition
and
14 deletion
+240
-14
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java
...bc/src/main/java/com/taosdata/jdbc/AbstractStatement.java
+58
-13
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java
...bc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java
+182
-1
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java
浏览文件 @
55729a6e
...
...
@@ -4,7 +4,6 @@ import java.sql.*;
public
abstract
class
AbstractStatement
extends
WrapperImpl
implements
Statement
{
private
volatile
boolean
closeOnCompletion
;
private
int
fetchSize
;
@Override
...
...
@@ -45,13 +44,14 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
max
<
0
)
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
//
nothing to do
//
do nothing
}
@Override
public
void
setEscapeProcessing
(
boolean
enable
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
// do nothing
}
@Override
...
...
@@ -71,6 +71,9 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
@Override
public
void
cancel
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
...
...
@@ -92,6 +95,7 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
public
void
setCursorName
(
String
name
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
...
...
@@ -113,6 +117,15 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
public
void
setFetchDirection
(
int
direction
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
switch
(
direction
)
{
case
ResultSet
.
FETCH_FORWARD
:
case
ResultSet
.
FETCH_REVERSE
:
case
ResultSet
.
FETCH_UNKNOWN
:
break
;
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
//nothing to do
}
...
...
@@ -170,42 +183,73 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
public
boolean
getMoreResults
(
int
current
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
return
false
;
switch
(
current
)
{
case
Statement
.
CLOSE_CURRENT_RESULT
:
return
false
;
case
Statement
.
KEEP_CURRENT_RESULT
:
case
Statement
.
CLOSE_ALL_RESULTS
:
break
;
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
ResultSet
getGeneratedKeys
()
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
int
executeUpdate
(
String
sql
,
int
autoGeneratedKeys
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
int
executeUpdate
(
String
sql
,
int
[]
columnIndexes
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
int
executeUpdate
(
String
sql
,
String
[]
columnNames
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
boolean
execute
(
String
sql
,
int
autoGeneratedKeys
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
boolean
execute
(
String
sql
,
int
[]
columnIndexes
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
boolean
execute
(
String
sql
,
String
[]
columnNames
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
@@ -222,7 +266,7 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
public
void
setPoolable
(
boolean
poolable
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
//
nothing to do
//
do nothing
}
@Override
...
...
@@ -236,14 +280,15 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
public
void
closeOnCompletion
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
this
.
closeOnCompletion
=
true
;
// do nothing
}
@Override
public
boolean
isCloseOnCompletion
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
return
this
.
closeOnCompletion
;
return
false
;
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java
浏览文件 @
55729a6e
...
...
@@ -51,6 +51,68 @@ public class TSDBStatementTest {
@Test
public
void
close
()
{
// test in AfterClass method
}
@Test
public
void
getMaxFieldSize
()
throws
SQLException
{
Assert
.
assertEquals
(
16
*
1024
,
stmt
.
getMaxFieldSize
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setMaxFieldSize
()
throws
SQLException
{
stmt
.
setMaxFieldSize
(
0
);
stmt
.
setMaxFieldSize
(-
1
);
}
@Test
public
void
getMaxRows
()
throws
SQLException
{
Assert
.
assertEquals
(
0
,
stmt
.
getMaxRows
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setMaxRows
()
throws
SQLException
{
stmt
.
setMaxRows
(
0
);
stmt
.
setMaxRows
(-
1
);
}
@Test
public
void
setEscapeProcessing
()
throws
SQLException
{
stmt
.
setEscapeProcessing
(
true
);
stmt
.
setEscapeProcessing
(
false
);
}
@Test
public
void
getQueryTimeout
()
throws
SQLException
{
Assert
.
assertEquals
(
0
,
stmt
.
getQueryTimeout
());
}
@Test
public
void
setQueryTimeout
()
throws
SQLException
{
stmt
.
setQueryTimeout
(
0
);
stmt
.
setQueryTimeout
(-
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
cancel
()
throws
SQLException
{
stmt
.
cancel
();
}
@Test
public
void
getWarnings
()
throws
SQLException
{
Assert
.
assertNull
(
stmt
.
getWarnings
());
}
@Test
public
void
clearWarnings
()
throws
SQLException
{
stmt
.
clearWarnings
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setCursorName
()
throws
SQLException
{
stmt
.
setCursorName
(
""
);
}
@Test
...
...
@@ -130,7 +192,48 @@ public class TSDBStatementTest {
@Test
public
void
getUpdateCount
()
{
execute
();
// already test in execute method
}
@Test
public
void
getMoreResults
()
throws
SQLException
{
Assert
.
assertEquals
(
false
,
stmt
.
getMoreResults
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setFetchDirection
()
throws
SQLException
{
stmt
.
setFetchDirection
(
ResultSet
.
FETCH_FORWARD
);
stmt
.
setFetchDirection
(
ResultSet
.
FETCH_REVERSE
);
stmt
.
setFetchDirection
(
ResultSet
.
FETCH_UNKNOWN
);
stmt
.
setFetchDirection
(-
1
);
}
@Test
public
void
getFetchDirection
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
FETCH_FORWARD
,
stmt
.
getFetchDirection
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setFetchSize
()
throws
SQLException
{
stmt
.
setFetchSize
(
0
);
stmt
.
setFetchSize
(-
1
);
}
@Test
public
void
getFetchSize
()
throws
SQLException
{
stmt
.
setFetchSize
(
0
);
Assert
.
assertEquals
(
0
,
stmt
.
getFetchSize
());
stmt
.
setFetchSize
(
0
);
}
@Test
public
void
getResultSetConcurrency
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
CONCUR_READ_ONLY
,
stmt
.
getResultSetConcurrency
());
}
@Test
public
void
getResultSetType
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
TYPE_FORWARD_ONLY
,
stmt
.
getResultSetType
());
}
@Test
...
...
@@ -194,6 +297,52 @@ public class TSDBStatementTest {
}
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testGetMoreResults
()
throws
SQLException
{
Assert
.
assertEquals
(
false
,
stmt
.
getMoreResults
(
Statement
.
CLOSE_CURRENT_RESULT
));
stmt
.
getMoreResults
(
Statement
.
KEEP_CURRENT_RESULT
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getGeneratedKeys
()
throws
SQLException
{
stmt
.
getGeneratedKeys
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecuteUpdate
()
throws
SQLException
{
stmt
.
executeUpdate
(
""
,
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecuteUpdate1
()
throws
SQLException
{
stmt
.
executeUpdate
(
""
,
new
int
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecuteUpdate2
()
throws
SQLException
{
stmt
.
executeUpdate
(
""
,
new
String
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecute
()
throws
SQLException
{
stmt
.
execute
(
""
,
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecute1
()
throws
SQLException
{
stmt
.
execute
(
""
,
new
int
[]{});
}
@Test
public
void
testExecute2
()
throws
SQLException
{
stmt
.
execute
(
""
,
new
String
[]{});
}
@Test
public
void
getResultSetHoldability
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
,
stmt
.
getResultSetHoldability
());
}
@Test
public
void
isClosed
()
{
try
{
...
...
@@ -203,6 +352,38 @@ public class TSDBStatementTest {
}
}
@Test
public
void
setPoolable
()
throws
SQLException
{
stmt
.
setPoolable
(
true
);
stmt
.
setPoolable
(
false
);
}
@Test
public
void
isPoolable
()
throws
SQLException
{
Assert
.
assertEquals
(
false
,
stmt
.
isPoolable
());
}
@Test
public
void
closeOnCompletion
()
throws
SQLException
{
stmt
.
closeOnCompletion
();
}
@Test
public
void
isCloseOnCompletion
()
throws
SQLException
{
Assert
.
assertFalse
(
stmt
.
isCloseOnCompletion
());
}
@Test
public
void
unwrap
()
throws
SQLException
{
TSDBStatement
unwrap
=
stmt
.
unwrap
(
TSDBStatement
.
class
);
Assert
.
assertNotNull
(
unwrap
);
}
@Test
public
void
isWrapperFor
()
throws
SQLException
{
Assert
.
assertTrue
(
stmt
.
isWrapperFor
(
TSDBStatement
.
class
));
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录