| 32 | connection_close_id_(NULL) { } |
| 33 | |
| 34 | Status HBaseTableFactory::GetConnection(jobject* connection) { |
| 35 | lock_guard<mutex> lock(connection_lock_); |
| 36 | if (connection_ != NULL) { |
| 37 | *connection = connection_; |
| 38 | return Status::OK(); |
| 39 | } |
| 40 | |
| 41 | // Get the JNIEnv* corresponding to current thread. |
| 42 | JNIEnv* env = JniUtil::GetJNIEnv(); |
| 43 | if (env == NULL) return Status("Error creating JNIEnv"); |
| 44 | JniLocalFrame jni_frame; |
| 45 | RETURN_IF_ERROR(jni_frame.push(env)); |
| 46 | |
| 47 | // Get o.a.h.Configuration via HBaseConfiguration. Used to create a connection. |
| 48 | jclass hbase_conf_cl = env->FindClass("org/apache/hadoop/hbase/HBaseConfiguration"); |
| 49 | RETURN_ERROR_IF_EXC(env); |
| 50 | |
| 51 | jmethodID hbase_conf_create_id = env->GetStaticMethodID(hbase_conf_cl, "create", |
| 52 | "()Lorg/apache/hadoop/conf/Configuration;"); |
| 53 | RETURN_ERROR_IF_EXC(env); |
| 54 | |
| 55 | // Cleaned up by JniLocalFrame. |
| 56 | jobject conf = env->CallStaticObjectMethod(hbase_conf_cl, hbase_conf_create_id); |
| 57 | RETURN_ERROR_IF_EXC(env); |
| 58 | |
| 59 | // Connection related methods. |
| 60 | connection_cl_ = env->FindClass("org/apache/hadoop/hbase/client/Connection"); |
| 61 | RETURN_ERROR_IF_EXC(env); |
| 62 | |
| 63 | connection_close_id_ = env->GetMethodID(connection_cl_, "close", "()V"); |
| 64 | RETURN_ERROR_IF_EXC(env); |
| 65 | |
| 66 | jclass connection_factory_cl = |
| 67 | env->FindClass("org/apache/hadoop/hbase/client/ConnectionFactory"); |
| 68 | RETURN_ERROR_IF_EXC(env); |
| 69 | |
| 70 | jmethodID connection_factory_create_connection = env->GetStaticMethodID( |
| 71 | connection_factory_cl, "createConnection", |
| 72 | "(Lorg/apache/hadoop/conf/Configuration;)" |
| 73 | "Lorg/apache/hadoop/hbase/client/Connection;"); |
| 74 | RETURN_ERROR_IF_EXC(env); |
| 75 | |
| 76 | // Cleaned up by JniLocalFrame. |
| 77 | jobject local_connection = env->CallStaticObjectMethod(connection_factory_cl, |
| 78 | connection_factory_create_connection, conf); |
| 79 | RETURN_ERROR_IF_EXC(env); |
| 80 | |
| 81 | RETURN_IF_ERROR(JniUtil::LocalToGlobalRef(env, local_connection, &connection_)); |
| 82 | RETURN_ERROR_IF_EXC(env); |
| 83 | |
| 84 | *connection = connection_; |
| 85 | return Status::OK(); |
| 86 | } |
| 87 | |
| 88 | HBaseTableFactory::~HBaseTableFactory() { |
| 89 | JNIEnv* env = JniUtil::GetJNIEnv(); |
nothing calls this directly
no test coverage detected