Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
哥们要飞
TDengine
提交
5800fdf9
T
TDengine
项目概览
哥们要飞
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5800fdf9
编写于
6月 02, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-314]
上级
18528495
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
74 addition
and
57 deletion
+74
-57
src/client/src/TSDBJNIConnector.c
src/client/src/TSDBJNIConnector.c
+74
-57
未找到文件。
src/client/src/TSDBJNIConnector.c
浏览文件 @
5800fdf9
...
...
@@ -13,19 +13,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "com_taosdata_jdbc_TSDBJNIConnector.h"
#include "os.h"
#include "taos.h"
#include "t
scSubquery
.h"
#include "t
log
.h"
#include "tscUtil.h"
#include "tsclient.h"
#include "tlog.h"
#include "ttime.h"
#define jniError(...) { if (jniDebugFlag & DEBUG_ERROR) { taosPrintLog("ERROR JNI ", jniDebugFlag, __VA_ARGS__); }}
#define jniWarn(...) { if (jniDebugFlag & DEBUG_WARN) { taosPrintLog("WARN JNI ", jniDebugFlag, __VA_ARGS__); }}
#define jniTrace(...) { if (jniDebugFlag & DEBUG_TRACE) { taosPrintLog("JNI ", jniDebugFlag, __VA_ARGS__); }}
#define jniPrint(...) { taosPrintLog("JNI ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }
#include "com_taosdata_jdbc_TSDBJNIConnector.h"
#define jniError(...) \
{ \
if (jniDebugFlag & DEBUG_ERROR) { \
taosPrintLog("ERROR JNI ", jniDebugFlag, __VA_ARGS__); \
} \
}
#define jniWarn(...) \
{ \
if (jniDebugFlag & DEBUG_WARN) { \
taosPrintLog("WARN JNI ", jniDebugFlag, __VA_ARGS__); \
} \
}
#define jniTrace(...) \
{ \
if (jniDebugFlag & DEBUG_TRACE) { \
taosPrintLog("JNI ", jniDebugFlag, __VA_ARGS__); \
} \
}
#define jniPrint(...) \
{ taosPrintLog("JNI ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }
int
__init
=
0
;
...
...
@@ -117,7 +133,8 @@ void jniGetGlobalMethod(JNIEnv *env) {
jniTrace
(
"native method register finished"
);
}
JNIEXPORT
void
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_setAllocModeImp
(
JNIEnv
*
env
,
jobject
jobj
,
jint
jMode
,
jstring
jPath
,
jboolean
jAutoDump
)
{
JNIEXPORT
void
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_setAllocModeImp
(
JNIEnv
*
env
,
jobject
jobj
,
jint
jMode
,
jstring
jPath
,
jboolean
jAutoDump
)
{
if
(
jPath
!=
NULL
)
{
const
char
*
path
=
(
*
env
)
->
GetStringUTFChars
(
env
,
jPath
,
NULL
);
taosSetAllocMode
(
jMode
,
path
,
!!
jAutoDump
);
...
...
@@ -264,7 +281,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(
(
*
env
)
->
GetByteArrayRegion
(
env
,
jsql
,
0
,
len
,
(
jbyte
*
)
dst
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
//todo handle error
//
todo handle error
}
jniTrace
(
"jobj:%p, conn:%p, sql:%s"
,
jobj
,
tscon
,
dst
);
...
...
@@ -285,7 +302,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(
}
free
(
dst
);
return
(
jlong
)
pSql
;
return
(
jlong
)
pSql
;
}
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
con
)
{
...
...
@@ -299,31 +316,32 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp(JNI
}
JNIEXPORT
jstring
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_getErrMsgImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
tres
)
{
TAOS_RES
*
pSql
=
(
TAOS_RES
*
)
tres
;
TAOS_RES
*
pSql
=
(
TAOS_RES
*
)
tres
;
return
(
*
env
)
->
NewStringUTF
(
env
,
(
const
char
*
)
taos_errstr
(
pSql
));
}
JNIEXPORT
jlong
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
con
,
jlong
tres
)
{
JNIEXPORT
jlong
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
con
,
jlong
tres
)
{
TAOS
*
tscon
=
(
TAOS
*
)
con
;
if
(
tscon
==
NULL
)
{
jniError
(
"jobj:%p, connection is closed"
,
jobj
);
return
JNI_CONNECTION_NULL
;
}
if
((
void
*
)
tres
==
NULL
)
{
if
((
void
*
)
tres
==
NULL
)
{
jniError
(
"jobj:%p, conn:%p, resultset is null"
,
jobj
,
tscon
);
return
JNI_RESULT_SET_NULL
;
}
SSqlObj
*
pSql
=
(
TAOS_RES
*
)
tres
;
STscObj
*
pObj
=
pSql
->
pTscObj
;
SSqlObj
*
pSql
=
(
TAOS_RES
*
)
tres
;
STscObj
*
pObj
=
pSql
->
pTscObj
;
if
(
tscIsUpdateQuery
(
pSql
))
{
taos_free_result
(
pSql
);
// free result here
jniTrace
(
"jobj:%p, conn:%p, no resultset, %p"
,
jobj
,
pObj
,
(
void
*
)
tres
);
jniTrace
(
"jobj:%p, conn:%p, no resultset, %p"
,
jobj
,
pObj
,
(
void
*
)
tres
);
return
0
;
}
else
{
jniTrace
(
"jobj:%p, conn:%p, get resultset, %p"
,
jobj
,
pObj
,
(
void
*
)
tres
);
jniTrace
(
"jobj:%p, conn:%p, get resultset, %p"
,
jobj
,
pObj
,
(
void
*
)
tres
);
return
tres
;
}
}
...
...
@@ -346,8 +364,8 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp(
return
JNI_SUCCESS
;
}
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_getAffectedRowsImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
con
,
jlong
res
)
{
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_getAffectedRowsImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
con
,
jlong
res
)
{
TAOS
*
tscon
=
(
TAOS
*
)
con
;
if
(
tscon
==
NULL
)
{
jniError
(
"jobj:%p, connection is closed"
,
jobj
);
...
...
@@ -359,7 +377,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getAffectedRowsIm
return
JNI_RESULT_SET_NULL
;
}
jint
ret
=
taos_affected_rows
((
SSqlObj
*
)
res
);
jint
ret
=
taos_affected_rows
((
SSqlObj
*
)
res
);
jniTrace
(
"jobj:%p, conn:%p, sql:%p, affect rows:%d"
,
jobj
,
tscon
,
(
void
*
)
con
,
res
,
ret
);
return
ret
;
...
...
@@ -483,24 +501,22 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn
float
fv
=
0
;
fv
=
GET_FLOAT_VAL
(
row
[
i
]);
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_rowdataSetFloatFp
,
i
,
(
jfloat
)
fv
);
}
break
;
}
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
dv
=
0
;
dv
=
GET_DOUBLE_VAL
(
row
[
i
]);
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_rowdataSetDoubleFp
,
i
,
(
jdouble
)
dv
);
}
break
;
}
break
;
case
TSDB_DATA_TYPE_BINARY
:
{
strncpy
(
tmp
,
row
[
i
],
(
size_t
)
fields
[
i
].
bytes
);
// handle the case that terminated does not exist
strncpy
(
tmp
,
row
[
i
],
(
size_t
)
fields
[
i
].
bytes
);
// handle the case that terminated does not exist
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_rowdataSetStringFp
,
i
,
(
*
env
)
->
NewStringUTF
(
env
,
tmp
));
memset
(
tmp
,
0
,
(
size_t
)
fields
[
i
].
bytes
);
memset
(
tmp
,
0
,
(
size_t
)
fields
[
i
].
bytes
);
break
;
}
case
TSDB_DATA_TYPE_NCHAR
:
{
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_rowdataSetByteArrayFp
,
i
,
jniFromNCharToByteArray
(
env
,
(
char
*
)
row
[
i
],
fields
[
i
].
bytes
));
jniFromNCharToByteArray
(
env
,
(
char
*
)
row
[
i
],
fields
[
i
].
bytes
));
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
...
...
@@ -528,7 +544,8 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_closeConnectionIm
}
JNIEXPORT
jlong
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_subscribeImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
con
,
jboolean
restart
,
jstring
jtopic
,
jstring
jsql
,
jint
jinterval
)
{
jboolean
restart
,
jstring
jtopic
,
jstring
jsql
,
jint
jinterval
)
{
jlong
sub
=
0
;
TAOS
*
taos
=
(
TAOS
*
)
con
;
char
*
topic
=
NULL
;
...
...
@@ -559,7 +576,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_subscribeImp(JNI
return
sub
;
}
static
jobject
convert_one_row
(
JNIEnv
*
env
,
TAOS_ROW
row
,
TAOS_FIELD
*
fields
,
int
num_fields
)
{
static
jobject
convert_one_row
(
JNIEnv
*
env
,
TAOS_ROW
row
,
TAOS_FIELD
*
fields
,
int
num_fields
)
{
jobject
rowobj
=
(
*
env
)
->
NewObject
(
env
,
g_rowdataClass
,
g_rowdataConstructor
,
num_fields
);
jniTrace
(
"created a rowdata object, rowobj:%p"
,
rowobj
);
...
...
@@ -588,25 +605,23 @@ static jobject convert_one_row(JNIEnv *env, TAOS_ROW row, TAOS_FIELD* fields, in
float
fv
=
0
;
fv
=
GET_FLOAT_VAL
(
row
[
i
]);
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_rowdataSetFloatFp
,
i
,
(
jfloat
)
fv
);
}
break
;
case
TSDB_DATA_TYPE_DOUBLE
:{
}
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
dv
=
0
;
dv
=
GET_DOUBLE_VAL
(
row
[
i
]);
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_rowdataSetDoubleFp
,
i
,
(
jdouble
)
dv
);
}
break
;
}
break
;
case
TSDB_DATA_TYPE_BINARY
:
{
char
tmp
[
TSDB_MAX_BYTES_PER_ROW
]
=
{
0
};
strncpy
(
tmp
,
row
[
i
],
(
size_t
)
fields
[
i
].
bytes
);
// handle the case that terminated does not exist
strncpy
(
tmp
,
row
[
i
],
(
size_t
)
fields
[
i
].
bytes
);
// handle the case that terminated does not exist
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_rowdataSetStringFp
,
i
,
(
*
env
)
->
NewStringUTF
(
env
,
tmp
));
memset
(
tmp
,
0
,
(
size_t
)
fields
[
i
].
bytes
);
memset
(
tmp
,
0
,
(
size_t
)
fields
[
i
].
bytes
);
break
;
}
case
TSDB_DATA_TYPE_NCHAR
:
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_rowdataSetByteArrayFp
,
i
,
jniFromNCharToByteArray
(
env
,
(
char
*
)
row
[
i
],
fields
[
i
].
bytes
));
jniFromNCharToByteArray
(
env
,
(
char
*
)
row
[
i
],
fields
[
i
].
bytes
));
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_rowdataSetTimestampFp
,
i
,
(
jlong
)
*
((
int64_t
*
)
row
[
i
]));
...
...
@@ -618,7 +633,8 @@ static jobject convert_one_row(JNIEnv *env, TAOS_ROW row, TAOS_FIELD* fields, in
return
rowobj
;
}
JNIEXPORT
jobject
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_consumeImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
sub
,
jint
timeout
)
{
JNIEXPORT
jobject
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_consumeImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
sub
,
jint
timeout
)
{
jniTrace
(
"jobj:%p, in TSDBJNIConnector_consumeImp, sub:%ld"
,
jobj
,
sub
);
jniGetGlobalMethod
(
env
);
...
...
@@ -629,7 +645,7 @@ JNIEXPORT jobject JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_consumeImp(JNI
int
count
=
0
;
while
(
true
)
{
TAOS_RES
*
res
=
taos_consume
(
tsub
);
TAOS_RES
*
res
=
taos_consume
(
tsub
);
if
(
res
==
NULL
)
{
jniError
(
"jobj:%p, tsub:%p, taos_consume returns NULL"
,
jobj
,
tsub
);
return
NULL
;
...
...
@@ -662,7 +678,8 @@ JNIEXPORT jobject JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_consumeImp(JNI
return
rows
;
}
JNIEXPORT
void
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_unsubscribeImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
sub
,
jboolean
keepProgress
)
{
JNIEXPORT
void
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_unsubscribeImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
sub
,
jboolean
keepProgress
)
{
TAOS_SUB
*
tsub
=
(
TAOS_SUB
*
)
sub
;
taos_unsubscribe
(
tsub
,
keepProgress
);
}
...
...
@@ -685,7 +702,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_validateCreateTab
char
*
dst
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
(
len
+
1
));
(
*
env
)
->
GetByteArrayRegion
(
env
,
jsql
,
0
,
len
,
(
jbyte
*
)
dst
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
//todo handle error
//
todo handle error
}
int
code
=
taos_validate_sql
(
tscon
,
dst
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录