xref: /AOO41X/main/connectivity/source/drivers/jdbc/Object.cxx (revision 9b5730f6ddef7eb82608ca4d31dc0d7678e652cf)
1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #ifndef _CONNECTIVITY_JAVA_LANG_OBJJECT_HXX_
29cdf0e10cSrcweir #include "java/lang/Class.hxx"
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir #include "connectivity/CommonTools.hxx"
32cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp>
33cdf0e10cSrcweir #include "java/tools.hxx"
34cdf0e10cSrcweir #include "java/sql/SQLException.hxx"
35cdf0e10cSrcweir #include <vos/process.hxx>
36cdf0e10cSrcweir #include <vos/mutex.hxx>
37cdf0e10cSrcweir #include <osl/thread.h>
38cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
39cdf0e10cSrcweir #include "java/LocalRef.hxx"
40cdf0e10cSrcweir #include "resource/jdbc_log.hrc"
41cdf0e10cSrcweir #include <rtl/logfile.hxx>
42cdf0e10cSrcweir #include <comphelper/logging.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <memory>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir using namespace connectivity;
47cdf0e10cSrcweir using namespace ::com::sun::star::uno;
48cdf0e10cSrcweir using namespace ::com::sun::star::beans;
49cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
50cdf0e10cSrcweir using namespace ::com::sun::star::container;
51cdf0e10cSrcweir using namespace ::com::sun::star::lang;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir // -----------------------------------------------------------------------------
getJavaVM2(const::rtl::Reference<jvmaccess::VirtualMachine> & _rVM=::rtl::Reference<jvmaccess::VirtualMachine> (),sal_Bool _bSet=sal_False)55cdf0e10cSrcweir ::rtl::Reference< jvmaccess::VirtualMachine > getJavaVM2(const ::rtl::Reference< jvmaccess::VirtualMachine >& _rVM = ::rtl::Reference< jvmaccess::VirtualMachine >(),
56cdf0e10cSrcweir 														sal_Bool _bSet = sal_False)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir 	static ::rtl::Reference< jvmaccess::VirtualMachine > s_VM;
59cdf0e10cSrcweir 	if ( _rVM.is() || _bSet )
60cdf0e10cSrcweir 		s_VM = _rVM;
61cdf0e10cSrcweir 	return s_VM;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir // -----------------------------------------------------------------------------
getVM(const Reference<XMultiServiceFactory> & _rxFactory)64cdf0e10cSrcweir ::rtl::Reference< jvmaccess::VirtualMachine > java_lang_Object::getVM(const Reference<XMultiServiceFactory >& _rxFactory)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	::rtl::Reference< jvmaccess::VirtualMachine > xVM = getJavaVM2();
67cdf0e10cSrcweir 	if ( !xVM.is() && _rxFactory.is() )
68cdf0e10cSrcweir 		xVM = getJavaVM2(::connectivity::getJavaVM(_rxFactory));
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	return xVM;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir // -----------------------------------------------------------------------------
SDBThreadAttach()73cdf0e10cSrcweir SDBThreadAttach::SDBThreadAttach()
74cdf0e10cSrcweir  : m_aGuard(java_lang_Object::getVM())
75cdf0e10cSrcweir  , pEnv(NULL)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	pEnv = m_aGuard.getEnvironment();
78cdf0e10cSrcweir     OSL_ENSURE(pEnv,"Environment is nULL!");
79cdf0e10cSrcweir }
80cdf0e10cSrcweir // -----------------------------------------------------------------------------
~SDBThreadAttach()81cdf0e10cSrcweir SDBThreadAttach::~SDBThreadAttach()
82cdf0e10cSrcweir {
83cdf0e10cSrcweir }
84cdf0e10cSrcweir // -----------------------------------------------------------------------------
getJavaVMRefCount()85cdf0e10cSrcweir oslInterlockedCount& getJavaVMRefCount()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	static oslInterlockedCount s_nRefCount = 0;
88cdf0e10cSrcweir 	return s_nRefCount;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir // -----------------------------------------------------------------------------
addRef()91cdf0e10cSrcweir void SDBThreadAttach::addRef()
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     osl_incrementInterlockedCount(&getJavaVMRefCount());
94cdf0e10cSrcweir }
95cdf0e10cSrcweir // -----------------------------------------------------------------------------
releaseRef()96cdf0e10cSrcweir void SDBThreadAttach::releaseRef()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     osl_decrementInterlockedCount(&getJavaVMRefCount());
99cdf0e10cSrcweir 	if ( getJavaVMRefCount() == 0 )
100cdf0e10cSrcweir 	{
101cdf0e10cSrcweir 		getJavaVM2(::rtl::Reference< jvmaccess::VirtualMachine >(),sal_True);
102cdf0e10cSrcweir 	}
103cdf0e10cSrcweir }
104cdf0e10cSrcweir // -----------------------------------------------------------------------------
105cdf0e10cSrcweir // statische Variablen der Klasse:
106cdf0e10cSrcweir jclass java_lang_Object::theClass = 0;
107cdf0e10cSrcweir 
getMyClass() const108cdf0e10cSrcweir jclass java_lang_Object::getMyClass() const
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	if( !theClass )
111cdf0e10cSrcweir         theClass = findMyClass("java/lang/Object");
112cdf0e10cSrcweir 	return theClass;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir // der eigentliche Konstruktor
java_lang_Object(const Reference<XMultiServiceFactory> & _rxFactory)115cdf0e10cSrcweir java_lang_Object::java_lang_Object(const Reference<XMultiServiceFactory >& _rxFactory)
116cdf0e10cSrcweir             : m_xFactory(_rxFactory),object( 0 )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     SDBThreadAttach::addRef();
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir // der protected-Konstruktor fuer abgeleitete Klassen
java_lang_Object(JNIEnv * pXEnv,jobject myObj)122cdf0e10cSrcweir java_lang_Object::java_lang_Object( JNIEnv * pXEnv, jobject myObj )
123cdf0e10cSrcweir 	: object( NULL )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     SDBThreadAttach::addRef();
126cdf0e10cSrcweir 	if( pXEnv && myObj )
127cdf0e10cSrcweir 		object = pXEnv->NewGlobalRef( myObj );
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
~java_lang_Object()130cdf0e10cSrcweir java_lang_Object::~java_lang_Object()
131cdf0e10cSrcweir {
132cdf0e10cSrcweir 	if( object )
133cdf0e10cSrcweir 	{
134cdf0e10cSrcweir 		SDBThreadAttach t;
135cdf0e10cSrcweir         clearObject(*t.pEnv);
136cdf0e10cSrcweir 	}
137cdf0e10cSrcweir     SDBThreadAttach::releaseRef();
138cdf0e10cSrcweir }
clearObject(JNIEnv & rEnv)139cdf0e10cSrcweir void java_lang_Object::clearObject(JNIEnv& rEnv)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	if( object )
142cdf0e10cSrcweir 	{
143cdf0e10cSrcweir 		rEnv.DeleteGlobalRef( object );
144cdf0e10cSrcweir 		object = NULL;
145cdf0e10cSrcweir 	}
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
clearObject()148cdf0e10cSrcweir void java_lang_Object::clearObject()
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	if( object )
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		SDBThreadAttach t;
153cdf0e10cSrcweir         clearObject(*t.pEnv);
154cdf0e10cSrcweir 	}
155cdf0e10cSrcweir }
156cdf0e10cSrcweir // der protected-Konstruktor fuer abgeleitete Klassen
saveRef(JNIEnv * pXEnv,jobject myObj)157cdf0e10cSrcweir void java_lang_Object::saveRef( JNIEnv * pXEnv, jobject myObj )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	OSL_ENSURE( myObj, "object in c++ -> Java Wrapper" );
160cdf0e10cSrcweir 	if( myObj )
161cdf0e10cSrcweir 		object = pXEnv->NewGlobalRef( myObj );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 
toString() const165cdf0e10cSrcweir ::rtl::OUString java_lang_Object::toString() const
166cdf0e10cSrcweir {
167cdf0e10cSrcweir     static jmethodID mID(NULL);
168cdf0e10cSrcweir     return callStringMethod("toString",mID);
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir // --------------------------------------------------------------------------------
172cdf0e10cSrcweir namespace
173cdf0e10cSrcweir {
lcl_translateJNIExceptionToUNOException(JNIEnv * _pEnvironment,const Reference<XInterface> & _rxContext,SQLException & _out_rException)174cdf0e10cSrcweir     bool    lcl_translateJNIExceptionToUNOException(
175cdf0e10cSrcweir         JNIEnv* _pEnvironment, const Reference< XInterface >& _rxContext, SQLException& _out_rException )
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         jthrowable jThrow = _pEnvironment ? _pEnvironment->ExceptionOccurred() : NULL;
178cdf0e10cSrcweir         if ( !jThrow )
179cdf0e10cSrcweir             return false;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         _pEnvironment->ExceptionClear();
182cdf0e10cSrcweir             // we have to clear the exception here because we want to handle it itself
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         if ( _pEnvironment->IsInstanceOf( jThrow, java_sql_SQLException_BASE::st_getMyClass() ) )
185cdf0e10cSrcweir         {
186cdf0e10cSrcweir             ::std::auto_ptr< java_sql_SQLException_BASE > pException( new java_sql_SQLException_BASE( _pEnvironment, jThrow ) );
187cdf0e10cSrcweir             _out_rException = SQLException( pException->getMessage(), _rxContext,
188cdf0e10cSrcweir                 pException->getSQLState(), pException->getErrorCode(), Any() );
189cdf0e10cSrcweir             return true;
190cdf0e10cSrcweir         }
191cdf0e10cSrcweir         else if ( _pEnvironment->IsInstanceOf( jThrow, java_lang_Throwable::st_getMyClass() ) )
192cdf0e10cSrcweir         {
193cdf0e10cSrcweir             ::std::auto_ptr< java_lang_Throwable > pThrow( new java_lang_Throwable( _pEnvironment, jThrow ) );
194cdf0e10cSrcweir             ::rtl::OUString sMessage = pThrow->getMessage();
195cdf0e10cSrcweir             if ( !sMessage.getLength() )
196cdf0e10cSrcweir                 sMessage = pThrow->getLocalizedMessage();
197cdf0e10cSrcweir             if(  !sMessage.getLength() )
198cdf0e10cSrcweir                 sMessage = pThrow->toString();
199cdf0e10cSrcweir             _out_rException = SQLException( sMessage, _rxContext, ::rtl::OUString(), -1, Any() );
200cdf0e10cSrcweir             return true;
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir         else
203cdf0e10cSrcweir             _pEnvironment->DeleteLocalRef( jThrow );
204cdf0e10cSrcweir         return false;
205cdf0e10cSrcweir     }
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir // --------------------------------------------------------------------------------
ThrowLoggedSQLException(const::comphelper::ResourceBasedEventLogger & _rLogger,JNIEnv * _pEnvironment,const Reference<XInterface> & _rxContext)209cdf0e10cSrcweir void java_lang_Object::ThrowLoggedSQLException( const ::comphelper::ResourceBasedEventLogger& _rLogger, JNIEnv* _pEnvironment,
210cdf0e10cSrcweir     const Reference< XInterface >& _rxContext )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     SQLException aException;
213cdf0e10cSrcweir     if ( lcl_translateJNIExceptionToUNOException( _pEnvironment, _rxContext, aException ) )
214cdf0e10cSrcweir     {
215cdf0e10cSrcweir         _rLogger.log( ::com::sun::star::logging::LogLevel::SEVERE, STR_LOG_THROWING_EXCEPTION, aException.Message, aException.SQLState, aException.ErrorCode );
216cdf0e10cSrcweir         throw aException;
217cdf0e10cSrcweir     }
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir // --------------------------------------------------------------------------------
ThrowSQLException(JNIEnv * _pEnvironment,const Reference<XInterface> & _rxContext)221cdf0e10cSrcweir void java_lang_Object::ThrowSQLException( JNIEnv* _pEnvironment, const Reference< XInterface>& _rxContext )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir     SQLException aException;
224cdf0e10cSrcweir     if ( lcl_translateJNIExceptionToUNOException( _pEnvironment, _rxContext, aException ) )
225cdf0e10cSrcweir         throw aException;
226cdf0e10cSrcweir }
227cdf0e10cSrcweir // -----------------------------------------------------------------------------
obtainMethodId(JNIEnv * _pEnv,const char * _pMethodName,const char * _pSignature,jmethodID & _inout_MethodID) const228cdf0e10cSrcweir void java_lang_Object::obtainMethodId(JNIEnv* _pEnv,const char* _pMethodName, const char* _pSignature,jmethodID& _inout_MethodID) const
229cdf0e10cSrcweir {
230cdf0e10cSrcweir     if  ( !_inout_MethodID )
231cdf0e10cSrcweir     {
232cdf0e10cSrcweir         _inout_MethodID  = _pEnv->GetMethodID( getMyClass(), _pMethodName, _pSignature );
233cdf0e10cSrcweir         OSL_ENSURE( _inout_MethodID, _pSignature );
234cdf0e10cSrcweir         if  ( !_inout_MethodID )
235cdf0e10cSrcweir             throw SQLException();
236cdf0e10cSrcweir     } // if  ( !_inout_MethodID )
237cdf0e10cSrcweir }
238cdf0e10cSrcweir // -----------------------------------------------------------------------------
callBooleanMethod(const char * _pMethodName,jmethodID & _inout_MethodID) const239cdf0e10cSrcweir sal_Bool java_lang_Object::callBooleanMethod( const char* _pMethodName, jmethodID& _inout_MethodID ) const
240cdf0e10cSrcweir {
241cdf0e10cSrcweir 	jboolean out( sal_False );
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     SDBThreadAttach t;
244cdf0e10cSrcweir     OSL_ENSURE( t.pEnv, "java_lang_Object::callBooleanMethod: no Java enviroment anymore!" );
245cdf0e10cSrcweir     obtainMethodId(t.pEnv, _pMethodName,"()Z", _inout_MethodID);
246cdf0e10cSrcweir     // call method
247cdf0e10cSrcweir 	out = t.pEnv->CallBooleanMethod( object, _inout_MethodID );
248cdf0e10cSrcweir 	ThrowSQLException( t.pEnv, NULL );
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	return out;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir // -----------------------------------------------------------------------------
callBooleanMethodWithIntArg(const char * _pMethodName,jmethodID & _inout_MethodID,sal_Int32 _nArgument) const253cdf0e10cSrcweir sal_Bool java_lang_Object::callBooleanMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const
254cdf0e10cSrcweir {
255cdf0e10cSrcweir 	jboolean out( sal_False );
256cdf0e10cSrcweir     SDBThreadAttach t;
257cdf0e10cSrcweir     OSL_ENSURE( t.pEnv, "java_lang_Object::callBooleanMethodWithIntArg: no Java enviroment anymore!" );
258cdf0e10cSrcweir 	obtainMethodId(t.pEnv, _pMethodName,"(I)Z", _inout_MethodID);
259cdf0e10cSrcweir     // call method
260cdf0e10cSrcweir 	out = t.pEnv->CallBooleanMethod( object, _inout_MethodID, _nArgument );
261cdf0e10cSrcweir 	ThrowSQLException( t.pEnv, NULL );
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	return out;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir // -------------------------------------------------------------------------
callResultSetMethod(JNIEnv & _rEnv,const char * _pMethodName,jmethodID & _inout_MethodID) const266cdf0e10cSrcweir jobject java_lang_Object::callResultSetMethod( JNIEnv& _rEnv,const char* _pMethodName, jmethodID& _inout_MethodID ) const
267cdf0e10cSrcweir {
268cdf0e10cSrcweir     // call method
269cdf0e10cSrcweir     jobject out = callObjectMethod(&_rEnv,_pMethodName,"()Ljava/sql/ResultSet;", _inout_MethodID);
270cdf0e10cSrcweir     return out;
271cdf0e10cSrcweir }
272cdf0e10cSrcweir // -------------------------------------------------------------------------
callIntMethod(const char * _pMethodName,jmethodID & _inout_MethodID,bool _bIgnoreException) const273cdf0e10cSrcweir sal_Int32 java_lang_Object::callIntMethod( const char* _pMethodName, jmethodID& _inout_MethodID,bool _bIgnoreException ) const
274cdf0e10cSrcweir {
275cdf0e10cSrcweir     SDBThreadAttach t;
276cdf0e10cSrcweir     OSL_ENSURE( t.pEnv, "java_lang_Object::callIntMethod: no Java enviroment anymore!" );
277cdf0e10cSrcweir     obtainMethodId(t.pEnv, _pMethodName,"()I", _inout_MethodID);
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     // call method
280cdf0e10cSrcweir 	jint out( t.pEnv->CallIntMethod( object, _inout_MethodID ) );
281cdf0e10cSrcweir     if ( _bIgnoreException )
282cdf0e10cSrcweir         isExceptionOccured(t.pEnv,sal_True);
283cdf0e10cSrcweir     else
284cdf0e10cSrcweir 	    ThrowSQLException( t.pEnv, NULL );
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 	return (sal_Int32)out;
287cdf0e10cSrcweir }
288cdf0e10cSrcweir // -------------------------------------------------------------------------
callIntMethodWithIntArg(const char * _pMethodName,jmethodID & _inout_MethodID,sal_Int32 _nArgument) const289cdf0e10cSrcweir sal_Int32 java_lang_Object::callIntMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID,sal_Int32 _nArgument ) const
290cdf0e10cSrcweir {
291cdf0e10cSrcweir     SDBThreadAttach t;
292cdf0e10cSrcweir     OSL_ENSURE( t.pEnv, "java_lang_Object::callIntMethod: no Java enviroment anymore!" );
293cdf0e10cSrcweir     obtainMethodId(t.pEnv, _pMethodName,"(I)I", _inout_MethodID);
294cdf0e10cSrcweir     // call method
295cdf0e10cSrcweir 	jint out( t.pEnv->CallIntMethod( object, _inout_MethodID , _nArgument) );
296cdf0e10cSrcweir 	ThrowSQLException( t.pEnv, NULL );
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 	return (sal_Int32)out;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir // -------------------------------------------------------------------------
callVoidMethod(const char * _pMethodName,jmethodID & _inout_MethodID) const301cdf0e10cSrcweir void java_lang_Object::callVoidMethod( const char* _pMethodName, jmethodID& _inout_MethodID) const
302cdf0e10cSrcweir {
303cdf0e10cSrcweir     SDBThreadAttach t;
304cdf0e10cSrcweir     OSL_ENSURE( t.pEnv, "java_lang_Object::callIntMethod: no Java enviroment anymore!" );
305cdf0e10cSrcweir     obtainMethodId(t.pEnv, _pMethodName,"()V", _inout_MethodID);
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     // call method
308cdf0e10cSrcweir 	t.pEnv->CallVoidMethod( object, _inout_MethodID );
309cdf0e10cSrcweir 	ThrowSQLException( t.pEnv, NULL );
310cdf0e10cSrcweir }
311cdf0e10cSrcweir // -------------------------------------------------------------------------
callVoidMethodWithIntArg(const char * _pMethodName,jmethodID & _inout_MethodID,sal_Int32 _nArgument,bool _bIgnoreException) const312cdf0e10cSrcweir void java_lang_Object::callVoidMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument,bool _bIgnoreException ) const
313cdf0e10cSrcweir {
314cdf0e10cSrcweir     SDBThreadAttach t;
315cdf0e10cSrcweir     OSL_ENSURE( t.pEnv, "java_lang_Object::callIntMethod: no Java enviroment anymore!" );
316cdf0e10cSrcweir     obtainMethodId(t.pEnv, _pMethodName,"(I)V", _inout_MethodID);
317cdf0e10cSrcweir 
318cdf0e10cSrcweir     // call method
319cdf0e10cSrcweir 	t.pEnv->CallVoidMethod( object, _inout_MethodID,_nArgument );
320cdf0e10cSrcweir     if ( _bIgnoreException )
321cdf0e10cSrcweir         isExceptionOccured(t.pEnv,sal_True);
322cdf0e10cSrcweir     else
323cdf0e10cSrcweir 	    ThrowSQLException( t.pEnv, NULL );
324cdf0e10cSrcweir }
325cdf0e10cSrcweir // -------------------------------------------------------------------------
callVoidMethodWithBoolArg(const char * _pMethodName,jmethodID & _inout_MethodID,sal_Int32 _nArgument,bool _bIgnoreException) const326cdf0e10cSrcweir void java_lang_Object::callVoidMethodWithBoolArg( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument,bool _bIgnoreException ) const
327cdf0e10cSrcweir {
328cdf0e10cSrcweir     SDBThreadAttach t;
329cdf0e10cSrcweir     OSL_ENSURE( t.pEnv, "java_lang_Object::callIntMethod: no Java enviroment anymore!" );
330cdf0e10cSrcweir     obtainMethodId(t.pEnv, _pMethodName,"(Z)V", _inout_MethodID);
331cdf0e10cSrcweir     // call method
332cdf0e10cSrcweir 	t.pEnv->CallVoidMethod( object, _inout_MethodID,_nArgument );
333cdf0e10cSrcweir     if ( _bIgnoreException )
334cdf0e10cSrcweir         isExceptionOccured(t.pEnv,sal_True);
335cdf0e10cSrcweir     else
336cdf0e10cSrcweir 	    ThrowSQLException( t.pEnv, NULL );
337cdf0e10cSrcweir }
338cdf0e10cSrcweir // -----------------------------------------------------------------------------
callStringMethod(const char * _pMethodName,jmethodID & _inout_MethodID) const339cdf0e10cSrcweir ::rtl::OUString java_lang_Object::callStringMethod( const char* _pMethodName, jmethodID& _inout_MethodID ) const
340cdf0e10cSrcweir {
341cdf0e10cSrcweir     SDBThreadAttach t;
342cdf0e10cSrcweir     OSL_ENSURE( t.pEnv, "java_lang_Object::callStringMethod: no Java enviroment anymore!" );
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     // call method
345cdf0e10cSrcweir     jstring out = (jstring)callObjectMethod(t.pEnv,_pMethodName,"()Ljava/lang/String;", _inout_MethodID);
346cdf0e10cSrcweir 	return JavaString2String( t.pEnv, out );
347cdf0e10cSrcweir }
348cdf0e10cSrcweir // -----------------------------------------------------------------------------
callObjectMethod(JNIEnv * _pEnv,const char * _pMethodName,const char * _pSignature,jmethodID & _inout_MethodID) const349cdf0e10cSrcweir jobject java_lang_Object::callObjectMethod( JNIEnv * _pEnv,const char* _pMethodName,const char* _pSignature, jmethodID& _inout_MethodID ) const
350cdf0e10cSrcweir {
351cdf0e10cSrcweir     // obtain method ID
352cdf0e10cSrcweir     obtainMethodId(_pEnv, _pMethodName,_pSignature, _inout_MethodID);
353cdf0e10cSrcweir     // call method
354cdf0e10cSrcweir 	jobject out = _pEnv->CallObjectMethod( object, _inout_MethodID);
355cdf0e10cSrcweir 	ThrowSQLException( _pEnv, NULL );
356cdf0e10cSrcweir     return out;
357cdf0e10cSrcweir }
358cdf0e10cSrcweir 
359cdf0e10cSrcweir // -----------------------------------------------------------------------------
callObjectMethodWithIntArg(JNIEnv * _pEnv,const char * _pMethodName,const char * _pSignature,jmethodID & _inout_MethodID,sal_Int32 _nArgument) const360cdf0e10cSrcweir jobject java_lang_Object::callObjectMethodWithIntArg( JNIEnv * _pEnv,const char* _pMethodName,const char* _pSignature, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const
361cdf0e10cSrcweir {
362cdf0e10cSrcweir     obtainMethodId(_pEnv, _pMethodName,_pSignature, _inout_MethodID);
363cdf0e10cSrcweir     // call method
364cdf0e10cSrcweir 	jobject out = _pEnv->CallObjectMethod( object, _inout_MethodID,_nArgument );
365cdf0e10cSrcweir 	ThrowSQLException( _pEnv, NULL );
366cdf0e10cSrcweir     return out;
367cdf0e10cSrcweir }
368cdf0e10cSrcweir // -----------------------------------------------------------------------------
callStringMethodWithIntArg(const char * _pMethodName,jmethodID & _inout_MethodID,sal_Int32 _nArgument) const369cdf0e10cSrcweir ::rtl::OUString java_lang_Object::callStringMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const
370cdf0e10cSrcweir {
371cdf0e10cSrcweir     SDBThreadAttach t;
372cdf0e10cSrcweir     OSL_ENSURE( t.pEnv, "java_lang_Object::callStringMethod: no Java enviroment anymore!" );
373cdf0e10cSrcweir 	jstring out = (jstring)callObjectMethodWithIntArg(t.pEnv,_pMethodName,"(I)Ljava/lang/String;",_inout_MethodID,_nArgument);
374cdf0e10cSrcweir 	return JavaString2String( t.pEnv, out );
375cdf0e10cSrcweir }
376cdf0e10cSrcweir // -------------------------------------------------------------------------
callVoidMethodWithStringArg(const char * _pMethodName,jmethodID & _inout_MethodID,const::rtl::OUString & _nArgument) const377cdf0e10cSrcweir void java_lang_Object::callVoidMethodWithStringArg( const char* _pMethodName, jmethodID& _inout_MethodID,const ::rtl::OUString& _nArgument ) const
378cdf0e10cSrcweir {
379cdf0e10cSrcweir     SDBThreadAttach t;
380cdf0e10cSrcweir     OSL_ENSURE( t.pEnv, "java_lang_Object::callIntMethod: no Java enviroment anymore!" );
381cdf0e10cSrcweir     obtainMethodId(t.pEnv, _pMethodName,"(Ljava/lang/String;)V", _inout_MethodID);
382cdf0e10cSrcweir 
383cdf0e10cSrcweir     jdbc::LocalRef< jstring > str( t.env(),convertwchar_tToJavaString(t.pEnv,_nArgument));
384cdf0e10cSrcweir     // call method
385cdf0e10cSrcweir 	t.pEnv->CallVoidMethod( object, _inout_MethodID , str.get());
386cdf0e10cSrcweir 	ThrowSQLException( t.pEnv, NULL );
387cdf0e10cSrcweir }
388cdf0e10cSrcweir // -------------------------------------------------------------------------
callIntMethodWithStringArg(const char * _pMethodName,jmethodID & _inout_MethodID,const::rtl::OUString & _nArgument) const389cdf0e10cSrcweir sal_Int32 java_lang_Object::callIntMethodWithStringArg( const char* _pMethodName, jmethodID& _inout_MethodID,const ::rtl::OUString& _nArgument ) const
390cdf0e10cSrcweir {
391cdf0e10cSrcweir     SDBThreadAttach t;
392cdf0e10cSrcweir     OSL_ENSURE( t.pEnv, "java_lang_Object::callIntMethodWithStringArg: no Java enviroment anymore!" );
393cdf0e10cSrcweir     obtainMethodId(t.pEnv, _pMethodName,"(Ljava/lang/String;)I", _inout_MethodID);
394cdf0e10cSrcweir 
395cdf0e10cSrcweir     //TODO: Check if the code below is needed
396cdf0e10cSrcweir             //jdbc::LocalRef< jstring > str( t.env(), convertwchar_tToJavaString( t.pEnv, sql ) );
397cdf0e10cSrcweir             //{
398cdf0e10cSrcweir             //    jdbc::ContextClassLoaderScope ccl( t.env(),
399cdf0e10cSrcweir             //        m_pConnection ? m_pConnection->getDriverClassLoader() : jdbc::GlobalRef< jobject >(),
400cdf0e10cSrcweir             //        m_aLogger,
401cdf0e10cSrcweir             //        *this
402cdf0e10cSrcweir             //    );
403cdf0e10cSrcweir 
404cdf0e10cSrcweir     jdbc::LocalRef< jstring > str( t.env(),convertwchar_tToJavaString(t.pEnv,_nArgument));
405cdf0e10cSrcweir     // call method
406cdf0e10cSrcweir 	jint out = t.pEnv->CallIntMethod( object, _inout_MethodID , str.get());
407cdf0e10cSrcweir 	ThrowSQLException( t.pEnv, NULL );
408cdf0e10cSrcweir     return (sal_Int32)out;
409cdf0e10cSrcweir }
410cdf0e10cSrcweir // -----------------------------------------------------------------------------
findMyClass(const char * _pClassName)411cdf0e10cSrcweir jclass java_lang_Object::findMyClass(const char* _pClassName)
412cdf0e10cSrcweir {
413cdf0e10cSrcweir 	// die Klasse muss nur einmal geholt werden, daher statisch
414cdf0e10cSrcweir 	SDBThreadAttach t;
415cdf0e10cSrcweir 	jclass tempClass = t.pEnv->FindClass(_pClassName); OSL_ENSURE(tempClass,"Java : FindClass nicht erfolgreich!");
416cdf0e10cSrcweir     if(!tempClass)
417cdf0e10cSrcweir 	{
418cdf0e10cSrcweir 		t.pEnv->ExceptionDescribe();
419cdf0e10cSrcweir 		t.pEnv->ExceptionClear();
420cdf0e10cSrcweir 	}
421cdf0e10cSrcweir 	jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass );
422cdf0e10cSrcweir 	t.pEnv->DeleteLocalRef( tempClass );
423cdf0e10cSrcweir 	return globClass;
424cdf0e10cSrcweir }
425cdf0e10cSrcweir 
426