21#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
22#include <com/sun/star/logging/LogLevel.hpp>
25#include <osl/diagnose.h>
43 static ::rtl::Reference< jvmaccess::VirtualMachine > s_VM;
44 if ( _rVM.is() || _bSet )
52 if ( !xVM.is() && _rxContext.is() )
53 xVM =
getJavaVM2(::connectivity::getJavaVM(_rxContext));
63 OSL_ENSURE(
pEnv,
"Environment is nULL!");
72 static oslInterlockedCount s_nRefCount = 0;
112 object = pXEnv->NewGlobalRef( myObj );
128 rEnv.DeleteGlobalRef(
object );
144 OSL_ENSURE( myObj,
"object in c++ -> Java Wrapper" );
146 object = pXEnv->NewGlobalRef( myObj );
152 static jmethodID mID(
nullptr);
159 bool lcl_translateJNIExceptionToUNOException(
160 JNIEnv* _pEnvironment,
const Reference< XInterface >& _rxContext, SQLException& _out_rException )
162 jthrowable jThrow = _pEnvironment ? _pEnvironment->ExceptionOccurred() :
nullptr;
166 _pEnvironment->ExceptionClear();
172 _out_rException = SQLException( aException.getMessage(), _rxContext,
173 aException.getSQLState(), aException.getErrorCode(),
Any() );
179#if OSL_DEBUG_LEVEL > 0
180 aThrow.printStackTrace();
182 OUString
sMessage = aThrow.getMessage();
184 sMessage = aThrow.getLocalizedMessage();
187 _out_rException = SQLException( sMessage, _rxContext, OUString(), -1,
Any() );
191 _pEnvironment->DeleteLocalRef( jThrow );
198 const Reference< XInterface >& _rxContext )
200 SQLException aException;
201 if ( lcl_translateJNIExceptionToUNOException( _pEnvironment, _rxContext, aException ) )
203 _rLogger.log( css::logging::LogLevel::SEVERE,
STR_LOG_THROWING_EXCEPTION, aException.Message, aException.SQLState, aException.ErrorCode );
210 SQLException aException;
211 if ( lcl_translateJNIExceptionToUNOException( _pEnvironment, _rxContext, aException ) )
221 catch (
const SQLException& e)
224 throw css::lang::WrappedTargetRuntimeException( e.Message,
231 if ( !_inout_MethodID )
233 _inout_MethodID = _pEnv->GetMethodID(
getMyClass(), _pMethodName, _pSignature );
234 OSL_ENSURE( _inout_MethodID, _pSignature );
235 if ( !_inout_MethodID )
236 throw SQLException();
242 if ( !_inout_MethodID )
244 _inout_MethodID = _pEnv->GetMethodID(
getMyClass(), _pMethodName, _pSignature );
245 OSL_ENSURE( _inout_MethodID, _pSignature );
246 if ( !_inout_MethodID )
247 throw RuntimeException();
257 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callBooleanMethod: no Java environment anymore!" );
260 out =
t.pEnv->CallBooleanMethod(
object, _inout_MethodID );
270 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callBooleanMethodWithIntArg: no Java environment anymore!" );
273 out =
t.pEnv->CallBooleanMethod(
object, _inout_MethodID, _nArgument );
282 jobject out =
callObjectMethod(&_rEnv,_pMethodName,
"()Ljava/sql/ResultSet;", _inout_MethodID);
289 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethod: no Java environment anymore!" );
292 jint out(
t.pEnv->CallIntMethod(
object, _inout_MethodID ) );
294 return static_cast<sal_Int32
>(out);
300 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethod: no Java environment anymore!" );
303 jint out(
t.pEnv->CallIntMethod(
object, _inout_MethodID ) );
305 return static_cast<sal_Int32
>(out);
311 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethod: no Java environment anymore!" );
314 jint out(
t.pEnv->CallIntMethod(
object, _inout_MethodID , _nArgument) );
316 return static_cast<sal_Int32
>(out);
322 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethod: no Java environment anymore!" );
325 jint out(
t.pEnv->CallIntMethod(
object, _inout_MethodID , _nArgument) );
327 return static_cast<sal_Int32
>(out);
333 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethod: no Java environment anymore!" );
337 t.pEnv->CallVoidMethod(
object, _inout_MethodID );
344 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethod: no Java environment anymore!" );
348 t.pEnv->CallVoidMethod(
object, _inout_MethodID );
355 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethod: no Java environment anymore!" );
359 t.pEnv->CallVoidMethod(
object, _inout_MethodID,_nArgument );
366 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethod: no Java environment anymore!" );
370 t.pEnv->CallVoidMethod(
object, _inout_MethodID,_nArgument );
377 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethod: no Java environment anymore!" );
380 t.pEnv->CallVoidMethod(
object, _inout_MethodID,
int(_nArgument) );
387 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethod: no Java environment anymore!" );
390 t.pEnv->CallVoidMethod(
object, _inout_MethodID,
int(_nArgument) );
397 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callStringMethod: no Java environment anymore!" );
400 jstring out =
static_cast<jstring
>(
callObjectMethod(
t.pEnv,_pMethodName,
"()Ljava/lang/String;", _inout_MethodID));
409 jobject out = _pEnv->CallObjectMethod(
object, _inout_MethodID);
419 jobject out = _pEnv->CallObjectMethod(
object, _inout_MethodID,_nArgument );
427 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callStringMethod: no Java environment anymore!" );
428 jstring out =
static_cast<jstring
>(
callObjectMethodWithIntArg(
t.pEnv,_pMethodName,
"(I)Ljava/lang/String;",_inout_MethodID,_nArgument));
435 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethod: no Java environment anymore!" );
440 t.pEnv->CallVoidMethod(
object, _inout_MethodID , str.
get());
447 OSL_ENSURE(
t.pEnv,
"java_lang_Object::callIntMethodWithStringArg: no Java environment anymore!" );
461 jint out =
t.pEnv->CallIntMethod(
object, _inout_MethodID , str.
get());
463 return static_cast<sal_Int32
>(out);
470 jclass tempClass =
t.pEnv->FindClass(_pClassName); OSL_ENSURE(tempClass,
"Java : FindClass not successful!");
473 t.pEnv->ExceptionDescribe();
474 t.pEnv->ExceptionClear();
476 jclass globClass =
static_cast<jclass
>(
t.pEnv->NewGlobalRef( tempClass ));
477 t.pEnv->DeleteLocalRef( tempClass );
static oslInterlockedCount & getJavaVMRefCount()
static ::rtl::Reference< jvmaccess::VirtualMachine > const & getJavaVM2(const ::rtl::Reference< jvmaccess::VirtualMachine > &_rVM=::rtl::Reference< jvmaccess::VirtualMachine >(), bool _bSet=false)
jvmaccess::VirtualMachine::AttachGuard m_aGuard
jobject callObjectMethod(JNIEnv *pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
jobject callResultSetMethod(JNIEnv &_rEnv, const char *_pMethodName, jmethodID &_inout_MethodID) const
virtual ~java_lang_Object() COVERITY_NOEXCEPT_FALSE
sal_Int32 callIntMethod_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID) const
virtual jclass getMyClass() const
bool callBooleanMethod(const char *_pMethodName, jmethodID &_inout_MethodID) const
OUString toString() const
sal_Int32 callIntMethodWithStringArg(const char *_pMethodName, jmethodID &_inout_MethodID, const OUString &_nArgument) const
void callVoidMethodWithStringArg(const char *_pMethodName, jmethodID &_inout_MethodID, const OUString &_nArgument) const
void callVoidMethod_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID) const
sal_Int32 callIntMethodWithIntArg_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
void callVoidMethodWithIntArg_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
void saveRef(JNIEnv *pEnv, jobject myObj)
void callVoidMethodWithBoolArg_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID, bool _nArgument) const
void callVoidMethodWithIntArg_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
OUString callStringMethod(const char *_pMethodName, jmethodID &_inout_MethodID) const
jobject callObjectMethodWithIntArg(JNIEnv *pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
bool callBooleanMethodWithIntArg(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
OUString callStringMethodWithIntArg(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
static void ThrowSQLException(JNIEnv *pEnv, const css::uno::Reference< css::uno::XInterface > &_rContext)
sal_Int32 callIntMethod_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID) const
static void ThrowLoggedSQLException(const ::comphelper::EventLogger &_rLogger, JNIEnv *pEnvironment, const css::uno::Reference< css::uno::XInterface > &_rxContext)
static jclass findMyClass(const char *_pClassName)
void obtainMethodId_throwRuntime(JNIEnv *_pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
static void ThrowRuntimeException(JNIEnv *pEnv, const css::uno::Reference< css::uno::XInterface > &_rContext)
void callVoidMethod_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID) const
void callVoidMethodWithBoolArg_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID, bool _nArgument) const
sal_Int32 callIntMethodWithIntArg_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
void obtainMethodId_throwSQL(JNIEnv *_pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
static jclass st_getMyClass()
static jclass st_getMyClass()
helper class to hold a local ref to a JNI object
JNIEnv * getEnvironment() const
osl::ClearableMutexGuard m_aGuard
OUString JavaString2String(JNIEnv *pEnv, jstring Str)
jstring convertwchar_tToJavaString(JNIEnv *pEnv, const OUString &Temp)
Any SAL_CALL getCaughtException()
#define STR_LOG_THROWING_EXCEPTION