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_connectivity.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 // ------------------------------------------------------------------------- 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 //------------------------------------------------------------------------------ 81 java_sql_Statement_Base::~java_sql_Statement_Base() 82 { 83 } 84 85 //------------------------------------------------------------------------------ 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 // ------------------------------------------------------------------------- 105 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 // ----------------------------------------------------------------------------- 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 121 void SAL_CALL OStatement_BASE2::release() throw() 122 { 123 relase_ChildImpl(); 124 } 125 126 // ------------------------------------------------------------------------- 127 Any SAL_CALL java_sql_Statement_Base::queryInterface( const Type & rType ) throw(RuntimeException) 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 // ------------------------------------------------------------------------- 135 Sequence< Type > SAL_CALL java_sql_Statement_Base::getTypes( ) throw(RuntimeException) 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 // ----------------------------------------------------------------------------- 152 Reference< XResultSet > SAL_CALL java_sql_Statement_Base::getGeneratedValues( ) throw (SQLException, RuntimeException) 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 Enviroment geloescht worden!"); 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 195 void SAL_CALL java_sql_Statement_Base::cancel( ) throw(RuntimeException) 196 { 197 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 198 createStatement(t.pEnv); 199 static jmethodID mID(NULL); 200 callVoidMethod("cancel",mID); 201 } 202 // ------------------------------------------------------------------------- 203 204 void SAL_CALL java_sql_Statement_Base::close( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) 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 215 void SAL_CALL java_sql_Statement::clearBatch( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) 216 { 217 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 218 { 219 220 createStatement(t.pEnv); 221 static jmethodID mID(NULL); 222 callVoidMethod("clearBatch",mID); 223 } //t.pEnv 224 } 225 // ------------------------------------------------------------------------- 226 227 sal_Bool SAL_CALL java_sql_Statement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 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 Enviroment geloescht worden!"); 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 261 Reference< XResultSet > SAL_CALL java_sql_Statement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 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 Enviroment geloescht worden!"); 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 // ------------------------------------------------------------------------- 296 Reference< XConnection > SAL_CALL java_sql_Statement_Base::getConnection( ) throw(SQLException, RuntimeException) 297 { 298 ::osl::MutexGuard aGuard( m_aMutex ); 299 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 300 return (Reference< XConnection >)m_pConnection; 301 } 302 // ------------------------------------------------------------------------- 303 304 Any SAL_CALL java_sql_Statement::queryInterface( const Type & rType ) throw(RuntimeException) 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 311 void SAL_CALL java_sql_Statement::addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) 312 { 313 ::osl::MutexGuard aGuard( m_aMutex ); 314 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 315 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 316 { 317 createStatement(t.pEnv); 318 static jmethodID mID(NULL); 319 callVoidMethodWithStringArg("addBatch",mID,sql); 320 } //t.pEnv 321 } 322 // ------------------------------------------------------------------------- 323 324 Sequence< sal_Int32 > SAL_CALL java_sql_Statement::executeBatch( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) 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 Enviroment geloescht worden!"); 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 345 sal_Int32 SAL_CALL java_sql_Statement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 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 Enviroment geloescht worden!"); 352 createStatement(t.pEnv); 353 m_sSqlStatement = sql; 354 static jmethodID mID(NULL); 355 return callIntMethodWithStringArg("executeUpdate",mID,sql); 356 } 357 // ------------------------------------------------------------------------- 358 359 Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL java_sql_Statement_Base::getResultSet( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) 360 { 361 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 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 371 sal_Int32 SAL_CALL java_sql_Statement_Base::getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) 372 { 373 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 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 382 sal_Bool SAL_CALL java_sql_Statement_Base::getMoreResults( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) 383 { 384 static jmethodID mID(NULL); 385 return callBooleanMethod( "getMoreResults", mID ); 386 } 387 // ------------------------------------------------------------------------- 388 389 // ------------------------------------------------------------------------- 390 Any SAL_CALL java_sql_Statement_Base::getWarnings( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) 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 // ------------------------------------------------------------------------- 408 void SAL_CALL java_sql_Statement_Base::clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) 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 //------------------------------------------------------------------------------ 421 sal_Int32 java_sql_Statement_Base::getQueryTimeOut() throw(SQLException, RuntimeException) 422 { 423 static jmethodID mID(NULL); 424 return impl_getProperty("getQueryTimeOut",mID); 425 } 426 //------------------------------------------------------------------------------ 427 sal_Int32 java_sql_Statement_Base::getMaxRows() throw(SQLException, RuntimeException) 428 { 429 static jmethodID mID(NULL); 430 return impl_getProperty("getMaxRows",mID); 431 } 432 //------------------------------------------------------------------------------ 433 sal_Int32 java_sql_Statement_Base::getResultSetConcurrency() throw(SQLException, RuntimeException) 434 { 435 static jmethodID mID(NULL); 436 return impl_getProperty("getResultSetConcurrency",mID,m_nResultSetConcurrency); 437 } 438 439 //------------------------------------------------------------------------------ 440 sal_Int32 java_sql_Statement_Base::getResultSetType() throw(SQLException, RuntimeException) 441 { 442 static jmethodID mID(NULL); 443 return impl_getProperty("getResultSetType",mID,m_nResultSetType); 444 } 445 //------------------------------------------------------------------------------ 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 //------------------------------------------------------------------------------ 455 sal_Int32 java_sql_Statement_Base::impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID) 456 { 457 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 458 createStatement(t.pEnv); 459 return callIntMethod(_pMethodName,_inout_MethodID,true); 460 } 461 462 //------------------------------------------------------------------------------ 463 sal_Int32 java_sql_Statement_Base::getFetchDirection() throw(SQLException, RuntimeException) 464 { 465 static jmethodID mID(NULL); 466 return impl_getProperty("getFetchDirection",mID); 467 } 468 //------------------------------------------------------------------------------ 469 sal_Int32 java_sql_Statement_Base::getFetchSize() throw(SQLException, RuntimeException) 470 { 471 static jmethodID mID(NULL); 472 return impl_getProperty("getFetchSize",mID); 473 } 474 //------------------------------------------------------------------------------ 475 sal_Int32 java_sql_Statement_Base::getMaxFieldSize() throw(SQLException, RuntimeException) 476 { 477 static jmethodID mID(NULL); 478 return impl_getProperty("getMaxFieldSize",mID); 479 } 480 //------------------------------------------------------------------------------ 481 ::rtl::OUString java_sql_Statement_Base::getCursorName() throw(SQLException, RuntimeException) 482 { 483 ::osl::MutexGuard aGuard( m_aMutex ); 484 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 485 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 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 //------------------------------------------------------------------------------ 498 void java_sql_Statement_Base::setQueryTimeOut(sal_Int32 _par0) throw(SQLException, RuntimeException) 499 { 500 ::osl::MutexGuard aGuard( m_aMutex ); 501 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 502 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 503 createStatement(t.pEnv); 504 static jmethodID mID(NULL); 505 callVoidMethodWithIntArg("setQueryTimeOut",mID,_par0,true); 506 } 507 508 //------------------------------------------------------------------------------ 509 void java_sql_Statement_Base::setEscapeProcessing(sal_Bool _par0) throw(SQLException, RuntimeException) 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 Enviroment geloescht worden!"); 516 m_bEscapeProcessing = _par0; 517 createStatement( t.pEnv ); 518 static jmethodID mID(NULL); 519 callVoidMethodWithBoolArg("setEscapeProcessing",mID,_par0,true); 520 } 521 522 //------------------------------------------------------------------------------ 523 void java_sql_Statement_Base::setMaxRows(sal_Int32 _par0) throw(SQLException, RuntimeException) 524 { 525 ::osl::MutexGuard aGuard( m_aMutex ); 526 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 527 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 528 createStatement(t.pEnv); 529 static jmethodID mID(NULL); 530 callVoidMethodWithIntArg("setMaxRows",mID,_par0,true); 531 } 532 //------------------------------------------------------------------------------ 533 void java_sql_Statement_Base::setResultSetConcurrency(sal_Int32 _par0) throw(SQLException, RuntimeException) 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 //------------------------------------------------------------------------------ 543 void java_sql_Statement_Base::setResultSetType(sal_Int32 _par0) throw(SQLException, RuntimeException) 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 //------------------------------------------------------------------------------ 553 void java_sql_Statement_Base::setFetchDirection(sal_Int32 _par0) throw(SQLException, RuntimeException) 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 Enviroment geloescht worden!"); 559 createStatement(t.pEnv); 560 static jmethodID mID(NULL); 561 callVoidMethodWithIntArg("setFetchDirection",mID,_par0,true); 562 } 563 //------------------------------------------------------------------------------ 564 void java_sql_Statement_Base::setFetchSize(sal_Int32 _par0) throw(SQLException, RuntimeException) 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 Enviroment geloescht worden!"); 571 createStatement(t.pEnv); 572 static jmethodID mID(NULL); 573 callVoidMethodWithIntArg("setFetchSize",mID,_par0,true); 574 } 575 //------------------------------------------------------------------------------ 576 void java_sql_Statement_Base::setMaxFieldSize(sal_Int32 _par0) throw(SQLException, RuntimeException) 577 { 578 ::osl::MutexGuard aGuard( m_aMutex ); 579 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 580 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 581 createStatement(t.pEnv); 582 static jmethodID mID(NULL); 583 callVoidMethodWithIntArg("setMaxFieldSize",mID,_par0,true); 584 } 585 //------------------------------------------------------------------------------ 586 void java_sql_Statement_Base::setCursorName(const ::rtl::OUString &_par0) throw(SQLException, RuntimeException) 587 { 588 ::osl::MutexGuard aGuard( m_aMutex ); 589 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 590 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 591 { 592 createStatement(t.pEnv); 593 static jmethodID mID(NULL); 594 callVoidMethodWithStringArg("setCursorName",mID,_par0); 595 } //t.pEnv 596 } 597 598 // ------------------------------------------------------------------------- 599 ::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 // ------------------------------------------------------------------------- 619 ::cppu::IPropertyArrayHelper & java_sql_Statement_Base::getInfoHelper() 620 621 { 622 return *const_cast<java_sql_Statement_Base*>(this)->getArrayHelper(); 623 } 624 // ------------------------------------------------------------------------- 625 sal_Bool java_sql_Statement_Base::convertFastPropertyValue( 626 Any & rConvertedValue, 627 Any & rOldValue, 628 sal_Int32 nHandle, 629 const Any& rValue ) 630 throw (::com::sun::star::lang::IllegalArgumentException) 631 { 632 switch(nHandle) 633 { 634 case PROPERTY_ID_QUERYTIMEOUT: 635 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut()); 636 case PROPERTY_ID_MAXFIELDSIZE: 637 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize()); 638 case PROPERTY_ID_MAXROWS: 639 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxRows()); 640 case PROPERTY_ID_CURSORNAME: 641 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName()); 642 case PROPERTY_ID_RESULTSETCONCURRENCY: 643 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency()); 644 case PROPERTY_ID_RESULTSETTYPE: 645 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType()); 646 case PROPERTY_ID_FETCHDIRECTION: 647 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection()); 648 case PROPERTY_ID_FETCHSIZE: 649 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize()); 650 case PROPERTY_ID_ESCAPEPROCESSING: 651 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bEscapeProcessing ); 652 case PROPERTY_ID_USEBOOKMARKS: 653 // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink); 654 default: 655 ; 656 } 657 return sal_False; 658 } 659 // ------------------------------------------------------------------------- 660 void java_sql_Statement_Base::setFastPropertyValue_NoBroadcast( 661 sal_Int32 nHandle, 662 const Any& rValue 663 ) 664 throw (Exception) 665 { 666 switch(nHandle) 667 { 668 case PROPERTY_ID_QUERYTIMEOUT: 669 setQueryTimeOut(comphelper::getINT32(rValue)); 670 break; 671 case PROPERTY_ID_MAXFIELDSIZE: 672 setMaxFieldSize(comphelper::getINT32(rValue)); 673 break; 674 case PROPERTY_ID_MAXROWS: 675 setMaxRows(comphelper::getINT32(rValue)); 676 break; 677 case PROPERTY_ID_CURSORNAME: 678 setCursorName(comphelper::getString(rValue)); 679 break; 680 case PROPERTY_ID_RESULTSETCONCURRENCY: 681 setResultSetConcurrency(comphelper::getINT32(rValue)); 682 break; 683 case PROPERTY_ID_RESULTSETTYPE: 684 setResultSetType(comphelper::getINT32(rValue)); 685 break; 686 case PROPERTY_ID_FETCHDIRECTION: 687 setFetchDirection(comphelper::getINT32(rValue)); 688 break; 689 case PROPERTY_ID_FETCHSIZE: 690 setFetchSize(comphelper::getINT32(rValue)); 691 break; 692 case PROPERTY_ID_ESCAPEPROCESSING: 693 setEscapeProcessing( ::comphelper::getBOOL( rValue ) ); 694 break; 695 case PROPERTY_ID_USEBOOKMARKS: 696 // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink); 697 default: 698 ; 699 } 700 } 701 // ------------------------------------------------------------------------- 702 void java_sql_Statement_Base::getFastPropertyValue( 703 Any& rValue, 704 sal_Int32 nHandle 705 ) const 706 { 707 java_sql_Statement_Base* THIS = const_cast<java_sql_Statement_Base*>(this); 708 try 709 { 710 switch(nHandle) 711 { 712 case PROPERTY_ID_QUERYTIMEOUT: 713 rValue <<= THIS->getQueryTimeOut(); 714 break; 715 case PROPERTY_ID_MAXFIELDSIZE: 716 rValue <<= THIS->getMaxFieldSize(); 717 break; 718 case PROPERTY_ID_MAXROWS: 719 rValue <<= THIS->getMaxRows(); 720 break; 721 case PROPERTY_ID_CURSORNAME: 722 rValue <<= THIS->getCursorName(); 723 break; 724 case PROPERTY_ID_RESULTSETCONCURRENCY: 725 rValue <<= THIS->getResultSetConcurrency(); 726 break; 727 case PROPERTY_ID_RESULTSETTYPE: 728 rValue <<= THIS->getResultSetType(); 729 break; 730 case PROPERTY_ID_FETCHDIRECTION: 731 rValue <<= THIS->getFetchDirection(); 732 break; 733 case PROPERTY_ID_FETCHSIZE: 734 rValue <<= THIS->getFetchSize(); 735 break; 736 case PROPERTY_ID_ESCAPEPROCESSING: 737 rValue <<= (sal_Bool)m_bEscapeProcessing; 738 break; 739 case PROPERTY_ID_USEBOOKMARKS: 740 default: 741 ; 742 } 743 } 744 catch(const Exception&) 745 { 746 } 747 } 748 // ------------------------------------------------------------------------- 749 jclass java_sql_Statement::theClass = 0; 750 751 java_sql_Statement::~java_sql_Statement() 752 {} 753 754 jclass java_sql_Statement::getMyClass() const 755 { 756 // die Klasse muss nur einmal geholt werden, daher statisch 757 if( !theClass ) 758 theClass = findMyClass("java/sql/Statement"); 759 return theClass; 760 } 761 762 // ----------------------------------------------------------------------------- 763 void java_sql_Statement::createStatement(JNIEnv* _pEnv) 764 { 765 ::osl::MutexGuard aGuard( m_aMutex ); 766 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 767 768 if( _pEnv && !object ){ 769 // temporaere Variable initialisieren 770 static const char * cSignature = "(II)Ljava/sql/Statement;"; 771 static const char * cMethodName = "createStatement"; 772 // Java-Call absetzen 773 jobject out = NULL; 774 static jmethodID mID(NULL); 775 if ( !mID ) 776 mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature ); 777 if( mID ){ 778 out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID,m_nResultSetType,m_nResultSetConcurrency ); 779 } //mID 780 else 781 { 782 static const char * cSignature2 = "()Ljava/sql/Statement;"; 783 static jmethodID mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID2,"Unknown method id!"); 784 if( mID2 ){ 785 out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2); 786 } //mID 787 } 788 ThrowLoggedSQLException( m_aLogger, _pEnv, *this ); 789 790 if ( out ) 791 object = _pEnv->NewGlobalRef( out ); 792 } //_pEnv 793 } 794 // ----------------------------------------------------------------------------- 795 796 797 IMPLEMENT_SERVICE_INFO(java_sql_Statement,"com.sun.star.sdbcx.JStatement","com.sun.star.sdbc.Statement"); 798 // ----------------------------------------------------------------------------- 799 void SAL_CALL java_sql_Statement_Base::acquire() throw() 800 { 801 java_sql_Statement_BASE::acquire(); 802 } 803 // ----------------------------------------------------------------------------- 804 void SAL_CALL java_sql_Statement_Base::release() throw() 805 { 806 java_sql_Statement_BASE::release(); 807 } 808 // ----------------------------------------------------------------------------- 809 void SAL_CALL java_sql_Statement::acquire() throw() 810 { 811 OStatement_BASE2::acquire(); 812 } 813 // ----------------------------------------------------------------------------- 814 void SAL_CALL java_sql_Statement::release() throw() 815 { 816 OStatement_BASE2::release(); 817 } 818 // ----------------------------------------------------------------------------- 819 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL java_sql_Statement_Base::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) 820 { 821 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); 822 } 823 // ----------------------------------------------------------------------------- 824 825 826