diff --git a/src/odbc/include/ignite/odbc/jni/java.h b/src/odbc/include/ignite/odbc/jni/java.h index 39672417f..e67dec390 100644 --- a/src/odbc/include/ignite/odbc/jni/java.h +++ b/src/odbc/include/ignite/odbc/jni/java.h @@ -487,8 +487,6 @@ class IGNITE_IMPORT_EXPORT JniContext { static int Reallocate(int64_t memPtr, int cap); static void Detach(); static void Release(jobject obj); - static void SetConsoleHandler(ConsoleWriteHandler consoleHandler); - static int RemoveConsoleHandler(ConsoleWriteHandler consoleHandler); std::string JavaStringToCppString(const SharedPointer< GlobalJObject >& jstring); @@ -680,37 +678,8 @@ class IGNITE_IMPORT_EXPORT JniContext { boost::optional< std::string >& columnClassName, JniErrorInfo& errInfo); - int64_t TargetInLongOutLong(jobject obj, int type, int64_t memPtr, - JniErrorInfo* errInfo = NULL); - int64_t TargetInStreamOutLong(jobject obj, int type, int64_t memPtr, - JniErrorInfo* errInfo = NULL); - void TargetInStreamOutStream(jobject obj, int opType, int64_t inMemPtr, - int64_t outMemPtr, JniErrorInfo* errInfo = NULL); - jobject TargetInStreamOutObject(jobject obj, int type, int64_t memPtr, - JniErrorInfo* errInfo = NULL); - jobject TargetInObjectStreamOutObjectStream(jobject obj, int opType, - void* arg, int64_t inMemPtr, - int64_t outMemPtr, - JniErrorInfo* errInfo = NULL); - void TargetOutStream(jobject obj, int opType, int64_t memPtr, - JniErrorInfo* errInfo = NULL); - jobject TargetOutObject(jobject obj, int opType, - JniErrorInfo* errInfo = NULL); - void TargetInStreamAsync(jobject obj, int type, int64_t memPtr, - JniErrorInfo* errInfo = NULL); - jobject TargetInStreamOutObjectAsync(jobject obj, int type, int64_t memPtr, - JniErrorInfo* errInfo = NULL); - - jobject CacheOutOpQueryCursor(jobject obj, int type, int64_t memPtr, - JniErrorInfo* errInfo = NULL); - jobject CacheOutOpContinuousQuery(jobject obj, int type, int64_t memPtr, - JniErrorInfo* errInfo = NULL); - jobject Acquire(jobject obj); - void DestroyJvm(); - void ThrowToJava(char* errMsg); - private: JniJvm* jvm; JniHandlers hnds; @@ -720,7 +689,6 @@ class IGNITE_IMPORT_EXPORT JniContext { JNIEnv* Attach(); void ExceptionCheck(JNIEnv* env); void ExceptionCheck(JNIEnv* env, JniErrorInfo* errInfo); - jobject LocalToGlobal(JNIEnv* env, jobject obj); JniErrorCode CallBooleanMethod(const SharedPointer< GlobalJObject >& object, const jmethodID& method, bool& value, @@ -904,22 +872,6 @@ JNIEXPORT void JNICALL JniAffinityFunctionRemoveNode(JNIEnv* env, jclass cls, JNIEXPORT void JNICALL JniAffinityFunctionDestroy(JNIEnv* env, jclass cls, jlong envPtr, jlong ptr); -JNIEXPORT void JNICALL JniConsoleWrite(JNIEnv* env, jclass cls, jstring str, - jboolean isErr); - -JNIEXPORT void JNICALL JniLoggerLog(JNIEnv* env, jclass cls, jlong envPtr, - jint level, jstring message, - jstring category, jstring errorInfo, - jlong memPtr); -JNIEXPORT jboolean JNICALL JniLoggerIsLevelEnabled(JNIEnv* env, jclass cls, - jlong envPtr, jint level); - -JNIEXPORT jlong JNICALL JniInLongOutLong(JNIEnv* env, jclass cls, jlong envPtr, - jint type, jlong val); -JNIEXPORT jlong JNICALL JniInLongLongLongObjectOutLong(JNIEnv* env, jclass cls, - jlong envPtr, jint type, - jlong val1, jlong val2, - jlong val3, jobject arg); } // namespace java } // namespace jni } // namespace odbc diff --git a/src/odbc/src/jni/java.cpp b/src/odbc/src/jni/java.cpp index 3cb91afff..2eaad6295 100644 --- a/src/odbc/src/jni/java.cpp +++ b/src/odbc/src/jni/java.cpp @@ -2423,181 +2423,6 @@ JniErrorCode JniContext::JdbcColumnMetadataGetColumnClassName( errInfo); } -int64_t JniContext::TargetInLongOutLong(jobject obj, int opType, int64_t val, - JniErrorInfo* err) { - LOG_DEBUG_MSG("TargetInLongOutLong is called"); - - JNIEnv* env = Attach(); - - int64_t res = env->CallLongMethod( - obj, jvm->GetMembers().m_PlatformTarget_inLongOutLong, opType, val); - - ExceptionCheck(env, err); - - LOG_DEBUG_MSG("TargetInLongOutLong exiting"); - - return res; -} - -int64_t JniContext::TargetInStreamOutLong(jobject obj, int opType, - int64_t memPtr, JniErrorInfo* err) { - LOG_DEBUG_MSG("TargetInStreamOutLong is called"); - - JNIEnv* env = Attach(); - - int64_t res = env->CallLongMethod( - obj, jvm->GetMembers().m_PlatformTarget_inStreamOutLong, opType, memPtr); - - ExceptionCheck(env, err); - - LOG_DEBUG_MSG("TargetInStreamOutLong exiting"); - - return res; -} - -void JniContext::TargetInStreamOutStream(jobject obj, int opType, - int64_t inMemPtr, int64_t outMemPtr, - JniErrorInfo* err) { - LOG_DEBUG_MSG("TargetInStreamOutStream is called"); - - JNIEnv* env = Attach(); - - env->CallVoidMethod(obj, jvm->GetMembers().m_PlatformTarget_inStreamOutStream, - opType, inMemPtr, outMemPtr); - - ExceptionCheck(env, err); - - LOG_DEBUG_MSG("TargetInStreamOutStream exiting"); -} - -jobject JniContext::TargetInStreamOutObject(jobject obj, int opType, - int64_t memPtr, JniErrorInfo* err) { - LOG_DEBUG_MSG("TargetInStreamOutObject is called"); - - JNIEnv* env = Attach(); - - jobject res = env->CallObjectMethod( - obj, jvm->GetMembers().m_PlatformTarget_inStreamOutObject, opType, - memPtr); - - ExceptionCheck(env, err); - - LOG_DEBUG_MSG("TargetInStreamOutObject exiting"); - - return LocalToGlobal(env, res); -} - -jobject JniContext::TargetInObjectStreamOutObjectStream(jobject obj, int opType, - void* arg, - int64_t inMemPtr, - int64_t outMemPtr, - JniErrorInfo* err) { - LOG_DEBUG_MSG("TargetInObjectStreamOutObjectStream is called"); - - JNIEnv* env = Attach(); - - jobject res = env->CallObjectMethod( - obj, jvm->GetMembers().m_PlatformTarget_inObjectStreamOutObjectStream, - opType, arg, inMemPtr, outMemPtr); - - ExceptionCheck(env, err); - - LOG_DEBUG_MSG("TargetInObjectStreamOutObjectStream exiting"); - - return LocalToGlobal(env, res); -} - -void JniContext::TargetOutStream(jobject obj, int opType, int64_t memPtr, - JniErrorInfo* err) { - JNIEnv* env = Attach(); - - env->CallVoidMethod(obj, jvm->GetMembers().m_PlatformTarget_outStream, opType, - memPtr); - - ExceptionCheck(env, err); -} - -jobject JniContext::TargetOutObject(jobject obj, int opType, - JniErrorInfo* err) { - LOG_DEBUG_MSG("TargetOutObject is called"); - - JNIEnv* env = Attach(); - - jobject res = env->CallObjectMethod( - obj, jvm->GetMembers().m_PlatformTarget_outObject, opType); - - ExceptionCheck(env, err); - - LOG_DEBUG_MSG("TargetOutObject exiting"); - - return LocalToGlobal(env, res); -} - -void JniContext::TargetInStreamAsync(jobject obj, int opType, int64_t memPtr, - JniErrorInfo* err) { - LOG_DEBUG_MSG("TargetInStreamAsync is called"); - - JNIEnv* env = Attach(); - - env->CallVoidMethod(obj, jvm->GetMembers().m_PlatformTarget_inStreamAsync, - opType, memPtr); - - ExceptionCheck(env, err); - - LOG_DEBUG_MSG("TargetInStreamAsync exiting"); -} - -jobject JniContext::TargetInStreamOutObjectAsync(jobject obj, int opType, - int64_t memPtr, - JniErrorInfo* err) { - LOG_DEBUG_MSG("TargetInStreamOutObjectAsync is called"); - - JNIEnv* env = Attach(); - - jobject res = env->CallObjectMethod( - obj, jvm->GetMembers().m_PlatformTarget_inStreamOutObjectAsync, opType, - memPtr); - - ExceptionCheck(env, err); - - LOG_DEBUG_MSG("TargetInStreamOutObjectAsync exiting"); - - return LocalToGlobal(env, res); -} - -jobject JniContext::CacheOutOpQueryCursor(jobject obj, int type, int64_t memPtr, - JniErrorInfo* err) { - LOG_DEBUG_MSG("CacheOutOpQueryCursor is called"); - - JNIEnv* env = Attach(); - - jobject res = env->CallObjectMethod( - obj, jvm->GetMembers().m_PlatformTarget_inStreamOutObject, type, memPtr); - - ExceptionCheck(env, err); - - LOG_DEBUG_MSG("CacheOutOpQueryCursor exiting"); - - return LocalToGlobal(env, res); -} - -jobject JniContext::CacheOutOpContinuousQuery(jobject obj, int type, - int64_t memPtr, - JniErrorInfo* err) { - LOG_DEBUG_MSG("CacheOutOpContinuousQuery is called"); - - JNIEnv* env = Attach(); - - jobject res = env->CallObjectMethod( - obj, jvm->GetMembers().m_PlatformTarget_inStreamOutObject, type, memPtr); - - ExceptionCheck(env, err); - - LOG_DEBUG_MSG("CacheOutOpContinuousQuery exiting"); - - return LocalToGlobal(env, res); -} - jobject JniContext::Acquire(jobject obj) { LOG_DEBUG_MSG("Acquire is called"); @@ -2640,62 +2465,6 @@ void JniContext::Release(jobject obj) { LOG_DEBUG_MSG("Release exiting"); } -void JniContext::SetConsoleHandler(ConsoleWriteHandler consoleHandler) { - LOG_DEBUG_MSG("SetConsoleHandler is called"); - - if (!consoleHandler) - throw std::invalid_argument("consoleHandler can not be null"); - - CONSOLE_LOCK.Enter(); - - consoleWriteHandlers.push_back(consoleHandler); - - CONSOLE_LOCK.Leave(); - - LOG_DEBUG_MSG("SetConsoleHandler exiting"); -} - -int JniContext::RemoveConsoleHandler(ConsoleWriteHandler consoleHandler) { - LOG_DEBUG_MSG("RemoveConsoleHandler is called"); - - if (!consoleHandler) - throw std::invalid_argument("consoleHandler can not be null"); - - CONSOLE_LOCK.Enter(); - - int oldSize = static_cast< int >(consoleWriteHandlers.size()); - - consoleWriteHandlers.erase(remove(consoleWriteHandlers.begin(), - consoleWriteHandlers.end(), consoleHandler), - consoleWriteHandlers.end()); - - int removedCnt = oldSize - static_cast< int >(consoleWriteHandlers.size()); - - CONSOLE_LOCK.Leave(); - - LOG_DEBUG_MSG("RemoveConsoleHandler exiting"); - - return removedCnt; -} - -void JniContext::ThrowToJava(char* msg) { - LOG_DEBUG_MSG("ThrowToJava is called"); - - JNIEnv* env = Attach(); - - env->ThrowNew(jvm->GetMembers().c_IgniteException, msg); - - LOG_DEBUG_MSG("ThrowToJava exiting"); -} - -void JniContext::DestroyJvm() { - LOG_DEBUG_MSG("DestroyJvm is called"); - - jvm->GetJvm()->DestroyJavaVM(); - - LOG_DEBUG_MSG("DestroyJvm exiting"); -} - /** * Attach thread to JVM. */ @@ -2806,116 +2575,6 @@ void JniContext::ExceptionCheck(JNIEnv* env, JniErrorInfo* errInfo) { } LOG_DEBUG_MSG("ExceptionCheck(JNIEnv* env, JniErrorInfo* errInfo) exiting"); } - -/** - * Convert local reference to global. - */ -jobject JniContext::LocalToGlobal(JNIEnv* env, jobject localRef) { - LOG_DEBUG_MSG("LocalToGlobal is called"); - - if (localRef) { - jobject globalRef = env->NewGlobalRef(localRef); - - env->DeleteLocalRef(localRef); // Clear local ref irrespective of result. - - if (!globalRef) - ExceptionCheck(env); - - LOG_DEBUG_MSG("LocalToGlobal exiting with globalRef variable"); - - return globalRef; - } else { - LOG_DEBUG_MSG( - "LocalToGlobal exiting with nullptr because localRef variable is null"); - - return nullptr; - } -} - -JNIEXPORT void JNICALL JniConsoleWrite(JNIEnv* env, jclass, jstring str, - jboolean isErr) { - LOG_DEBUG_MSG("JniConsoleWrite is called"); - - CONSOLE_LOCK.Enter(); - - if (consoleWriteHandlers.size() > 0) { - ConsoleWriteHandler consoleWrite = consoleWriteHandlers.at(0); - - const char* strChars = env->GetStringUTFChars(str, 0); - const int strCharsLen = env->GetStringUTFLength(str); - - consoleWrite(strChars, strCharsLen, isErr); - - env->ReleaseStringUTFChars(str, strChars); - } - - CONSOLE_LOCK.Leave(); - - LOG_DEBUG_MSG("JniConsoleWrite exiting"); -} - -JNIEXPORT void JNICALL JniLoggerLog(JNIEnv* env, jclass, jlong envPtr, - jint level, jstring message, - jstring category, jstring errorInfo, - jlong memPtr) { - LOG_DEBUG_MSG("JniLoggerLog is called"); - - int messageLen; - char* messageChars = StringToChars(env, message, &messageLen); - - int categoryLen; - char* categoryChars = StringToChars(env, category, &categoryLen); - - int errorInfoLen; - char* errorInfoChars = StringToChars(env, errorInfo, &errorInfoLen); - - IGNITE_SAFE_PROC(env, envPtr, LoggerLogHandler, loggerLog, level, - messageChars, messageLen, categoryChars, categoryLen, - errorInfoChars, errorInfoLen, memPtr); - - if (messageChars) - delete[] messageChars; - - if (categoryChars) - delete[] categoryChars; - - if (errorInfoChars) - delete[] errorInfoChars; - - LOG_DEBUG_MSG("JniLoggerLog exiting"); -} - -JNIEXPORT jboolean JNICALL JniLoggerIsLevelEnabled(JNIEnv* env, jclass, - jlong envPtr, jint level) { - LOG_DEBUG_MSG("JniLoggerIsLevelEnabled is called"); - - IGNITE_SAFE_FUNC(env, envPtr, LoggerIsLevelEnabledHandler, - loggerIsLevelEnabled, level); - - LOG_DEBUG_MSG("JniLoggerIsLevelEnabled exiting"); -} - -JNIEXPORT jlong JNICALL JniInLongOutLong(JNIEnv* env, jclass, jlong envPtr, - jint type, jlong val) { - LOG_DEBUG_MSG("JniInLongOutLong is called"); - - IGNITE_SAFE_FUNC(env, envPtr, InLongOutLongHandler, inLongOutLong, type, val); - - LOG_DEBUG_MSG("JniInLongOutLong exiting"); -} - -JNIEXPORT jlong JNICALL JniInLongLongLongObjectOutLong(JNIEnv* env, jclass, - jlong envPtr, jint type, - jlong val1, jlong val2, - jlong val3, - jobject arg) { - LOG_DEBUG_MSG("JniInLongLongLongObjectOutLong is called"); - - IGNITE_SAFE_FUNC(env, envPtr, InLongLongLongObjectOutLongHandler, - inLongLongLongObjectOutLong, type, val1, val2, val3, arg); - - LOG_DEBUG_MSG("JniInLongLongLongObjectOutLong exiting"); -} } // namespace java } // namespace jni } // namespace odbc