Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/CSDK/src/CarbonSchemaReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobject CarbonSchemaReader::readSchema(char *path) {
return readSchema(path, conf);
}

jobject CarbonSchemaReader::readSchema(char *path, Configuration conf) {
jobject CarbonSchemaReader::readSchema(char *path, Configuration &conf) {
if (path == NULL) {
throw std::runtime_error("path parameter can't be NULL.");
}
Expand All @@ -54,7 +54,7 @@ jobject CarbonSchemaReader::readSchema(char *path, Configuration conf) {
return result;
}

jobject CarbonSchemaReader::readSchema(char *path, bool validateSchema, Configuration conf) {
jobject CarbonSchemaReader::readSchema(char *path, bool validateSchema, Configuration &conf) {
if (path == NULL) {
throw std::runtime_error("path parameter can't be NULL.");
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/CSDK/src/CarbonSchemaReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CarbonSchemaReader {
* end point and other conf with this
* @return schema
*/
jobject readSchema(char *path, Configuration conf);
jobject readSchema(char *path, Configuration &conf);

/**
* read schema from path,
Expand All @@ -73,7 +73,7 @@ class CarbonSchemaReader {
* end point and other conf with this
* @return schema
*/
jobject readSchema(char *path, bool validateSchema, Configuration conf);
jobject readSchema(char *path, bool validateSchema, Configuration &conf);

/**
* read schema from path,
Expand Down
60 changes: 53 additions & 7 deletions sdk/CSDK/src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,51 @@

Configuration::Configuration(JNIEnv *env) {
this->jniEnv = env;
configurationClass = env->FindClass("org/apache/hadoop/conf/Configuration");
jclass localClass = env->FindClass("org/apache/hadoop/conf/Configuration");
if (localClass == NULL) {
throw std::runtime_error("Can't find the class in java: org/apache/hadoop/conf/Configuration");
}
configurationClass = (jclass) env->NewGlobalRef(localClass);
env->DeleteLocalRef(localClass);
if (configurationClass == NULL) {
throw std::runtime_error("Can't find the class in java: org/apache/hadoop/conf/Configuration");
}

initID = jniEnv->GetMethodID(configurationClass, "<init>", "()V");
if (initID == NULL) {
jniEnv->DeleteGlobalRef(configurationClass);
configurationClass = NULL;
throw std::runtime_error("Can't find init it in java: org/apache/hadoop/conf/Configuration");
}
configurationObject = jniEnv->NewObject(configurationClass, initID);
if (configurationClass == NULL) {
jobject localObject = jniEnv->NewObject(configurationClass, initID);
if (localObject == NULL) {
jniEnv->DeleteGlobalRef(configurationClass);
configurationClass = NULL;
throw std::runtime_error("Can't create object in java: org/apache/hadoop/conf/Configuration");
}
configurationObject = jniEnv->NewGlobalRef(localObject);
jniEnv->DeleteLocalRef(localObject);
if (configurationObject == NULL) {
jniEnv->DeleteGlobalRef(configurationClass);
configurationClass = NULL;
throw std::runtime_error("Can't create object in java: org/apache/hadoop/conf/Configuration");
}
}

Configuration::~Configuration() {
if (jniEnv == NULL) {
return;
}
if (configurationObject != NULL) {
jniEnv->DeleteGlobalRef(configurationObject);
configurationObject = NULL;
}
if (configurationClass != NULL) {
jniEnv->DeleteGlobalRef(configurationClass);
configurationClass = NULL;
}
}

void Configuration::check() {
if (configurationClass == NULL) {
throw std::runtime_error("configurationClass can't be NULL. Please init first.");
Expand All @@ -61,10 +91,18 @@ void Configuration::set(char *key, char *value) {
}
}

jstring jKey = jniEnv->NewStringUTF(key);
jstring jValue = jniEnv->NewStringUTF(value);
jvalue args[2];
args[0].l = jniEnv->NewStringUTF(key);
args[1].l = jniEnv->NewStringUTF(value);
args[0].l = jKey;
args[1].l = jValue;
jniEnv->CallObjectMethodA(configurationObject, setID, args);
if (jKey != NULL) {
jniEnv->DeleteLocalRef(jKey);
}
if (jValue != NULL) {
jniEnv->DeleteLocalRef(jValue);
}
}


Expand All @@ -86,12 +124,20 @@ char *Configuration::get(char *key, char *defaultValue) {
}
}

jstring jKey = jniEnv->NewStringUTF(key);
jstring jDefaultValue = jniEnv->NewStringUTF(defaultValue);
jvalue args[2];
args[0].l = jniEnv->NewStringUTF(key);
args[1].l = jniEnv->NewStringUTF(defaultValue);
args[0].l = jKey;
args[1].l = jDefaultValue;

jobject result = jniEnv->CallObjectMethodA(configurationObject, getID, args);
char *str = (char *) jniEnv->GetStringUTFChars((jstring) result, JNI_FALSE);
if (jKey != NULL) {
jniEnv->DeleteLocalRef(jKey);
}
if (jDefaultValue != NULL) {
jniEnv->DeleteLocalRef(jDefaultValue);
}
jniEnv->DeleteLocalRef(result);
return str;
}
Expand Down
3 changes: 3 additions & 0 deletions sdk/CSDK/src/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Configuration {
* @param env JNI env
*/
Configuration(JNIEnv *env);
~Configuration();
Configuration(const Configuration &) = delete;
Configuration &operator=(const Configuration &) = delete;

/**
* configure parameter, including ak,sk and endpoint
Expand Down