1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 
31 #include "java/sql/JStatement.hxx"
32 #include "java/sql/ResultSet.hxx"
33 #include "java/sql/Connection.hxx"
34 #include "java/sql/SQLWarning.hxx"
35 #include "java/tools.hxx"
36 #include "java/ContextClassLoader.hxx"
37 #include <comphelper/property.hxx>
38 #include <com/sun/star/lang/DisposedException.hpp>
39 #include <cppuhelper/typeprovider.hxx>
40 #include <comphelper/sequence.hxx>
41 #include "TConnection.hxx"
42 #include <comphelper/types.hxx>
43 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
44 #include <com/sun/star/sdbc/ResultSetType.hpp>
45 #include <com/sun/star/sdbc/FetchDirection.hpp>
46 
47 #include "resource/jdbc_log.hrc"
48 
49 #include <algorithm>
50 #include <string.h>
51 
52 using namespace ::comphelper;
53 using namespace connectivity;
54 using namespace ::cppu;
55 //------------------------------------------------------------------------------
56 using namespace ::com::sun::star::uno;
57 using namespace ::com::sun::star::beans;
58 using namespace ::com::sun::star::sdbc;
59 using namespace ::com::sun::star::container;
60 using namespace ::com::sun::star::lang;
61 
62 //------------------------------------------------------------------------------
63 //**************************************************************
64 //************ Class: java.sql.Statement
65 //**************************************************************
66 
67 jclass java_sql_Statement_Base::theClass = 0;
68 
69 // -------------------------------------------------------------------------
70 java_sql_Statement_Base::java_sql_Statement_Base( JNIEnv * pEnv, java_sql_Connection& _rCon )
71 	:java_sql_Statement_BASE(m_aMutex)
72 	,java_lang_Object( pEnv, NULL )
73 	,OPropertySetHelper(java_sql_Statement_BASE::rBHelper)
74 	,m_pConnection( &_rCon )
75     ,m_aLogger( _rCon.getLogger(), java::sql::ConnectionLog::STATEMENT )
76 	,m_nResultSetConcurrency(ResultSetConcurrency::READ_ONLY)
77 	,m_nResultSetType(ResultSetType::FORWARD_ONLY)
78     ,m_bEscapeProcessing(sal_True)
79     ,rBHelper(java_sql_Statement_BASE::rBHelper)
80 {
81 	m_pConnection->acquire();
82 }
83 
84 //------------------------------------------------------------------------------
85 java_sql_Statement_Base::~java_sql_Statement_Base()
86 {
87 }
88 
89 //------------------------------------------------------------------------------
90 void SAL_CALL OStatement_BASE2::disposing()
91 {
92 	::osl::MutexGuard aGuard(m_aMutex);
93 
94 	if ( object )
95 	{
96         static jmethodID mID(NULL);
97         callVoidMethod("close",mID);
98 	}
99 
100 	::comphelper::disposeComponent(m_xGeneratedStatement);
101 	if (m_pConnection)
102 		m_pConnection->release();
103 	m_pConnection = NULL;
104 
105 	dispose_ChildImpl();
106 	java_sql_Statement_Base::disposing();
107 }
108 // -------------------------------------------------------------------------
109 jclass java_sql_Statement_Base::getMyClass() const
110 {
111 	// die Klasse muss nur einmal geholt werden, daher statisch
112 	if( !theClass )
113         theClass = findMyClass("java/sql/Statement");
114 	return theClass;
115 }
116 // -----------------------------------------------------------------------------
117 void SAL_CALL java_sql_Statement_Base::disposing(void)
118 {
119     m_aLogger.log( LogLevel::FINE, STR_LOG_CLOSING_STATEMENT );
120 	java_sql_Statement_BASE::disposing();
121 	clearObject();
122 }
123 // -------------------------------------------------------------------------
124 
125 void SAL_CALL OStatement_BASE2::release() throw()
126 {
127 	relase_ChildImpl();
128 }
129 
130 // -------------------------------------------------------------------------
131 Any SAL_CALL java_sql_Statement_Base::queryInterface( const Type & rType ) throw(RuntimeException)
132 {
133 	if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() && rType == ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ) )
134 		return Any();
135 	Any aRet( java_sql_Statement_BASE::queryInterface(rType) );
136 	return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType);
137 }
138 // -------------------------------------------------------------------------
139 Sequence< Type > SAL_CALL java_sql_Statement_Base::getTypes(  ) throw(RuntimeException)
140 {
141 	::cppu::OTypeCollection aTypes(	::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
142 												::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
143 												::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
144 
145 	Sequence< Type > aOldTypes = java_sql_Statement_BASE::getTypes();
146 	if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() )
147 	{
148 		::std::remove(aOldTypes.getArray(),aOldTypes.getArray() + aOldTypes.getLength(),
149 						::getCppuType( (const Reference< XGeneratedResultSet > *)0 ));
150 		aOldTypes.realloc(aOldTypes.getLength() - 1);
151 	}
152 
153 	return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes);
154 }
155 // -----------------------------------------------------------------------------
156 Reference< XResultSet > SAL_CALL java_sql_Statement_Base::getGeneratedValues(  ) throw (SQLException, RuntimeException)
157 {
158     m_aLogger.log( LogLevel::FINE, STR_LOG_GENERATED_VALUES );
159     ::osl::MutexGuard aGuard( m_aMutex );
160 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
161 
162 	jobject out(0);
163     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
164 	createStatement(t.pEnv);
165 	// temporaere Variable initialisieren
166 	try
167     {
168         static jmethodID mID(NULL);
169         out = callResultSetMethod(t.env(),"getGeneratedKeys",mID);
170     }
171     catch(const SQLException&)
172     {
173         // ignore
174     }
175 
176 	Reference< XResultSet > xRes;
177 	if ( !out )
178 	{
179 		OSL_ENSURE(	m_pConnection && m_pConnection->isAutoRetrievingEnabled(),"Illegal call here. isAutoRetrievingEnabled is false!");
180 		if ( m_pConnection )
181 		{
182 			::rtl::OUString sStmt = m_pConnection->getTransformedGeneratedStatement(m_sSqlStatement);
183 			if ( sStmt.getLength() )
184 			{
185                 m_aLogger.log( LogLevel::FINER, STR_LOG_GENERATED_VALUES_FALLBACK, sStmt );
186 				::comphelper::disposeComponent(m_xGeneratedStatement);
187 				m_xGeneratedStatement = m_pConnection->createStatement();
188 				xRes = m_xGeneratedStatement->executeQuery(sStmt);
189 			}
190 		}
191 	}
192 	else
193 		xRes = new java_sql_ResultSet( t.pEnv, out, m_aLogger,*m_pConnection, this );
194 	return xRes;
195 }
196 
197 // -------------------------------------------------------------------------
198 
199 void SAL_CALL java_sql_Statement_Base::cancel(  ) throw(RuntimeException)
200 {
201     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
202 	createStatement(t.pEnv);
203     static jmethodID mID(NULL);
204     callVoidMethod("cancel",mID);
205 }
206 // -------------------------------------------------------------------------
207 
208 void SAL_CALL java_sql_Statement_Base::close(  ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
209 {
210 	{
211 		::osl::MutexGuard aGuard( m_aMutex );
212 		if (java_sql_Statement_BASE::rBHelper.bDisposed)
213 			throw DisposedException();
214 	}
215 	dispose();
216 }
217 // -------------------------------------------------------------------------
218 
219 void SAL_CALL java_sql_Statement::clearBatch(  ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
220 {
221     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
222 	{
223 
224 		createStatement(t.pEnv);
225         static jmethodID mID(NULL);
226         callVoidMethod("clearBatch",mID);
227 	} //t.pEnv
228 }
229 // -------------------------------------------------------------------------
230 
231 sal_Bool SAL_CALL java_sql_Statement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
232 {
233     m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_STATEMENT, sql );
234     ::osl::MutexGuard aGuard( m_aMutex );
235 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
236 
237 	jboolean out(sal_False);
238     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
239 	{
240 		createStatement(t.pEnv);
241 		m_sSqlStatement = sql;
242 		// temporaere Variable initialisieren
243 		static const char * cSignature = "(Ljava/lang/String;)Z";
244 		static const char * cMethodName = "execute";
245 		// Java-Call absetzen
246 		static jmethodID mID(NULL);
247         obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
248 		// Parameter konvertieren
249         jdbc::LocalRef< jstring > str( t.env(), convertwchar_tToJavaString( t.pEnv, sql ) );
250         {
251             jdbc::ContextClassLoaderScope ccl( t.env(),
252                 m_pConnection ? m_pConnection->getDriverClassLoader() : jdbc::GlobalRef< jobject >(),
253                 m_aLogger,
254                 *this
255             );
256 
257 		    out = t.pEnv->CallBooleanMethod( object, mID, str.get() );
258 		    ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
259         }
260 	} //t.pEnv
261 	return out;
262 }
263 // -------------------------------------------------------------------------
264 
265 Reference< XResultSet > SAL_CALL java_sql_Statement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
266 {
267     ::osl::MutexGuard aGuard( m_aMutex );
268 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
269     m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_QUERY, sql );
270 
271     jobject out(0);
272     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
273 
274 	{
275 		createStatement(t.pEnv);
276 		m_sSqlStatement = sql;
277 		// temporaere Variable initialisieren
278 		static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/ResultSet;";
279 		static const char * cMethodName = "executeQuery";
280 		// Java-Call absetzen
281 		static jmethodID mID(NULL);
282         obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
283 		// Parameter konvertieren
284         jdbc::LocalRef< jstring > str( t.env(), convertwchar_tToJavaString( t.pEnv, sql ) );
285         {
286             jdbc::ContextClassLoaderScope ccl( t.env(),
287                 m_pConnection ? m_pConnection->getDriverClassLoader() : jdbc::GlobalRef< jobject >(),
288                 m_aLogger,
289                 *this
290             );
291 
292 			out = t.pEnv->CallObjectMethod( object, mID, str.get() );
293     		ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
294         }
295 	} //t.pEnv
296 	// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
297     return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this );
298 }
299 // -------------------------------------------------------------------------
300 Reference< XConnection > SAL_CALL java_sql_Statement_Base::getConnection(  ) throw(SQLException, RuntimeException)
301 {
302     ::osl::MutexGuard aGuard( m_aMutex );
303 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
304 	return (Reference< XConnection >)m_pConnection;
305 }
306 // -------------------------------------------------------------------------
307 
308 Any SAL_CALL java_sql_Statement::queryInterface( const Type & rType ) throw(RuntimeException)
309 {
310 	Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
311 	return aRet.hasValue() ? aRet : java_sql_Statement_Base::queryInterface(rType);
312 }
313 // -------------------------------------------------------------------------
314 
315 void SAL_CALL java_sql_Statement::addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
316 {
317     ::osl::MutexGuard aGuard( m_aMutex );
318 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
319     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
320 	{
321 		createStatement(t.pEnv);
322         static jmethodID mID(NULL);
323         callVoidMethodWithStringArg("addBatch",mID,sql);
324 	} //t.pEnv
325 }
326 // -------------------------------------------------------------------------
327 
328 Sequence< sal_Int32 > SAL_CALL java_sql_Statement::executeBatch(  ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
329 {
330     ::osl::MutexGuard aGuard( m_aMutex );
331 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
332 	Sequence< sal_Int32 > aSeq;
333     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
334     createStatement(t.pEnv);
335     static jmethodID mID(NULL);
336     jintArray out = (jintArray)callObjectMethod(t.pEnv,"executeBatch","()[I", mID);
337 	if (out)
338 	{
339 		jboolean p = sal_False;
340 		aSeq.realloc(t.pEnv->GetArrayLength(out));
341 		memcpy(aSeq.getArray(),t.pEnv->GetIntArrayElements(out,&p),aSeq.getLength());
342 		t.pEnv->DeleteLocalRef(out);
343 	}
344 	return aSeq;
345 }
346 // -------------------------------------------------------------------------
347 
348 
349 sal_Int32 SAL_CALL java_sql_Statement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
350 {
351     ::osl::MutexGuard aGuard( m_aMutex );
352 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
353     m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_UPDATE, sql );
354 
355     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
356 	createStatement(t.pEnv);
357 	m_sSqlStatement = sql;
358     static jmethodID mID(NULL);
359     return callIntMethodWithStringArg("executeUpdate",mID,sql);
360 }
361 // -------------------------------------------------------------------------
362 
363 Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL java_sql_Statement_Base::getResultSet(  ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
364 {
365     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
366 	createStatement(t.pEnv);
367     static jmethodID mID(NULL);
368     jobject out = callResultSetMethod(t.env(),"getResultSet",mID);
369 
370 	// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
371 	return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this );
372 }
373 // -------------------------------------------------------------------------
374 
375 sal_Int32 SAL_CALL java_sql_Statement_Base::getUpdateCount(  ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
376 {
377     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
378 	createStatement(t.pEnv);
379     static jmethodID mID(NULL);
380 	sal_Int32 out = callIntMethod("getUpdateCount",mID);
381     m_aLogger.log( LogLevel::FINER, STR_LOG_UPDATE_COUNT, (sal_Int32)out );
382 	return out;
383 }
384 // -------------------------------------------------------------------------
385 
386 sal_Bool SAL_CALL java_sql_Statement_Base::getMoreResults(  ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
387 {
388     static jmethodID mID(NULL);
389     return callBooleanMethod( "getMoreResults", mID );
390 }
391 // -------------------------------------------------------------------------
392 
393 // -------------------------------------------------------------------------
394 Any SAL_CALL java_sql_Statement_Base::getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
395 {
396 	SDBThreadAttach t;
397     createStatement(t.pEnv);
398     static jmethodID mID(NULL);
399     jobject out = callObjectMethod(t.pEnv,"getWarnings","()Ljava/sql/SQLWarning;", mID);
400 	// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
401 	if( out )
402 	{
403 		java_sql_SQLWarning_BASE		warn_base( t.pEnv, out );
404 		return makeAny(
405             static_cast< starsdbc::SQLException >(
406                 java_sql_SQLWarning(warn_base,*(::cppu::OWeakObject*)this)));
407 	}
408 
409 	return Any();
410 }
411 // -------------------------------------------------------------------------
412 void SAL_CALL java_sql_Statement_Base::clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
413 {
414     ::osl::MutexGuard aGuard( m_aMutex );
415 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
416 	SDBThreadAttach t;
417 
418 	{
419 		createStatement(t.pEnv);
420         static jmethodID mID(NULL);
421         callVoidMethod("clearWarnings",mID);
422 	}
423 }
424 //------------------------------------------------------------------------------
425 sal_Int32 java_sql_Statement_Base::getQueryTimeOut()  throw(SQLException, RuntimeException)
426 {
427     static jmethodID mID(NULL);
428     return impl_getProperty("getQueryTimeOut",mID);
429 }
430 //------------------------------------------------------------------------------
431 sal_Int32 java_sql_Statement_Base::getMaxRows() throw(SQLException, RuntimeException)
432 {
433     static jmethodID mID(NULL);
434     return impl_getProperty("getMaxRows",mID);
435 }
436 //------------------------------------------------------------------------------
437 sal_Int32 java_sql_Statement_Base::getResultSetConcurrency() throw(SQLException, RuntimeException)
438 {
439     static jmethodID mID(NULL);
440     return impl_getProperty("getResultSetConcurrency",mID,m_nResultSetConcurrency);
441 }
442 
443 //------------------------------------------------------------------------------
444 sal_Int32 java_sql_Statement_Base::getResultSetType() throw(SQLException, RuntimeException)
445 {
446     static jmethodID mID(NULL);
447     return impl_getProperty("getResultSetType",mID,m_nResultSetType);
448 }
449 //------------------------------------------------------------------------------
450 sal_Int32 java_sql_Statement_Base::impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID,sal_Int32 _nDefault)
451 {
452     sal_Int32 out = _nDefault;
453     if ( object )
454         out = callIntMethod(_pMethodName,_inout_MethodID,true);
455 
456 	return out;
457 }
458 //------------------------------------------------------------------------------
459 sal_Int32 java_sql_Statement_Base::impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID)
460 {
461     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
462 	createStatement(t.pEnv);
463     return callIntMethod(_pMethodName,_inout_MethodID,true);
464 }
465 
466 //------------------------------------------------------------------------------
467 sal_Int32 java_sql_Statement_Base::getFetchDirection() throw(SQLException, RuntimeException)
468 {
469     static jmethodID mID(NULL);
470     return impl_getProperty("getFetchDirection",mID);
471 }
472 //------------------------------------------------------------------------------
473 sal_Int32 java_sql_Statement_Base::getFetchSize() throw(SQLException, RuntimeException)
474 {
475     static jmethodID mID(NULL);
476     return impl_getProperty("getFetchSize",mID);
477 }
478 //------------------------------------------------------------------------------
479 sal_Int32 java_sql_Statement_Base::getMaxFieldSize() throw(SQLException, RuntimeException)
480 {
481     static jmethodID mID(NULL);
482     return impl_getProperty("getMaxFieldSize",mID);
483 }
484 //------------------------------------------------------------------------------
485 ::rtl::OUString java_sql_Statement_Base::getCursorName() throw(SQLException, RuntimeException)
486 {
487     ::osl::MutexGuard aGuard( m_aMutex );
488 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
489     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
490     createStatement(t.pEnv);
491     static jmethodID mID(NULL);
492     try
493     {
494         return callStringMethod("getCursorName",mID);
495     }
496     catch(const SQLException&)
497     {
498     }
499     return ::rtl::OUString();
500 }
501 //------------------------------------------------------------------------------
502 void java_sql_Statement_Base::setQueryTimeOut(sal_Int32 _par0) throw(SQLException, RuntimeException)
503 {
504     ::osl::MutexGuard aGuard( m_aMutex );
505 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
506     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
507     createStatement(t.pEnv);
508     static jmethodID mID(NULL);
509     callVoidMethodWithIntArg("setQueryTimeOut",mID,_par0,true);
510 }
511 
512 //------------------------------------------------------------------------------
513 void java_sql_Statement_Base::setEscapeProcessing(sal_Bool _par0) throw(SQLException, RuntimeException)
514 {
515     ::osl::MutexGuard aGuard( m_aMutex );
516 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
517     m_aLogger.log( LogLevel::FINE, STR_LOG_SET_ESCAPE_PROCESSING, _par0 );
518 
519     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
520     m_bEscapeProcessing = _par0;
521     createStatement( t.pEnv );
522     static jmethodID mID(NULL);
523     callVoidMethodWithBoolArg("setEscapeProcessing",mID,_par0,true);
524 }
525 
526 //------------------------------------------------------------------------------
527 void java_sql_Statement_Base::setMaxRows(sal_Int32 _par0) throw(SQLException, RuntimeException)
528 {
529     ::osl::MutexGuard aGuard( m_aMutex );
530 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
531     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
532     createStatement(t.pEnv);
533     static jmethodID mID(NULL);
534     callVoidMethodWithIntArg("setMaxRows",mID,_par0,true);
535 }
536 //------------------------------------------------------------------------------
537 void java_sql_Statement_Base::setResultSetConcurrency(sal_Int32 _par0) throw(SQLException, RuntimeException)
538 {
539     ::osl::MutexGuard aGuard( m_aMutex );
540 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
541     m_aLogger.log( LogLevel::FINE, STR_LOG_RESULT_SET_CONCURRENCY, (sal_Int32)_par0 );
542 	m_nResultSetConcurrency = _par0;
543 
544     clearObject();
545 }
546 //------------------------------------------------------------------------------
547 void java_sql_Statement_Base::setResultSetType(sal_Int32 _par0) throw(SQLException, RuntimeException)
548 {
549 	::osl::MutexGuard aGuard( m_aMutex );
550 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
551     m_aLogger.log( LogLevel::FINE, STR_LOG_RESULT_SET_TYPE, (sal_Int32)_par0 );
552 	m_nResultSetType = _par0;
553 
554     clearObject();
555 }
556 //------------------------------------------------------------------------------
557 void java_sql_Statement_Base::setFetchDirection(sal_Int32 _par0) throw(SQLException, RuntimeException)
558 {
559     ::osl::MutexGuard aGuard( m_aMutex );
560 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
561     m_aLogger.log( LogLevel::FINER, STR_LOG_FETCH_DIRECTION, (sal_Int32)_par0 );
562     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
563     createStatement(t.pEnv);
564     static jmethodID mID(NULL);
565     callVoidMethodWithIntArg("setFetchDirection",mID,_par0,true);
566 }
567 //------------------------------------------------------------------------------
568 void java_sql_Statement_Base::setFetchSize(sal_Int32 _par0) throw(SQLException, RuntimeException)
569 {
570     ::osl::MutexGuard aGuard( m_aMutex );
571 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
572     m_aLogger.log( LogLevel::FINER, STR_LOG_FETCH_SIZE, (sal_Int32)_par0 );
573 
574     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
575     createStatement(t.pEnv);
576     static jmethodID mID(NULL);
577     callVoidMethodWithIntArg("setFetchSize",mID,_par0,true);
578 }
579 //------------------------------------------------------------------------------
580 void java_sql_Statement_Base::setMaxFieldSize(sal_Int32 _par0) throw(SQLException, RuntimeException)
581 {
582     ::osl::MutexGuard aGuard( m_aMutex );
583 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
584     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
585     createStatement(t.pEnv);
586     static jmethodID mID(NULL);
587     callVoidMethodWithIntArg("setMaxFieldSize",mID,_par0,true);
588 }
589 //------------------------------------------------------------------------------
590 void java_sql_Statement_Base::setCursorName(const ::rtl::OUString &_par0) throw(SQLException, RuntimeException)
591 {
592     ::osl::MutexGuard aGuard( m_aMutex );
593 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
594     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
595 	{
596 		createStatement(t.pEnv);
597         static jmethodID mID(NULL);
598         callVoidMethodWithStringArg("setCursorName",mID,_par0);
599 	} //t.pEnv
600 }
601 
602 // -------------------------------------------------------------------------
603 ::cppu::IPropertyArrayHelper* java_sql_Statement_Base::createArrayHelper( ) const
604 {
605 	Sequence< Property > aProps(10);
606 	Property* pProperties = aProps.getArray();
607 	sal_Int32 nPos = 0;
608 	DECL_PROP0(CURSORNAME,	::rtl::OUString);
609 	DECL_BOOL_PROP0(ESCAPEPROCESSING);
610 	DECL_PROP0(FETCHDIRECTION,sal_Int32);
611 	DECL_PROP0(FETCHSIZE,	sal_Int32);
612 	DECL_PROP0(MAXFIELDSIZE,sal_Int32);
613 	DECL_PROP0(MAXROWS,		sal_Int32);
614 	DECL_PROP0(QUERYTIMEOUT,sal_Int32);
615 	DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
616 	DECL_PROP0(RESULTSETTYPE,sal_Int32);
617 	DECL_BOOL_PROP0(USEBOOKMARKS);
618 
619 	return new ::cppu::OPropertyArrayHelper(aProps);
620 }
621 
622 // -------------------------------------------------------------------------
623 ::cppu::IPropertyArrayHelper & java_sql_Statement_Base::getInfoHelper()
624 
625 {
626 	return *const_cast<java_sql_Statement_Base*>(this)->getArrayHelper();
627 }
628 // -------------------------------------------------------------------------
629 sal_Bool java_sql_Statement_Base::convertFastPropertyValue(
630 							Any & rConvertedValue,
631 							Any & rOldValue,
632 							sal_Int32 nHandle,
633 							const Any& rValue )
634 								throw (::com::sun::star::lang::IllegalArgumentException)
635 {
636 	switch(nHandle)
637 	{
638 		case PROPERTY_ID_QUERYTIMEOUT:
639 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut());
640 		case PROPERTY_ID_MAXFIELDSIZE:
641 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize());
642 		case PROPERTY_ID_MAXROWS:
643 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxRows());
644 		case PROPERTY_ID_CURSORNAME:
645 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName());
646 		case PROPERTY_ID_RESULTSETCONCURRENCY:
647 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency());
648 		case PROPERTY_ID_RESULTSETTYPE:
649 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType());
650 		case PROPERTY_ID_FETCHDIRECTION:
651 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
652 		case PROPERTY_ID_FETCHSIZE:
653 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
654 		case PROPERTY_ID_ESCAPEPROCESSING:
655 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bEscapeProcessing );
656 		case PROPERTY_ID_USEBOOKMARKS:
657 			//	return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
658 		default:
659 			;
660 	}
661 	return sal_False;
662 }
663 // -------------------------------------------------------------------------
664 void java_sql_Statement_Base::setFastPropertyValue_NoBroadcast(
665 								sal_Int32 nHandle,
666 								const Any& rValue
667 												 )
668 												 throw (Exception)
669 {
670 	switch(nHandle)
671 	{
672 		case PROPERTY_ID_QUERYTIMEOUT:
673 			setQueryTimeOut(comphelper::getINT32(rValue));
674 			break;
675 		case PROPERTY_ID_MAXFIELDSIZE:
676 			setMaxFieldSize(comphelper::getINT32(rValue));
677 			break;
678 		case PROPERTY_ID_MAXROWS:
679 			setMaxRows(comphelper::getINT32(rValue));
680 			break;
681 		case PROPERTY_ID_CURSORNAME:
682 			setCursorName(comphelper::getString(rValue));
683 			break;
684 		case PROPERTY_ID_RESULTSETCONCURRENCY:
685 			setResultSetConcurrency(comphelper::getINT32(rValue));
686 			break;
687 		case PROPERTY_ID_RESULTSETTYPE:
688 			setResultSetType(comphelper::getINT32(rValue));
689 			break;
690 		case PROPERTY_ID_FETCHDIRECTION:
691 			setFetchDirection(comphelper::getINT32(rValue));
692 			break;
693 		case PROPERTY_ID_FETCHSIZE:
694 			setFetchSize(comphelper::getINT32(rValue));
695 			break;
696 		case PROPERTY_ID_ESCAPEPROCESSING:
697             setEscapeProcessing( ::comphelper::getBOOL( rValue ) );
698             break;
699 		case PROPERTY_ID_USEBOOKMARKS:
700 			//	return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
701 		default:
702 			;
703 	}
704 }
705 // -------------------------------------------------------------------------
706 void java_sql_Statement_Base::getFastPropertyValue(
707 								Any& rValue,
708 								sal_Int32 nHandle
709 									 ) const
710 {
711 	java_sql_Statement_Base* THIS = const_cast<java_sql_Statement_Base*>(this);
712     try
713     {
714 	    switch(nHandle)
715 	    {
716 		    case PROPERTY_ID_QUERYTIMEOUT:
717 			    rValue <<= THIS->getQueryTimeOut();
718 			    break;
719 		    case PROPERTY_ID_MAXFIELDSIZE:
720 			    rValue <<= THIS->getMaxFieldSize();
721 			    break;
722 		    case PROPERTY_ID_MAXROWS:
723 			    rValue <<= THIS->getMaxRows();
724 			    break;
725 		    case PROPERTY_ID_CURSORNAME:
726 			    rValue <<= THIS->getCursorName();
727 			    break;
728 		    case PROPERTY_ID_RESULTSETCONCURRENCY:
729 			    rValue <<= THIS->getResultSetConcurrency();
730 			    break;
731 		    case PROPERTY_ID_RESULTSETTYPE:
732 			    rValue <<= THIS->getResultSetType();
733 			    break;
734 		    case PROPERTY_ID_FETCHDIRECTION:
735 			    rValue <<= THIS->getFetchDirection();
736 			    break;
737 		    case PROPERTY_ID_FETCHSIZE:
738 			    rValue <<= THIS->getFetchSize();
739 			    break;
740 		    case PROPERTY_ID_ESCAPEPROCESSING:
741                 rValue <<= (sal_Bool)m_bEscapeProcessing;
742                 break;
743 		    case PROPERTY_ID_USEBOOKMARKS:
744 		    default:
745 			    ;
746 	    }
747     }
748     catch(const Exception&)
749     {
750     }
751 }
752 // -------------------------------------------------------------------------
753 jclass java_sql_Statement::theClass = 0;
754 
755 java_sql_Statement::~java_sql_Statement()
756 {}
757 
758 jclass java_sql_Statement::getMyClass() const
759 {
760 	// die Klasse muss nur einmal geholt werden, daher statisch
761 	if( !theClass )
762         theClass = findMyClass("java/sql/Statement");
763 	return theClass;
764 }
765 
766 // -----------------------------------------------------------------------------
767 void java_sql_Statement::createStatement(JNIEnv* _pEnv)
768 {
769 	::osl::MutexGuard aGuard( m_aMutex );
770 	checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
771 
772 	if( _pEnv && !object ){
773 		// temporaere Variable initialisieren
774 		static const char * cSignature = "(II)Ljava/sql/Statement;";
775 		static const char * cMethodName = "createStatement";
776 		// Java-Call absetzen
777 		jobject out = NULL;
778 		static jmethodID mID(NULL);
779 		if ( !mID  )
780 			mID  = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature );
781 		if( mID ){
782 			out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID,m_nResultSetType,m_nResultSetConcurrency );
783 		} //mID
784 		else
785 		{
786 			static const char * cSignature2 = "()Ljava/sql/Statement;";
787 			static jmethodID mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID2,"Unknown method id!");
788 			if( mID2 ){
789 				out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2);
790 			} //mID
791 		}
792 		ThrowLoggedSQLException( m_aLogger, _pEnv, *this );
793 
794 		if ( out )
795 			object = _pEnv->NewGlobalRef( out );
796 	} //_pEnv
797 }
798 // -----------------------------------------------------------------------------
799 
800 
801 IMPLEMENT_SERVICE_INFO(java_sql_Statement,"com.sun.star.sdbcx.JStatement","com.sun.star.sdbc.Statement");
802 // -----------------------------------------------------------------------------
803 void SAL_CALL java_sql_Statement_Base::acquire() throw()
804 {
805 	java_sql_Statement_BASE::acquire();
806 }
807 // -----------------------------------------------------------------------------
808 void SAL_CALL java_sql_Statement_Base::release() throw()
809 {
810 	java_sql_Statement_BASE::release();
811 }
812 // -----------------------------------------------------------------------------
813 void SAL_CALL java_sql_Statement::acquire() throw()
814 {
815 	OStatement_BASE2::acquire();
816 }
817 // -----------------------------------------------------------------------------
818 void SAL_CALL java_sql_Statement::release() throw()
819 {
820 	OStatement_BASE2::release();
821 }
822 // -----------------------------------------------------------------------------
823 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL java_sql_Statement_Base::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
824 {
825 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
826 }
827 // -----------------------------------------------------------------------------
828 
829 
830