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