Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1d336b63
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1d336b63
编写于
3月 11, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
129f98e1
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
89 addition
and
127 deletion
+89
-127
src/connector/jdbc/src/main/java/com/taosdata/jdbc/ColumnMetaData.java
.../jdbc/src/main/java/com/taosdata/jdbc/ColumnMetaData.java
+10
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
.../jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
+3
-4
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+6
-2
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
+26
-31
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
+5
-5
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
...src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
+39
-85
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/ColumnMetaData.java
浏览文件 @
1d336b63
...
...
@@ -52,4 +52,14 @@ public class ColumnMetaData {
public
void
setColIndex
(
int
colIndex
)
{
this
.
colIndex
=
colIndex
;
}
@Override
public
String
toString
()
{
return
"ColumnMetaData{"
+
"colType="
+
colType
+
", colName='"
+
colName
+
'\''
+
", colSize="
+
colSize
+
", colIndex="
+
colIndex
+
'}'
;
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
浏览文件 @
1d336b63
...
...
@@ -87,11 +87,10 @@ public class TSDBConnection extends AbstractConnection {
}
public
void
close
()
throws
SQLException
{
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
this
.
isClosed
=
true
;
if
(
isClosed
)
return
;
this
.
connector
.
closeConnection
();
this
.
isClosed
=
true
;
}
public
boolean
isClosed
()
throws
SQLException
{
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
浏览文件 @
1d336b63
/***************************************************************************
/**
* *************************************************************************
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
...
...
@@ -11,7 +12,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
****************************************************************************
*/
package
com.taosdata.jdbc
;
import
com.taosdata.jdbc.utils.TaosInfo
;
...
...
@@ -20,6 +21,9 @@ import java.sql.SQLException;
import
java.sql.SQLWarning
;
import
java.util.List
;
/**
* JNI connector
* */
public
class
TSDBJNIConnector
{
private
static
volatile
Boolean
isInitialized
=
false
;
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
浏览文件 @
1d336b63
...
...
@@ -20,18 +20,16 @@ import java.util.ArrayList;
import
java.util.List
;
public
class
TSDBResultSet
extends
AbstractResultSet
implements
ResultSet
{
private
TSDBJNIConnector
jniConnector
;
private
final
TSDBJNIConnector
jniConnector
;
private
final
TSDBStatement
statement
;
private
long
resultSetPointer
=
0L
;
private
final
long
resultSetPointer
;
private
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
private
TSDBResultSetRowData
rowData
;
private
TSDBResultSetBlockData
blockData
;
private
final
TSDBResultSetRowData
rowData
;
private
final
TSDBResultSetBlockData
blockData
;
private
boolean
batchFetch
=
false
;
private
boolean
lastWasNull
=
false
;
private
final
int
COLUMN_INDEX_START_VALUE
=
1
;
private
boolean
isClosed
;
public
void
setBatchFetch
(
boolean
batchFetch
)
{
this
.
batchFetch
=
batchFetch
;
...
...
@@ -56,13 +54,13 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
int
code
=
this
.
jniConnector
.
getSchemaMetaData
(
this
.
resultSetPointer
,
this
.
columnMetaDataList
);
if
(
code
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
if
(
code
==
TSDBConstants
.
JNI_RESULT_SET_NULL
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_RESULT_SET_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_RESULT_SET_NULL
);
}
if
(
code
==
TSDBConstants
.
JNI_NUM_OF_FIELDS_0
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_NUM_OF_FIELDS_0
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_NUM_OF_FIELDS_0
);
}
this
.
rowData
=
new
TSDBResultSetRowData
(
this
.
columnMetaDataList
.
size
());
this
.
blockData
=
new
TSDBResultSetBlockData
(
this
.
columnMetaDataList
,
this
.
columnMetaDataList
.
size
());
...
...
@@ -78,16 +76,12 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
this
.
blockData
.
reset
();
if
(
code
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
else
if
(
code
==
TSDBConstants
.
JNI_RESULT_SET_NULL
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_RESULT_SET_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_RESULT_SET_NULL
);
}
else
if
(
code
==
TSDBConstants
.
JNI_NUM_OF_FIELDS_0
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_NUM_OF_FIELDS_0
));
}
else
if
(
code
==
TSDBConstants
.
JNI_FETCH_END
)
{
return
false
;
}
return
true
;
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_NUM_OF_FIELDS_0
);
}
else
return
code
!=
TSDBConstants
.
JNI_FETCH_END
;
}
else
{
if
(
rowData
!=
null
)
{
this
.
rowData
.
clear
();
...
...
@@ -95,11 +89,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
int
code
=
this
.
jniConnector
.
fetchRow
(
this
.
resultSetPointer
,
this
.
rowData
);
if
(
code
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
else
if
(
code
==
TSDBConstants
.
JNI_RESULT_SET_NULL
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_RESULT_SET_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_RESULT_SET_NULL
);
}
else
if
(
code
==
TSDBConstants
.
JNI_NUM_OF_FIELDS_0
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_NUM_OF_FIELDS_0
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_NUM_OF_FIELDS_0
);
}
else
if
(
code
==
TSDBConstants
.
JNI_FETCH_END
)
{
return
false
;
}
else
{
...
...
@@ -109,14 +103,17 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
}
public
void
close
()
throws
SQLException
{
if
(
isClosed
)
return
;
if
(
this
.
jniConnector
!=
null
)
{
int
code
=
this
.
jniConnector
.
freeResultSet
(
this
.
resultSetPointer
);
if
(
code
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
else
if
(
code
==
TSDBConstants
.
JNI_RESULT_SET_NULL
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_RESULT_SET_NULL
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_RESULT_SET_NULL
);
}
}
isClosed
=
true
;
}
public
boolean
wasNull
()
throws
SQLException
{
...
...
@@ -415,8 +412,8 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
}
public
boolean
isClosed
()
throws
SQLException
{
//TODO: check if need release resources
boolean
isClosed
=
true
;
if
(
isClosed
)
return
true
;
if
(
jniConnector
!=
null
)
{
isClosed
=
jniConnector
.
isResultsetClosed
();
}
...
...
@@ -429,14 +426,12 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
}
private
int
getTrueColumnIndex
(
int
columnIndex
)
throws
SQLException
{
if
(
columnIndex
<
this
.
COLUMN_INDEX_START_VALUE
)
{
throw
new
SQLException
(
"Column Index out of range, "
+
columnIndex
+
" < "
+
this
.
COLUMN_INDEX_START_VALUE
);
}
if
(
columnIndex
<
1
)
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_PARAMETER_INDEX_OUT_RANGE
,
"columnIndex("
+
columnIndex
+
"): < 1"
);
int
numOfCols
=
this
.
columnMetaDataList
.
size
();
if
(
columnIndex
>
numOfCols
)
{
throw
new
SQLException
(
"Column Index out of range, "
+
columnIndex
+
" > "
+
numOfCols
);
}
if
(
columnIndex
>
numOfCols
)
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_PARAMETER_INDEX_OUT_RANGE
,
"columnIndex: "
+
columnIndex
);
return
columnIndex
-
1
;
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
浏览文件 @
1d336b63
...
...
@@ -73,11 +73,11 @@ public class TSDBStatement extends AbstractStatement {
}
public
void
close
()
throws
SQLException
{
if
(
!
isClosed
)
{
if
(
this
.
resultSet
!=
null
)
this
.
resultSet
.
close
();
isClosed
=
true
;
}
if
(
isClosed
)
return
;
if
(
this
.
resultSet
!=
null
&&
!
this
.
resultSet
.
isClosed
())
this
.
resultSet
.
close
()
;
isClosed
=
true
;
}
public
boolean
execute
(
String
sql
)
throws
SQLException
{
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
浏览文件 @
1d336b63
...
...
@@ -7,10 +7,10 @@ import java.sql.SQLWarning;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.*;
public
class
TSDBJNIConnectorTest
{
private
static
TSDBResultSetRowData
rowData
;
public
static
void
main
(
String
[]
args
)
{
try
{
TSDBJNIConnector
.
init
(
"/etc/taos/taos.cfg"
,
"en_US.UTF-8"
,
""
,
""
);
...
...
@@ -24,7 +24,6 @@ public class TSDBJNIConnectorTest {
}
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
int
code
=
connector
.
getSchemaMetaData
(
pSql
,
columnMetaDataList
);
if
(
code
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
...
...
@@ -35,6 +34,27 @@ public class TSDBJNIConnectorTest {
if
(
code
==
TSDBConstants
.
JNI_NUM_OF_FIELDS_0
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_NUM_OF_FIELDS_0
));
}
int
columnSize
=
columnMetaDataList
.
size
();
// print metadata
for
(
int
i
=
0
;
i
<
columnSize
;
i
++)
{
System
.
out
.
println
(
columnMetaDataList
.
get
(
i
));
}
rowData
=
new
TSDBResultSetRowData
(
columnSize
);
// iterate resultSet
while
(
next
(
connector
,
pSql
))
{
System
.
out
.
println
(
rowData
.
getColSize
());
rowData
.
getData
().
stream
().
forEach
(
System
.
out
::
println
);
}
// close resultSet
code
=
connector
.
freeResultSet
(
pSql
);
if
(
code
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
else
if
(
code
==
TSDBConstants
.
JNI_RESULT_SET_NULL
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_RESULT_SET_NULL
);
}
// close statement
// close connection
connector
.
closeConnection
();
}
catch
(
SQLWarning
throwables
)
{
throwables
.
printStackTrace
();
...
...
@@ -43,88 +63,22 @@ public class TSDBJNIConnectorTest {
}
}
@Test
public
void
isClosed
()
{
}
@Test
public
void
isResultsetClosed
()
{
}
@Test
public
void
init
()
{
}
@Test
public
void
initImp
()
{
}
@Test
public
void
setOptions
()
{
}
@Test
public
void
getTsCharset
()
{
}
@Test
public
void
connect
()
{
}
@Test
public
void
executeQuery
()
{
}
@Test
public
void
getErrCode
()
{
}
@Test
public
void
getErrMsg
()
{
}
@Test
public
void
isUpdateQuery
()
{
}
@Test
public
void
freeResultSet
()
{
}
@Test
public
void
getAffectedRows
()
{
}
@Test
public
void
getSchemaMetaData
()
{
}
@Test
public
void
fetchRow
()
{
}
@Test
public
void
fetchBlock
()
{
}
@Test
public
void
closeConnection
()
{
}
@Test
public
void
subscribe
()
{
}
@Test
public
void
consume
()
{
}
@Test
public
void
unsubscribe
()
{
private
static
boolean
next
(
TSDBJNIConnector
connector
,
long
pSql
)
throws
SQLException
{
if
(
rowData
!=
null
)
rowData
.
clear
();
int
code
=
connector
.
fetchRow
(
pSql
,
rowData
);
if
(
code
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
else
if
(
code
==
TSDBConstants
.
JNI_RESULT_SET_NULL
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_RESULT_SET_NULL
);
}
else
if
(
code
==
TSDBConstants
.
JNI_NUM_OF_FIELDS_0
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_NUM_OF_FIELDS_0
);
}
else
if
(
code
==
TSDBConstants
.
JNI_FETCH_END
)
{
return
false
;
}
else
{
return
true
;
}
}
@Test
public
void
validateCreateTableSql
()
{
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录