Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
0dc94d66
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看板
提交
0dc94d66
编写于
2月 22, 2021
作者:
sangshuduo
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' into hotfix/sangshuduo/TD-2984-combine-taosdemo-and-taosdemox
上级
c34bd9e4
c4fb5028
变更
29
展开全部
隐藏空白更改
内联
并排
Showing
29 changed file
with
2626 addition
and
973 deletion
+2626
-973
src/connector/jdbc/pom.xml
src/connector/jdbc/pom.xml
+1
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java
...c/src/main/java/com/taosdata/jdbc/AbstractConnection.java
+529
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
...main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
+3
-18
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
.../jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
+17
-417
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java
...src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java
+6
-7
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java
...ctor/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java
+7
-7
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
...ector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
+9
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
+9
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBSubscribe.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBSubscribe.java
+1
-5
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
...src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
+8
-418
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaData.java
...in/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaData.java
+17
-11
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
.../src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
+18
-15
src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java
.../jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java
+0
-39
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java
...c/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java
+423
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java
.../jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java
+23
-25
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java
...dbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java
+2
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/QueryDataTest.java
.../src/test/java/com/taosdata/jdbc/cases/QueryDataTest.java
+2
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/SelectTest.java
...dbc/src/test/java/com/taosdata/jdbc/cases/SelectTest.java
+2
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/StableTest.java
...dbc/src/test/java/com/taosdata/jdbc/cases/StableTest.java
+2
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java
...test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java
+406
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java
...ava/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java
+984
-0
src/plugins/http/src/httpContext.c
src/plugins/http/src/httpContext.c
+2
-2
tests/examples/JDBC/taosdemo/pom.xml
tests/examples/JDBC/taosdemo/pom.xml
+1
-1
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
.../main/java/com/taosdata/taosdemo/TaosDemoApplication.java
+7
-0
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/DataSourceFactory.java
...a/com/taosdata/taosdemo/components/DataSourceFactory.java
+0
-1
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/QueryService.java
...main/java/com/taosdata/taosdemo/service/QueryService.java
+104
-0
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/TableService.java
...main/java/com/taosdata/taosdemo/service/TableService.java
+0
-1
tests/examples/JDBC/taosdemo/src/main/resources/query.json
tests/examples/JDBC/taosdemo/src/main/resources/query.json
+2
-2
tests/examples/JDBC/taosdemo/src/test/java/com/taosdata/taosdemo/service/QueryServiceTest.java
.../java/com/taosdata/taosdemo/service/QueryServiceTest.java
+41
-0
未找到文件。
src/connector/jdbc/pom.xml
浏览文件 @
0dc94d66
...
...
@@ -128,6 +128,7 @@
</includes>
<excludes>
<exclude>
**/AppMemoryLeakTest.java
</exclude>
<exclude>
**/AuthenticationTest.java
</exclude>
<exclude>
**/TaosInfoMonitorTest.java
</exclude>
<exclude>
**/FailOverTest.java
</exclude>
<exclude>
**/InvalidResultSetPointerTest.java
</exclude>
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java
0 → 100644
浏览文件 @
0dc94d66
package
com.taosdata.jdbc
;
import
java.sql.*
;
import
java.util.Enumeration
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.concurrent.*
;
public
abstract
class
AbstractConnection
extends
WrapperImpl
implements
Connection
{
protected
volatile
boolean
isClosed
;
protected
volatile
String
catalog
;
protected
volatile
Properties
clientInfoProps
=
new
Properties
();
@Override
public
abstract
Statement
createStatement
()
throws
SQLException
;
@Override
public
abstract
PreparedStatement
prepareStatement
(
String
sql
)
throws
SQLException
;
@Override
public
CallableStatement
prepareCall
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
String
nativeSQL
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
// do nothing
return
sql
;
}
@Override
public
void
setAutoCommit
(
boolean
autoCommit
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
//do nothing
}
@Override
public
boolean
getAutoCommit
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
true
;
}
@Override
public
void
commit
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
// do nothing
}
@Override
public
void
rollback
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
// do nothing
}
@Override
public
abstract
void
close
()
throws
SQLException
;
@Override
public
abstract
boolean
isClosed
()
throws
SQLException
;
@Override
public
abstract
DatabaseMetaData
getMetaData
()
throws
SQLException
;
@Override
public
void
setReadOnly
(
boolean
readOnly
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
//do nothing
}
@Override
public
boolean
isReadOnly
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
true
;
}
@Override
public
void
setCatalog
(
String
catalog
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
/*
try (Statement stmt = createStatement()) {
boolean execute = stmt.execute("use " + catalog);
if (execute)
this.catalog = catalog;
} catch (SQLException e) {
// do nothing
}
*/
this
.
catalog
=
catalog
;
}
@Override
public
String
getCatalog
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
this
.
catalog
;
}
@Override
public
void
setTransactionIsolation
(
int
level
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
switch
(
level
)
{
case
Connection
.
TRANSACTION_NONE
:
break
;
case
Connection
.
TRANSACTION_READ_UNCOMMITTED
:
case
Connection
.
TRANSACTION_READ_COMMITTED
:
case
Connection
.
TRANSACTION_REPEATABLE_READ
:
case
Connection
.
TRANSACTION_SERIALIZABLE
:
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
default
:
throw
new
SQLException
(
TSDBConstants
.
INVALID_VARIABLES
);
}
//do nothing
}
@Override
public
int
getTransactionIsolation
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
Connection
.
TRANSACTION_NONE
;
}
@Override
public
SQLWarning
getWarnings
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
null
;
}
@Override
public
void
clearWarnings
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
// do nothing
}
@Override
public
Statement
createStatement
(
int
resultSetType
,
int
resultSetConcurrency
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
switch
(
resultSetType
)
{
case
ResultSet
.
TYPE_FORWARD_ONLY
:
break
;
case
ResultSet
.
TYPE_SCROLL_INSENSITIVE
:
case
ResultSet
.
TYPE_SCROLL_SENSITIVE
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
switch
(
resultSetConcurrency
)
{
case
ResultSet
.
CONCUR_READ_ONLY
:
break
;
case
ResultSet
.
CONCUR_UPDATABLE
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
return
createStatement
();
}
@Override
public
PreparedStatement
prepareStatement
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
switch
(
resultSetType
)
{
case
ResultSet
.
TYPE_FORWARD_ONLY
:
break
;
case
ResultSet
.
TYPE_SCROLL_INSENSITIVE
:
case
ResultSet
.
TYPE_SCROLL_SENSITIVE
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
switch
(
resultSetConcurrency
)
{
case
ResultSet
.
CONCUR_READ_ONLY
:
break
;
case
ResultSet
.
CONCUR_UPDATABLE
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
return
prepareStatement
(
sql
);
}
@Override
public
CallableStatement
prepareCall
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
Map
<
String
,
Class
<?>>
getTypeMap
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setTypeMap
(
Map
<
String
,
Class
<?>>
map
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setHoldability
(
int
holdability
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
switch
(
holdability
)
{
case
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
:
break
;
case
ResultSet
.
CLOSE_CURSORS_AT_COMMIT
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
//do nothing
}
@Override
public
int
getHoldability
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
;
}
@Override
public
Savepoint
setSavepoint
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
Savepoint
setSavepoint
(
String
name
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
rollback
(
Savepoint
savepoint
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
releaseSavepoint
(
Savepoint
savepoint
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
Statement
createStatement
(
int
resultSetType
,
int
resultSetConcurrency
,
int
resultSetHoldability
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
switch
(
resultSetHoldability
)
{
case
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
:
break
;
case
ResultSet
.
CLOSE_CURSORS_AT_COMMIT
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
return
createStatement
(
resultSetType
,
resultSetConcurrency
);
}
@Override
public
PreparedStatement
prepareStatement
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
,
int
resultSetHoldability
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
switch
(
resultSetHoldability
)
{
case
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
:
break
;
case
ResultSet
.
CLOSE_CURSORS_AT_COMMIT
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
return
prepareStatement
(
sql
,
resultSetType
,
resultSetConcurrency
);
}
@Override
public
CallableStatement
prepareCall
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
,
int
resultSetHoldability
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
PreparedStatement
prepareStatement
(
String
sql
,
int
autoGeneratedKeys
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
switch
(
autoGeneratedKeys
)
{
case
Statement
.
RETURN_GENERATED_KEYS
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
case
Statement
.
NO_GENERATED_KEYS
:
break
;
}
return
prepareStatement
(
sql
,
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
}
@Override
public
PreparedStatement
prepareStatement
(
String
sql
,
int
[]
columnIndexes
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
PreparedStatement
prepareStatement
(
String
sql
,
String
[]
columnNames
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
Clob
createClob
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
Blob
createBlob
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
NClob
createNClob
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
SQLXML
createSQLXML
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
boolean
isValid
(
int
timeout
)
throws
SQLException
{
//true if the connection is valid, false otherwise
if
(
isClosed
())
return
false
;
if
(
timeout
<
0
)
//SQLException - if the value supplied for timeout is less then 0
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
ExecutorService
executor
=
Executors
.
newCachedThreadPool
();
Future
<
Boolean
>
future
=
executor
.
submit
(()
->
{
int
status
;
try
(
Statement
stmt
=
createStatement
())
{
ResultSet
resultSet
=
stmt
.
executeQuery
(
"select server_status()"
);
resultSet
.
next
();
status
=
resultSet
.
getInt
(
"server_status()"
);
resultSet
.
close
();
}
return
status
==
1
?
true
:
false
;
});
boolean
status
=
false
;
try
{
if
(
timeout
==
0
)
status
=
future
.
get
();
else
status
=
future
.
get
(
timeout
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
catch
(
ExecutionException
e
)
{
e
.
printStackTrace
();
}
catch
(
TimeoutException
e
)
{
future
.
cancel
(
true
);
status
=
false
;
}
finally
{
executor
.
shutdownNow
();
}
return
status
;
}
@Override
public
void
setClientInfo
(
String
name
,
String
value
)
throws
SQLClientInfoException
{
if
(
isClosed
)
throw
TSDBError
.
createSQLClientInfoException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
if
(
clientInfoProps
==
null
)
clientInfoProps
=
new
Properties
();
clientInfoProps
.
setProperty
(
name
,
value
);
}
@Override
public
void
setClientInfo
(
Properties
properties
)
throws
SQLClientInfoException
{
if
(
isClosed
)
throw
TSDBError
.
createSQLClientInfoException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
for
(
Enumeration
<
Object
>
enumer
=
properties
.
keys
();
enumer
.
hasMoreElements
();
)
{
String
name
=
(
String
)
enumer
.
nextElement
();
clientInfoProps
.
put
(
name
,
properties
.
getProperty
(
name
));
}
}
@Override
public
String
getClientInfo
(
String
name
)
throws
SQLException
{
if
(
isClosed
)
throw
TSDBError
.
createSQLClientInfoException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
clientInfoProps
.
getProperty
(
name
);
}
@Override
public
Properties
getClientInfo
()
throws
SQLException
{
if
(
isClosed
)
throw
TSDBError
.
createSQLClientInfoException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
clientInfoProps
;
}
@Override
public
Array
createArrayOf
(
String
typeName
,
Object
[]
elements
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
Struct
createStruct
(
String
typeName
,
Object
[]
attributes
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setSchema
(
String
schema
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
//do nothing
}
@Override
public
String
getSchema
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
null
;
}
@Override
public
void
abort
(
Executor
executor
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
// do nothing
}
@Override
public
void
setNetworkTimeout
(
Executor
executor
,
int
milliseconds
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
if
(
milliseconds
<
0
)
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
int
getNetworkTimeout
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
浏览文件 @
0dc94d66
...
...
@@ -4,7 +4,7 @@ import java.sql.*;
import
java.util.ArrayList
;
import
java.util.List
;
public
abstract
class
AbstractDatabaseMetaData
implements
DatabaseMetaData
,
Wrapper
{
public
abstract
class
AbstractDatabaseMetaData
extends
WrapperImpl
implements
DatabaseMetaData
{
private
final
static
String
PRODUCT_NAME
=
"TDengine"
;
private
final
static
String
PRODUCT_VESION
=
"2.0.x.x"
;
...
...
@@ -981,9 +981,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrap
return
getEmptyResultSet
();
}
public
Connection
getConnection
()
throws
SQLException
{
return
null
;
}
public
abstract
Connection
getConnection
()
throws
SQLException
;
public
boolean
supportsSavepoints
()
throws
SQLException
{
return
false
;
...
...
@@ -1067,6 +1065,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrap
}
public
ResultSet
getClientInfoProperties
()
throws
SQLException
{
//TODO: see https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#setClientInfo-java.lang.String-java.lang.String-
return
getEmptyResultSet
();
}
...
...
@@ -1093,20 +1092,6 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrap
return
new
EmptyResultSet
();
}
@Override
public
<
T
>
T
unwrap
(
Class
<
T
>
iface
)
throws
SQLException
{
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
{
return
iface
.
isInstance
(
this
);
}
protected
ResultSet
getCatalogs
(
Connection
conn
)
throws
SQLException
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
浏览文件 @
0dc94d66
...
...
@@ -14,41 +14,25 @@
*****************************************************************************/
package
com.taosdata.jdbc
;
import
java.sql.Array
;
import
java.sql.Blob
;
import
java.sql.CallableStatement
;
import
java.sql.Clob
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
java.sql.NClob
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLClientInfoException
;
import
java.sql.SQLException
;
import
java.sql.SQLWarning
;
import
java.sql.SQLXML
;
import
java.sql.Savepoint
;
import
java.sql.Statement
;
import
java.sql.Struct
;
import
java.util.*
;
import
java.util.concurrent.Executor
;
import
java.sql.*
;
import
java.util.Properties
;
public
class
TSDBConnection
implements
Connection
{
public
class
TSDBConnection
extends
Abstract
Connection
{
private
TSDBJNIConnector
connector
=
null
;
private
TSDBJNIConnector
connector
;
private
TSDBDatabaseMetaData
databaseMetaData
;
private
boolean
batchFetch
;
private
String
catalog
=
null
;
private
TSDBDatabaseMetaData
dbMetaData
;
private
Properties
clientInfoProps
=
new
Properties
();
private
int
timeoutMilliseconds
=
0
;
public
Boolean
getBatchFetch
()
{
return
this
.
batchFetch
;
}
private
boolean
batchFetch
=
false
;
public
void
setBatchFetch
(
Boolean
batchFetch
)
{
this
.
batchFetch
=
batchFetch
;
}
public
TSDBConnection
(
Properties
info
,
TSDBDatabaseMetaData
meta
)
throws
SQLException
{
this
.
d
b
MetaData
=
meta
;
this
.
d
atabase
MetaData
=
meta
;
connect
(
info
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
),
Integer
.
parseInt
(
info
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_PORT
,
"0"
)),
info
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_DBNAME
),
...
...
@@ -64,8 +48,8 @@ public class TSDBConnection implements Connection {
private
void
connect
(
String
host
,
int
port
,
String
dbName
,
String
user
,
String
password
)
throws
SQLException
{
this
.
connector
=
new
TSDBJNIConnector
();
this
.
connector
.
connect
(
host
,
port
,
dbName
,
user
,
password
);
this
.
setCatalog
(
dbName
)
;
this
.
d
b
MetaData
.
setConnection
(
this
);
this
.
catalog
=
dbName
;
this
.
d
atabase
MetaData
.
setConnection
(
this
);
}
public
TSDBJNIConnector
getConnection
()
{
...
...
@@ -102,52 +86,11 @@ public class TSDBConnection implements Connection {
return
new
TSDBPreparedStatement
(
this
,
this
.
connector
,
sql
);
}
public
CallableStatement
prepareCall
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
String
nativeSQL
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
void
setAutoCommit
(
boolean
autoCommit
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
}
public
boolean
getAutoCommit
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
true
;
}
public
void
commit
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
}
public
void
rollback
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
void
close
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
this
.
isClosed
=
true
;
this
.
connector
.
closeConnection
();
}
...
...
@@ -155,105 +98,11 @@ public class TSDBConnection implements Connection {
return
this
.
connector
!=
null
&&
this
.
connector
.
isClosed
();
}
/**
* A connection's database is able to provide information describing its tables,
* its supported SQL grammar, its stored procedures, the capabilities of this
* connection, etc. This information is made available through a
* DatabaseMetaData object.
*
* @return a DatabaseMetaData object for this connection
* @throws SQLException if a database access error occurs
*/
public
DatabaseMetaData
getMetaData
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
this
.
dbMetaData
;
}
/**
* This readOnly option is not supported by TDengine. However, the method is intentionally left blank here to
* support HikariCP connection.
*
* @param readOnly
* @throws SQLException
*/
public
void
setReadOnly
(
boolean
readOnly
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
}
public
boolean
isReadOnly
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
true
;
}
public
void
setCatalog
(
String
catalog
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
this
.
catalog
=
catalog
;
}
public
String
getCatalog
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
this
.
catalog
;
}
/**
* The transaction isolation level option is not supported by TDengine.
* This method is intentionally left empty to support HikariCP connection.
*
* @param level
* @throws SQLException
*/
public
void
setTransactionIsolation
(
int
level
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
switch
(
level
)
{
case
Connection
.
TRANSACTION_NONE
:
case
Connection
.
TRANSACTION_READ_COMMITTED
:
case
Connection
.
TRANSACTION_READ_UNCOMMITTED
:
case
Connection
.
TRANSACTION_REPEATABLE_READ
:
case
Connection
.
TRANSACTION_SERIALIZABLE
:
break
;
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
}
/**
* The transaction isolation level option is not supported by TDengine.
*
* @return
* @throws SQLException
*/
public
int
getTransactionIsolation
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
Connection
.
TRANSACTION_NONE
;
}
public
SQLWarning
getWarnings
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
//todo: implement getWarnings according to the warning messages returned from TDengine
return
null
;
}
public
void
clearWarnings
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
//todo: implement clearWarnings according to the warning messages returned from TDengine
return
this
.
databaseMetaData
;
}
public
Statement
createStatement
(
int
resultSetType
,
int
resultSetConcurrency
)
throws
SQLException
{
...
...
@@ -263,253 +112,4 @@ public class TSDBConnection implements Connection {
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
PreparedStatement
prepareStatement
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
)
throws
SQLException
{
// This method is implemented in the current way to support Spark
if
(
resultSetType
!=
ResultSet
.
TYPE_FORWARD_ONLY
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
if
(
resultSetConcurrency
!=
ResultSet
.
CONCUR_READ_ONLY
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
return
this
.
prepareStatement
(
sql
);
}
public
Boolean
getBatchFetch
()
{
return
this
.
batchFetch
;
}
public
void
setBatchFetch
(
Boolean
batchFetch
)
{
this
.
batchFetch
=
batchFetch
;
}
public
CallableStatement
prepareCall
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
Map
<
String
,
Class
<?>>
getTypeMap
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
void
setTypeMap
(
Map
<
String
,
Class
<?>>
map
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
void
setHoldability
(
int
holdability
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
}
/**
* the transaction is not supported by TDengine, so the opened ResultSet Objects will remain open
*
* @return
* @throws SQLException
*/
public
int
getHoldability
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
;
}
public
Savepoint
setSavepoint
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
Savepoint
setSavepoint
(
String
name
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
void
rollback
(
Savepoint
savepoint
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
void
releaseSavepoint
(
Savepoint
savepoint
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
Statement
createStatement
(
int
resultSetType
,
int
resultSetConcurrency
,
int
resultSetHoldability
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
PreparedStatement
prepareStatement
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
,
int
resultSetHoldability
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
CallableStatement
prepareCall
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
,
int
resultSetHoldability
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
PreparedStatement
prepareStatement
(
String
sql
,
int
autoGeneratedKeys
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
PreparedStatement
prepareStatement
(
String
sql
,
int
[]
columnIndexes
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
PreparedStatement
prepareStatement
(
String
sql
,
String
[]
columnNames
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
Clob
createClob
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
Blob
createBlob
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
NClob
createNClob
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
SQLXML
createSQLXML
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
boolean
isValid
(
int
timeout
)
throws
SQLException
{
return
!
this
.
isClosed
();
}
public
void
setClientInfo
(
String
name
,
String
value
)
throws
SQLClientInfoException
{
clientInfoProps
.
setProperty
(
name
,
value
);
}
public
void
setClientInfo
(
Properties
properties
)
throws
SQLClientInfoException
{
for
(
Enumeration
<
Object
>
enumer
=
properties
.
keys
();
enumer
.
hasMoreElements
();
)
{
String
name
=
(
String
)
enumer
.
nextElement
();
clientInfoProps
.
put
(
name
,
properties
.
getProperty
(
name
));
}
}
public
String
getClientInfo
(
String
name
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
clientInfoProps
.
getProperty
(
name
);
}
public
Properties
getClientInfo
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
clientInfoProps
;
}
public
Array
createArrayOf
(
String
typeName
,
Object
[]
elements
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
Struct
createStruct
(
String
typeName
,
Object
[]
attributes
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
void
setSchema
(
String
schema
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
String
getSchema
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
void
abort
(
Executor
executor
)
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
public
void
setNetworkTimeout
(
Executor
executor
,
int
milliseconds
)
throws
SQLException
{
this
.
timeoutMilliseconds
=
milliseconds
;
}
public
int
getNetworkTimeout
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
this
.
timeoutMilliseconds
;
}
public
<
T
>
T
unwrap
(
Class
<
T
>
iface
)
throws
SQLException
{
try
{
return
iface
.
cast
(
this
);
}
catch
(
ClassCastException
cce
)
{
throw
new
SQLException
(
"Unable to unwrap to "
+
iface
.
toString
());
}
}
public
boolean
isWrapperFor
(
Class
<?>
iface
)
throws
SQLException
{
return
iface
.
isInstance
(
this
);
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java
浏览文件 @
0dc94d66
...
...
@@ -57,39 +57,38 @@ public class TSDBDatabaseMetaData extends AbstractDatabaseMetaData {
*/
public
ResultSet
getTables
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
[]
types
)
throws
SQLException
{
if
(
conn
==
null
||
conn
.
isClosed
())
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
super
.
getTables
(
catalog
,
schemaPattern
,
tableNamePattern
,
types
,
conn
);
}
public
ResultSet
getCatalogs
()
throws
SQLException
{
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
super
.
getCatalogs
(
conn
);
}
public
ResultSet
getTableTypes
()
throws
SQLException
{
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
super
.
getTableTypes
();
}
public
ResultSet
getColumns
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
columnNamePattern
)
throws
SQLException
{
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
super
.
getColumns
(
catalog
,
schemaPattern
,
tableNamePattern
,
columnNamePattern
,
conn
);
}
public
ResultSet
getPrimaryKeys
(
String
catalog
,
String
schema
,
String
table
)
throws
SQLException
{
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
super
.
getPrimaryKeys
(
catalog
,
schema
,
table
,
conn
);
}
public
ResultSet
getSuperTables
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
)
throws
SQLException
{
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
super
.
getSuperTables
(
catalog
,
schemaPattern
,
tableNamePattern
,
conn
);
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java
浏览文件 @
0dc94d66
...
...
@@ -90,7 +90,7 @@ public class TSDBDriver extends AbstractDriver {
* fetch data from native function in a batch model
*/
public
static
final
String
PROPERTY_KEY_BATCH_LOAD
=
"batchfetch"
;
private
TSDBDatabaseMetaData
dbMetaData
=
null
;
static
{
...
...
@@ -179,18 +179,18 @@ public class TSDBDriver extends AbstractDriver {
while
(
queryParams
.
hasMoreElements
())
{
String
oneToken
=
queryParams
.
nextToken
();
String
[]
pair
=
oneToken
.
split
(
"="
);
if
((
pair
[
0
]
!=
null
&&
pair
[
0
].
trim
().
length
()
>
0
)
&&
(
pair
[
1
]
!=
null
&&
pair
[
1
].
trim
().
length
()
>
0
))
{
urlProps
.
setProperty
(
pair
[
0
].
trim
(),
pair
[
1
].
trim
());
}
}
}
// parse Product Name
String
dbProductName
=
url
.
substring
(
0
,
beginningOfSlashes
);
dbProductName
=
dbProductName
.
substring
(
dbProductName
.
indexOf
(
":"
)
+
1
);
dbProductName
=
dbProductName
.
substring
(
0
,
dbProductName
.
indexOf
(
":"
));
// parse database name
url
=
url
.
substring
(
beginningOfSlashes
+
2
);
int
indexOfSlash
=
url
.
indexOf
(
"/"
);
...
...
@@ -200,7 +200,7 @@ public class TSDBDriver extends AbstractDriver {
}
url
=
url
.
substring
(
0
,
indexOfSlash
);
}
// parse port
int
indexOfColon
=
url
.
indexOf
(
":"
);
if
(
indexOfColon
!=
-
1
)
{
...
...
@@ -209,11 +209,11 @@ public class TSDBDriver extends AbstractDriver {
}
url
=
url
.
substring
(
0
,
indexOfColon
);
}
if
(
url
!=
null
&&
url
.
length
()
>
0
&&
url
.
trim
().
length
()
>
0
)
{
urlProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
url
);
}
this
.
dbMetaData
=
new
TSDBDatabaseMetaData
(
urlForMeta
,
urlProps
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_USER
));
return
urlProps
;
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
浏览文件 @
0dc94d66
package
com.taosdata.jdbc
;
import
java.sql.SQLClientInfoException
;
import
java.sql.SQLException
;
import
java.sql.SQLFeatureNotSupportedException
;
import
java.util.HashMap
;
...
...
@@ -17,6 +18,10 @@ public class TSDBError {
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_BATCH_IS_EMPTY
,
"Batch is empty!"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_INVALID_WITH_EXECUTEQUERY
,
"Can not issue data manipulation statements with executeQuery()"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_INVALID_WITH_EXECUTEUPDATE
,
"Can not issue SELECT via executeUpdate()"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE_QUERY
,
"not a valid sql for executeQuery: (?)"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
,
"Database not specified or available"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE_UPDATE
,
"not a valid sql for executeUpdate: (?)"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE
,
"not a valid sql for execute: (?)"
);
/**************************************************/
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"unknown error"
);
...
...
@@ -58,4 +63,8 @@ public class TSDBError {
// JNI exception's error number is large than 0x2350
return
new
SQLException
(
"TDengine ERROR ("
+
Integer
.
toHexString
(
errorNumber
)
+
"): "
+
message
);
}
public
static
SQLClientInfoException
createSQLClientInfoException
(
int
errorNumber
)
{
return
new
SQLClientInfoException
();
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
浏览文件 @
0dc94d66
...
...
@@ -12,6 +12,10 @@ public class TSDBErrorNumbers {
public
static
final
int
ERROR_BATCH_IS_EMPTY
=
0x2306
;
//Batch is empty!
public
static
final
int
ERROR_INVALID_WITH_EXECUTEQUERY
=
0x2307
;
//Can not issue data manipulation statements with executeQuery()
public
static
final
int
ERROR_INVALID_WITH_EXECUTEUPDATE
=
0x2308
;
//Can not issue SELECT via executeUpdate()
public
static
final
int
ERROR_INVALID_FOR_EXECUTE_QUERY
=
0x2309
;
//not a valid sql for executeQuery: (SQL)
public
static
final
int
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
=
0x2310
;
//Database not specified or available
public
static
final
int
ERROR_INVALID_FOR_EXECUTE_UPDATE
=
0x2311
;
//not a valid sql for executeUpdate: (SQL)
public
static
final
int
ERROR_INVALID_FOR_EXECUTE
=
0x2312
;
//not a valid sql for execute: (SQL)
public
static
final
int
ERROR_UNKNOWN
=
0x2350
;
//unknown error
...
...
@@ -37,6 +41,11 @@ public class TSDBErrorNumbers {
errorNumbers
.
add
(
ERROR_RESULTSET_CLOSED
);
errorNumbers
.
add
(
ERROR_INVALID_WITH_EXECUTEQUERY
);
errorNumbers
.
add
(
ERROR_INVALID_WITH_EXECUTEUPDATE
);
errorNumbers
.
add
(
ERROR_INVALID_FOR_EXECUTE_QUERY
);
errorNumbers
.
add
(
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
);
errorNumbers
.
add
(
ERROR_INVALID_FOR_EXECUTE_UPDATE
);
errorNumbers
.
add
(
ERROR_INVALID_FOR_EXECUTE
);
/*****************************************************/
errorNumbers
.
add
(
ERROR_SUBSCRIBE_FAILED
);
errorNumbers
.
add
(
ERROR_UNSUPPORTED_ENCODING
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBSubscribe.java
浏览文件 @
0dc94d66
...
...
@@ -16,9 +16,6 @@ package com.taosdata.jdbc;
import
javax.management.OperationsException
;
import
java.sql.SQLException
;
import
java.util.Map
;
import
java.util.TimerTask
;
import
java.util.concurrent.*
;
public
class
TSDBSubscribe
{
private
TSDBJNIConnector
connecter
=
null
;
...
...
@@ -36,9 +33,8 @@ public class TSDBSubscribe {
/**
* consume
*
* @throws OperationsException, SQLException
*/
public
TSDBResultSet
consume
()
throws
OperationsException
,
SQLException
{
public
TSDBResultSet
consume
()
throws
SQLException
{
if
(
this
.
connecter
.
isClosed
())
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
浏览文件 @
0dc94d66
package
com.taosdata.jdbc.rs
;
import
com.taosdata.jdbc.TSDBConstants
;
import
com.taosdata.jdbc.TSDBDriver
;
import
com.taosdata.jdbc.*
;
import
java.sql.*
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.concurrent.Executor
;
public
class
RestfulConnection
implements
Connection
{
public
class
RestfulConnection
extends
Abstract
Connection
{
private
static
final
String
CONNECTION_IS_CLOSED
=
"connection is closed."
;
private
static
final
String
AUTO_COMMIT_IS_TRUE
=
"auto commit is true"
;
private
final
String
host
;
private
final
int
port
;
private
final
Properties
props
;
private
volatile
String
database
;
private
final
String
url
;
private
volatile
String
database
;
/******************************************************/
private
boolean
isClosed
;
private
DatabaseMetaData
metadata
;
private
Map
<
String
,
Class
<?>>
typeMap
;
private
Properties
clientInfoProps
=
new
Properties
();
private
final
DatabaseMetaData
metadata
;
public
RestfulConnection
(
String
host
,
String
port
,
Properties
props
,
String
database
,
String
url
)
{
this
.
host
=
host
;
this
.
port
=
Integer
.
parseInt
(
port
);
this
.
props
=
props
;
this
.
database
=
database
;
this
.
url
=
url
;
this
.
metadata
=
new
RestfulDatabaseMetaData
(
url
,
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_USER
),
this
);
...
...
@@ -37,7 +26,7 @@ public class RestfulConnection implements Connection {
@Override
public
Statement
createStatement
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
)
;
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
;
return
new
RestfulStatement
(
this
,
database
);
}
...
...
@@ -45,61 +34,11 @@ public class RestfulConnection implements Connection {
@Override
public
PreparedStatement
prepareStatement
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
)
;
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
;
//TODO: prepareStatement
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
CallableStatement
prepareCall
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
String
nativeSQL
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
//nothing did
return
sql
;
}
@Override
public
void
setAutoCommit
(
boolean
autoCommit
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
if
(!
autoCommit
)
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
boolean
getAutoCommit
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
return
true
;
}
@Override
public
void
commit
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
if
(
getAutoCommit
())
throw
new
SQLException
(
AUTO_COMMIT_IS_TRUE
);
//nothing to do
}
@Override
public
void
rollback
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
if
(
getAutoCommit
())
throw
new
SQLException
(
AUTO_COMMIT_IS_TRUE
);
//nothing to do
}
@Override
public
void
close
()
throws
SQLException
{
if
(
isClosed
)
...
...
@@ -116,356 +55,11 @@ public class RestfulConnection implements Connection {
@Override
public
DatabaseMetaData
getMetaData
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
)
;
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
;
return
this
.
metadata
;
}
@Override
public
void
setReadOnly
(
boolean
readOnly
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
// nothing to do
}
@Override
public
boolean
isReadOnly
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
return
true
;
}
@Override
public
void
setCatalog
(
String
catalog
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
synchronized
(
RestfulConnection
.
class
)
{
this
.
database
=
catalog
;
}
}
@Override
public
String
getCatalog
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
return
this
.
database
;
}
@Override
public
void
setTransactionIsolation
(
int
level
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
switch
(
level
)
{
case
Connection
.
TRANSACTION_NONE
:
break
;
case
Connection
.
TRANSACTION_READ_UNCOMMITTED
:
case
Connection
.
TRANSACTION_READ_COMMITTED
:
case
Connection
.
TRANSACTION_REPEATABLE_READ
:
case
Connection
.
TRANSACTION_SERIALIZABLE
:
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
default
:
throw
new
SQLException
(
TSDBConstants
.
INVALID_VARIABLES
);
}
}
@Override
public
int
getTransactionIsolation
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
//Connection.TRANSACTION_NONE specifies that transactions are not supported.
return
Connection
.
TRANSACTION_NONE
;
}
@Override
public
SQLWarning
getWarnings
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
return
null
;
}
@Override
public
void
clearWarnings
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
//nothing to do
}
@Override
public
Statement
createStatement
(
int
resultSetType
,
int
resultSetConcurrency
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
if
(
resultSetType
!=
ResultSet
.
TYPE_FORWARD_ONLY
)
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
if
(
resultSetConcurrency
!=
ResultSet
.
CONCUR_READ_ONLY
)
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
return
createStatement
();
}
@Override
public
PreparedStatement
prepareStatement
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
if
(
resultSetType
!=
ResultSet
.
TYPE_FORWARD_ONLY
||
resultSetConcurrency
!=
ResultSet
.
CONCUR_READ_ONLY
)
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
INVALID_VARIABLES
);
return
this
.
prepareStatement
(
sql
);
}
@Override
public
CallableStatement
prepareCall
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
if
(
resultSetType
!=
ResultSet
.
TYPE_FORWARD_ONLY
||
resultSetConcurrency
!=
ResultSet
.
CONCUR_READ_ONLY
)
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
INVALID_VARIABLES
);
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
Map
<
String
,
Class
<?>>
getTypeMap
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
synchronized
(
RestfulConnection
.
class
)
{
if
(
this
.
typeMap
==
null
)
{
this
.
typeMap
=
new
HashMap
<>();
}
return
this
.
typeMap
;
}
}
@Override
public
void
setTypeMap
(
Map
<
String
,
Class
<?>>
map
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
synchronized
(
RestfulConnection
.
class
)
{
this
.
typeMap
=
map
;
}
}
@Override
public
void
setHoldability
(
int
holdability
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
if
(
holdability
!=
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
)
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
int
getHoldability
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
return
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
;
}
@Override
public
Savepoint
setSavepoint
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
if
(
getAutoCommit
())
throw
new
SQLException
(
TSDBConstants
.
INVALID_VARIABLES
);
//nothing to do
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
Savepoint
setSavepoint
(
String
name
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
if
(
getAutoCommit
())
throw
new
SQLException
(
TSDBConstants
.
INVALID_VARIABLES
);
//nothing to do
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
void
rollback
(
Savepoint
savepoint
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
if
(
getAutoCommit
())
throw
new
SQLException
(
TSDBConstants
.
INVALID_VARIABLES
);
//nothing to do
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
void
releaseSavepoint
(
Savepoint
savepoint
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
Statement
createStatement
(
int
resultSetType
,
int
resultSetConcurrency
,
int
resultSetHoldability
)
throws
SQLException
{
if
(
resultSetHoldability
!=
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
)
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
return
createStatement
(
resultSetType
,
resultSetConcurrency
);
}
@Override
public
PreparedStatement
prepareStatement
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
,
int
resultSetHoldability
)
throws
SQLException
{
if
(
resultSetHoldability
!=
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
)
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
return
prepareStatement
(
sql
,
resultSetType
,
resultSetConcurrency
);
}
@Override
public
CallableStatement
prepareCall
(
String
sql
,
int
resultSetType
,
int
resultSetConcurrency
,
int
resultSetHoldability
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
PreparedStatement
prepareStatement
(
String
sql
,
int
autoGeneratedKeys
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
PreparedStatement
prepareStatement
(
String
sql
,
int
[]
columnIndexes
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
PreparedStatement
prepareStatement
(
String
sql
,
String
[]
columnNames
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
Clob
createClob
()
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
Blob
createBlob
()
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
NClob
createNClob
()
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
SQLXML
createSQLXML
()
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
boolean
isValid
(
int
timeout
)
throws
SQLException
{
if
(
timeout
<
0
)
throw
new
SQLException
(
TSDBConstants
.
INVALID_VARIABLES
);
// TODO:
/* The driver shall submit a query on the connection or use some other mechanism that positively verifies
the connection is still valid when this method is called.*/
return
!
isClosed
();
}
@Override
public
void
setClientInfo
(
String
name
,
String
value
)
throws
SQLClientInfoException
{
if
(
isClosed
)
throw
new
SQLClientInfoException
();
clientInfoProps
.
setProperty
(
name
,
value
);
}
@Override
public
void
setClientInfo
(
Properties
properties
)
throws
SQLClientInfoException
{
if
(
isClosed
)
throw
new
SQLClientInfoException
();
for
(
Enumeration
<
Object
>
enumer
=
properties
.
keys
();
enumer
.
hasMoreElements
();
)
{
String
name
=
(
String
)
enumer
.
nextElement
();
clientInfoProps
.
put
(
name
,
properties
.
getProperty
(
name
));
}
}
@Override
public
String
getClientInfo
(
String
name
)
throws
SQLException
{
if
(
isClosed
)
throw
new
SQLClientInfoException
();
return
clientInfoProps
.
getProperty
(
name
);
}
@Override
public
Properties
getClientInfo
()
throws
SQLException
{
if
(
isClosed
)
throw
new
SQLClientInfoException
();
return
clientInfoProps
;
}
@Override
public
Array
createArrayOf
(
String
typeName
,
Object
[]
elements
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
Struct
createStruct
(
String
typeName
,
Object
[]
attributes
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
void
setSchema
(
String
schema
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
synchronized
(
RestfulConnection
.
class
)
{
this
.
database
=
schema
;
}
}
@Override
public
String
getSchema
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
return
this
.
database
;
}
@Override
public
void
abort
(
Executor
executor
)
throws
SQLException
{
if
(
executor
==
null
)
{
throw
new
SQLException
(
"Executor can not be null"
);
}
executor
.
execute
(()
->
{
try
{
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
});
}
@Override
public
void
setNetworkTimeout
(
Executor
executor
,
int
milliseconds
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
}
@Override
public
int
getNetworkTimeout
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
CONNECTION_IS_CLOSED
);
return
0
;
}
@Override
public
<
T
>
T
unwrap
(
Class
<
T
>
iface
)
throws
SQLException
{
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
{
return
iface
.
isInstance
(
this
);
}
public
String
getHost
()
{
return
host
;
}
...
...
@@ -474,10 +68,6 @@ public class RestfulConnection implements Connection {
return
port
;
}
public
Properties
getProps
()
{
return
props
;
}
public
String
getDatabase
()
{
return
database
;
}
...
...
@@ -485,4 +75,4 @@ public class RestfulConnection implements Connection {
public
String
getUrl
()
{
return
url
;
}
}
}
\ No newline at end of file
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaData.java
浏览文件 @
0dc94d66
package
com.taosdata.jdbc.rs
;
import
com.taosdata.jdbc.*
;
import
com.taosdata.jdbc.AbstractDatabaseMetaData
;
import
com.taosdata.jdbc.TSDBError
;
import
com.taosdata.jdbc.TSDBErrorNumbers
;
import
java.sql.
*
;
import
java.
util.ArrayLis
t
;
import
java.
util.List
;
import
java.sql.
Connection
;
import
java.
sql.ResultSe
t
;
import
java.
sql.SQLException
;
public
class
RestfulDatabaseMetaData
extends
AbstractDatabaseMetaData
{
...
...
@@ -33,11 +35,10 @@ public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData {
return
RestfulDriver
.
class
.
getName
();
}
@Override
public
ResultSet
getTables
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
[]
types
)
throws
SQLException
{
if
(
connection
==
null
||
connection
.
isClosed
())
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
super
.
getTables
(
catalog
,
schemaPattern
,
tableNamePattern
,
types
,
connection
);
}
...
...
@@ -45,14 +46,14 @@ public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData {
@Override
public
ResultSet
getCatalogs
()
throws
SQLException
{
if
(
connection
==
null
||
connection
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
super
.
getCatalogs
(
connection
);
}
@Override
public
ResultSet
getTableTypes
()
throws
SQLException
{
if
(
connection
==
null
||
connection
.
isClosed
())
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
super
.
getTableTypes
();
}
...
...
@@ -60,21 +61,26 @@ public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData {
@Override
public
ResultSet
getColumns
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
columnNamePattern
)
throws
SQLException
{
if
(
connection
==
null
||
connection
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
super
.
getColumns
(
catalog
,
schemaPattern
,
tableNamePattern
,
columnNamePattern
,
connection
);
}
@Override
public
ResultSet
getPrimaryKeys
(
String
catalog
,
String
schema
,
String
table
)
throws
SQLException
{
if
(
connection
==
null
||
connection
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
super
.
getPrimaryKeys
(
catalog
,
schema
,
table
,
connection
);
}
@Override
public
Connection
getConnection
()
throws
SQLException
{
return
this
.
connection
;
}
@Override
public
ResultSet
getSuperTables
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
)
throws
SQLException
{
if
(
connection
==
null
||
connection
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
super
.
getSuperTables
(
catalog
,
schemaPattern
,
tableNamePattern
,
connection
);
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
浏览文件 @
0dc94d66
...
...
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
import
com.alibaba.fastjson.JSONObject
;
import
com.taosdata.jdbc.AbstractStatement
;
import
com.taosdata.jdbc.TSDBConstants
;
import
com.taosdata.jdbc.TSDBError
;
import
com.taosdata.jdbc.TSDBErrorNumbers
;
import
com.taosdata.jdbc.rs.util.HttpClientPoolUtil
;
import
com.taosdata.jdbc.utils.SqlSyntaxValidator
;
...
...
@@ -63,9 +65,9 @@ public class RestfulStatement extends AbstractStatement {
@Override
public
ResultSet
executeQuery
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
"statement already closed"
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(!
SqlSyntaxValidator
.
isValidForExecuteQuery
(
sql
))
throw
new
SQLException
(
"not a valid sql for executeQuery: "
+
sql
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE_QUERY
,
"not a valid sql for executeQuery: "
+
sql
);
final
String
url
=
"http://"
+
conn
.
getHost
()
+
":"
+
conn
.
getPort
()
+
"/rest/sql"
;
if
(
SqlSyntaxValidator
.
isDatabaseUnspecifiedQuery
(
sql
))
{
...
...
@@ -73,7 +75,7 @@ public class RestfulStatement extends AbstractStatement {
}
if
(
this
.
database
==
null
||
this
.
database
.
isEmpty
())
throw
new
SQLException
(
"Database not specified or available"
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
);
HttpClientPoolUtil
.
execute
(
url
,
"use "
+
this
.
database
);
return
executeOneQuery
(
url
,
sql
);
}
...
...
@@ -81,9 +83,9 @@ public class RestfulStatement extends AbstractStatement {
@Override
public
int
executeUpdate
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
"statement already closed"
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(!
SqlSyntaxValidator
.
isValidForExecuteUpdate
(
sql
))
throw
new
SQLException
(
"not a valid sql for executeUpdate: "
+
sql
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE_UPDATE
,
"not a valid sql for executeUpdate: "
+
sql
);
final
String
url
=
"http://"
+
conn
.
getHost
()
+
":"
+
conn
.
getPort
()
+
"/rest/sql"
;
if
(
SqlSyntaxValidator
.
isDatabaseUnspecifiedUpdate
(
sql
))
{
...
...
@@ -91,7 +93,8 @@ public class RestfulStatement extends AbstractStatement {
}
if
(
this
.
database
==
null
||
this
.
database
.
isEmpty
())
throw
new
SQLException
(
"Database not specified or available"
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
);
HttpClientPoolUtil
.
execute
(
url
,
"use "
+
this
.
database
);
return
executeOneUpdate
(
url
,
sql
);
}
...
...
@@ -107,9 +110,9 @@ public class RestfulStatement extends AbstractStatement {
@Override
public
boolean
execute
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
"Invalid method call on a closed statement."
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(!
SqlSyntaxValidator
.
isValidForExecute
(
sql
))
throw
new
SQLException
(
"not a valid sql for execute: "
+
sql
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE
,
"not a valid sql for execute: "
+
sql
);
//如果执行了use操作应该将当前Statement的catalog设置为新的database
final
String
url
=
"http://"
+
conn
.
getHost
()
+
":"
+
conn
.
getPort
()
+
"/rest/sql"
;
...
...
@@ -134,7 +137,7 @@ public class RestfulStatement extends AbstractStatement {
private
ResultSet
executeOneQuery
(
String
url
,
String
sql
)
throws
SQLException
{
if
(!
SqlSyntaxValidator
.
isValidForExecuteQuery
(
sql
))
throw
new
SQLException
(
"not a select
sql for executeQuery: "
+
sql
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE_QUERY
,
"not a valid
sql for executeQuery: "
+
sql
);
// row data
String
result
=
HttpClientPoolUtil
.
execute
(
url
,
sql
);
...
...
@@ -165,7 +168,7 @@ public class RestfulStatement extends AbstractStatement {
private
int
executeOneUpdate
(
String
url
,
String
sql
)
throws
SQLException
{
if
(!
SqlSyntaxValidator
.
isValidForExecuteUpdate
(
sql
))
throw
new
SQLException
(
"not a valid sql for executeUpdate: "
+
sql
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE_UPDATE
,
"not a valid sql for executeUpdate: "
+
sql
);
String
result
=
HttpClientPoolUtil
.
execute
(
url
,
sql
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
result
);
...
...
@@ -186,16 +189,16 @@ public class RestfulStatement extends AbstractStatement {
@Override
public
int
getUpdateCount
()
throws
SQLException
{
if
(
isClosed
())
{
throw
new
SQLException
(
"Invalid method call on a closed statement."
);
}
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
return
this
.
affectedRows
;
}
@Override
public
void
addBatch
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_
STATEMENT_CLOSED
);
//TODO:
}
...
...
@@ -213,7 +216,7 @@ public class RestfulStatement extends AbstractStatement {
@Override
public
Connection
getConnection
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_
STATEMENT_CLOSED
);
return
this
.
conn
;
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java
已删除
100644 → 0
浏览文件 @
c34bd9e4
package
com.taosdata.jdbc
;
import
org.junit.Assert
;
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
ConnectionTest
{
private
Connection
connection
;
private
Statement
statement
;
private
static
String
host
=
"127.0.0.1"
;
@Test
public
void
testConnection
()
{
Properties
properties
=
new
Properties
();
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"
);
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
,
properties
);
Assert
.
assertTrue
(
null
!=
connection
);
statement
=
connection
.
createStatement
();
Assert
.
assertTrue
(
null
!=
statement
);
statement
.
close
();
connection
.
close
();
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java
0 → 100644
浏览文件 @
0dc94d66
package
com.taosdata.jdbc
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
javax.management.OperationsException
;
import
java.sql.*
;
import
java.util.Properties
;
public
class
TSDBConnectionTest
{
private
static
final
String
host
=
"127.0.0.1"
;
private
static
Connection
conn
;
@Test
public
void
getConnection
()
{
// already test in beforeClass method
}
@Test
public
void
createStatement
()
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
ResultSet
rs
=
stmt
.
executeQuery
(
"select server_status()"
);
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
subscribe
()
{
try
{
TSDBConnection
unwrap
=
conn
.
unwrap
(
TSDBConnection
.
class
);
TSDBSubscribe
subscribe
=
unwrap
.
subscribe
(
"topic1"
,
"select * from log.log"
,
false
);
TSDBResultSet
rs
=
subscribe
.
consume
();
ResultSetMetaData
metaData
=
rs
.
getMetaData
();
for
(
int
count
=
0
;
count
<
10
&&
rs
.
next
();
count
++)
{
for
(
int
i
=
1
;
i
<=
metaData
.
getColumnCount
();
i
++)
{
String
value
=
rs
.
getString
(
i
);
System
.
out
.
print
(
metaData
.
getColumnLabel
(
i
)
+
":"
+
value
+
"\t"
);
}
System
.
out
.
println
();
}
Assert
.
assertNotNull
(
rs
);
subscribe
.
close
(
false
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
prepareStatement
()
throws
SQLException
{
PreparedStatement
pstmt
=
conn
.
prepareStatement
(
"select server_status()"
);
ResultSet
rs
=
pstmt
.
executeQuery
();
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
prepareCall
()
throws
SQLException
{
conn
.
prepareCall
(
"select server_status()"
);
}
@Test
public
void
nativeSQL
()
throws
SQLException
{
String
nativeSQL
=
conn
.
nativeSQL
(
"select * from log.log"
);
Assert
.
assertEquals
(
"select * from log.log"
,
nativeSQL
);
}
@Test
public
void
setAutoCommit
()
throws
SQLException
{
conn
.
setAutoCommit
(
true
);
conn
.
setAutoCommit
(
false
);
}
@Test
public
void
getAutoCommit
()
throws
SQLException
{
Assert
.
assertTrue
(
conn
.
getAutoCommit
());
}
@Test
public
void
commit
()
throws
SQLException
{
conn
.
commit
();
}
@Test
public
void
rollback
()
throws
SQLException
{
conn
.
rollback
();
}
@Test
public
void
close
()
{
// connection will close in afterClass method
}
@Test
public
void
isClosed
()
throws
SQLException
{
Assert
.
assertFalse
(
conn
.
isClosed
());
}
@Test
public
void
getMetaData
()
throws
SQLException
{
DatabaseMetaData
meta
=
conn
.
getMetaData
();
Assert
.
assertNotNull
(
meta
);
Assert
.
assertEquals
(
"com.taosdata.jdbc.TSDBDriver"
,
meta
.
getDriverName
());
}
@Test
public
void
setReadOnly
()
throws
SQLException
{
conn
.
setReadOnly
(
true
);
}
@Test
public
void
isReadOnly
()
throws
SQLException
{
Assert
.
assertTrue
(
conn
.
isReadOnly
());
}
@Test
public
void
setCatalog
()
throws
SQLException
{
conn
.
setCatalog
(
"test"
);
Assert
.
assertEquals
(
"test"
,
conn
.
getCatalog
());
}
@Test
public
void
getCatalog
()
throws
SQLException
{
conn
.
setCatalog
(
"log"
);
Assert
.
assertEquals
(
"log"
,
conn
.
getCatalog
());
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setTransactionIsolation
()
throws
SQLException
{
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_NONE
);
Assert
.
assertEquals
(
Connection
.
TRANSACTION_NONE
,
conn
.
getTransactionIsolation
());
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_READ_UNCOMMITTED
);
}
@Test
public
void
getTransactionIsolation
()
throws
SQLException
{
Assert
.
assertEquals
(
Connection
.
TRANSACTION_NONE
,
conn
.
getTransactionIsolation
());
}
@Test
public
void
getWarnings
()
throws
SQLException
{
Assert
.
assertNull
(
conn
.
getWarnings
());
}
@Test
public
void
clearWarnings
()
throws
SQLException
{
conn
.
clearWarnings
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testCreateStatement
()
throws
SQLException
{
Statement
stmt
=
conn
.
createStatement
(
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
);
ResultSet
rs
=
stmt
.
executeQuery
(
"select server_status()"
);
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
conn
.
createStatement
(
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareStatement
()
throws
SQLException
{
PreparedStatement
pstmt
=
conn
.
prepareStatement
(
"select server_status()"
,
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
);
ResultSet
rs
=
pstmt
.
executeQuery
();
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
conn
.
prepareStatement
(
"select server_status"
,
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareCall
()
throws
SQLException
{
conn
.
prepareCall
(
""
,
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getTypeMap
()
throws
SQLException
{
conn
.
getTypeMap
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setTypeMap
()
throws
SQLException
{
conn
.
setTypeMap
(
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setHoldability
()
throws
SQLException
{
conn
.
setHoldability
(
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
Assert
.
assertEquals
(
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
,
conn
.
getHoldability
());
conn
.
setHoldability
(
ResultSet
.
CLOSE_CURSORS_AT_COMMIT
);
}
@Test
public
void
getHoldability
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
,
conn
.
getHoldability
());
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setSavepoint
()
throws
SQLException
{
conn
.
setSavepoint
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testSetSavepoint
()
throws
SQLException
{
conn
.
setSavepoint
(
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testRollback
()
throws
SQLException
{
conn
.
rollback
(
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
releaseSavepoint
()
throws
SQLException
{
conn
.
releaseSavepoint
(
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testCreateStatement1
()
throws
SQLException
{
Statement
stmt
=
conn
.
createStatement
(
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
ResultSet
rs
=
stmt
.
executeQuery
(
"select server_status()"
);
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
conn
.
createStatement
(
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareStatement1
()
throws
SQLException
{
PreparedStatement
pstmt
=
conn
.
prepareStatement
(
"select server_status()"
,
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
ResultSet
rs
=
pstmt
.
executeQuery
();
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
conn
.
prepareStatement
(
"select server_status"
,
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareCall1
()
throws
SQLException
{
conn
.
prepareCall
(
""
,
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareStatement2
()
throws
SQLException
{
Assert
.
assertNotNull
(
""
,
Statement
.
NO_GENERATED_KEYS
);
conn
.
prepareStatement
(
""
,
Statement
.
RETURN_GENERATED_KEYS
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareStatement3
()
throws
SQLException
{
conn
.
prepareStatement
(
""
,
new
int
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareStatement4
()
throws
SQLException
{
conn
.
prepareStatement
(
""
,
new
String
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createClob
()
throws
SQLException
{
conn
.
createClob
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createBlob
()
throws
SQLException
{
conn
.
createBlob
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createNClob
()
throws
SQLException
{
conn
.
createNClob
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createSQLXML
()
throws
SQLException
{
conn
.
createSQLXML
();
}
@Test
(
expected
=
SQLException
.
class
)
public
void
isValid
()
throws
SQLException
{
Assert
.
assertTrue
(
conn
.
isValid
(
10
));
Assert
.
assertTrue
(
conn
.
isValid
(
0
));
conn
.
isValid
(-
1
);
}
@Test
public
void
setClientInfo
()
throws
SQLClientInfoException
{
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"en_US.UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTC-8"
);
}
@Test
public
void
testSetClientInfo
()
throws
SQLClientInfoException
{
Properties
properties
=
new
Properties
();
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"
);
conn
.
setClientInfo
(
properties
);
}
@Test
public
void
getClientInfo
()
throws
SQLException
{
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
Properties
info
=
conn
.
getClientInfo
();
String
charset
=
info
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
);
Assert
.
assertEquals
(
"UTF-8"
,
charset
);
String
locale
=
info
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
);
Assert
.
assertEquals
(
"en_US.UTF-8"
,
locale
);
String
timezone
=
info
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
);
Assert
.
assertEquals
(
"UTC-8"
,
timezone
);
}
@Test
public
void
testGetClientInfo
()
throws
SQLException
{
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
String
charset
=
conn
.
getClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
);
Assert
.
assertEquals
(
"UTF-8"
,
charset
);
String
locale
=
conn
.
getClientInfo
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
);
Assert
.
assertEquals
(
"en_US.UTF-8"
,
locale
);
String
timezone
=
conn
.
getClientInfo
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
);
Assert
.
assertEquals
(
"UTC-8"
,
timezone
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createArrayOf
()
throws
SQLException
{
conn
.
createArrayOf
(
""
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createStruct
()
throws
SQLException
{
conn
.
createStruct
(
""
,
null
);
}
@Test
public
void
setSchema
()
throws
SQLException
{
conn
.
setSchema
(
"test"
);
}
@Test
public
void
getSchema
()
throws
SQLException
{
Assert
.
assertNull
(
conn
.
getSchema
());
}
@Test
public
void
abort
()
throws
SQLException
{
conn
.
abort
(
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setNetworkTimeout
()
throws
SQLException
{
conn
.
setNetworkTimeout
(
null
,
1000
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getNetworkTimeout
()
throws
SQLException
{
conn
.
getNetworkTimeout
();
}
@Test
public
void
unwrap
()
{
try
{
TSDBConnection
tsdbConnection
=
conn
.
unwrap
(
TSDBConnection
.
class
);
Assert
.
assertNotNull
(
tsdbConnection
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
isWrapperFor
()
throws
SQLException
{
Assert
.
assertTrue
(
conn
.
isWrapperFor
(
TSDBConnection
.
class
));
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Properties
properties
=
new
Properties
();
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"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":6030/log?user=root&password=taosdata"
,
properties
);
// create test database for test cases
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
"create database if not exists test"
);
}
}
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
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java
浏览文件 @
0dc94d66
...
...
@@ -24,11 +24,10 @@ public class TSDBDriverTest {
"jdbc:TAOS://:/test"
,
"jdbc:TAOS://localhost:0/?user=root&password=taosdata"
};
private
Connection
conn
;
@Test
public
void
testC
onnectWithJdbcURL
()
{
public
void
c
onnectWithJdbcURL
()
{
final
String
url
=
"jdbc:TAOS://localhost:6030/log?user=root&password=taosdata"
;
try
{
conn
=
DriverManager
.
getConnection
(
url
);
...
...
@@ -40,7 +39,7 @@ public class TSDBDriverTest {
}
@Test
public
void
testC
onnectWithProperties
()
{
public
void
c
onnectWithProperties
()
{
final
String
jdbcUrl
=
"jdbc:TAOS://localhost:6030/log?user=root&password=taosdata"
;
Properties
connProps
=
new
Properties
();
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
...
...
@@ -56,7 +55,7 @@ public class TSDBDriverTest {
}
@Test
public
void
testC
onnectWithConfigFile
()
{
public
void
c
onnectWithConfigFile
()
{
String
jdbcUrl
=
"jdbc:TAOS://:/log?user=root&password=taosdata"
;
Properties
connProps
=
new
Properties
();
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
...
...
@@ -71,16 +70,6 @@ public class TSDBDriverTest {
}
}
@Test
(
expected
=
SQLException
.
class
)
public
void
testAcceptsURL
()
throws
SQLException
{
Driver
driver
=
new
TSDBDriver
();
for
(
String
url
:
validURLs
)
{
assertTrue
(
"failure - acceptsURL(\" "
+
url
+
" \") should be true"
,
driver
.
acceptsURL
(
url
));
}
driver
.
acceptsURL
(
null
);
fail
(
"acceptsURL throws exception when parameter is null"
);
}
@Test
public
void
testParseURL
()
{
TSDBDriver
driver
=
new
TSDBDriver
();
...
...
@@ -121,8 +110,19 @@ public class TSDBDriverTest {
assertNull
(
"failure - dbname should be null"
,
actual
.
getProperty
(
"dbname"
));
}
@Test
(
expected
=
SQLException
.
class
)
public
void
acceptsURL
()
throws
SQLException
{
Driver
driver
=
new
TSDBDriver
();
for
(
String
url
:
validURLs
)
{
assertTrue
(
"failure - acceptsURL(\" "
+
url
+
" \") should be true"
,
driver
.
acceptsURL
(
url
));
}
driver
.
acceptsURL
(
null
);
fail
(
"acceptsURL throws exception when parameter is null"
);
}
@Test
public
void
testG
etPropertyInfo
()
throws
SQLException
{
public
void
g
etPropertyInfo
()
throws
SQLException
{
Driver
driver
=
new
TSDBDriver
();
final
String
url
=
"jdbc:TAOS://localhost:6030/log?user=root&password=taosdata"
;
Properties
connProps
=
new
Properties
();
...
...
@@ -142,23 +142,23 @@ public class TSDBDriverTest {
}
@Test
public
void
testG
etMajorVersion
()
{
assertEquals
(
"failure - getMajorVersion should be 2"
,
2
,
new
TSDBDriver
().
getMajorVersion
());
public
void
g
etMajorVersion
()
{
assertEquals
(
2
,
new
TSDBDriver
().
getMajorVersion
());
}
@Test
public
void
testG
etMinorVersion
()
{
assertEquals
(
"failure - getMinorVersion should be 0"
,
0
,
new
TSDBDriver
().
getMinorVersion
());
public
void
g
etMinorVersion
()
{
assertEquals
(
0
,
new
TSDBDriver
().
getMinorVersion
());
}
@Test
public
void
testJ
dbcCompliant
()
{
assertFalse
(
"failure - jdbcCompliant should be false"
,
new
TSDBDriver
().
jdbcCompliant
());
public
void
j
dbcCompliant
()
{
assertFalse
(
new
TSDBDriver
().
jdbcCompliant
());
}
@Test
public
void
testG
etParentLogger
()
throws
SQLFeatureNotSupportedException
{
assertNull
(
"failure - getParentLogger should be be null"
,
new
TSDBDriver
().
getParentLogger
());
public
void
g
etParentLogger
()
throws
SQLFeatureNotSupportedException
{
assertNull
(
new
TSDBDriver
().
getParentLogger
());
}
@BeforeClass
...
...
@@ -169,6 +169,4 @@ public class TSDBDriverTest {
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
src/connector/jdbc/src/test/java/com/taosdata/jdbc/ImportTest.java
→
src/connector/jdbc/src/test/java/com/taosdata/jdbc/
cases/
ImportTest.java
浏览文件 @
0dc94d66
package
com.taosdata.jdbc
;
package
com.taosdata.jdbc
.cases
;
import
com.taosdata.jdbc.TSDBDriver
;
import
org.junit.*
;
import
org.junit.runners.MethodSorters
;
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java
→
src/connector/jdbc/src/test/java/com/taosdata/jdbc/
cases/
QueryDataTest.java
浏览文件 @
0dc94d66
package
com.taosdata.jdbc
;
package
com.taosdata.jdbc
.cases
;
import
com.taosdata.jdbc.TSDBDriver
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java
→
src/connector/jdbc/src/test/java/com/taosdata/jdbc/
cases/
SelectTest.java
浏览文件 @
0dc94d66
package
com.taosdata.jdbc
;
package
com.taosdata.jdbc
.cases
;
import
com.taosdata.jdbc.TSDBDriver
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java
→
src/connector/jdbc/src/test/java/com/taosdata/jdbc/
cases/
StableTest.java
浏览文件 @
0dc94d66
package
com.taosdata.jdbc
;
package
com.taosdata.jdbc
.cases
;
import
com.taosdata.jdbc.TSDBDriver
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.FixMethodOrder
;
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java
0 → 100644
浏览文件 @
0dc94d66
package
com.taosdata.jdbc.rs
;
import
com.taosdata.jdbc.TSDBConnection
;
import
com.taosdata.jdbc.TSDBDriver
;
import
com.taosdata.jdbc.TSDBResultSet
;
import
com.taosdata.jdbc.TSDBSubscribe
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
javax.management.OperationsException
;
import
java.sql.*
;
import
java.util.Properties
;
public
class
RestfulConnectionTest
{
// private static final String host = "127.0.0.1";
private
static
final
String
host
=
"master"
;
private
static
Connection
conn
;
@Test
public
void
getConnection
()
{
// already test in beforeClass method
}
@Test
public
void
createStatement
()
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
ResultSet
rs
=
stmt
.
executeQuery
(
"select server_status()"
);
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
prepareStatement
()
throws
SQLException
{
PreparedStatement
pstmt
=
conn
.
prepareStatement
(
"select server_status()"
);
ResultSet
rs
=
pstmt
.
executeQuery
();
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
prepareCall
()
throws
SQLException
{
conn
.
prepareCall
(
"select server_status()"
);
}
@Test
public
void
nativeSQL
()
throws
SQLException
{
String
nativeSQL
=
conn
.
nativeSQL
(
"select * from log.log"
);
Assert
.
assertEquals
(
"select * from log.log"
,
nativeSQL
);
}
@Test
public
void
setAutoCommit
()
throws
SQLException
{
conn
.
setAutoCommit
(
true
);
conn
.
setAutoCommit
(
false
);
}
@Test
public
void
getAutoCommit
()
throws
SQLException
{
Assert
.
assertTrue
(
conn
.
getAutoCommit
());
}
@Test
public
void
commit
()
throws
SQLException
{
conn
.
commit
();
}
@Test
public
void
rollback
()
throws
SQLException
{
conn
.
rollback
();
}
@Test
public
void
close
()
{
// connection will close in afterClass method
}
@Test
public
void
isClosed
()
throws
SQLException
{
Assert
.
assertFalse
(
conn
.
isClosed
());
}
@Test
public
void
getMetaData
()
throws
SQLException
{
DatabaseMetaData
meta
=
conn
.
getMetaData
();
Assert
.
assertNotNull
(
meta
);
Assert
.
assertEquals
(
"com.taosdata.jdbc.rs.RestfulDriver"
,
meta
.
getDriverName
());
}
@Test
public
void
setReadOnly
()
throws
SQLException
{
conn
.
setReadOnly
(
true
);
}
@Test
public
void
isReadOnly
()
throws
SQLException
{
Assert
.
assertTrue
(
conn
.
isReadOnly
());
}
@Test
public
void
setCatalog
()
throws
SQLException
{
conn
.
setCatalog
(
"test"
);
Assert
.
assertEquals
(
"test"
,
conn
.
getCatalog
());
}
@Test
public
void
getCatalog
()
throws
SQLException
{
conn
.
setCatalog
(
"log"
);
Assert
.
assertEquals
(
"log"
,
conn
.
getCatalog
());
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setTransactionIsolation
()
throws
SQLException
{
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_NONE
);
Assert
.
assertEquals
(
Connection
.
TRANSACTION_NONE
,
conn
.
getTransactionIsolation
());
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_READ_UNCOMMITTED
);
}
@Test
public
void
getTransactionIsolation
()
throws
SQLException
{
Assert
.
assertEquals
(
Connection
.
TRANSACTION_NONE
,
conn
.
getTransactionIsolation
());
}
@Test
public
void
getWarnings
()
throws
SQLException
{
Assert
.
assertNull
(
conn
.
getWarnings
());
}
@Test
public
void
clearWarnings
()
throws
SQLException
{
conn
.
clearWarnings
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testCreateStatement
()
throws
SQLException
{
Statement
stmt
=
conn
.
createStatement
(
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
);
ResultSet
rs
=
stmt
.
executeQuery
(
"select server_status()"
);
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
conn
.
createStatement
(
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareStatement
()
throws
SQLException
{
PreparedStatement
pstmt
=
conn
.
prepareStatement
(
"select server_status()"
,
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
);
ResultSet
rs
=
pstmt
.
executeQuery
();
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
conn
.
prepareStatement
(
"select server_status"
,
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareCall
()
throws
SQLException
{
conn
.
prepareCall
(
""
,
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getTypeMap
()
throws
SQLException
{
conn
.
getTypeMap
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setTypeMap
()
throws
SQLException
{
conn
.
setTypeMap
(
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setHoldability
()
throws
SQLException
{
conn
.
setHoldability
(
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
Assert
.
assertEquals
(
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
,
conn
.
getHoldability
());
conn
.
setHoldability
(
ResultSet
.
CLOSE_CURSORS_AT_COMMIT
);
}
@Test
public
void
getHoldability
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
,
conn
.
getHoldability
());
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setSavepoint
()
throws
SQLException
{
conn
.
setSavepoint
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testSetSavepoint
()
throws
SQLException
{
conn
.
setSavepoint
(
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testRollback
()
throws
SQLException
{
conn
.
rollback
(
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
releaseSavepoint
()
throws
SQLException
{
conn
.
releaseSavepoint
(
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testCreateStatement1
()
throws
SQLException
{
Statement
stmt
=
conn
.
createStatement
(
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
ResultSet
rs
=
stmt
.
executeQuery
(
"select server_status()"
);
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
conn
.
createStatement
(
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareStatement1
()
throws
SQLException
{
PreparedStatement
pstmt
=
conn
.
prepareStatement
(
"select server_status()"
,
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
ResultSet
rs
=
pstmt
.
executeQuery
();
rs
.
next
();
int
status
=
rs
.
getInt
(
"server_status()"
);
Assert
.
assertEquals
(
1
,
status
);
conn
.
prepareStatement
(
"select server_status"
,
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareCall1
()
throws
SQLException
{
conn
.
prepareCall
(
""
,
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_READ_ONLY
,
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareStatement2
()
throws
SQLException
{
Assert
.
assertNotNull
(
""
,
Statement
.
NO_GENERATED_KEYS
);
conn
.
prepareStatement
(
""
,
Statement
.
RETURN_GENERATED_KEYS
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareStatement3
()
throws
SQLException
{
conn
.
prepareStatement
(
""
,
new
int
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testPrepareStatement4
()
throws
SQLException
{
conn
.
prepareStatement
(
""
,
new
String
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createClob
()
throws
SQLException
{
conn
.
createClob
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createBlob
()
throws
SQLException
{
conn
.
createBlob
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createNClob
()
throws
SQLException
{
conn
.
createNClob
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createSQLXML
()
throws
SQLException
{
conn
.
createSQLXML
();
}
@Test
(
expected
=
SQLException
.
class
)
public
void
isValid
()
throws
SQLException
{
Assert
.
assertTrue
(
conn
.
isValid
(
10
));
Assert
.
assertTrue
(
conn
.
isValid
(
0
));
conn
.
isValid
(-
1
);
}
@Test
public
void
setClientInfo
()
throws
SQLClientInfoException
{
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"en_US.UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTC-8"
);
}
@Test
public
void
testSetClientInfo
()
throws
SQLClientInfoException
{
Properties
properties
=
new
Properties
();
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"
);
conn
.
setClientInfo
(
properties
);
}
@Test
public
void
getClientInfo
()
throws
SQLException
{
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
Properties
info
=
conn
.
getClientInfo
();
String
charset
=
info
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
);
Assert
.
assertEquals
(
"UTF-8"
,
charset
);
String
locale
=
info
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
);
Assert
.
assertEquals
(
"en_US.UTF-8"
,
locale
);
String
timezone
=
info
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
);
Assert
.
assertEquals
(
"UTC-8"
,
timezone
);
}
@Test
public
void
testGetClientInfo
()
throws
SQLException
{
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
conn
.
setClientInfo
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
String
charset
=
conn
.
getClientInfo
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
);
Assert
.
assertEquals
(
"UTF-8"
,
charset
);
String
locale
=
conn
.
getClientInfo
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
);
Assert
.
assertEquals
(
"en_US.UTF-8"
,
locale
);
String
timezone
=
conn
.
getClientInfo
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
);
Assert
.
assertEquals
(
"UTC-8"
,
timezone
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createArrayOf
()
throws
SQLException
{
conn
.
createArrayOf
(
""
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
createStruct
()
throws
SQLException
{
conn
.
createStruct
(
""
,
null
);
}
@Test
public
void
setSchema
()
throws
SQLException
{
conn
.
setSchema
(
"test"
);
}
@Test
public
void
getSchema
()
throws
SQLException
{
Assert
.
assertNull
(
conn
.
getSchema
());
}
@Test
public
void
abort
()
throws
SQLException
{
conn
.
abort
(
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setNetworkTimeout
()
throws
SQLException
{
conn
.
setNetworkTimeout
(
null
,
1000
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getNetworkTimeout
()
throws
SQLException
{
conn
.
getNetworkTimeout
();
}
@Test
public
void
unwrap
()
{
try
{
RestfulConnection
restfulConnection
=
conn
.
unwrap
(
RestfulConnection
.
class
);
Assert
.
assertNotNull
(
restfulConnection
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
isWrapperFor
()
throws
SQLException
{
Assert
.
assertTrue
(
conn
.
isWrapperFor
(
RestfulConnection
.
class
));
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.rs.RestfulDriver"
);
Properties
properties
=
new
Properties
();
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"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS-RS://"
+
host
+
":6041/log?user=root&password=taosdata"
,
properties
);
// create test database for test cases
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
"create database if not exists test"
);
}
}
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
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java
0 → 100644
浏览文件 @
0dc94d66
此差异已折叠。
点击以展开。
src/plugins/http/src/httpContext.c
浏览文件 @
0dc94d66
...
...
@@ -186,9 +186,9 @@ void httpCloseContextByApp(HttpContext *pContext) {
pContext
->
parsed
=
false
;
bool
keepAlive
=
true
;
if
(
parser
->
httpVersion
==
HTTP_VERSION_10
&&
parser
->
keepAlive
!=
HTTP_KEEPALIVE_ENABLE
)
{
if
(
parser
&&
parser
->
httpVersion
==
HTTP_VERSION_10
&&
parser
->
keepAlive
!=
HTTP_KEEPALIVE_ENABLE
)
{
keepAlive
=
false
;
}
else
if
(
parser
->
httpVersion
!=
HTTP_VERSION_10
&&
parser
->
keepAlive
==
HTTP_KEEPALIVE_DISABLE
)
{
}
else
if
(
parser
&&
parser
->
httpVersion
!=
HTTP_VERSION_10
&&
parser
->
keepAlive
==
HTTP_KEEPALIVE_DISABLE
)
{
keepAlive
=
false
;
}
else
{
}
...
...
tests/examples/JDBC/taosdemo/pom.xml
浏览文件 @
0dc94d66
...
...
@@ -67,7 +67,7 @@
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.1
8
</version>
<version>
2.0.1
9
</version>
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
</dependency>
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
浏览文件 @
0dc94d66
...
...
@@ -4,6 +4,7 @@ import com.taosdata.taosdemo.components.DataSourceFactory;
import
com.taosdata.taosdemo.components.JdbcTaosdemoConfig
;
import
com.taosdata.taosdemo.domain.SuperTableMeta
;
import
com.taosdata.taosdemo.service.DatabaseService
;
import
com.taosdata.taosdemo.service.QueryService
;
import
com.taosdata.taosdemo.service.SubTableService
;
import
com.taosdata.taosdemo.service.SuperTableService
;
import
com.taosdata.taosdemo.service.data.SuperTableMetaGenerator
;
...
...
@@ -34,6 +35,7 @@ public class TaosDemoApplication {
final
DatabaseService
databaseService
=
new
DatabaseService
(
dataSource
);
final
SuperTableService
superTableService
=
new
SuperTableService
(
dataSource
);
final
SubTableService
subTableService
=
new
SubTableService
(
dataSource
);
final
QueryService
queryService
=
new
QueryService
(
dataSource
);
// 创建数据库
long
start
=
System
.
currentTimeMillis
();
Map
<
String
,
String
>
databaseParam
=
new
HashMap
<>();
...
...
@@ -90,6 +92,11 @@ public class TaosDemoApplication {
int
affectedRows
=
subTableService
.
insertMultiThreads
(
superTableMeta
,
threadSize
,
tableSize
,
startTime
,
gap
,
config
);
end
=
System
.
currentTimeMillis
();
logger
.
info
(
"insert "
+
affectedRows
+
" rows, time cost: "
+
(
end
-
start
)
+
" ms"
);
/**********************************************************************************/
// 查询
/**********************************************************************************/
// 删除表
if
(
config
.
dropTable
)
{
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/DataSourceFactory.java
浏览文件 @
0dc94d66
...
...
@@ -23,7 +23,6 @@ public class DataSourceFactory {
properties
.
load
(
is
);
HikariConfig
config
=
new
HikariConfig
();
if
(
properties
.
containsKey
(
"jdbc.driver"
))
{
// String driverName = properties.getProperty("jdbc.driver");
// System.out.println(">>> load driver : " + driverName);
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/QueryService.java
0 → 100644
浏览文件 @
0dc94d66
package
com.taosdata.taosdemo.service
;
import
com.taosdata.jdbc.utils.SqlSyntaxValidator
;
import
javax.sql.DataSource
;
import
java.sql.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
import
java.util.stream.IntStream
;
public
class
QueryService
{
private
final
DataSource
dataSource
;
public
QueryService
(
DataSource
dataSource
)
{
this
.
dataSource
=
dataSource
;
}
/* only select or show SQL Statement is valid for executeQuery */
public
Boolean
[]
areValidQueries
(
String
[]
sqls
)
{
Boolean
[]
ret
=
new
Boolean
[
sqls
.
length
];
for
(
int
i
=
0
;
i
<
sqls
.
length
;
i
++)
{
ret
[
i
]
=
true
;
if
(!
SqlSyntaxValidator
.
isValidForExecuteQuery
(
sqls
[
i
]))
{
ret
[
i
]
=
false
;
continue
;
}
try
(
Connection
conn
=
dataSource
.
getConnection
();
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
executeQuery
(
sqls
[
i
]);
}
catch
(
SQLException
e
)
{
ret
[
i
]
=
false
;
continue
;
}
}
return
ret
;
}
public
String
[]
generateSuperTableQueries
(
String
dbName
)
{
List
<
String
>
sqls
=
new
ArrayList
<>();
try
(
Connection
conn
=
dataSource
.
getConnection
();
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
"use "
+
dbName
);
ResultSet
rs
=
stmt
.
executeQuery
(
"show stables"
);
while
(
rs
.
next
())
{
String
name
=
rs
.
getString
(
"name"
);
sqls
.
add
(
"select count(*) from "
+
dbName
+
"."
+
name
);
sqls
.
add
(
"select first(*) from "
+
dbName
+
"."
+
name
);
sqls
.
add
(
"select last(*) from "
+
dbName
+
"."
+
name
);
sqls
.
add
(
"select last_row(*) from "
+
dbName
+
"."
+
name
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
String
[]
sqlArr
=
new
String
[
sqls
.
size
()];
return
sqls
.
toArray
(
sqlArr
);
}
public
void
querySuperTable
(
String
[]
sqls
,
int
interval
,
int
threadCount
,
long
queryTimes
)
{
List
<
Thread
>
threads
=
IntStream
.
range
(
0
,
threadCount
).
mapToObj
(
i
->
new
Thread
(()
->
{
// do query
try
(
Connection
conn
=
dataSource
.
getConnection
();
Statement
stmt
=
conn
.
createStatement
())
{
long
count
=
queryTimes
;
if
(
count
==
0
)
count
=
Long
.
MAX_VALUE
;
while
(
count
>
0
)
{
for
(
String
sql
:
sqls
)
{
long
start
=
System
.
currentTimeMillis
();
ResultSet
rs
=
stmt
.
executeQuery
(
sql
);
printResultSet
(
rs
);
long
end
=
System
.
currentTimeMillis
();
long
timecost
=
end
-
start
;
if
(
interval
-
timecost
>
0
)
{
TimeUnit
.
MILLISECONDS
.
sleep
(
interval
-
timecost
);
}
}
count
--;
}
}
catch
(
SQLException
|
InterruptedException
e
)
{
e
.
printStackTrace
();
}
})).
collect
(
Collectors
.
toList
());
threads
.
stream
().
forEach
(
Thread:
:
start
);
for
(
Thread
thread
:
threads
)
{
try
{
thread
.
join
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
private
void
printResultSet
(
ResultSet
rs
)
throws
SQLException
{
ResultSetMetaData
meta
=
rs
.
getMetaData
();
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
System
.
out
.
print
(
meta
.
getColumnLabel
(
i
)
+
": "
+
rs
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
();
}
}
}
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/TableService.java
浏览文件 @
0dc94d66
...
...
@@ -2,7 +2,6 @@ package com.taosdata.taosdemo.service;
import
com.taosdata.taosdemo.dao.TableMapper
;
import
com.taosdata.taosdemo.domain.TableMeta
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
...
...
tests/examples/JDBC/taosdemo/src/main/resources/query.json
浏览文件 @
0dc94d66
...
...
@@ -7,10 +7,10 @@
"password"
:
"taosdata"
,
"databases"
:
"db01"
,
"super_table_query"
:
{
"rate"
:
1
,
"concurrent"
:
1
,
{
"rate"
:
1
,
"concurrent"
:
1
,
"time"
:
10000
,
"sqls"
:
[{
"sql"
:
"select count(*) from stb01"
,
"result"
:
"./query_res0.txt"
}]
},
"sub_table_query"
:
"sub_table_query"
:
{
"stblname"
:
"stb01"
,
"rate"
:
1
,
"threads"
:
1
,
"sqls"
:
[{
"sql"
:
"select count(*) from xxxx"
,
"result"
:
"./query_res1.txt"
}]
}
...
...
tests/examples/JDBC/taosdemo/src/test/java/com/taosdata/taosdemo/service/QueryServiceTest.java
0 → 100644
浏览文件 @
0dc94d66
package
com.taosdata.taosdemo.service
;
import
com.zaxxer.hikari.HikariConfig
;
import
com.zaxxer.hikari.HikariDataSource
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
public
class
QueryServiceTest
{
private
static
QueryService
queryService
;
@Test
public
void
areValidQueries
()
{
}
@Test
public
void
generateSuperTableQueries
()
{
String
[]
sqls
=
queryService
.
generateSuperTableQueries
(
"restful_test"
);
for
(
String
sql
:
sqls
)
{
System
.
out
.
println
(
sql
);
}
}
@Test
public
void
querySuperTable
()
{
String
[]
sqls
=
queryService
.
generateSuperTableQueries
(
"restful_test"
);
queryService
.
querySuperTable
(
sqls
,
1000
,
10
,
10
);
}
@BeforeClass
public
static
void
beforeClass
()
throws
ClassNotFoundException
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
HikariConfig
config
=
new
HikariConfig
();
config
.
setJdbcUrl
(
"jdbc:TAOS://127.0.0.1:6030/?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8"
);
config
.
setUsername
(
"root"
);
config
.
setPassword
(
"taosdata"
);
HikariDataSource
dataSource
=
new
HikariDataSource
(
config
);
queryService
=
new
QueryService
(
dataSource
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录