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