提交 8c90553a 编写于 作者: H huolibo

[TD-10401]<feat>:add JNIConnector corresponding c code

上级 4c6ccf5f
......@@ -239,6 +239,22 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_closeStmt(JNIEnv
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setTableNameTagsImp
(JNIEnv *, jobject, jlong, jstring, jint, jbyteArray, jbyteArray, jbyteArray, jbyteArray, jlong);
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
* Method: insertTelnetLinesImp
* Signature: ([Ljava/lang/String;J)I
*/
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_insertTelnetLinesImp
(JNIEnv *, jobject, jobjectArray, jlong);
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
* Method: insertJsonPayloadImp
* Signature: (Ljava/lang/String;J)I
*/
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_insertJsonPayloadImp
(JNIEnv *, jobject, jstring, jlong);
#ifdef __cplusplus
}
#endif
......
......@@ -98,6 +98,7 @@ jmethodID g_blockdataSetNumOfColsFp;
#define JNI_SQL_NULL -5
#define JNI_FETCH_END -6
#define JNI_OUT_OF_MEMORY -7
#define JNI_PARAMETER_NULL -8
static void jniGetGlobalMethod(JNIEnv *env) {
// make sure init function executed once
......@@ -1085,3 +1086,67 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_insertLinesImp(J
}
return code;
}
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_insertTelnetLinesImp(JNIEnv *env, jobject jobj,
jobjectArray lines, jlong conn) {
TAOS *taos = (TAOS *)conn;
if (taos == NULL) {
jniError("jobj:%p, connection already closed", jobj);
return JNI_CONNECTION_NULL;
}
int numLines = (*env)->GetArrayLength(env, lines);
char **c_lines = calloc(numLines, sizeof(char *));
if (c_lines == NULL) {
jniError("c_lines:%p, alloc memory failed", c_lines);
return JNI_OUT_OF_MEMORY;
}
for (int i = 0; i < numLines; ++i) {
jstring line = (jstring)((*env)->GetObjectArrayElement(env, lines, i));
c_lines[i] = (char *)(*env)->GetStringUTFChars(env, line, 0);
}
int code = taos_insert_telnet_lines(taos, c_lines, numLines);
for (int i = 0; i < numLines; ++i) {
jstring line = (jstring)((*env)->GetObjectArrayElement(env, lines, i));
(*env)->ReleaseStringUTFChars(env, line, c_lines[i]);
}
tfree(c_lines);
if (code != TSDB_CODE_SUCCESS) {
jniError("jobj:%p, conn:%p, code:%s", jobj, taos, tstrerror(code));
return JNI_TDENGINE_ERROR;
}
return code;
}
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_insertJsonPayloadImp(JNIEnv *env, jobject jobj, jstring jsonString, jlong conn){
TAOS *taos = (TAOS *)conn;
if (taos == NULL) {
jniError("jobj:%p, connection already closed", jobj);
return JNI_CONNECTION_NULL;
}
char *payload = NULL;
if (jsonString != NULL) {
payload = (char *)(*env)->GetStringUTFChars(env, jsonString, NULL);
}
if (payload == NULL) {
jniDebug("jobj:%p, invalid argument: opentsdb insert json is NULL", jobj);
return JNI_PARAMETER_NULL;
}
int code = taos_insert_json_payload(taos, payload);
(*env)->ReleaseStringUTFChars(env, jsonString, payload);
if (code != TSDB_CODE_SUCCESS) {
jniError("jobj:%p, conn:%p, code:%s", jobj, taos, tstrerror(code));
return JNI_TDENGINE_ERROR;
}
return code;
}
\ No newline at end of file
......@@ -376,13 +376,13 @@ public class TSDBJNIConnector {
* @throws SQLException execute insert error
*/
public void insertTelnetLines(String[] lines) throws SQLException {
int code = insertTelnetLinesImp(lines, lines.length, this.taos);
int code = insertTelnetLinesImp(lines, this.taos);
if (TSDBConstants.JNI_SUCCESS != code) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to insertTelnetLines");
}
}
private native int insertTelnetLinesImp(String[] lines, int numOfRows, long conn);
private native int insertTelnetLinesImp(String[] lines, long conn);
/**
* insert openTSDB data with json format
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册