merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / jdbc / JStatement.cxx
blob7aa1750bb65b406d19c5d7ca16134d560d323e06
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: JStatement.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "java/sql/JStatement.hxx"
35 #include "java/sql/ResultSet.hxx"
36 #include "java/sql/Connection.hxx"
37 #include "java/sql/SQLWarning.hxx"
38 #include "java/tools.hxx"
39 #include "java/ContextClassLoader.hxx"
40 #include <comphelper/property.hxx>
41 #include <com/sun/star/lang/DisposedException.hpp>
42 #include <cppuhelper/typeprovider.hxx>
43 #include <comphelper/sequence.hxx>
44 #include "TConnection.hxx"
45 #include <comphelper/types.hxx>
46 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
47 #include <com/sun/star/sdbc/ResultSetType.hpp>
48 #include <com/sun/star/sdbc/FetchDirection.hpp>
50 #include "resource/jdbc_log.hrc"
52 #include <algorithm>
53 #include <string.h>
55 using namespace ::comphelper;
56 using namespace connectivity;
57 using namespace ::cppu;
58 //------------------------------------------------------------------------------
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::sdbc;
62 using namespace ::com::sun::star::container;
63 using namespace ::com::sun::star::lang;
65 //------------------------------------------------------------------------------
66 //**************************************************************
67 //************ Class: java.sql.Statement
68 //**************************************************************
70 jclass java_sql_Statement_Base::theClass = 0;
72 // -------------------------------------------------------------------------
73 java_sql_Statement_Base::java_sql_Statement_Base( JNIEnv * pEnv, java_sql_Connection& _rCon )
74 :java_sql_Statement_BASE(m_aMutex)
75 ,java_lang_Object( pEnv, NULL )
76 ,OPropertySetHelper(java_sql_Statement_BASE::rBHelper)
77 ,m_pConnection( &_rCon )
78 ,m_aLogger( _rCon.getLogger(), java::sql::ConnectionLog::STATEMENT )
79 ,m_nResultSetConcurrency(ResultSetConcurrency::READ_ONLY)
80 ,m_nResultSetType(ResultSetType::FORWARD_ONLY)
81 ,m_bEscapeProcessing(sal_True)
82 ,rBHelper(java_sql_Statement_BASE::rBHelper)
84 m_pConnection->acquire();
87 //------------------------------------------------------------------------------
88 java_sql_Statement_Base::~java_sql_Statement_Base()
92 //------------------------------------------------------------------------------
93 void SAL_CALL OStatement_BASE2::disposing()
95 ::osl::MutexGuard aGuard(m_aMutex);
97 if ( object )
99 static jmethodID mID(NULL);
100 callVoidMethod("close",mID);
103 ::comphelper::disposeComponent(m_xGeneratedStatement);
104 if (m_pConnection)
105 m_pConnection->release();
106 m_pConnection = NULL;
108 dispose_ChildImpl();
109 java_sql_Statement_Base::disposing();
111 // -------------------------------------------------------------------------
112 jclass java_sql_Statement_Base::getMyClass() const
114 // die Klasse muss nur einmal geholt werden, daher statisch
115 if( !theClass )
116 theClass = findMyClass("java/sql/Statement");
117 return theClass;
119 // -----------------------------------------------------------------------------
120 void SAL_CALL java_sql_Statement_Base::disposing(void)
122 m_aLogger.log( LogLevel::FINE, STR_LOG_CLOSING_STATEMENT );
123 java_sql_Statement_BASE::disposing();
124 clearObject();
126 // -------------------------------------------------------------------------
128 void SAL_CALL OStatement_BASE2::release() throw()
130 relase_ChildImpl();
133 // -------------------------------------------------------------------------
134 Any SAL_CALL java_sql_Statement_Base::queryInterface( const Type & rType ) throw(RuntimeException)
136 if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() && rType == ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ) )
137 return Any();
138 Any aRet( java_sql_Statement_BASE::queryInterface(rType) );
139 return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType);
141 // -------------------------------------------------------------------------
142 Sequence< Type > SAL_CALL java_sql_Statement_Base::getTypes( ) throw(RuntimeException)
144 ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
145 ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
146 ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
148 Sequence< Type > aOldTypes = java_sql_Statement_BASE::getTypes();
149 if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() )
151 ::std::remove(aOldTypes.getArray(),aOldTypes.getArray() + aOldTypes.getLength(),
152 ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ));
153 aOldTypes.realloc(aOldTypes.getLength() - 1);
156 return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes);
158 // -----------------------------------------------------------------------------
159 Reference< XResultSet > SAL_CALL java_sql_Statement_Base::getGeneratedValues( ) throw (SQLException, RuntimeException)
161 m_aLogger.log( LogLevel::FINE, STR_LOG_GENERATED_VALUES );
162 ::osl::MutexGuard aGuard( m_aMutex );
163 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
165 jobject out(0);
166 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
167 createStatement(t.pEnv);
168 // temporaere Variable initialisieren
171 static jmethodID mID(NULL);
172 out = callResultSetMethod(t.env(),"getGeneratedKeys",mID);
174 catch(const SQLException&)
176 // ignore
179 Reference< XResultSet > xRes;
180 if ( !out )
182 OSL_ENSURE( m_pConnection && m_pConnection->isAutoRetrievingEnabled(),"Illegal call here. isAutoRetrievingEnabled is false!");
183 if ( m_pConnection )
185 ::rtl::OUString sStmt = m_pConnection->getTransformedGeneratedStatement(m_sSqlStatement);
186 if ( sStmt.getLength() )
188 m_aLogger.log( LogLevel::FINER, STR_LOG_GENERATED_VALUES_FALLBACK, sStmt );
189 ::comphelper::disposeComponent(m_xGeneratedStatement);
190 m_xGeneratedStatement = m_pConnection->createStatement();
191 xRes = m_xGeneratedStatement->executeQuery(sStmt);
195 else
196 xRes = new java_sql_ResultSet( t.pEnv, out, m_aLogger,*m_pConnection, this );
197 return xRes;
200 // -------------------------------------------------------------------------
202 void SAL_CALL java_sql_Statement_Base::cancel( ) throw(RuntimeException)
204 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
205 createStatement(t.pEnv);
206 static jmethodID mID(NULL);
207 callVoidMethod("cancel",mID);
209 // -------------------------------------------------------------------------
211 void SAL_CALL java_sql_Statement_Base::close( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
214 ::osl::MutexGuard aGuard( m_aMutex );
215 if (java_sql_Statement_BASE::rBHelper.bDisposed)
216 throw DisposedException();
218 dispose();
220 // -------------------------------------------------------------------------
222 void SAL_CALL java_sql_Statement::clearBatch( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
224 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
227 createStatement(t.pEnv);
228 static jmethodID mID(NULL);
229 callVoidMethod("clearBatch",mID);
230 } //t.pEnv
232 // -------------------------------------------------------------------------
234 sal_Bool SAL_CALL java_sql_Statement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
236 m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_STATEMENT, sql );
237 ::osl::MutexGuard aGuard( m_aMutex );
238 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
240 jboolean out(sal_False);
241 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
243 createStatement(t.pEnv);
244 m_sSqlStatement = sql;
245 // temporaere Variable initialisieren
246 static const char * cSignature = "(Ljava/lang/String;)Z";
247 static const char * cMethodName = "execute";
248 // Java-Call absetzen
249 static jmethodID mID(NULL);
250 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
251 // Parameter konvertieren
252 jdbc::LocalRef< jstring > str( t.env(), convertwchar_tToJavaString( t.pEnv, sql ) );
254 jdbc::ContextClassLoaderScope ccl( t.env(),
255 m_pConnection ? m_pConnection->getDriverClassLoader() : jdbc::GlobalRef< jobject >(),
256 m_aLogger,
257 *this
260 out = t.pEnv->CallBooleanMethod( object, mID, str.get() );
261 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
263 } //t.pEnv
264 return out;
266 // -------------------------------------------------------------------------
268 Reference< XResultSet > SAL_CALL java_sql_Statement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
270 ::osl::MutexGuard aGuard( m_aMutex );
271 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
272 m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_QUERY, sql );
274 jobject out(0);
275 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
278 createStatement(t.pEnv);
279 m_sSqlStatement = sql;
280 // temporaere Variable initialisieren
281 static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/ResultSet;";
282 static const char * cMethodName = "executeQuery";
283 // Java-Call absetzen
284 static jmethodID mID(NULL);
285 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
286 // Parameter konvertieren
287 jdbc::LocalRef< jstring > str( t.env(), convertwchar_tToJavaString( t.pEnv, sql ) );
289 jdbc::ContextClassLoaderScope ccl( t.env(),
290 m_pConnection ? m_pConnection->getDriverClassLoader() : jdbc::GlobalRef< jobject >(),
291 m_aLogger,
292 *this
295 out = t.pEnv->CallObjectMethod( object, mID, str.get() );
296 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
298 } //t.pEnv
299 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
300 return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this );
302 // -------------------------------------------------------------------------
303 Reference< XConnection > SAL_CALL java_sql_Statement_Base::getConnection( ) throw(SQLException, RuntimeException)
305 ::osl::MutexGuard aGuard( m_aMutex );
306 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
307 return (Reference< XConnection >)m_pConnection;
309 // -------------------------------------------------------------------------
311 Any SAL_CALL java_sql_Statement::queryInterface( const Type & rType ) throw(RuntimeException)
313 Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
314 return aRet.hasValue() ? aRet : java_sql_Statement_Base::queryInterface(rType);
316 // -------------------------------------------------------------------------
318 void SAL_CALL java_sql_Statement::addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
320 ::osl::MutexGuard aGuard( m_aMutex );
321 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
322 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
324 createStatement(t.pEnv);
325 static jmethodID mID(NULL);
326 callVoidMethodWithStringArg("addBatch",mID,sql);
327 } //t.pEnv
329 // -------------------------------------------------------------------------
331 Sequence< sal_Int32 > SAL_CALL java_sql_Statement::executeBatch( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
333 ::osl::MutexGuard aGuard( m_aMutex );
334 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
335 Sequence< sal_Int32 > aSeq;
336 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
337 createStatement(t.pEnv);
338 static jmethodID mID(NULL);
339 jintArray out = (jintArray)callObjectMethod(t.pEnv,"executeBatch","()[I", mID);
340 if (out)
342 jboolean p = sal_False;
343 aSeq.realloc(t.pEnv->GetArrayLength(out));
344 memcpy(aSeq.getArray(),t.pEnv->GetIntArrayElements(out,&p),aSeq.getLength());
345 t.pEnv->DeleteLocalRef(out);
347 return aSeq;
349 // -------------------------------------------------------------------------
352 sal_Int32 SAL_CALL java_sql_Statement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
354 ::osl::MutexGuard aGuard( m_aMutex );
355 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
356 m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_UPDATE, sql );
358 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
359 createStatement(t.pEnv);
360 m_sSqlStatement = sql;
361 static jmethodID mID(NULL);
362 return callIntMethodWithStringArg("executeUpdate",mID,sql);
364 // -------------------------------------------------------------------------
366 Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL java_sql_Statement_Base::getResultSet( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
368 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
369 createStatement(t.pEnv);
370 static jmethodID mID(NULL);
371 jobject out = callResultSetMethod(t.env(),"getResultSet",mID);
373 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
374 return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this );
376 // -------------------------------------------------------------------------
378 sal_Int32 SAL_CALL java_sql_Statement_Base::getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
380 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
381 createStatement(t.pEnv);
382 static jmethodID mID(NULL);
383 sal_Int32 out = callIntMethod("getUpdateCount",mID);
384 m_aLogger.log( LogLevel::FINER, STR_LOG_UPDATE_COUNT, (sal_Int32)out );
385 return out;
387 // -------------------------------------------------------------------------
389 sal_Bool SAL_CALL java_sql_Statement_Base::getMoreResults( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
391 static jmethodID mID(NULL);
392 return callBooleanMethod( "getMoreResults", mID );
394 // -------------------------------------------------------------------------
396 // -------------------------------------------------------------------------
397 Any SAL_CALL java_sql_Statement_Base::getWarnings( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
399 SDBThreadAttach t;
400 createStatement(t.pEnv);
401 static jmethodID mID(NULL);
402 jobject out = callObjectMethod(t.pEnv,"getWarnings","()Ljava/sql/SQLWarning;", mID);
403 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
404 if( out )
406 java_sql_SQLWarning_BASE warn_base( t.pEnv, out );
407 return makeAny(
408 static_cast< starsdbc::SQLException >(
409 java_sql_SQLWarning(warn_base,*(::cppu::OWeakObject*)this)));
412 return Any();
414 // -------------------------------------------------------------------------
415 void SAL_CALL java_sql_Statement_Base::clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
417 ::osl::MutexGuard aGuard( m_aMutex );
418 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
419 SDBThreadAttach t;
422 createStatement(t.pEnv);
423 static jmethodID mID(NULL);
424 callVoidMethod("clearWarnings",mID);
427 //------------------------------------------------------------------------------
428 sal_Int32 java_sql_Statement_Base::getQueryTimeOut() throw(SQLException, RuntimeException)
430 static jmethodID mID(NULL);
431 return impl_getProperty("getQueryTimeOut",mID);
433 //------------------------------------------------------------------------------
434 sal_Int32 java_sql_Statement_Base::getMaxRows() throw(SQLException, RuntimeException)
436 static jmethodID mID(NULL);
437 return impl_getProperty("getMaxRows",mID);
439 //------------------------------------------------------------------------------
440 sal_Int32 java_sql_Statement_Base::getResultSetConcurrency() throw(SQLException, RuntimeException)
442 static jmethodID mID(NULL);
443 return impl_getProperty("getResultSetConcurrency",mID,m_nResultSetConcurrency);
446 //------------------------------------------------------------------------------
447 sal_Int32 java_sql_Statement_Base::getResultSetType() throw(SQLException, RuntimeException)
449 static jmethodID mID(NULL);
450 return impl_getProperty("getResultSetType",mID,m_nResultSetType);
452 //------------------------------------------------------------------------------
453 sal_Int32 java_sql_Statement_Base::impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID,sal_Int32 _nDefault)
455 sal_Int32 out = _nDefault;
456 if ( object )
457 out = callIntMethod(_pMethodName,_inout_MethodID,true);
459 return out;
461 //------------------------------------------------------------------------------
462 sal_Int32 java_sql_Statement_Base::impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID)
464 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
465 createStatement(t.pEnv);
466 return callIntMethod(_pMethodName,_inout_MethodID,true);
469 //------------------------------------------------------------------------------
470 sal_Int32 java_sql_Statement_Base::getFetchDirection() throw(SQLException, RuntimeException)
472 static jmethodID mID(NULL);
473 return impl_getProperty("getFetchDirection",mID);
475 //------------------------------------------------------------------------------
476 sal_Int32 java_sql_Statement_Base::getFetchSize() throw(SQLException, RuntimeException)
478 static jmethodID mID(NULL);
479 return impl_getProperty("getFetchSize",mID);
481 //------------------------------------------------------------------------------
482 sal_Int32 java_sql_Statement_Base::getMaxFieldSize() throw(SQLException, RuntimeException)
484 static jmethodID mID(NULL);
485 return impl_getProperty("getMaxFieldSize",mID);
487 //------------------------------------------------------------------------------
488 ::rtl::OUString java_sql_Statement_Base::getCursorName() throw(SQLException, RuntimeException)
490 ::osl::MutexGuard aGuard( m_aMutex );
491 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
492 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
493 createStatement(t.pEnv);
494 static jmethodID mID(NULL);
497 return callStringMethod("getCursorName",mID);
499 catch(const SQLException&)
502 return ::rtl::OUString();
504 //------------------------------------------------------------------------------
505 void java_sql_Statement_Base::setQueryTimeOut(sal_Int32 _par0) throw(SQLException, RuntimeException)
507 ::osl::MutexGuard aGuard( m_aMutex );
508 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
509 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
510 createStatement(t.pEnv);
511 static jmethodID mID(NULL);
512 callVoidMethodWithIntArg("setQueryTimeOut",mID,_par0,true);
515 //------------------------------------------------------------------------------
516 void java_sql_Statement_Base::setEscapeProcessing(sal_Bool _par0) throw(SQLException, RuntimeException)
518 ::osl::MutexGuard aGuard( m_aMutex );
519 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
520 m_aLogger.log( LogLevel::FINE, STR_LOG_SET_ESCAPE_PROCESSING, _par0 );
522 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
523 m_bEscapeProcessing = _par0;
524 createStatement( t.pEnv );
525 static jmethodID mID(NULL);
526 callVoidMethodWithBoolArg("setEscapeProcessing",mID,_par0,true);
529 //------------------------------------------------------------------------------
530 void java_sql_Statement_Base::setMaxRows(sal_Int32 _par0) throw(SQLException, RuntimeException)
532 ::osl::MutexGuard aGuard( m_aMutex );
533 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
534 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
535 createStatement(t.pEnv);
536 static jmethodID mID(NULL);
537 callVoidMethodWithIntArg("setMaxRows",mID,_par0,true);
539 //------------------------------------------------------------------------------
540 void java_sql_Statement_Base::setResultSetConcurrency(sal_Int32 _par0) throw(SQLException, RuntimeException)
542 ::osl::MutexGuard aGuard( m_aMutex );
543 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
544 m_aLogger.log( LogLevel::FINE, STR_LOG_RESULT_SET_CONCURRENCY, (sal_Int32)_par0 );
545 m_nResultSetConcurrency = _par0;
547 clearObject();
549 //------------------------------------------------------------------------------
550 void java_sql_Statement_Base::setResultSetType(sal_Int32 _par0) throw(SQLException, RuntimeException)
552 ::osl::MutexGuard aGuard( m_aMutex );
553 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
554 m_aLogger.log( LogLevel::FINE, STR_LOG_RESULT_SET_TYPE, (sal_Int32)_par0 );
555 m_nResultSetType = _par0;
557 clearObject();
559 //------------------------------------------------------------------------------
560 void java_sql_Statement_Base::setFetchDirection(sal_Int32 _par0) throw(SQLException, RuntimeException)
562 ::osl::MutexGuard aGuard( m_aMutex );
563 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
564 m_aLogger.log( LogLevel::FINER, STR_LOG_FETCH_DIRECTION, (sal_Int32)_par0 );
565 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
566 createStatement(t.pEnv);
567 static jmethodID mID(NULL);
568 callVoidMethodWithIntArg("setFetchDirection",mID,_par0,true);
570 //------------------------------------------------------------------------------
571 void java_sql_Statement_Base::setFetchSize(sal_Int32 _par0) throw(SQLException, RuntimeException)
573 ::osl::MutexGuard aGuard( m_aMutex );
574 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
575 m_aLogger.log( LogLevel::FINER, STR_LOG_FETCH_SIZE, (sal_Int32)_par0 );
577 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
578 createStatement(t.pEnv);
579 static jmethodID mID(NULL);
580 callVoidMethodWithIntArg("setFetchSize",mID,_par0,true);
582 //------------------------------------------------------------------------------
583 void java_sql_Statement_Base::setMaxFieldSize(sal_Int32 _par0) throw(SQLException, RuntimeException)
585 ::osl::MutexGuard aGuard( m_aMutex );
586 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
587 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
588 createStatement(t.pEnv);
589 static jmethodID mID(NULL);
590 callVoidMethodWithIntArg("setMaxFieldSize",mID,_par0,true);
592 //------------------------------------------------------------------------------
593 void java_sql_Statement_Base::setCursorName(const ::rtl::OUString &_par0) throw(SQLException, RuntimeException)
595 ::osl::MutexGuard aGuard( m_aMutex );
596 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
597 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
599 createStatement(t.pEnv);
600 static jmethodID mID(NULL);
601 callVoidMethodWithStringArg("setCursorName",mID,_par0);
602 } //t.pEnv
605 // -------------------------------------------------------------------------
606 ::cppu::IPropertyArrayHelper* java_sql_Statement_Base::createArrayHelper( ) const
608 Sequence< Property > aProps(10);
609 Property* pProperties = aProps.getArray();
610 sal_Int32 nPos = 0;
611 DECL_PROP0(CURSORNAME, ::rtl::OUString);
612 DECL_BOOL_PROP0(ESCAPEPROCESSING);
613 DECL_PROP0(FETCHDIRECTION,sal_Int32);
614 DECL_PROP0(FETCHSIZE, sal_Int32);
615 DECL_PROP0(MAXFIELDSIZE,sal_Int32);
616 DECL_PROP0(MAXROWS, sal_Int32);
617 DECL_PROP0(QUERYTIMEOUT,sal_Int32);
618 DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
619 DECL_PROP0(RESULTSETTYPE,sal_Int32);
620 DECL_BOOL_PROP0(USEBOOKMARKS);
622 return new ::cppu::OPropertyArrayHelper(aProps);
625 // -------------------------------------------------------------------------
626 ::cppu::IPropertyArrayHelper & java_sql_Statement_Base::getInfoHelper()
629 return *const_cast<java_sql_Statement_Base*>(this)->getArrayHelper();
631 // -------------------------------------------------------------------------
632 sal_Bool java_sql_Statement_Base::convertFastPropertyValue(
633 Any & rConvertedValue,
634 Any & rOldValue,
635 sal_Int32 nHandle,
636 const Any& rValue )
637 throw (::com::sun::star::lang::IllegalArgumentException)
639 switch(nHandle)
641 case PROPERTY_ID_QUERYTIMEOUT:
642 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut());
643 case PROPERTY_ID_MAXFIELDSIZE:
644 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize());
645 case PROPERTY_ID_MAXROWS:
646 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxRows());
647 case PROPERTY_ID_CURSORNAME:
648 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName());
649 case PROPERTY_ID_RESULTSETCONCURRENCY:
650 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency());
651 case PROPERTY_ID_RESULTSETTYPE:
652 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType());
653 case PROPERTY_ID_FETCHDIRECTION:
654 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
655 case PROPERTY_ID_FETCHSIZE:
656 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
657 case PROPERTY_ID_ESCAPEPROCESSING:
658 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bEscapeProcessing );
659 case PROPERTY_ID_USEBOOKMARKS:
660 // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
661 default:
664 return sal_False;
666 // -------------------------------------------------------------------------
667 void java_sql_Statement_Base::setFastPropertyValue_NoBroadcast(
668 sal_Int32 nHandle,
669 const Any& rValue
671 throw (Exception)
673 switch(nHandle)
675 case PROPERTY_ID_QUERYTIMEOUT:
676 setQueryTimeOut(comphelper::getINT32(rValue));
677 break;
678 case PROPERTY_ID_MAXFIELDSIZE:
679 setMaxFieldSize(comphelper::getINT32(rValue));
680 break;
681 case PROPERTY_ID_MAXROWS:
682 setMaxRows(comphelper::getINT32(rValue));
683 break;
684 case PROPERTY_ID_CURSORNAME:
685 setCursorName(comphelper::getString(rValue));
686 break;
687 case PROPERTY_ID_RESULTSETCONCURRENCY:
688 setResultSetConcurrency(comphelper::getINT32(rValue));
689 break;
690 case PROPERTY_ID_RESULTSETTYPE:
691 setResultSetType(comphelper::getINT32(rValue));
692 break;
693 case PROPERTY_ID_FETCHDIRECTION:
694 setFetchDirection(comphelper::getINT32(rValue));
695 break;
696 case PROPERTY_ID_FETCHSIZE:
697 setFetchSize(comphelper::getINT32(rValue));
698 break;
699 case PROPERTY_ID_ESCAPEPROCESSING:
700 setEscapeProcessing( ::comphelper::getBOOL( rValue ) );
701 break;
702 case PROPERTY_ID_USEBOOKMARKS:
703 // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
704 default:
708 // -------------------------------------------------------------------------
709 void java_sql_Statement_Base::getFastPropertyValue(
710 Any& rValue,
711 sal_Int32 nHandle
712 ) const
714 java_sql_Statement_Base* THIS = const_cast<java_sql_Statement_Base*>(this);
715 switch(nHandle)
717 case PROPERTY_ID_QUERYTIMEOUT:
718 rValue <<= THIS->getQueryTimeOut();
719 break;
720 case PROPERTY_ID_MAXFIELDSIZE:
721 rValue <<= THIS->getMaxFieldSize();
722 break;
723 case PROPERTY_ID_MAXROWS:
724 rValue <<= THIS->getMaxRows();
725 break;
726 case PROPERTY_ID_CURSORNAME:
727 rValue <<= THIS->getCursorName();
728 break;
729 case PROPERTY_ID_RESULTSETCONCURRENCY:
730 rValue <<= THIS->getResultSetConcurrency();
731 break;
732 case PROPERTY_ID_RESULTSETTYPE:
733 rValue <<= THIS->getResultSetType();
734 break;
735 case PROPERTY_ID_FETCHDIRECTION:
736 rValue <<= THIS->getFetchDirection();
737 break;
738 case PROPERTY_ID_FETCHSIZE:
739 rValue <<= THIS->getFetchSize();
740 break;
741 case PROPERTY_ID_ESCAPEPROCESSING:
742 rValue <<= (sal_Bool)m_bEscapeProcessing;
743 break;
744 case PROPERTY_ID_USEBOOKMARKS:
745 default:
749 // -------------------------------------------------------------------------
750 jclass java_sql_Statement::theClass = 0;
752 java_sql_Statement::~java_sql_Statement()
755 jclass java_sql_Statement::getMyClass() const
757 // die Klasse muss nur einmal geholt werden, daher statisch
758 if( !theClass )
759 theClass = findMyClass("java/sql/Statement");
760 return theClass;
763 // -----------------------------------------------------------------------------
764 void java_sql_Statement::createStatement(JNIEnv* _pEnv)
766 ::osl::MutexGuard aGuard( m_aMutex );
767 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
769 if( _pEnv && !object ){
770 // temporaere Variable initialisieren
771 static const char * cSignature = "(II)Ljava/sql/Statement;";
772 static const char * cMethodName = "createStatement";
773 // Java-Call absetzen
774 jobject out = NULL;
775 static jmethodID mID(NULL);
776 if ( !mID )
777 mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature );
778 if( mID ){
779 out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID,m_nResultSetType,m_nResultSetConcurrency );
780 } //mID
781 else
783 static const char * cSignature2 = "()Ljava/sql/Statement;";
784 static jmethodID mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID2,"Unknown method id!");
785 if( mID2 ){
786 out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2);
787 } //mID
789 ThrowLoggedSQLException( m_aLogger, _pEnv, *this );
791 if ( out )
792 object = _pEnv->NewGlobalRef( out );
793 } //_pEnv
795 // -----------------------------------------------------------------------------
798 IMPLEMENT_SERVICE_INFO(java_sql_Statement,"com.sun.star.sdbcx.JStatement","com.sun.star.sdbc.Statement");
799 // -----------------------------------------------------------------------------
800 void SAL_CALL java_sql_Statement_Base::acquire() throw()
802 java_sql_Statement_BASE::acquire();
804 // -----------------------------------------------------------------------------
805 void SAL_CALL java_sql_Statement_Base::release() throw()
807 java_sql_Statement_BASE::release();
809 // -----------------------------------------------------------------------------
810 void SAL_CALL java_sql_Statement::acquire() throw()
812 OStatement_BASE2::acquire();
814 // -----------------------------------------------------------------------------
815 void SAL_CALL java_sql_Statement::release() throw()
817 OStatement_BASE2::release();
819 // -----------------------------------------------------------------------------
820 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL java_sql_Statement_Base::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
822 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
824 // -----------------------------------------------------------------------------