28 using ::com::sun::star::uno::Reference;
29 using ::com::sun::star::uno::XInterface;
31 using ::connectivity::java_lang_Object;
34 const ::comphelper::EventLogger& _rLoggerForErrors,
const Reference< XInterface >& _rxErrorContext )
35 :m_environment( environment )
36 ,m_currentThread( environment )
37 ,m_oldContextClassLoader( environment )
38 ,m_setContextClassLoaderMethod(
nullptr )
40 if ( !newClassLoader.
is() )
47 threadClass.
set( m_environment.FindClass(
"java/lang/Thread" ) );
48 if ( !threadClass.
is() )
51 jmethodID currentThreadMethod( m_environment.GetStaticMethodID(
52 threadClass.
get(),
"currentThread",
"()Ljava/lang/Thread;" ) );
53 if ( currentThreadMethod ==
nullptr )
56 m_currentThread.set( m_environment.CallStaticObjectMethod( threadClass.
get(), currentThreadMethod ) );
57 if ( !m_currentThread.is() )
60 jmethodID getContextClassLoaderMethod( m_environment.GetMethodID(
61 threadClass.
get(),
"getContextClassLoader",
"()Ljava/lang/ClassLoader;" ) );
62 if ( getContextClassLoaderMethod ==
nullptr )
64 m_oldContextClassLoader.set( m_environment.CallObjectMethod( m_currentThread.get(), getContextClassLoaderMethod ) );
69 m_setContextClassLoaderMethod = m_environment.GetMethodID(
70 threadClass.
get(),
"setContextClassLoader",
"(Ljava/lang/ClassLoader;)V" );
71 if ( m_setContextClassLoaderMethod ==
nullptr )
84 m_environment.CallObjectMethod( m_currentThread.get(), m_setContextClassLoaderMethod, newClassLoader.
get() );
88 m_currentThread.reset();
89 m_setContextClassLoaderMethod =
nullptr;
static void ThrowLoggedSQLException(const ::comphelper::EventLogger &_rLogger, JNIEnv *pEnvironment, const css::uno::Reference< css::uno::XInterface > &_rxContext)
LocalRef< jobject > m_oldContextClassLoader
LocalRef< jobject > m_currentThread
ContextClassLoaderScope(JNIEnv &environment, const GlobalRef< jobject > &newClassLoader, const ::comphelper::EventLogger &_rLoggerForErrors, const css::uno::Reference< css::uno::XInterface > &_rxErrorContext)
creates the instance.
jmethodID m_setContextClassLoaderMethod
~ContextClassLoaderScope()
helper class to hold a local ref to a JNI object