LibreOffice Module connectivity (master) 1
jdbc/PreparedStatement.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
26#include <java/tools.hxx>
30#include <comphelper/types.hxx>
34#include <strings.hrc>
36#include <java/LocalRef.hxx>
37#include <strings.hxx>
38#include <string.h>
39#include <memory>
40
41using namespace connectivity;
42using namespace ::com::sun::star::uno;
43using namespace ::com::sun::star::beans;
44using namespace ::com::sun::star::sdbc;
45using namespace ::com::sun::star::container;
46using namespace ::com::sun::star::lang;
47
48
49//************ Class: java.sql.PreparedStatement
50
51IMPLEMENT_SERVICE_INFO(java_sql_PreparedStatement,"com.sun.star.sdbcx.JPreparedStatement","com.sun.star.sdbc.PreparedStatement");
52
53java_sql_PreparedStatement::java_sql_PreparedStatement( JNIEnv * pEnv, java_sql_Connection& _rCon, const OUString& sql )
54 : OStatement_BASE2( pEnv, _rCon )
55{
57}
58
60
62{
63}
64
65
67{
68 // the class must be fetched only once, therefore static
69 if( !theClass )
70 theClass = findMyClass("java/sql/PreparedStatement");
71 return theClass;
72}
73
74
75css::uno::Any SAL_CALL java_sql_PreparedStatement::queryInterface( const css::uno::Type & rType )
76{
77 css::uno::Any aRet = OStatement_BASE2::queryInterface(rType);
78 return aRet.hasValue() ? aRet : ::cppu::queryInterface( rType,
79 static_cast< XPreparedStatement*>(this),
80 static_cast< XParameters*>(this),
81 static_cast< XResultSetMetaDataSupplier*>(this),
82 static_cast< XPreparedBatchExecution*>(this));
83}
84
85css::uno::Sequence< css::uno::Type > SAL_CALL java_sql_PreparedStatement::getTypes( )
86{
91
92 return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_BASE2::getTypes());
93}
94
95
97{
98 m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTING_PREPARED );
99 ::osl::MutexGuard aGuard( m_aMutex );
100 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
101
102 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
103 createStatement(t.pEnv);
104 static jmethodID mID(nullptr);
105 return callBooleanMethod( "execute", mID );
106}
107
108
110{
111 ::osl::MutexGuard aGuard( m_aMutex );
112 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
114
115 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
116 createStatement(t.pEnv);
117 static jmethodID mID(nullptr);
118 return callIntMethod_ThrowSQL("executeUpdate", mID);
119}
120
121
122void SAL_CALL java_sql_PreparedStatement::setString( sal_Int32 parameterIndex, const OUString& x )
123{
124 ::osl::MutexGuard aGuard( m_aMutex );
125 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
126 m_aLogger.log( LogLevel::FINER, STR_LOG_STRING_PARAMETER, parameterIndex, x );
127
128 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
129 { // initialize temporary Variable
130 createStatement(t.pEnv);
131 static const char * const cSignature = "(ILjava/lang/String;)V";
132 static const char * const cMethodName = "setString";
133 // Java-Call
134 static jmethodID mID(nullptr);
135 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
137 t.pEnv->CallVoidMethod( object, mID, parameterIndex,str.get());
138 // and clean up
139 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
140 } //t.pEnv
141}
142
143
144css::uno::Reference< css::sdbc::XConnection > SAL_CALL java_sql_PreparedStatement::getConnection( )
145{
146 return m_pConnection;
147}
148
149
150css::uno::Reference< css::sdbc::XResultSet > SAL_CALL java_sql_PreparedStatement::executeQuery( )
151{
153 ::osl::MutexGuard aGuard( m_aMutex );
154 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
155
156 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
157 createStatement(t.pEnv);
158 static jmethodID mID(nullptr);
159 jobject out = callResultSetMethod(t.env(),"executeQuery",mID);
160
161 return out==nullptr ? nullptr : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this);
162}
163
164
165void SAL_CALL java_sql_PreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x )
166{
167 m_aLogger.log( LogLevel::FINER, STR_LOG_BOOLEAN_PARAMETER, parameterIndex, bool(x) );
168 ::osl::MutexGuard aGuard( m_aMutex );
169 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
170
171 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
172 createStatement(t.pEnv);
173 static jmethodID mID(nullptr);
174 callVoidMethod_ThrowSQL("setBoolean", "(IZ)V", mID, parameterIndex, x);
175}
176
177
178void SAL_CALL java_sql_PreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x )
179{
180 m_aLogger.log( LogLevel::FINER, STR_LOG_BYTE_PARAMETER, parameterIndex, static_cast<sal_Int32>(x) );
181 ::osl::MutexGuard aGuard( m_aMutex );
182 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
183
184 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
185 createStatement(t.pEnv);
186 static jmethodID mID(nullptr);
187 callVoidMethod_ThrowSQL("setByte", "(IB)V", mID, parameterIndex, x);
188}
189
190
191void SAL_CALL java_sql_PreparedStatement::setDate( sal_Int32 parameterIndex, const css::util::Date& x )
192{
193 m_aLogger.log( LogLevel::FINER, STR_LOG_DATE_PARAMETER, parameterIndex, x );
194 ::osl::MutexGuard aGuard( m_aMutex );
195 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
196
197 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
198 createStatement(t.pEnv);
199 java_sql_Date aT(x);
200 static jmethodID mID(nullptr);
201 callVoidMethod_ThrowSQL("setDate", "(ILjava/sql/Date;)V", mID, parameterIndex, aT.getJavaObject());
202}
203
204
205void SAL_CALL java_sql_PreparedStatement::setTime( sal_Int32 parameterIndex, const css::util::Time& x )
206{
207 m_aLogger.log( LogLevel::FINER, STR_LOG_TIME_PARAMETER, parameterIndex, x );
208 ::osl::MutexGuard aGuard( m_aMutex );
209 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
210
211 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
212 createStatement(t.pEnv);
213 java_sql_Time aT(x);
214 static jmethodID mID(nullptr);
215 callVoidMethod_ThrowSQL("setTime", "(ILjava/sql/Time;)V", mID, parameterIndex, aT.getJavaObject());
216}
217
218
219void SAL_CALL java_sql_PreparedStatement::setTimestamp( sal_Int32 parameterIndex, const css::util::DateTime& x )
220{
221 m_aLogger.log( LogLevel::FINER, STR_LOG_TIMESTAMP_PARAMETER, parameterIndex, x );
222 ::osl::MutexGuard aGuard( m_aMutex );
223 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
224
225 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
226 createStatement(t.pEnv);
227 static jmethodID mID(nullptr);
229 callVoidMethod_ThrowSQL("setTimestamp", "(ILjava/sql/Timestamp;)V", mID, parameterIndex, aD.getJavaObject());
230}
231
232void SAL_CALL java_sql_PreparedStatement::setDouble( sal_Int32 parameterIndex, double x )
233{
234 m_aLogger.log( LogLevel::FINER, STR_LOG_DOUBLE_PARAMETER, parameterIndex, x );
235 ::osl::MutexGuard aGuard( m_aMutex );
236 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
237
238 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
239 createStatement(t.pEnv);
240 static jmethodID mID(nullptr);
241 callVoidMethod_ThrowSQL("setDouble", "(ID)V", mID, parameterIndex, x);
242}
243
244
245void SAL_CALL java_sql_PreparedStatement::setFloat( sal_Int32 parameterIndex, float x )
246{
247 m_aLogger.log( LogLevel::FINER, STR_LOG_FLOAT_PARAMETER, parameterIndex, x );
248 ::osl::MutexGuard aGuard( m_aMutex );
249 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
250
251 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
252 createStatement(t.pEnv);
253 static jmethodID mID(nullptr);
254 callVoidMethod_ThrowSQL("setFloat", "(IF)V", mID, parameterIndex, x);
255}
256
257
258void SAL_CALL java_sql_PreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x )
259{
260 m_aLogger.log( LogLevel::FINER, STR_LOG_INT_PARAMETER, parameterIndex, x );
261 ::osl::MutexGuard aGuard( m_aMutex );
262 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
263
264 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
265 createStatement(t.pEnv);
266 static jmethodID mID(nullptr);
267 callVoidMethod_ThrowSQL("setInt", "(II)V", mID, parameterIndex, x);
268}
269
270
271void SAL_CALL java_sql_PreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x )
272{
273 m_aLogger.log( LogLevel::FINER, STR_LOG_LONG_PARAMETER, parameterIndex, x );
274 ::osl::MutexGuard aGuard( m_aMutex );
275 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
276
277 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
278 createStatement(t.pEnv);
279 static jmethodID mID(nullptr);
280 callVoidMethod_ThrowSQL("setLong", "(IJ)V", mID, parameterIndex, x);
281}
282
283
284void SAL_CALL java_sql_PreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType )
285{
286 m_aLogger.log( LogLevel::FINER, STR_LOG_NULL_PARAMETER, parameterIndex, sqlType );
287 ::osl::MutexGuard aGuard( m_aMutex );
288 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
289
290 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
291 createStatement(t.pEnv);
292 static jmethodID mID(nullptr);
293 callVoidMethod_ThrowSQL("setNull", "(II)V", mID, parameterIndex, sqlType);
294}
295
296
297void SAL_CALL java_sql_PreparedStatement::setClob( sal_Int32 /*parameterIndex*/, const css::uno::Reference< css::sdbc::XClob >& /*x*/ )
298{
299 ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setClob", *this );
300}
301
302
303void SAL_CALL java_sql_PreparedStatement::setBlob( sal_Int32 /*parameterIndex*/, const css::uno::Reference< css::sdbc::XBlob >& /*x*/ )
304{
305 ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setBlob", *this );
306}
307
308
309void SAL_CALL java_sql_PreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const css::uno::Reference< css::sdbc::XArray >& /*x*/ )
310{
311 ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setArray", *this );
312}
313
314
315void SAL_CALL java_sql_PreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const css::uno::Reference< css::sdbc::XRef >& /*x*/ )
316{
317 ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setRef", *this );
318}
319
320
321void SAL_CALL java_sql_PreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const css::uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale )
322{
323 m_aLogger.log( LogLevel::FINER, STR_LOG_OBJECT_NULL_PARAMETER, parameterIndex );
324 ::osl::MutexGuard aGuard( m_aMutex );
325 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
326
327 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
328 {
329 createStatement(t.pEnv);
330
331 // initialize temporary Variable
332 static const char * const cSignature = "(ILjava/lang/Object;II)V";
333 static const char * const cMethodName = "setObject";
334 // Java-Call
335 static jmethodID mID(nullptr);
336 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
337 {
338 jobject obj = nullptr;
339 switch(targetSqlType)
340 {
341 case DataType::DECIMAL:
342 case DataType::NUMERIC:
343 {
344 double nTemp = 0.0;
345
346 std::unique_ptr<java_math_BigDecimal> pBigDecimal;
347 if ( x >>= nTemp)
348 {
349 pBigDecimal.reset(new java_math_BigDecimal(nTemp));
350 //setDouble(parameterIndex,nTemp);
351 //return;
352 }
353 else
354 {
355 ORowSetValue aValue;
356 aValue.fill(x);
357 const OUString sValue = aValue.getString();
358 if ( !sValue.isEmpty() )
359 pBigDecimal.reset(new java_math_BigDecimal(sValue));
360 else
361 pBigDecimal.reset(new java_math_BigDecimal(0.0));
362 }
363 //obj = convertwchar_tToJavaString(t.pEnv,::comphelper::getString(x));
364 t.pEnv->CallVoidMethod( object, mID, parameterIndex,pBigDecimal->getJavaObject(),targetSqlType,scale);
365 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
366 return;
367 }
368 default:
369 obj = convertwchar_tToJavaString(t.pEnv,::comphelper::getString(x));
370 break;
371 }
372 t.pEnv->CallVoidMethod( object, mID, parameterIndex,obj,targetSqlType,scale);
373 t.pEnv->DeleteLocalRef(obj);
374 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
375 // and clean up
376 } //mID
377 } //t.pEnv
378}
379
380
381void SAL_CALL java_sql_PreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 /*sqlType*/, const OUString& /*typeName*/ )
382{
383 m_aLogger.log( LogLevel::FINER, STR_LOG_OBJECT_NULL_PARAMETER, parameterIndex );
384 ::osl::MutexGuard aGuard( m_aMutex );
385 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
386
387 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
388 createStatement(t.pEnv);
389 static jmethodID mID(nullptr);
390 callVoidMethod_ThrowSQL<jobject>("setObject", "(ILjava/lang/Object;)V", mID, parameterIndex, nullptr);
391}
392
393
394void SAL_CALL java_sql_PreparedStatement::setObject( sal_Int32 parameterIndex, const css::uno::Any& x )
395{
396 if(!::dbtools::implSetObject(this,parameterIndex,x))
397 {
398 const OUString sError( m_pConnection->getResources().getResourceStringWithSubstitution(
399 STR_UNKNOWN_PARA_TYPE,
400 "$position$", OUString::number(parameterIndex)
401 ) );
403 }
404}
405
406
407void SAL_CALL java_sql_PreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x )
408{
409 m_aLogger.log( LogLevel::FINER, STR_LOG_SHORT_PARAMETER, parameterIndex, x );
410 ::osl::MutexGuard aGuard( m_aMutex );
411 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
412
413 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
414 createStatement(t.pEnv);
415 static jmethodID mID(nullptr);
416 callVoidMethod_ThrowSQL("setShort", "(IS)V", mID, parameterIndex, x);
417}
418
419
420void SAL_CALL java_sql_PreparedStatement::setBytes( sal_Int32 parameterIndex, const css::uno::Sequence< sal_Int8 >& x )
421{
422 m_aLogger.log( LogLevel::FINER, STR_LOG_BYTES_PARAMETER, parameterIndex );
423 ::osl::MutexGuard aGuard( m_aMutex );
424 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
425
426 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
427 {
428 createStatement(t.pEnv);
429
430 // initialize temporary Variable
431 static const char * const cSignature = "(I[B)V";
432 static const char * const cMethodName = "setBytes";
433 // Java-Call
434 static jmethodID mID(nullptr);
435 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
436 jbyteArray pByteArray = t.pEnv->NewByteArray(x.getLength());
437 jbyte * pData = reinterpret_cast<jbyte *>(
438 const_cast<sal_Int8 *>(x.getConstArray()));
439 // 4th param of Set*ArrayRegion changed from pointer to non-const to
440 // pointer to const between <http://docs.oracle.com/javase/6/docs/
441 // technotes/guides/jni/spec/functions.html#wp22933> and
442 // <http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/
443 // functions.html#wp22933>; work around that difference in a way
444 // that doesn't trigger loplugin:redundantcast
445 t.pEnv->SetByteArrayRegion(pByteArray,0,x.getLength(),pData);
446 t.pEnv->CallVoidMethod( object, mID, parameterIndex,pByteArray);
447 t.pEnv->DeleteLocalRef(pByteArray);
448 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
449 } //t.pEnv
450}
451
452
453void SAL_CALL java_sql_PreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length )
454{
455 m_aLogger.log( LogLevel::FINER, STR_LOG_CHARSTREAM_PARAMETER, parameterIndex );
456 ::osl::MutexGuard aGuard( m_aMutex );
457 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
458
460 assert(t.pEnv && "Java environment has been deleted!");
461 {
462 createStatement(t.pEnv);
463
464 // initialize temporary variable
465 static const char * const cSignature = "(ILjava/io/InputStream;I)V";
466 static const char * const cMethodName = "setCharacterStream";
467 // Java-Call
468 static jmethodID mID(nullptr);
469 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
470 Sequence< sal_Int8 > aSeq;
471 if ( x.is() )
472 x->readBytes( aSeq, length );
473 sal_Int32 actualLength = aSeq.getLength();
474
475 jvalue args2[3];
476 jbyteArray pByteArray = t.pEnv->NewByteArray( actualLength );
477 jbyte * aSeqData = reinterpret_cast<jbyte *>(
478 const_cast<sal_Int8 *>(aSeq.getConstArray()));
479 // 4th param of Set*ArrayRegion changed from pointer to non-const to
480 // pointer to const between <http://docs.oracle.com/javase/6/docs/
481 // technotes/guides/jni/spec/functions.html#wp22933> and
482 // <http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/
483 // functions.html#wp22933>; work around that difference in a way
484 // that doesn't trigger loplugin:redundantcast
485 t.pEnv->SetByteArrayRegion(pByteArray,0,actualLength,aSeqData);
486 args2[0].l = pByteArray;
487 args2[1].i = 0;
488 args2[2].i = actualLength;
489 // Java-Call
490 jclass aClass = t.pEnv->FindClass("java/io/CharArrayInputStream");
491 static jmethodID mID2 = nullptr;
492 if ( !mID2 )
493 {
494 // initialize temporary variable
495 const char * const cSignatureStream = "([BII)V";
496 mID2 = t.pEnv->GetMethodID( aClass, "<init>", cSignatureStream );
497 }
498 jobject tempObj = nullptr;
499 if(mID2)
500 tempObj = t.pEnv->NewObjectA( aClass, mID2, args2 );
501
502 t.pEnv->CallVoidMethod( object, mID, parameterIndex,tempObj,actualLength);
503 // and clean up
504 t.pEnv->DeleteLocalRef(pByteArray);
505 t.pEnv->DeleteLocalRef(tempObj);
506 t.pEnv->DeleteLocalRef(aClass);
507 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
508 } //t.pEnv
509}
510
511
512void SAL_CALL java_sql_PreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length )
513{
514 m_aLogger.log( LogLevel::FINER, STR_LOG_BINARYSTREAM_PARAMETER, parameterIndex );
515 ::osl::MutexGuard aGuard( m_aMutex );
516 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
517
518 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
519 {
520 createStatement(t.pEnv);
521 // initialize temporary variable
522 static const char * const cSignature = "(ILjava/io/InputStream;I)V";
523 static const char * const cMethodName = "setBinaryStream";
524 // Java-Call
525 static jmethodID mID(nullptr);
526 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
527 {
528 Sequence< sal_Int8 > aSeq;
529 if ( x.is() )
530 x->readBytes( aSeq, length );
531 sal_Int32 actualLength = aSeq.getLength();
532
533 jvalue args2[3];
534 jbyteArray pByteArray = t.pEnv->NewByteArray(actualLength);
535 jbyte * aSeqData = reinterpret_cast<jbyte *>(
536 const_cast<sal_Int8 *>(aSeq.getConstArray()));
537 // 4th param of Set*ArrayRegion changed from pointer to non-const to
538 // pointer to const between <http://docs.oracle.com/javase/6/docs/
539 // technotes/guides/jni/spec/functions.html#wp22933> and
540 // <http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/
541 // functions.html#wp22933>; work around that difference in a way
542 // that doesn't trigger loplugin:redundantcast
543 t.pEnv->SetByteArrayRegion(pByteArray,0,actualLength,aSeqData);
544 args2[0].l = pByteArray;
545 args2[1].i = 0;
546 args2[2].i = actualLength;
547
548 // Java-Call
549 jclass aClass = t.pEnv->FindClass("java/io/ByteArrayInputStream");
550 static jmethodID mID2 = nullptr;
551 if ( !mID2 )
552 {
553 // initialize temporary variable
554 const char * const cSignatureStream = "([BII)V";
555 mID2 = t.pEnv->GetMethodID( aClass, "<init>", cSignatureStream );
556 }
557 jobject tempObj = nullptr;
558 if(mID2)
559 tempObj = t.pEnv->NewObjectA( aClass, mID2, args2 );
560 t.pEnv->CallVoidMethod( object, mID, parameterIndex,tempObj,actualLength);
561 // and clean up
562 t.pEnv->DeleteLocalRef(pByteArray);
563 t.pEnv->DeleteLocalRef(tempObj);
564 t.pEnv->DeleteLocalRef(aClass);
565 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
566 }
567 } //t.pEnv
568}
569
570
572{
573 m_aLogger.log( LogLevel::FINER, STR_LOG_CLEAR_PARAMETERS );
574 ::osl::MutexGuard aGuard( m_aMutex );
575 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
576
578 {
579 createStatement(t.pEnv);
580
581 static jmethodID mID(nullptr);
582 callVoidMethod_ThrowSQL("clearParameters",mID);
583 } //t.pEnv
584}
585
587{
588 ::osl::MutexGuard aGuard( m_aMutex );
589 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
590 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
591 {
592 createStatement(t.pEnv);
593 static jmethodID mID(nullptr);
594 callVoidMethod_ThrowSQL("clearBatch",mID);
595 } //t.pEnv
596}
597
598
600{
601 ::osl::MutexGuard aGuard( m_aMutex );
602 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
603 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
604 {
605 createStatement(t.pEnv);
606 static jmethodID mID(nullptr);
607 callVoidMethod_ThrowSQL("addBatch", mID);
608 } //t.pEnv
609}
610
611
612css::uno::Sequence< sal_Int32 > SAL_CALL java_sql_PreparedStatement::executeBatch( )
613{
614 ::osl::MutexGuard aGuard( m_aMutex );
615 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
616 css::uno::Sequence< sal_Int32 > aSeq;
617 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
618 createStatement(t.pEnv);
619 static jmethodID mID(nullptr);
620 jintArray out = static_cast<jintArray>(callObjectMethod(t.pEnv,"executeBatch","()[I", mID));
621 if(out)
622 {
623 jboolean p = false;
624 aSeq.realloc(t.pEnv->GetArrayLength(out));
625 memcpy(aSeq.getArray(),t.pEnv->GetIntArrayElements(out,&p),aSeq.getLength());
626 t.pEnv->DeleteLocalRef(out);
627 }
628 return aSeq;
629}
630
631css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL java_sql_PreparedStatement::getMetaData( )
632{
633 ::osl::MutexGuard aGuard( m_aMutex );
634 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
635 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
636 createStatement(t.pEnv);
637 static jmethodID mID(nullptr);
638 jobject out = callObjectMethod(t.pEnv,"getMetaData","()Ljava/sql/ResultSetMetaData;", mID);
639
640 return out==nullptr ? nullptr : new java_sql_ResultSetMetaData( t.pEnv, out, *m_pConnection );
641}
642
644{
646}
647
649{
651}
652
654{
655 ::osl::MutexGuard aGuard( m_aMutex );
656 checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
657
658 if( object || !_pEnv )
659 return;
660
661 // initialize temporary variable
662 static const char * const cMethodName = "prepareStatement";
663
664 jvalue args[1];
665 // convert Parameter
667 // Java-Call
668 jobject out = nullptr;
669 static jmethodID mID(nullptr);
670 if ( !mID )
671 {
672 static const char * const cSignature = "(Ljava/lang/String;II)Ljava/sql/PreparedStatement;";
673 mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature );
674 }
675 if( mID )
676 {
677 out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID, args[0].l ,m_nResultSetType,m_nResultSetConcurrency);
678 }
679 else
680 {
681 static jmethodID mID2 = nullptr;
682 if ( !mID2 )
683 {
684 static const char * const cSignature2 = "(Ljava/lang/String;)Ljava/sql/PreparedStatement;";
685 mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );
686 }
687 if ( mID2 )
688 out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2, args[0].l );
689 }
690 _pEnv->DeleteLocalRef(static_cast<jstring>(args[0].l));
691 ThrowLoggedSQLException( m_aLogger, _pEnv, *this );
692 if ( out )
693 object = _pEnv->NewGlobalRef( out );
694}
695
696
697/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
OUString getString() const
Definition: FValue.cxx:933
void fill(sal_Int32 _nPos, sal_Int32 _nType, const css::uno::Reference< css::sdbc::XRow > &_xRow)
fetches a single value out of the row
Definition: FValue.cxx:2215
void log(const sal_Int32 _nLogLevel, const OUString &rMessage)
logs a given message, without any arguments, or source class/method names
jobject callObjectMethod(JNIEnv *pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
Definition: Object.cxx:404
jobject callResultSetMethod(JNIEnv &_rEnv, const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:279
sal_Int32 callIntMethod_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:286
bool callBooleanMethod(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:252
void callVoidMethod_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:330
static void ThrowLoggedSQLException(const ::comphelper::EventLogger &_rLogger, JNIEnv *pEnvironment, const css::uno::Reference< css::uno::XInterface > &_rxContext)
Definition: Object.cxx:197
jobject getJavaObject() const
Definition: Object.hxx:83
static jclass findMyClass(const char *_pClassName)
Definition: Object.cxx:466
void obtainMethodId_throwSQL(JNIEnv *_pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
Definition: Object.cxx:229
virtual void SAL_CALL setArray(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XArray > &x) override
virtual void SAL_CALL setLong(sal_Int32 parameterIndex, sal_Int64 x) override
virtual void SAL_CALL setString(sal_Int32 parameterIndex, const OUString &x) override
virtual void SAL_CALL setCharacterStream(sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
virtual void SAL_CALL setObjectWithInfo(sal_Int32 parameterIndex, const css::uno::Any &x, sal_Int32 targetSqlType, sal_Int32 scale) override
virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch() override
virtual void createStatement(JNIEnv *_pEnv) override
virtual jclass getMyClass() const override
virtual sal_Int32 SAL_CALL executeUpdate() override
virtual void SAL_CALL setBlob(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XBlob > &x) override
virtual sal_Bool SAL_CALL execute() override
virtual void SAL_CALL setBinaryStream(sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
virtual void SAL_CALL clearParameters() override
virtual void SAL_CALL setShort(sal_Int32 parameterIndex, sal_Int16 x) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual void SAL_CALL setRef(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XRef > &x) override
virtual void SAL_CALL setBytes(sal_Int32 parameterIndex, const css::uno::Sequence< sal_Int8 > &x) override
virtual void SAL_CALL setTimestamp(sal_Int32 parameterIndex, const css::util::DateTime &x) override
virtual void SAL_CALL setObjectNull(sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString &typeName) override
virtual void SAL_CALL release() noexcept override
virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData() override
virtual void SAL_CALL setInt(sal_Int32 parameterIndex, sal_Int32 x) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL setBoolean(sal_Int32 parameterIndex, sal_Bool x) override
virtual void SAL_CALL setFloat(sal_Int32 parameterIndex, float x) override
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection() override
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery() override
virtual void SAL_CALL setDouble(sal_Int32 parameterIndex, double x) override
virtual void SAL_CALL setObject(sal_Int32 parameterIndex, const css::uno::Any &x) override
virtual void SAL_CALL setDate(sal_Int32 parameterIndex, const css::util::Date &x) override
virtual void SAL_CALL clearBatch() override
virtual void SAL_CALL setNull(sal_Int32 parameterIndex, sal_Int32 sqlType) override
virtual void SAL_CALL setTime(sal_Int32 parameterIndex, const css::util::Time &x) override
virtual void SAL_CALL acquire() noexcept override
virtual void SAL_CALL setByte(sal_Int32 parameterIndex, sal_Int8 x) override
virtual void SAL_CALL setClob(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XClob > &x) override
java::sql::ConnectionLog m_aLogger
Definition: JStatement.hxx:114
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: JStatement.cxx:118
virtual void SAL_CALL release() noexcept override
Definition: JStatement.cxx:843
rtl::Reference< java_sql_Connection > m_pConnection
Definition: JStatement.hxx:113
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: JStatement.cxx:110
virtual void SAL_CALL acquire() noexcept override
Definition: JStatement.cxx:838
helper class to hold a local ref to a JNI object
Definition: LocalRef.hxx:42
mutable::osl::Mutex m_aMutex
float x
IMPLEMENT_SERVICE_INFO(java_sql_PreparedStatement,"com.sun.star.sdbcx.JPreparedStatement","com.sun.star.sdbc.PreparedStatement")
void * p
Sequence< sal_Int8 > aSeq
std::unique_ptr< sal_Int32[]> pData
jstring convertwchar_tToJavaString(JNIEnv *pEnv, const OUString &Temp)
Definition: tools.cxx:93
void checkDisposed(bool _bThrow)
Definition: dbtools.cxx:1951
bool implSetObject(const Reference< XParameters > &_rxParameters, const sal_Int32 _nColumnIndex, const Any &_rValue)
Definition: dbtools.cxx:1516
void throwFeatureNotImplementedSQLException(const OUString &_rFeatureName, const Reference< XInterface > &_rxContext, const Any &_rNextException)
void throwGenericSQLException(const OUString &_rMsg, const css::uno::Reference< css::uno::XInterface > &_rxSource)
throw a generic SQLException, i.e.
args
sal_Int32 scale
Definition: pq_statics.cxx:62
constexpr OUStringLiteral STR_LOG_TIMESTAMP_PARAMETER
Definition: strings.hxx:51
constexpr OUStringLiteral STR_LOG_BINARYSTREAM_PARAMETER
Definition: strings.hxx:61
constexpr OUStringLiteral STR_LOG_DATE_PARAMETER
Definition: strings.hxx:49
constexpr OUStringLiteral STR_LOG_DOUBLE_PARAMETER
Definition: strings.hxx:52
constexpr OUStringLiteral STR_LOG_INT_PARAMETER
Definition: strings.hxx:54
constexpr OUStringLiteral STR_LOG_CHARSTREAM_PARAMETER
Definition: strings.hxx:60
constexpr OUStringLiteral STR_LOG_STRING_PARAMETER
Definition: strings.hxx:46
constexpr OUStringLiteral STR_LOG_EXECUTING_PREPARED_UPDATE
Definition: strings.hxx:44
constexpr OUStringLiteral STR_LOG_FLOAT_PARAMETER
Definition: strings.hxx:53
constexpr OUStringLiteral STR_LOG_BOOLEAN_PARAMETER
Definition: strings.hxx:47
constexpr OUStringLiteral STR_LOG_TIME_PARAMETER
Definition: strings.hxx:50
constexpr OUStringLiteral STR_LOG_CLEAR_PARAMETERS
Definition: strings.hxx:62
constexpr OUStringLiteral STR_LOG_LONG_PARAMETER
Definition: strings.hxx:55
constexpr OUStringLiteral STR_LOG_SHORT_PARAMETER
Definition: strings.hxx:58
constexpr OUStringLiteral STR_LOG_EXECUTING_PREPARED
Definition: strings.hxx:43
constexpr OUStringLiteral STR_LOG_NULL_PARAMETER
Definition: strings.hxx:56
constexpr OUStringLiteral STR_LOG_EXECUTING_PREPARED_QUERY
Definition: strings.hxx:45
constexpr OUStringLiteral STR_LOG_BYTES_PARAMETER
Definition: strings.hxx:59
constexpr OUStringLiteral STR_LOG_BYTE_PARAMETER
Definition: strings.hxx:48
constexpr OUStringLiteral STR_LOG_OBJECT_NULL_PARAMETER
Definition: strings.hxx:57
unsigned char sal_Bool
signed char sal_Int8
const SvXMLTokenMapEntry aTypes[]