1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 #include "java/sql/PreparedStatement.hxx" 31 #include "java/sql/ResultSet.hxx" 32 #include "java/sql/ResultSetMetaData.hxx" 33 #include "java/sql/Connection.hxx" 34 #include "java/sql/Timestamp.hxx" 35 #include "java/math/BigDecimal.hxx" 36 #include "java/tools.hxx" 37 #include <cppuhelper/typeprovider.hxx> 38 #include <comphelper/sequence.hxx> 39 #include "connectivity/dbtools.hxx" 40 #include "connectivity/FValue.hxx" 41 #include "connectivity/dbexception.hxx" 42 #include "resource/jdbc_log.hrc" 43 #include "resource/common_res.hrc" 44 #include "resource/sharedresources.hxx" 45 #include "java/LocalRef.hxx" 46 #include <string.h> 47 48 using namespace connectivity; 49 using namespace ::com::sun::star::uno; 50 using namespace ::com::sun::star::beans; 51 using namespace ::com::sun::star::sdbc; 52 using namespace ::com::sun::star::container; 53 using namespace ::com::sun::star::lang; 54 55 //************************************************************** 56 //************ Class: java.sql.PreparedStatement 57 //************************************************************** 58 IMPLEMENT_SERVICE_INFO(java_sql_PreparedStatement,"com.sun.star.sdbcx.JPreparedStatement","com.sun.star.sdbc.PreparedStatement"); 59 60 java_sql_PreparedStatement::java_sql_PreparedStatement( JNIEnv * pEnv, java_sql_Connection& _rCon, const ::rtl::OUString& sql ) 61 : OStatement_BASE2( pEnv, _rCon ) 62 { 63 m_sSqlStatement = sql; 64 } 65 // ----------------------------------------------------------------------------- 66 jclass java_sql_PreparedStatement::theClass = 0; 67 68 java_sql_PreparedStatement::~java_sql_PreparedStatement() 69 { 70 } 71 // ----------------------------------------------------------------------------- 72 73 jclass java_sql_PreparedStatement::getMyClass() const 74 { 75 // die Klasse muss nur einmal geholt werden, daher statisch 76 if( !theClass ) 77 theClass = findMyClass("java/sql/PreparedStatement"); 78 return theClass; 79 } 80 // ------------------------------------------------------------------------- 81 82 ::com::sun::star::uno::Any SAL_CALL java_sql_PreparedStatement::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) 83 { 84 ::com::sun::star::uno::Any aRet = OStatement_BASE2::queryInterface(rType); 85 return aRet.hasValue() ? aRet : ::cppu::queryInterface( rType, 86 static_cast< XPreparedStatement*>(this), 87 static_cast< XParameters*>(this), 88 static_cast< XResultSetMetaDataSupplier*>(this), 89 static_cast< XPreparedBatchExecution*>(this)); 90 } 91 // ------------------------------------------------------------------------- 92 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL java_sql_PreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException) 93 { 94 ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedStatement > *)0 ), 95 ::getCppuType( (const ::com::sun::star::uno::Reference< XParameters > *)0 ), 96 ::getCppuType( (const ::com::sun::star::uno::Reference< XResultSetMetaDataSupplier > *)0 ), 97 ::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedBatchExecution > *)0 )); 98 99 return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_BASE2::getTypes()); 100 } 101 // ------------------------------------------------------------------------- 102 103 sal_Bool SAL_CALL java_sql_PreparedStatement::execute( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 104 { 105 m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTING_PREPARED ); 106 ::osl::MutexGuard aGuard( m_aMutex ); 107 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 108 109 static jmethodID mID(NULL); 110 return callBooleanMethod( "execute", mID ); 111 } 112 // ------------------------------------------------------------------------- 113 114 sal_Int32 SAL_CALL java_sql_PreparedStatement::executeUpdate( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 115 { 116 ::osl::MutexGuard aGuard( m_aMutex ); 117 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 118 m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTING_PREPARED_UPDATE ); 119 static jmethodID mID(NULL); 120 return callIntMethod("executeUpdate",mID); 121 } 122 // ------------------------------------------------------------------------- 123 124 void SAL_CALL java_sql_PreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 125 { 126 ::osl::MutexGuard aGuard( m_aMutex ); 127 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 128 m_aLogger.log( LogLevel::FINER, STR_LOG_STRING_PARAMETER, parameterIndex, x ); 129 130 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 131 { // temporaere Variable initialisieren 132 createStatement(t.pEnv); 133 static const char * cSignature = "(ILjava/lang/String;)V"; 134 static const char * cMethodName = "setString"; 135 // Java-Call absetzen 136 static jmethodID mID(NULL); 137 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 138 jdbc::LocalRef< jstring > str( t.env(),convertwchar_tToJavaString(t.pEnv,x)); 139 t.pEnv->CallVoidMethod( object, mID, parameterIndex,str.get()); 140 // und aufraeumen 141 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this ); 142 } //t.pEnv 143 } 144 // ------------------------------------------------------------------------- 145 146 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL java_sql_PreparedStatement::getConnection( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 147 { 148 return (Reference< XConnection >)m_pConnection; 149 } 150 // ------------------------------------------------------------------------- 151 152 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL java_sql_PreparedStatement::executeQuery( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 153 { 154 m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTING_PREPARED_QUERY ); 155 ::osl::MutexGuard aGuard( m_aMutex ); 156 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 157 158 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 159 createStatement(t.pEnv); 160 static jmethodID mID(NULL); 161 jobject out = callResultSetMethod(t.env(),"executeQuery",mID); 162 163 return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this); 164 } 165 // ------------------------------------------------------------------------- 166 167 void SAL_CALL java_sql_PreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 168 { 169 m_aLogger.log( LogLevel::FINER, STR_LOG_BOOLEAN_PARAMETER, parameterIndex, x ); 170 ::osl::MutexGuard aGuard( m_aMutex ); 171 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 172 173 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 174 createStatement(t.pEnv); 175 static jmethodID mID(NULL); 176 callVoidMethod("setBoolean", "(IZ)V", mID, parameterIndex, x); 177 } 178 // ------------------------------------------------------------------------- 179 180 void SAL_CALL java_sql_PreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 181 { 182 m_aLogger.log( LogLevel::FINER, STR_LOG_BYTE_PARAMETER, parameterIndex, (sal_Int32)x ); 183 ::osl::MutexGuard aGuard( m_aMutex ); 184 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 185 186 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 187 createStatement(t.pEnv); 188 static jmethodID mID(NULL); 189 callVoidMethod("setByte", "(IB)V", mID, parameterIndex, x); 190 } 191 // ------------------------------------------------------------------------- 192 193 void SAL_CALL java_sql_PreparedStatement::setDate( sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 194 { 195 m_aLogger.log( LogLevel::FINER, STR_LOG_DATE_PARAMETER, parameterIndex, x ); 196 ::osl::MutexGuard aGuard( m_aMutex ); 197 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 198 199 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 200 createStatement(t.pEnv); 201 java_sql_Date aT(x); 202 static jmethodID mID(NULL); 203 callVoidMethod("setDate", "(ILjava/sql/Date;)V", mID, parameterIndex, aT.getJavaObject()); 204 } 205 // ------------------------------------------------------------------------- 206 207 208 void SAL_CALL java_sql_PreparedStatement::setTime( sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 209 { 210 m_aLogger.log( LogLevel::FINER, STR_LOG_TIME_PARAMETER, parameterIndex, x ); 211 ::osl::MutexGuard aGuard( m_aMutex ); 212 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 213 214 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 215 createStatement(t.pEnv); 216 java_sql_Time aT(x); 217 static jmethodID mID(NULL); 218 callVoidMethod("setTime", "(ILjava/sql/Time;)V", mID, parameterIndex, aT.getJavaObject()); 219 } 220 // ------------------------------------------------------------------------- 221 222 void SAL_CALL java_sql_PreparedStatement::setTimestamp( sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 223 { 224 m_aLogger.log( LogLevel::FINER, STR_LOG_TIMESTAMP_PARAMETER, parameterIndex, x ); 225 ::osl::MutexGuard aGuard( m_aMutex ); 226 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 227 228 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 229 createStatement(t.pEnv); 230 static jmethodID mID(NULL); 231 java_sql_Timestamp aD(x); 232 callVoidMethod("setTimestamp", "(ILjava/sql/Timestamp;)V", mID, parameterIndex, aD.getJavaObject()); 233 } 234 // ------------------------------------------------------------------------- 235 void SAL_CALL java_sql_PreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 236 { 237 m_aLogger.log( LogLevel::FINER, STR_LOG_DOUBLE_PARAMETER, parameterIndex, x ); 238 ::osl::MutexGuard aGuard( m_aMutex ); 239 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 240 241 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 242 createStatement(t.pEnv); 243 static jmethodID mID(NULL); 244 callVoidMethod("setDouble", "(ID)V", mID, parameterIndex, x); 245 } 246 // ------------------------------------------------------------------------- 247 248 void SAL_CALL java_sql_PreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 249 { 250 m_aLogger.log( LogLevel::FINER, STR_LOG_FLOAT_PARAMETER, parameterIndex, x ); 251 ::osl::MutexGuard aGuard( m_aMutex ); 252 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 253 254 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 255 createStatement(t.pEnv); 256 static jmethodID mID(NULL); 257 callVoidMethod("setFloat", "(IF)V", mID, parameterIndex, x); 258 } 259 // ------------------------------------------------------------------------- 260 261 void SAL_CALL java_sql_PreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 262 { 263 m_aLogger.log( LogLevel::FINER, STR_LOG_INT_PARAMETER, parameterIndex, x ); 264 ::osl::MutexGuard aGuard( m_aMutex ); 265 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 266 267 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 268 createStatement(t.pEnv); 269 static jmethodID mID(NULL); 270 callVoidMethod("setInt", "(II)V", mID, parameterIndex, x); 271 } 272 // ------------------------------------------------------------------------- 273 274 void SAL_CALL java_sql_PreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 275 { 276 m_aLogger.log( LogLevel::FINER, STR_LOG_LONG_PARAMETER, parameterIndex, x ); 277 ::osl::MutexGuard aGuard( m_aMutex ); 278 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 279 280 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 281 createStatement(t.pEnv); 282 static jmethodID mID(NULL); 283 callVoidMethod("setLong", "(IJ)V", mID, parameterIndex, x); 284 } 285 // ------------------------------------------------------------------------- 286 287 void SAL_CALL java_sql_PreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 288 { 289 m_aLogger.log( LogLevel::FINER, STR_LOG_NULL_PARAMETER, parameterIndex, sqlType ); 290 ::osl::MutexGuard aGuard( m_aMutex ); 291 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 292 293 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 294 createStatement(t.pEnv); 295 static jmethodID mID(NULL); 296 callVoidMethod("setNull", "(II)V", mID, parameterIndex, sqlType); 297 } 298 // ------------------------------------------------------------------------- 299 300 void SAL_CALL java_sql_PreparedStatement::setClob( sal_Int32 /*parameterIndex*/, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob >& /*x*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 301 { 302 ::dbtools::throwFeatureNotImplementedException( "XParameters::setClob", *this ); 303 } 304 // ------------------------------------------------------------------------- 305 306 void SAL_CALL java_sql_PreparedStatement::setBlob( sal_Int32 /*parameterIndex*/, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob >& /*x*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 307 { 308 ::dbtools::throwFeatureNotImplementedException( "XParameters::setBlob", *this ); 309 } 310 // ------------------------------------------------------------------------- 311 312 void SAL_CALL java_sql_PreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray >& /*x*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 313 { 314 ::dbtools::throwFeatureNotImplementedException( "XParameters::setArray", *this ); 315 } 316 // ------------------------------------------------------------------------- 317 318 void SAL_CALL java_sql_PreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef >& /*x*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 319 { 320 ::dbtools::throwFeatureNotImplementedException( "XParameters::setRef", *this ); 321 } 322 // ------------------------------------------------------------------------- 323 324 void SAL_CALL java_sql_PreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const ::com::sun::star::uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 325 { 326 m_aLogger.log( LogLevel::FINER, STR_LOG_OBJECT_NULL_PARAMETER, parameterIndex ); 327 ::osl::MutexGuard aGuard( m_aMutex ); 328 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 329 330 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 331 { 332 createStatement(t.pEnv); 333 334 // temporaere Variable initialisieren 335 static const char * cSignature = "(ILjava/lang/Object;II)V"; 336 static const char * cMethodName = "setObject"; 337 // Java-Call absetzen 338 static jmethodID mID(NULL); 339 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 340 { 341 jobject obj = NULL; 342 double nTemp = 0.0; 343 switch(targetSqlType) 344 { 345 case DataType::DECIMAL: 346 case DataType::NUMERIC: 347 { 348 ::std::auto_ptr<java_math_BigDecimal> pBigDecimal; 349 if ( x >>= nTemp) 350 { 351 pBigDecimal.reset(new java_math_BigDecimal(nTemp)); 352 //setDouble(parameterIndex,nTemp); 353 //return; 354 } 355 else 356 { 357 ORowSetValue aValue; 358 aValue.fill(x); 359 const ::rtl::OUString sValue = aValue; 360 if ( sValue.getLength() ) 361 pBigDecimal.reset(new java_math_BigDecimal(sValue)); 362 else 363 pBigDecimal.reset(new java_math_BigDecimal(0.0)); 364 } 365 //obj = convertwchar_tToJavaString(t.pEnv,::comphelper::getString(x)); 366 t.pEnv->CallVoidMethod( object, mID, parameterIndex,pBigDecimal->getJavaObject(),targetSqlType,scale); 367 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this ); 368 return; 369 } 370 default: 371 obj = convertwchar_tToJavaString(t.pEnv,::comphelper::getString(x)); 372 break; 373 } 374 t.pEnv->CallVoidMethod( object, mID, parameterIndex,obj,targetSqlType,scale); 375 t.pEnv->DeleteLocalRef(obj); 376 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this ); 377 // und aufraeumen 378 } //mID 379 } //t.pEnv 380 } 381 // ------------------------------------------------------------------------- 382 383 void SAL_CALL java_sql_PreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 /*sqlType*/, const ::rtl::OUString& /*typeName*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 384 { 385 m_aLogger.log( LogLevel::FINER, STR_LOG_OBJECT_NULL_PARAMETER, parameterIndex ); 386 ::osl::MutexGuard aGuard( m_aMutex ); 387 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 388 389 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 390 createStatement(t.pEnv); 391 static jmethodID mID(NULL); 392 callVoidMethod<jobject>("setObject", "(ILjava/lang/Object;)V", mID, parameterIndex, NULL); 393 } 394 // ------------------------------------------------------------------------- 395 396 void SAL_CALL java_sql_PreparedStatement::setObject( sal_Int32 parameterIndex, const ::com::sun::star::uno::Any& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 397 { 398 if(!::dbtools::implSetObject(this,parameterIndex,x)) 399 { 400 const ::rtl::OUString sError( m_pConnection->getResources().getResourceStringWithSubstitution( 401 STR_UNKNOWN_PARA_TYPE, 402 "$position$", ::rtl::OUString::valueOf(parameterIndex) 403 ) ); 404 ::dbtools::throwGenericSQLException(sError,*this); 405 } 406 } 407 // ------------------------------------------------------------------------- 408 409 void SAL_CALL java_sql_PreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 410 { 411 m_aLogger.log( LogLevel::FINER, STR_LOG_SHORT_PARAMETER, parameterIndex, x ); 412 ::osl::MutexGuard aGuard( m_aMutex ); 413 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 414 415 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 416 createStatement(t.pEnv); 417 static jmethodID mID(NULL); 418 callVoidMethod("setShort", "(IS)V", mID, parameterIndex, x); 419 } 420 // ------------------------------------------------------------------------- 421 422 void SAL_CALL java_sql_PreparedStatement::setBytes( sal_Int32 parameterIndex, const ::com::sun::star::uno::Sequence< sal_Int8 >& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 423 { 424 m_aLogger.log( LogLevel::FINER, STR_LOG_BYTES_PARAMETER, parameterIndex ); 425 ::osl::MutexGuard aGuard( m_aMutex ); 426 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 427 428 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 429 { 430 createStatement(t.pEnv); 431 432 // temporaere Variable initialisieren 433 static const char * cSignature = "(I[B)V"; 434 static const char * cMethodName = "setBytes"; 435 // Java-Call absetzen 436 static jmethodID mID(NULL); 437 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 438 jbyteArray pByteArray = t.pEnv->NewByteArray(x.getLength()); 439 t.pEnv->SetByteArrayRegion(pByteArray,0,x.getLength(),(jbyte*)x.getConstArray()); 440 t.pEnv->CallVoidMethod( object, mID, parameterIndex,pByteArray); 441 t.pEnv->DeleteLocalRef(pByteArray); 442 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this ); 443 } //t.pEnv 444 } 445 // ------------------------------------------------------------------------- 446 447 void SAL_CALL java_sql_PreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 448 { 449 m_aLogger.log( LogLevel::FINER, STR_LOG_CHARSTREAM_PARAMETER, parameterIndex ); 450 ::osl::MutexGuard aGuard( m_aMutex ); 451 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 452 453 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 454 { 455 createStatement(t.pEnv); 456 457 // temporaere Variable initialisieren 458 static const char * cSignature = "(ILjava/io/InputStream;I)V"; 459 static const char * cMethodName = "setCharacterStream"; 460 // Java-Call absetzen 461 static jmethodID mID(NULL); 462 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 463 Sequence< sal_Int8 > aSeq; 464 if ( x.is() ) 465 x->readBytes( aSeq, length ); 466 sal_Int32 actualLength = aSeq.getLength(); 467 468 jvalue args2[3]; 469 jbyteArray pByteArray = t.pEnv->NewByteArray( actualLength ); 470 t.pEnv->SetByteArrayRegion(pByteArray,0,actualLength,(jbyte*)aSeq.getConstArray()); 471 args2[0].l = pByteArray; 472 args2[1].i = 0; 473 args2[2].i = actualLength; 474 // temporaere Variable initialisieren 475 const char * cSignatureStream = "([BII)V"; 476 // Java-Call absetzen 477 jclass aClass = t.pEnv->FindClass("java/io/CharArrayInputStream"); 478 static jmethodID mID2 = NULL; 479 if ( !mID2 ) 480 mID2 = t.pEnv->GetMethodID( aClass, "<init>", cSignatureStream ); 481 jobject tempObj = NULL; 482 if(mID2) 483 tempObj = t.pEnv->NewObjectA( aClass, mID2, args2 ); 484 485 t.pEnv->CallVoidMethod( object, mID, parameterIndex,tempObj,actualLength); 486 // und aufraeumen 487 t.pEnv->DeleteLocalRef(pByteArray); 488 t.pEnv->DeleteLocalRef(tempObj); 489 t.pEnv->DeleteLocalRef(aClass); 490 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this ); 491 } //t.pEnv 492 } 493 // ------------------------------------------------------------------------- 494 495 void SAL_CALL java_sql_PreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 496 { 497 m_aLogger.log( LogLevel::FINER, STR_LOG_BINARYSTREAM_PARAMETER, parameterIndex ); 498 ::osl::MutexGuard aGuard( m_aMutex ); 499 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 500 501 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 502 { 503 createStatement(t.pEnv); 504 // temporaere Variable initialisieren 505 static const char * cSignature = "(ILjava/io/InputStream;I)V"; 506 static const char * cMethodName = "setBinaryStream"; 507 // Java-Call absetzen 508 static jmethodID mID(NULL); 509 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 510 { 511 Sequence< sal_Int8 > aSeq; 512 if ( x.is() ) 513 x->readBytes( aSeq, length ); 514 sal_Int32 actualLength = aSeq.getLength(); 515 516 jvalue args2[3]; 517 jbyteArray pByteArray = t.pEnv->NewByteArray(actualLength); 518 t.pEnv->SetByteArrayRegion(pByteArray,0,actualLength,(jbyte*)aSeq.getConstArray()); 519 args2[0].l = pByteArray; 520 args2[1].i = 0; 521 args2[2].i = (sal_Int32)actualLength; 522 523 // temporaere Variable initialisieren 524 const char * cSignatureStream = "([BII)V"; 525 // Java-Call absetzen 526 jclass aClass = t.pEnv->FindClass("java/io/ByteArrayInputStream"); 527 static jmethodID mID2 = NULL; 528 if ( !mID2 ) 529 mID2 = t.pEnv->GetMethodID( aClass, "<init>", cSignatureStream ); 530 jobject tempObj = NULL; 531 if(mID2) 532 tempObj = t.pEnv->NewObjectA( aClass, mID2, args2 ); 533 t.pEnv->CallVoidMethod( object, mID, parameterIndex,tempObj,(sal_Int32)actualLength); 534 // und aufraeumen 535 t.pEnv->DeleteLocalRef(pByteArray); 536 t.pEnv->DeleteLocalRef(tempObj); 537 t.pEnv->DeleteLocalRef(aClass); 538 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this ); 539 } 540 } //t.pEnv 541 } 542 // ------------------------------------------------------------------------- 543 544 void SAL_CALL java_sql_PreparedStatement::clearParameters( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 545 { 546 m_aLogger.log( LogLevel::FINER, STR_LOG_CLEAR_PARAMETERS ); 547 ::osl::MutexGuard aGuard( m_aMutex ); 548 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 549 550 SDBThreadAttach t; 551 { 552 createStatement(t.pEnv); 553 554 static jmethodID mID(NULL); 555 callVoidMethod("clearParameters",mID); 556 } //t.pEnv 557 } 558 // ------------------------------------------------------------------------- 559 void SAL_CALL java_sql_PreparedStatement::clearBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 560 { 561 ::osl::MutexGuard aGuard( m_aMutex ); 562 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 563 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 564 { 565 createStatement(t.pEnv); 566 static jmethodID mID(NULL); 567 callVoidMethod("clearBatch",mID); 568 } //t.pEnv 569 } 570 // ------------------------------------------------------------------------- 571 572 void SAL_CALL java_sql_PreparedStatement::addBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 573 { 574 ::osl::MutexGuard aGuard( m_aMutex ); 575 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 576 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 577 { 578 createStatement(t.pEnv); 579 static jmethodID mID(NULL); 580 callVoidMethod("addBatch",mID); 581 } //t.pEnv 582 } 583 // ------------------------------------------------------------------------- 584 585 ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL java_sql_PreparedStatement::executeBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 586 { 587 ::osl::MutexGuard aGuard( m_aMutex ); 588 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 589 ::com::sun::star::uno::Sequence< sal_Int32 > aSeq; 590 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 591 createStatement(t.pEnv); 592 static jmethodID mID(NULL); 593 jintArray out = (jintArray)callObjectMethod(t.pEnv,"executeBatch","()[I", mID); 594 if(out) 595 { 596 jboolean p = sal_False; 597 aSeq.realloc(t.pEnv->GetArrayLength(out)); 598 memcpy(aSeq.getArray(),t.pEnv->GetIntArrayElements(out,&p),aSeq.getLength()); 599 t.pEnv->DeleteLocalRef(out); 600 } 601 return aSeq; 602 } 603 // ------------------------------------------------------------------------- 604 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > SAL_CALL java_sql_PreparedStatement::getMetaData( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 605 { 606 ::osl::MutexGuard aGuard( m_aMutex ); 607 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 608 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 609 createStatement(t.pEnv); 610 static jmethodID mID(NULL); 611 jobject out = callObjectMethod(t.pEnv,"getMetaData","()Ljava/sql/ResultSetMetaData;", mID); 612 613 return out==0 ? 0 : new java_sql_ResultSetMetaData( t.pEnv, out, m_aLogger,*m_pConnection ); 614 } 615 // ----------------------------------------------------------------------------- 616 void SAL_CALL java_sql_PreparedStatement::acquire() throw() 617 { 618 OStatement_BASE2::acquire(); 619 } 620 // ----------------------------------------------------------------------------- 621 void SAL_CALL java_sql_PreparedStatement::release() throw() 622 { 623 OStatement_BASE2::release(); 624 } 625 // ----------------------------------------------------------------------------- 626 void java_sql_PreparedStatement::createStatement(JNIEnv* _pEnv) 627 { 628 ::osl::MutexGuard aGuard( m_aMutex ); 629 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); 630 631 if( !object && _pEnv ){ 632 // temporaere Variable initialisieren 633 static const char * cSignature = "(Ljava/lang/String;II)Ljava/sql/PreparedStatement;"; 634 static const char * cMethodName = "prepareStatement"; 635 636 jvalue args[1]; 637 // Parameter konvertieren 638 args[0].l = convertwchar_tToJavaString(_pEnv,m_sSqlStatement); 639 // Java-Call absetzen 640 jobject out = NULL; 641 static jmethodID mID(NULL); 642 if ( !mID ) 643 mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature ); 644 if( mID ) 645 { 646 out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID, args[0].l ,m_nResultSetType,m_nResultSetConcurrency); 647 } 648 else 649 { 650 static const char * cSignature2 = "(Ljava/lang/String;)Ljava/sql/PreparedStatement;"; 651 static jmethodID mID2 = NULL; 652 if ( !mID2) 653 mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID,"Unknown method id!"); 654 if ( mID2 ) 655 out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2, args[0].l ); 656 } 657 _pEnv->DeleteLocalRef((jstring)args[0].l); 658 ThrowLoggedSQLException( m_aLogger, _pEnv, *this ); 659 if ( out ) 660 object = _pEnv->NewGlobalRef( out ); 661 } //t.pEnv 662 } 663 // ----------------------------------------------------------------------------- 664 665 666 667