Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / connectivity / source / drivers / jdbc / JStatement.cxx
blob1d5326ca6302ee8212be2856d460828d9f95f1e4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <java/sql/JStatement.hxx>
22 #include <java/sql/ResultSet.hxx>
23 #include <java/sql/Connection.hxx>
24 #include <java/sql/SQLWarning.hxx>
25 #include <java/tools.hxx>
26 #include <java/ContextClassLoader.hxx>
27 #include <comphelper/property.hxx>
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include <cppuhelper/typeprovider.hxx>
30 #include <cppuhelper/queryinterface.hxx>
31 #include <comphelper/sequence.hxx>
32 #include <TConnection.hxx>
33 #include <comphelper/types.hxx>
34 #include <comphelper/diagnose_ex.hxx>
35 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
36 #include <com/sun/star/sdbc/ResultSetType.hpp>
38 #include <strings.hxx>
40 #include <algorithm>
41 #include <string.h>
43 using namespace ::comphelper;
44 using namespace connectivity;
45 using namespace ::cppu;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::sdbc;
50 using namespace ::com::sun::star::container;
51 using namespace ::com::sun::star::lang;
54 //************ Class: java.sql.Statement
57 jclass java_sql_Statement_Base::theClass = nullptr;
60 java_sql_Statement_Base::java_sql_Statement_Base( JNIEnv * pEnv, java_sql_Connection& _rCon )
61 :java_sql_Statement_BASE(m_aMutex)
62 ,java_lang_Object( pEnv, nullptr )
63 ,OPropertySetHelper(java_sql_Statement_BASE::rBHelper)
64 ,m_pConnection( &_rCon )
65 ,m_aLogger( _rCon.getLogger(), java::sql::ConnectionLog::STATEMENT )
66 ,m_nResultSetConcurrency(ResultSetConcurrency::READ_ONLY)
67 ,m_nResultSetType(ResultSetType::FORWARD_ONLY)
68 ,m_bEscapeProcessing(true)
73 java_sql_Statement_Base::~java_sql_Statement_Base()
78 void SAL_CALL OStatement_BASE2::disposing()
80 ::osl::MutexGuard aGuard(m_aMutex);
82 if ( object )
84 static jmethodID mID(nullptr);
85 callVoidMethod_ThrowSQL("close", mID);
88 ::comphelper::disposeComponent(m_xGeneratedStatement);
89 m_pConnection.clear();
91 java_sql_Statement_Base::disposing();
94 jclass java_sql_Statement_Base::getMyClass() const
96 // the class must be fetched only once, therefore static
97 if( !theClass )
98 theClass = findMyClass("java/sql/Statement");
99 return theClass;
102 void SAL_CALL java_sql_Statement_Base::disposing()
104 m_aLogger.log( LogLevel::FINE, STR_LOG_CLOSING_STATEMENT );
105 java_sql_Statement_BASE::disposing();
106 clearObject();
110 Any SAL_CALL java_sql_Statement_Base::queryInterface( const Type & rType )
112 if ( m_pConnection.is() && !m_pConnection->isAutoRetrievingEnabled() && rType == cppu::UnoType<XGeneratedResultSet>::get())
113 return Any();
114 Any aRet( java_sql_Statement_BASE::queryInterface(rType) );
115 return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType);
118 Sequence< Type > SAL_CALL java_sql_Statement_Base::getTypes( )
120 ::cppu::OTypeCollection aTypes( cppu::UnoType<css::beans::XMultiPropertySet>::get(),
121 cppu::UnoType<css::beans::XFastPropertySet>::get(),
122 cppu::UnoType<css::beans::XPropertySet>::get());
124 Sequence< Type > aOldTypes = java_sql_Statement_BASE::getTypes();
125 if ( m_pConnection.is() && !m_pConnection->isAutoRetrievingEnabled() )
127 auto [begin, end] = asNonConstRange(aOldTypes);
128 auto newEnd = std::remove(begin, end,
129 cppu::UnoType<XGeneratedResultSet>::get());
130 aOldTypes.realloc(std::distance(begin, newEnd));
133 return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes);
136 Reference< XResultSet > SAL_CALL java_sql_Statement_Base::getGeneratedValues( )
138 m_aLogger.log( LogLevel::FINE, STR_LOG_GENERATED_VALUES );
139 ::osl::MutexGuard aGuard( m_aMutex );
140 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
142 jobject out(nullptr);
143 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
144 createStatement(t.pEnv);
145 // initialize temporary Variable
148 static jmethodID mID(nullptr);
149 out = callResultSetMethod(t.env(),"getGeneratedKeys",mID);
151 catch(const SQLException&)
153 // ignore
156 Reference< XResultSet > xRes;
157 if ( !out )
159 OSL_ENSURE( m_pConnection.is() && m_pConnection->isAutoRetrievingEnabled(),"Illegal call here. isAutoRetrievingEnabled is false!");
160 if ( m_pConnection.is() )
162 OUString sStmt = m_pConnection->getTransformedGeneratedStatement(m_sSqlStatement);
163 if ( !sStmt.isEmpty() )
165 m_aLogger.log( LogLevel::FINER, STR_LOG_GENERATED_VALUES_FALLBACK, sStmt );
166 ::comphelper::disposeComponent(m_xGeneratedStatement);
167 m_xGeneratedStatement = m_pConnection->createStatement();
168 xRes = m_xGeneratedStatement->executeQuery(sStmt);
172 else
173 xRes = new java_sql_ResultSet( t.pEnv, out, m_aLogger,*m_pConnection, this );
174 return xRes;
178 void SAL_CALL java_sql_Statement_Base::cancel( )
180 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
181 createStatement(t.pEnv);
182 static jmethodID mID(nullptr);
183 callVoidMethod_ThrowRuntime("cancel",mID);
187 void SAL_CALL java_sql_Statement_Base::close( )
190 ::osl::MutexGuard aGuard( m_aMutex );
191 if (java_sql_Statement_BASE::rBHelper.bDisposed)
192 throw DisposedException();
194 dispose();
198 void SAL_CALL java_sql_Statement::clearBatch( )
200 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
203 createStatement(t.pEnv);
204 static jmethodID mID(nullptr);
205 callVoidMethod_ThrowSQL("clearBatch", mID);
206 } //t.pEnv
210 sal_Bool SAL_CALL java_sql_Statement_Base::execute( const OUString& sql )
212 m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_STATEMENT, sql );
213 ::osl::MutexGuard aGuard( m_aMutex );
214 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
216 bool out(false);
217 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
219 createStatement(t.pEnv);
220 m_sSqlStatement = sql;
221 // initialize temporary Variable
222 static const char * const cSignature = "(Ljava/lang/String;)Z";
223 static const char * const cMethodName = "execute";
224 // Java-Call
225 static jmethodID mID(nullptr);
226 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
227 // convert Parameter
228 jdbc::LocalRef< jstring > str( t.env(), convertwchar_tToJavaString( t.pEnv, sql ) );
230 jdbc::ContextClassLoaderScope ccl( t.env(),
231 m_pConnection.is() ? m_pConnection->getDriverClassLoader() : jdbc::GlobalRef< jobject >(),
232 m_aLogger,
233 *this
236 out = t.pEnv->CallBooleanMethod( object, mID, str.get() );
237 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
239 } //t.pEnv
240 return out;
244 Reference< XResultSet > SAL_CALL java_sql_Statement_Base::executeQuery( const OUString& sql )
246 ::osl::MutexGuard aGuard( m_aMutex );
247 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
248 m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_QUERY, sql );
250 jobject out(nullptr);
251 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
254 createStatement(t.pEnv);
255 m_sSqlStatement = sql;
256 // initialize temporary variable
257 static const char * const cSignature = "(Ljava/lang/String;)Ljava/sql/ResultSet;";
258 static const char * const cMethodName = "executeQuery";
259 // Java-Call
260 static jmethodID mID(nullptr);
261 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
262 // convert Parameter
263 jdbc::LocalRef< jstring > str( t.env(), convertwchar_tToJavaString( t.pEnv, sql ) );
265 jdbc::ContextClassLoaderScope ccl( t.env(),
266 m_pConnection.is() ? m_pConnection->getDriverClassLoader() : jdbc::GlobalRef< jobject >(),
267 m_aLogger,
268 *this
271 out = t.pEnv->CallObjectMethod( object, mID, str.get() );
272 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
274 } //t.pEnv
275 // WARNING: the caller becomes the owner of the returned pointer
276 return out==nullptr ? nullptr : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this );
279 Reference< XConnection > SAL_CALL java_sql_Statement_Base::getConnection( )
281 ::osl::MutexGuard aGuard( m_aMutex );
282 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
283 return m_pConnection;
287 Any SAL_CALL java_sql_Statement::queryInterface( const Type & rType )
289 Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
290 return aRet.hasValue() ? aRet : java_sql_Statement_Base::queryInterface(rType);
294 void SAL_CALL java_sql_Statement::addBatch( const OUString& sql )
296 ::osl::MutexGuard aGuard( m_aMutex );
297 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
298 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
300 createStatement(t.pEnv);
301 static jmethodID mID(nullptr);
302 callVoidMethodWithStringArg("addBatch",mID,sql);
303 } //t.pEnv
307 Sequence< sal_Int32 > SAL_CALL java_sql_Statement::executeBatch( )
309 ::osl::MutexGuard aGuard( m_aMutex );
310 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
311 Sequence< sal_Int32 > aSeq;
312 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
313 createStatement(t.pEnv);
314 static jmethodID mID(nullptr);
315 jintArray out = static_cast<jintArray>(callObjectMethod(t.pEnv,"executeBatch","()[I", mID));
316 if (out)
318 jboolean p = false;
319 aSeq.realloc(t.pEnv->GetArrayLength(out));
320 memcpy(aSeq.getArray(),t.pEnv->GetIntArrayElements(out,&p),aSeq.getLength());
321 t.pEnv->DeleteLocalRef(out);
323 return aSeq;
327 sal_Int32 SAL_CALL java_sql_Statement_Base::executeUpdate( const OUString& sql )
329 ::osl::MutexGuard aGuard( m_aMutex );
330 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
331 m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_UPDATE, sql );
333 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
334 createStatement(t.pEnv);
335 m_sSqlStatement = sql;
336 static jmethodID mID(nullptr);
337 return callIntMethodWithStringArg("executeUpdate",mID,sql);
341 Reference< css::sdbc::XResultSet > SAL_CALL java_sql_Statement_Base::getResultSet( )
343 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
344 createStatement(t.pEnv);
345 static jmethodID mID(nullptr);
346 jobject out = callResultSetMethod(t.env(),"getResultSet",mID);
348 // WARNING: the caller becomes the owner of the returned pointer
349 return out==nullptr ? nullptr : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this );
353 sal_Int32 SAL_CALL java_sql_Statement_Base::getUpdateCount( )
355 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
356 createStatement(t.pEnv);
357 static jmethodID mID(nullptr);
358 sal_Int32 out = callIntMethod_ThrowSQL("getUpdateCount", mID);
359 m_aLogger.log( LogLevel::FINER, STR_LOG_UPDATE_COUNT, out );
360 return out;
364 sal_Bool SAL_CALL java_sql_Statement_Base::getMoreResults( )
366 static jmethodID mID(nullptr);
367 return callBooleanMethod( "getMoreResults", mID );
371 Any SAL_CALL java_sql_Statement_Base::getWarnings( )
373 SDBThreadAttach t;
374 createStatement(t.pEnv);
375 static jmethodID mID(nullptr);
376 jobject out = callObjectMethod(t.pEnv,"getWarnings","()Ljava/sql/SQLWarning;", mID);
377 // WARNING: the caller becomes the owner of the returned pointer
378 if( out )
380 java_sql_SQLWarning_BASE warn_base( t.pEnv, out );
381 return Any(
382 static_cast< css::sdbc::SQLException >(
383 java_sql_SQLWarning(warn_base,getXWeak())));
386 return Any();
389 void SAL_CALL java_sql_Statement_Base::clearWarnings( )
391 ::osl::MutexGuard aGuard( m_aMutex );
392 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
393 SDBThreadAttach t;
396 createStatement(t.pEnv);
397 static jmethodID mID(nullptr);
398 callVoidMethod_ThrowSQL("clearWarnings", mID);
402 sal_Int32 java_sql_Statement_Base::getQueryTimeOut()
404 static jmethodID mID(nullptr);
405 return impl_getProperty("getQueryTimeOut",mID);
408 sal_Int32 java_sql_Statement_Base::getMaxRows()
410 static jmethodID mID(nullptr);
411 return impl_getProperty("getMaxRows",mID);
414 sal_Int32 java_sql_Statement_Base::getResultSetConcurrency()
416 static jmethodID mID(nullptr);
417 return impl_getProperty("getResultSetConcurrency",mID,m_nResultSetConcurrency);
421 sal_Int32 java_sql_Statement_Base::getResultSetType()
423 static jmethodID mID(nullptr);
424 return impl_getProperty("getResultSetType",mID,m_nResultSetType);
427 sal_Int32 java_sql_Statement_Base::impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID,sal_Int32 _nDefault)
429 sal_Int32 out = _nDefault;
430 if ( object )
431 out = callIntMethod_ThrowRuntime(_pMethodName, _inout_MethodID);
432 return out;
435 sal_Int32 java_sql_Statement_Base::impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID)
437 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
438 createStatement(t.pEnv);
439 return callIntMethod_ThrowRuntime(_pMethodName, _inout_MethodID);
442 sal_Int32 java_sql_Statement_Base::getFetchDirection()
444 static jmethodID mID(nullptr);
445 return impl_getProperty("getFetchDirection",mID);
448 sal_Int32 java_sql_Statement_Base::getFetchSize()
450 static jmethodID mID(nullptr);
451 return impl_getProperty("getFetchSize",mID);
454 sal_Int32 java_sql_Statement_Base::getMaxFieldSize()
456 static jmethodID mID(nullptr);
457 return impl_getProperty("getMaxFieldSize",mID);
460 OUString java_sql_Statement_Base::getCursorName()
462 ::osl::MutexGuard aGuard( m_aMutex );
463 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
464 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
465 createStatement(t.pEnv);
466 static jmethodID mID(nullptr);
469 return callStringMethod("getCursorName",mID);
471 catch(const SQLException&)
474 return OUString();
477 void java_sql_Statement_Base::setQueryTimeOut(sal_Int32 _par0)
479 ::osl::MutexGuard aGuard( m_aMutex );
480 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
481 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
482 createStatement(t.pEnv);
483 static jmethodID mID(nullptr);
484 callVoidMethodWithIntArg_ThrowRuntime("setQueryTimeOut", mID, _par0);
488 void java_sql_Statement_Base::setEscapeProcessing(bool _par0)
490 ::osl::MutexGuard aGuard( m_aMutex );
491 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
492 m_aLogger.log( LogLevel::FINE, STR_LOG_SET_ESCAPE_PROCESSING, _par0 );
494 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
495 m_bEscapeProcessing = _par0;
496 createStatement( t.pEnv );
497 static jmethodID mID(nullptr);
498 callVoidMethodWithBoolArg_ThrowRuntime("setEscapeProcessing", mID, _par0);
501 void java_sql_Statement_Base::setMaxRows(sal_Int32 _par0)
503 ::osl::MutexGuard aGuard( m_aMutex );
504 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
505 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
506 createStatement(t.pEnv);
507 static jmethodID mID(nullptr);
508 callVoidMethodWithIntArg_ThrowRuntime("setMaxRows", mID, _par0);
511 void java_sql_Statement_Base::setResultSetConcurrency(sal_Int32 _par0)
513 ::osl::MutexGuard aGuard( m_aMutex );
514 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
515 m_aLogger.log( LogLevel::FINE, STR_LOG_RESULT_SET_CONCURRENCY, _par0 );
516 m_nResultSetConcurrency = _par0;
518 clearObject();
521 void java_sql_Statement_Base::setResultSetType(sal_Int32 _par0)
523 ::osl::MutexGuard aGuard( m_aMutex );
524 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
525 m_aLogger.log( LogLevel::FINE, STR_LOG_RESULT_SET_TYPE, _par0 );
526 m_nResultSetType = _par0;
528 clearObject();
531 void java_sql_Statement_Base::setFetchDirection(sal_Int32 _par0)
533 ::osl::MutexGuard aGuard( m_aMutex );
534 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
535 m_aLogger.log( LogLevel::FINER, STR_LOG_FETCH_DIRECTION, _par0 );
536 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
537 createStatement(t.pEnv);
538 static jmethodID mID(nullptr);
539 callVoidMethodWithIntArg_ThrowRuntime("setFetchDirection", mID, _par0);
542 void java_sql_Statement_Base::setFetchSize(sal_Int32 _par0)
544 ::osl::MutexGuard aGuard( m_aMutex );
545 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
546 m_aLogger.log( LogLevel::FINER, STR_LOG_FETCH_SIZE, _par0 );
548 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
549 createStatement(t.pEnv);
550 static jmethodID mID(nullptr);
551 callVoidMethodWithIntArg_ThrowRuntime("setFetchSize", mID, _par0);
554 void java_sql_Statement_Base::setMaxFieldSize(sal_Int32 _par0)
556 ::osl::MutexGuard aGuard( m_aMutex );
557 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
558 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
559 createStatement(t.pEnv);
560 static jmethodID mID(nullptr);
561 callVoidMethodWithIntArg_ThrowRuntime("setMaxFieldSize", mID, _par0);
564 void java_sql_Statement_Base::setCursorName(const OUString &_par0)
566 ::osl::MutexGuard aGuard( m_aMutex );
567 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
568 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
570 createStatement(t.pEnv);
571 static jmethodID mID(nullptr);
572 callVoidMethodWithStringArg("setCursorName",mID,_par0);
573 } //t.pEnv
577 ::cppu::IPropertyArrayHelper* java_sql_Statement_Base::createArrayHelper( ) const
579 return new ::cppu::OPropertyArrayHelper
583 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME),
584 PROPERTY_ID_CURSORNAME,
585 cppu::UnoType<OUString>::get(),
589 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING),
590 PROPERTY_ID_ESCAPEPROCESSING,
591 cppu::UnoType<bool>::get(),
595 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION),
596 PROPERTY_ID_FETCHDIRECTION,
597 cppu::UnoType<sal_Int32>::get(),
601 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE),
602 PROPERTY_ID_FETCHSIZE,
603 cppu::UnoType<sal_Int32>::get(),
607 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE),
608 PROPERTY_ID_MAXFIELDSIZE,
609 cppu::UnoType<sal_Int32>::get(),
613 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS),
614 PROPERTY_ID_MAXROWS,
615 cppu::UnoType<sal_Int32>::get(),
619 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT),
620 PROPERTY_ID_QUERYTIMEOUT,
621 cppu::UnoType<sal_Int32>::get(),
625 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY),
626 PROPERTY_ID_RESULTSETCONCURRENCY,
627 cppu::UnoType<sal_Int32>::get(),
631 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE),
632 PROPERTY_ID_RESULTSETTYPE,
633 cppu::UnoType<sal_Int32>::get(),
637 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS),
638 PROPERTY_ID_USEBOOKMARKS,
639 cppu::UnoType<bool>::get(),
647 ::cppu::IPropertyArrayHelper & java_sql_Statement_Base::getInfoHelper()
650 return *getArrayHelper();
653 sal_Bool java_sql_Statement_Base::convertFastPropertyValue(
654 Any & rConvertedValue,
655 Any & rOldValue,
656 sal_Int32 nHandle,
657 const Any& rValue )
661 switch(nHandle)
663 case PROPERTY_ID_QUERYTIMEOUT:
664 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut());
665 case PROPERTY_ID_MAXFIELDSIZE:
666 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize());
667 case PROPERTY_ID_MAXROWS:
668 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxRows());
669 case PROPERTY_ID_CURSORNAME:
670 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName());
671 case PROPERTY_ID_RESULTSETCONCURRENCY:
672 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency());
673 case PROPERTY_ID_RESULTSETTYPE:
674 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType());
675 case PROPERTY_ID_FETCHDIRECTION:
676 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
677 case PROPERTY_ID_FETCHSIZE:
678 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
679 case PROPERTY_ID_ESCAPEPROCESSING:
680 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bEscapeProcessing );
681 case PROPERTY_ID_USEBOOKMARKS:
682 // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
683 default:
687 catch(const css::lang::IllegalArgumentException&)
689 throw;
691 catch(const css::uno::Exception&)
693 DBG_UNHANDLED_EXCEPTION("connectivity.jdbc");
695 return false;
698 void java_sql_Statement_Base::setFastPropertyValue_NoBroadcast(
699 sal_Int32 nHandle,
700 const Any& rValue
703 switch(nHandle)
705 case PROPERTY_ID_QUERYTIMEOUT:
706 setQueryTimeOut(comphelper::getINT32(rValue));
707 break;
708 case PROPERTY_ID_MAXFIELDSIZE:
709 setMaxFieldSize(comphelper::getINT32(rValue));
710 break;
711 case PROPERTY_ID_MAXROWS:
712 setMaxRows(comphelper::getINT32(rValue));
713 break;
714 case PROPERTY_ID_CURSORNAME:
715 setCursorName(comphelper::getString(rValue));
716 break;
717 case PROPERTY_ID_RESULTSETCONCURRENCY:
718 setResultSetConcurrency(comphelper::getINT32(rValue));
719 break;
720 case PROPERTY_ID_RESULTSETTYPE:
721 setResultSetType(comphelper::getINT32(rValue));
722 break;
723 case PROPERTY_ID_FETCHDIRECTION:
724 setFetchDirection(comphelper::getINT32(rValue));
725 break;
726 case PROPERTY_ID_FETCHSIZE:
727 setFetchSize(comphelper::getINT32(rValue));
728 break;
729 case PROPERTY_ID_ESCAPEPROCESSING:
730 setEscapeProcessing( ::comphelper::getBOOL( rValue ) );
731 break;
732 case PROPERTY_ID_USEBOOKMARKS:
733 // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
734 default:
739 void java_sql_Statement_Base::getFastPropertyValue(
740 Any& rValue,
741 sal_Int32 nHandle
742 ) const
744 java_sql_Statement_Base* THIS = const_cast<java_sql_Statement_Base*>(this);
747 switch(nHandle)
749 case PROPERTY_ID_QUERYTIMEOUT:
750 rValue <<= THIS->getQueryTimeOut();
751 break;
752 case PROPERTY_ID_MAXFIELDSIZE:
753 rValue <<= THIS->getMaxFieldSize();
754 break;
755 case PROPERTY_ID_MAXROWS:
756 rValue <<= THIS->getMaxRows();
757 break;
758 case PROPERTY_ID_CURSORNAME:
759 rValue <<= THIS->getCursorName();
760 break;
761 case PROPERTY_ID_RESULTSETCONCURRENCY:
762 rValue <<= THIS->getResultSetConcurrency();
763 break;
764 case PROPERTY_ID_RESULTSETTYPE:
765 rValue <<= THIS->getResultSetType();
766 break;
767 case PROPERTY_ID_FETCHDIRECTION:
768 rValue <<= THIS->getFetchDirection();
769 break;
770 case PROPERTY_ID_FETCHSIZE:
771 rValue <<= THIS->getFetchSize();
772 break;
773 case PROPERTY_ID_ESCAPEPROCESSING:
774 rValue <<= m_bEscapeProcessing;
775 break;
776 case PROPERTY_ID_USEBOOKMARKS:
777 default:
781 catch(const Exception&)
786 jclass java_sql_Statement::theClass = nullptr;
788 java_sql_Statement::~java_sql_Statement()
791 jclass java_sql_Statement::getMyClass() const
793 // the class must be fetched only once, therefore static
794 if( !theClass )
795 theClass = findMyClass("java/sql/Statement");
796 return theClass;
800 void java_sql_Statement::createStatement(JNIEnv* _pEnv)
802 ::osl::MutexGuard aGuard( m_aMutex );
803 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
805 if( !_pEnv || object )
806 return;
808 // initialize temporary variable
809 static const char * const cMethodName = "createStatement";
810 // Java-Call
811 jobject out = nullptr;
812 static jmethodID mID(nullptr);
813 if ( !mID )
815 static const char * const cSignature = "(II)Ljava/sql/Statement;";
816 mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature );
818 if( mID ){
819 out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID,m_nResultSetType,m_nResultSetConcurrency );
820 } //mID
821 else
823 static const char * const cSignature2 = "()Ljava/sql/Statement;";
824 static jmethodID mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID2,"Unknown method id!");
825 if( mID2 ){
826 out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2);
827 } //mID
829 ThrowLoggedSQLException( m_aLogger, _pEnv, *this );
831 if ( out )
832 object = _pEnv->NewGlobalRef( out );
836 IMPLEMENT_SERVICE_INFO(java_sql_Statement,"com.sun.star.sdbcx.JStatement","com.sun.star.sdbc.Statement");
838 void SAL_CALL java_sql_Statement_Base::acquire() noexcept
840 java_sql_Statement_BASE::acquire();
843 void SAL_CALL java_sql_Statement_Base::release() noexcept
845 java_sql_Statement_BASE::release();
848 void SAL_CALL java_sql_Statement::acquire() noexcept
850 OStatement_BASE2::acquire();
853 void SAL_CALL java_sql_Statement::release() noexcept
855 OStatement_BASE2::release();
858 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL java_sql_Statement_Base::getPropertySetInfo( )
860 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
864 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */