LibreOffice Module connectivity (master) 1
jdbc/ResultSet.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
20#include <java/lang/String.hxx>
21#include <java/lang/Boolean.hxx>
27#include <java/sql/Array.hxx>
28#include <java/sql/Ref.hxx>
29#include <java/sql/Clob.hxx>
30#include <java/sql/Blob.hxx>
33#include <java/io/Reader.hxx>
34#include <java/tools.hxx>
40#include <com/sun/star/beans/PropertyAttribute.hpp>
41#include <TConnection.hxx>
42#include <comphelper/types.hxx>
45#include <strings.hrc>
47#include <java/LocalRef.hxx>
48
49#include <string.h>
50#include <memory>
51
52using namespace ::comphelper;
53
54using namespace connectivity;
55using namespace ::com::sun::star::uno;
56using namespace ::com::sun::star::beans;
57using namespace ::com::sun::star::sdbc;
58using namespace ::com::sun::star::container;
59using namespace ::com::sun::star::lang;
60
61IMPLEMENT_SERVICE_INFO(java_sql_ResultSet,"com.sun.star.sdbcx.JResultSet","com.sun.star.sdbc.ResultSet");
62
63//************ Class: java.sql.ResultSet
64
65
66jclass java_sql_ResultSet::theClass = nullptr;
67java_sql_ResultSet::java_sql_ResultSet( JNIEnv * pEnv, jobject myObj, const java::sql::ConnectionLog& _rParentLogger,java_sql_Connection& _rConnection, java_sql_Statement_Base* pStmt)
69 ,java_lang_Object( pEnv, myObj )
71 ,m_aLogger( _rParentLogger, java::sql::ConnectionLog::RESULTSET )
72 ,m_pConnection(&_rConnection)
73{
75 osl_atomic_increment(&m_refCount);
76 if ( pStmt )
77 m_xStatement = *pStmt;
78
79 osl_atomic_decrement(&m_refCount);
80}
81
83{
84 if ( !java_sql_ResultSet_BASE::rBHelper.bDisposed && !java_sql_ResultSet_BASE::rBHelper.bInDispose )
85 {
86 // increment ref count to prevent double call of Dtor
87 osl_atomic_increment( &m_refCount );
88 dispose();
89 }
90}
91
93{
94 // the class must be fetched only once, therefore static
95 if( !theClass )
96 theClass = findMyClass("java/sql/ResultSet");
97 return theClass;
98}
99
101{
103
104 ::osl::MutexGuard aGuard(m_aMutex);
105 if( object )
106 {
107 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
108 static jmethodID mID(nullptr);
109 callVoidMethod_ThrowSQL("close", mID);
110 clearObject(*t.pEnv);
111 }
112
114}
115
116css::uno::Any SAL_CALL java_sql_ResultSet::queryInterface( const css::uno::Type & rType )
117{
118 css::uno::Any aRet = OPropertySetHelper::queryInterface(rType);
119 return aRet.hasValue() ? aRet : java_sql_ResultSet_BASE::queryInterface(rType);
120}
121
122css::uno::Sequence< css::uno::Type > SAL_CALL java_sql_ResultSet::getTypes( )
123{
127
128 return ::comphelper::concatSequences(aTypes.getTypes(),java_sql_ResultSet_BASE::getTypes());
129}
130
131
132sal_Int32 SAL_CALL java_sql_ResultSet::findColumn( const OUString& columnName )
133{
134 static jmethodID mID(nullptr);
135 return callIntMethodWithStringArg("findColumn",mID,columnName);
136}
137
138Reference< css::io::XInputStream > SAL_CALL java_sql_ResultSet::getBinaryStream( sal_Int32 columnIndex )
139{
140 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
141 static jmethodID mID(nullptr);
142 jobject out = callObjectMethodWithIntArg(t.pEnv,"getBinaryStream","(I)Ljava/io/InputStream;", mID, columnIndex);
143
144 // WARNING: the caller becomes the owner of the returned pointer
145 return out==nullptr ? nullptr : new java_io_InputStream( t.pEnv, out );
146}
147
148Reference< css::io::XInputStream > SAL_CALL java_sql_ResultSet::getCharacterStream( sal_Int32 columnIndex )
149{
150 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
151 static jmethodID mID(nullptr);
152 jobject out = callObjectMethodWithIntArg(t.pEnv,"getCharacterStream","(I)Ljava/io/Reader;", mID, columnIndex);
153
154 // WARNING: the caller becomes the owner of the returned pointer
155 return out==nullptr ? nullptr : new java_io_Reader( t.pEnv, out );
156}
157
158
159sal_Bool SAL_CALL java_sql_ResultSet::getBoolean( sal_Int32 columnIndex )
160{
161 static jmethodID mID(nullptr);
162 return callBooleanMethodWithIntArg( "getBoolean", mID,columnIndex );
163}
164
165
166sal_Int8 SAL_CALL java_sql_ResultSet::getByte( sal_Int32 columnIndex )
167{
168 static jmethodID mID(nullptr);
169 jbyte (JNIEnv::* const pCallMethod)( jobject obj, jmethodID methodID, ... ) = &JNIEnv::CallByteMethod;
170 return callMethodWithIntArg<jbyte>(pCallMethod,"getByte","(I)B",mID,columnIndex);
171}
172
173
174Sequence< sal_Int8 > SAL_CALL java_sql_ResultSet::getBytes( sal_Int32 columnIndex )
175{
176 Sequence< sal_Int8 > aSeq;
177 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
178 static jmethodID mID(nullptr);
179 jbyteArray out = static_cast<jbyteArray>(callObjectMethodWithIntArg(t.pEnv,"getBytes","(I)[B", mID, columnIndex));
180 if (out)
181 {
182 jboolean p = false;
183 aSeq.realloc(t.pEnv->GetArrayLength(out));
184 memcpy(aSeq.getArray(),t.pEnv->GetByteArrayElements(out,&p),aSeq.getLength());
185 t.pEnv->DeleteLocalRef(out);
186 }
187 return aSeq;
188}
189
190
191css::util::Date SAL_CALL java_sql_ResultSet::getDate( sal_Int32 columnIndex )
192{
193 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
194 static jmethodID mID(nullptr);
195 jobject out = callObjectMethodWithIntArg(t.pEnv,"getDate","(I)Ljava/sql/Date;", mID, columnIndex);
196 // WARNING: the caller becomes the owner of the returned pointer
197 return out ? static_cast <css::util::Date> (java_sql_Date( t.pEnv, out )) : css::util::Date();
198}
199
200
201double SAL_CALL java_sql_ResultSet::getDouble( sal_Int32 columnIndex )
202{
203 static jmethodID mID(nullptr);
204 jdouble (JNIEnv::* const pCallMethod)( jobject obj, jmethodID methodID, ... ) = &JNIEnv::CallDoubleMethod;
205 return callMethodWithIntArg<double>(pCallMethod,"getDouble","(I)D",mID,columnIndex);
206}
207
208
209float SAL_CALL java_sql_ResultSet::getFloat( sal_Int32 columnIndex )
210{
211 static jmethodID mID(nullptr);
212 jfloat (JNIEnv::* const pCallMethod)( jobject obj, jmethodID methodID, ... ) = &JNIEnv::CallFloatMethod;
213 return callMethodWithIntArg<jfloat>(pCallMethod,"getFloat","(I)F",mID,columnIndex);
214}
215
216
217sal_Int32 SAL_CALL java_sql_ResultSet::getInt( sal_Int32 columnIndex )
218{
219 static jmethodID mID(nullptr);
220 return callIntMethodWithIntArg_ThrowSQL("getInt",mID,columnIndex);
221}
222
223
224sal_Int32 SAL_CALL java_sql_ResultSet::getRow( )
225{
226 static jmethodID mID(nullptr);
227 return callIntMethod_ThrowSQL("getRow", mID);
228}
229
230
231sal_Int64 SAL_CALL java_sql_ResultSet::getLong( sal_Int32 columnIndex )
232{
233 static jmethodID mID(nullptr);
234 jlong (JNIEnv::* const pCallMethod)( jobject obj, jmethodID methodID, ... ) = &JNIEnv::CallLongMethod;
235 return callMethodWithIntArg<jlong>(pCallMethod,"getLong","(I)J",mID,columnIndex);
236}
237
238
239css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL java_sql_ResultSet::getMetaData( )
240{
241 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
242 static jmethodID mID(nullptr);
243 jobject out = callObjectMethod(t.pEnv,"getMetaData","()Ljava/sql/ResultSetMetaData;", mID);
244
245 return out==nullptr ? nullptr : new java_sql_ResultSetMetaData( t.pEnv, out, *m_pConnection );
246}
247
248Reference< XArray > SAL_CALL java_sql_ResultSet::getArray( sal_Int32 columnIndex )
249{
250 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
251 static jmethodID mID(nullptr);
252 jobject out = callObjectMethodWithIntArg(t.pEnv,"getArray","(I)Ljava/sql/Array;", mID, columnIndex);
253
254 // WARNING: the caller becomes the owner of the returned pointer
255 return out==nullptr ? nullptr : new java_sql_Array( t.pEnv, out );
256}
257
258
259Reference< XClob > SAL_CALL java_sql_ResultSet::getClob( sal_Int32 columnIndex )
260{
261 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
262 static jmethodID mID(nullptr);
263 jobject out = callObjectMethodWithIntArg(t.pEnv,"getClob","(I)Ljava/sql/Clob;", mID, columnIndex);
264 // WARNING: the caller becomes the owner of the returned pointer
265 return out==nullptr ? nullptr : new java_sql_Clob( t.pEnv, out );
266}
267
268Reference< XBlob > SAL_CALL java_sql_ResultSet::getBlob( sal_Int32 columnIndex )
269{
270 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
271 static jmethodID mID(nullptr);
272 jobject out = callObjectMethodWithIntArg(t.pEnv,"getBlob","(I)Ljava/sql/Blob;", mID, columnIndex);
273 // WARNING: the caller becomes the owner of the returned pointer
274 return out==nullptr ? nullptr : new java_sql_Blob( t.pEnv, out );
275}
276
277
278Reference< XRef > SAL_CALL java_sql_ResultSet::getRef( sal_Int32 columnIndex )
279{
280 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
281 static jmethodID mID(nullptr);
282 jobject out = callObjectMethodWithIntArg(t.pEnv,"getRef","(I)Ljava/sql/Ref;", mID, columnIndex);
283
284 // WARNING: the caller becomes the owner of the returned pointer
285 return out==nullptr ? nullptr : new java_sql_Ref( t.pEnv, out );
286}
287
288
289Any SAL_CALL java_sql_ResultSet::getObject( sal_Int32 columnIndex, const Reference< css::container::XNameAccess >& typeMap )
290{
291 Any aRet;
292 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
293 {
294 jvalue args[2];
295 // convert parameter
296 args[0].i = columnIndex;
297 args[1].l = convertTypeMapToJavaMap(typeMap);
298 // initialize temporary Variable
299 // Java-Call
300 static jmethodID mID(nullptr);
301 if ( !mID )
302 {
303 static const char * const cSignature = "(I)Ljava/lang/Object;";
304 static const char * const cMethodName = "getObject";
305
306 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
307 }
308
309 jobject out = t.pEnv->CallObjectMethodA( object, mID, args);
310 t.pEnv->DeleteLocalRef(static_cast<jstring>(args[1].l));
311 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
312 // and clean up
313 if ( out )
314 {
315 if ( t.pEnv->IsInstanceOf(out,java_lang_String::st_getMyClass()) )
316 {
317 java_lang_String aVal(t.pEnv,out);
318 aRet <<= OUString(aVal);
319 }
320 else if ( t.pEnv->IsInstanceOf(out,java_lang_Boolean::st_getMyClass()) )
321 {
322 java_lang_Boolean aVal(t.pEnv,out);
323 static jmethodID methodID = nullptr;
324 aRet <<= aVal.callBooleanMethod("booleanValue",methodID);
325 }
326 else if ( t.pEnv->IsInstanceOf(out,java_sql_Date::st_getMyClass()) )
327 {
328 java_sql_Date aVal(t.pEnv,out);
329 aRet <<= css::util::Date(aVal);
330 }
331 else if ( t.pEnv->IsInstanceOf(out,java_sql_Time::st_getMyClass()) )
332 {
333 java_sql_Time aVal(t.pEnv,out);
334 aRet <<= css::util::Time(aVal);
335 }
336 else if ( t.pEnv->IsInstanceOf(out,java_sql_Timestamp::st_getMyClass()) )
337 {
338 java_sql_Timestamp aVal(t.pEnv,out);
339 aRet <<= css::util::DateTime(aVal);
340 }
341 else
342 t.pEnv->DeleteLocalRef(out);
343 }
344 } //t.pEnv
345 return aRet;
346}
347
348
349sal_Int16 SAL_CALL java_sql_ResultSet::getShort( sal_Int32 columnIndex )
350{
351 static jmethodID mID(nullptr);
352 jshort (JNIEnv::* const pCallMethod)( jobject obj, jmethodID methodID, ... ) = &JNIEnv::CallShortMethod;
353 return callMethodWithIntArg<jshort>(pCallMethod,"getShort","(I)S",mID,columnIndex);
354}
355
356
357OUString SAL_CALL java_sql_ResultSet::getString( sal_Int32 columnIndex )
358{
359 static jmethodID mID(nullptr);
360 return callStringMethodWithIntArg("getString",mID,columnIndex);
361}
362
363
364css::util::Time SAL_CALL java_sql_ResultSet::getTime( sal_Int32 columnIndex )
365{
366 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
367 static jmethodID mID(nullptr);
368 jobject out = callObjectMethodWithIntArg(t.pEnv,"getTime","(I)Ljava/sql/Time;", mID, columnIndex);
369 // WARNING: the caller becomes the owner of the returned pointer
370 return out ? static_cast <css::util::Time> (java_sql_Time( t.pEnv, out )) : css::util::Time();
371}
372
373
374css::util::DateTime SAL_CALL java_sql_ResultSet::getTimestamp( sal_Int32 columnIndex )
375{
376 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
377 static jmethodID mID(nullptr);
378 jobject out = callObjectMethodWithIntArg(t.pEnv,"getTimestamp","(I)Ljava/sql/Timestamp;", mID, columnIndex);
379 // WARNING: the caller becomes the owner of the returned pointer
380 return out ? static_cast <css::util::DateTime> (java_sql_Timestamp( t.pEnv, out )) : css::util::DateTime();
381}
382
383
385{
386 static jmethodID mID(nullptr);
387 return callBooleanMethod( "isAfterLast", mID );
388}
389
391{
392 static jmethodID mID(nullptr);
393 return callBooleanMethod( "isFirst", mID );
394}
395
397{
398 static jmethodID mID(nullptr);
399 return callBooleanMethod( "isLast", mID );
400}
401
403{
404 static jmethodID mID(nullptr);
405 callVoidMethod_ThrowSQL("beforeFirst", mID);
406}
407
409{
410 static jmethodID mID(nullptr);
411 callVoidMethod_ThrowSQL("afterLast", mID);
412}
413
414
416{
417 dispose();
418}
419
420
422{
423 static jmethodID mID(nullptr);
424 return callBooleanMethod( "first", mID );
425}
426
427
429{
430 static jmethodID mID(nullptr);
431 return callBooleanMethod( "last", mID );
432}
433
434sal_Bool SAL_CALL java_sql_ResultSet::absolute( sal_Int32 row )
435{
436 static jmethodID mID(nullptr);
437 return callBooleanMethodWithIntArg( "absolute", mID,row );
438}
439
440sal_Bool SAL_CALL java_sql_ResultSet::relative( sal_Int32 row )
441{
442 static jmethodID mID(nullptr);
443 return callBooleanMethodWithIntArg( "relative", mID,row );
444}
445
447{
448 static jmethodID mID(nullptr);
449 return callBooleanMethod( "previous", mID );
450}
451
452Reference< XInterface > SAL_CALL java_sql_ResultSet::getStatement( )
453{
454 return m_xStatement;
455}
456
457
459{
460 static jmethodID mID(nullptr);
461 return callBooleanMethod( "rowDeleted", mID );
462}
463
465{
466 static jmethodID mID(nullptr);
467 return callBooleanMethod( "rowInserted", mID );
468}
469
471{
472 static jmethodID mID(nullptr);
473 return callBooleanMethod( "rowUpdated", mID );
474}
475
476
478{
479 static jmethodID mID(nullptr);
480 return callBooleanMethod( "isBeforeFirst", mID );
481}
482
483
485{
486 static jmethodID mID(nullptr);
487 return callBooleanMethod( "next", mID );
488}
489
491{
492 static jmethodID mID(nullptr);
493 return callBooleanMethod( "wasNull", mID );
494}
495
497{
498 static jmethodID mID(nullptr);
499 callVoidMethod_ThrowRuntime("cancel", mID);
500}
501
503{
504 static jmethodID mID(nullptr);
505 callVoidMethod_ThrowSQL("clearWarnings", mID);
506}
507
508css::uno::Any SAL_CALL java_sql_ResultSet::getWarnings( )
509{
511 static jmethodID mID(nullptr);
512 jobject out = callObjectMethod(t.pEnv,"getWarnings","()Ljava/sql/SQLWarning;", mID);
513 // WARNING: the caller becomes the owner of the returned pointer
514 if( out )
515 {
516 java_sql_SQLWarning_BASE warn_base( t.pEnv, out );
517 return Any(
518 static_cast< css::sdbc::SQLException >(
519 java_sql_SQLWarning(warn_base,*this)));
520 }
521
522 return css::uno::Any();
523}
524
525
527{
528 static jmethodID mID(nullptr);
529 callVoidMethod_ThrowSQL("insertRow", mID);
530}
531
533{
534 static jmethodID mID(nullptr);
535 callVoidMethod_ThrowSQL("updateRow", mID);
536}
537
539{
540 static jmethodID mID(nullptr);
541 callVoidMethod_ThrowSQL("deleteRow", mID);
542}
543
544
546{
547 static jmethodID mID(nullptr);
548 callVoidMethod_ThrowSQL("cancelRowUpdates", mID);
549}
550
551
553{
554 static jmethodID mID(nullptr);
555 callVoidMethod_ThrowSQL("moveToInsertRow", mID);
556}
557
558
560{
561 static jmethodID mID(nullptr);
562 callVoidMethod_ThrowSQL("moveToCurrentRow", mID);
563}
564
565
566void SAL_CALL java_sql_ResultSet::updateNull( sal_Int32 columnIndex )
567{
568 static jmethodID mID(nullptr);
569 callVoidMethodWithIntArg_ThrowSQL("updateNull", mID, columnIndex);
570}
571
572
573void SAL_CALL java_sql_ResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x )
574{
575 static jmethodID mID(nullptr);
576 callVoidMethod_ThrowSQL("updateBoolean", "(IZ)V", mID, columnIndex, x);
577}
578
579void SAL_CALL java_sql_ResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x )
580{
581 static jmethodID mID(nullptr);
582 callVoidMethod_ThrowSQL("updateByte", "(IB)V", mID, columnIndex, x);
583}
584
585
586void SAL_CALL java_sql_ResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x )
587{
588 static jmethodID mID(nullptr);
589 callVoidMethod_ThrowSQL("updateShort", "(IS)V", mID, columnIndex, x);
590}
591
592void SAL_CALL java_sql_ResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x )
593{
594 static jmethodID mID(nullptr);
595 callVoidMethod_ThrowSQL("updateInt", "(II)V", mID, columnIndex, x);
596}
597
598void SAL_CALL java_sql_ResultSet::updateLong( sal_Int32 columnIndex, sal_Int64 x )
599{
600 static jmethodID mID(nullptr);
601 callVoidMethod_ThrowSQL("updateLong", "(IJ)V", mID, columnIndex, x);
602}
603
604
605void SAL_CALL java_sql_ResultSet::updateFloat( sal_Int32 columnIndex, float x )
606{
607 static jmethodID mID(nullptr);
608 callVoidMethod_ThrowSQL("updateFloat", "(IF)V", mID, columnIndex, x);
609}
610
611
612void SAL_CALL java_sql_ResultSet::updateDouble( sal_Int32 columnIndex, double x )
613{
614 static jmethodID mID(nullptr);
615 callVoidMethod_ThrowSQL("updateDouble", "(ID)V", mID, columnIndex, x);
616}
617
618
619void SAL_CALL java_sql_ResultSet::updateString( sal_Int32 columnIndex, const OUString& x )
620{
622
623 {
624 // initialize temporary variable
625 // Java-Call
626 static jmethodID mID(nullptr);
627 if ( !mID )
628 {
629 static const char * const cSignature = "(ILjava/lang/String;)V";
630 static const char * const cMethodName = "updateString";
631
632 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
633 }
634
635 {
636 // convert parameter
638 t.pEnv->CallVoidMethod( object, mID,columnIndex,str.get());
639 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
640 }
641 }
642}
643
644
645void SAL_CALL java_sql_ResultSet::updateBytes( sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 >& x )
646{
648
649 {
650 // initialize temporary variable
651 // Java-Call
652 static jmethodID mID(nullptr);
653 if ( !mID )
654 {
655 static const char * const cSignature = "(I[B)V";
656 static const char * const cMethodName = "updateBytes";
657
658 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
659 }
660
661 {
662 jbyteArray aArray = t.pEnv->NewByteArray(x.getLength());
663 jbyte * pData = reinterpret_cast<jbyte *>(
664 const_cast<sal_Int8 *>(x.getConstArray()));
665 // 4th param of Set*ArrayRegion changed from pointer to non-const to
666 // pointer to const between <http://docs.oracle.com/javase/6/docs/
667 // technotes/guides/jni/spec/functions.html#wp22933> and
668 // <http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/
669 // functions.html#wp22933>; work around that difference in a way
670 // that doesn't trigger loplugin:redundantcast
671 t.pEnv->SetByteArrayRegion(aArray,0,x.getLength(),pData);
672 // convert parameter
673 t.pEnv->CallVoidMethod( object, mID,columnIndex,aArray);
674 t.pEnv->DeleteLocalRef(aArray);
675 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
676 }
677 }
678}
679
680
681void SAL_CALL java_sql_ResultSet::updateDate( sal_Int32 columnIndex, const css::util::Date& x )
682{
683 java_sql_Date aD(x);
684 static jmethodID mID(nullptr);
685 callVoidMethod_ThrowSQL("updateDate", "(ILjava/sql/Date;)V", mID, columnIndex, aD.getJavaObject());
686}
687
688
689void SAL_CALL java_sql_ResultSet::updateTime( sal_Int32 columnIndex, const css::util::Time& x )
690{
691 java_sql_Time aD(x);
692 static jmethodID mID(nullptr);
693 callVoidMethod_ThrowSQL("updateTime", "(ILjava/sql/Time;)V", mID, columnIndex, aD.getJavaObject());
694}
695
696
697void SAL_CALL java_sql_ResultSet::updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x )
698{
700 static jmethodID mID(nullptr);
701 callVoidMethod_ThrowSQL("updateTimestamp", "(ILjava/sql/Timestamp;)V", mID, columnIndex, aD.getJavaObject());
702}
703
704
705void SAL_CALL java_sql_ResultSet::updateBinaryStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length )
706{
707 try
708 {
710 {
711
712 // initialize temporary variable
713 // Java-Call
714 static jmethodID mID(nullptr);
715 if ( !mID )
716 {
717 static const char * const cSignature = "(ILjava/io/InputStream;I)V";
718 static const char * const cMethodName = "updateBinaryStream";
719 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
720 }
721
722 {
723 // convert Parameter
724 jobject obj = createByteInputStream(x,length);
725 t.pEnv->CallVoidMethod( object, mID, columnIndex,obj,length);
726 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
727 }
728 }
729 }
730 catch(const Exception&)
731 {
732 Any anyEx = ::cppu::getCaughtException();
733 ::dbtools::throwFeatureNotImplementedSQLException( "XRowUpdate::updateBinaryStream", *this, anyEx );
734 }
735}
736
737void SAL_CALL java_sql_ResultSet::updateCharacterStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length )
738{
739 try
740 {
742 {
743
744 // initialize temporary variable
745 // Java-Call
746 static jmethodID mID(nullptr);
747 if ( !mID )
748 {
749 static const char * const cSignature = "(ILjava/io/Reader;I)V";
750 static const char * const cMethodName = "updateCharacterStream";
751 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
752 }
753
754 {
755 // convert Parameter
756 jobject obj = createCharArrayReader(x,length);
757 t.pEnv->CallVoidMethod( object, mID, columnIndex,obj,length);
758 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
759 }
760 }
761 }
762 catch(const Exception&)
763 {
764 Any anyEx = ::cppu::getCaughtException();
765 ::dbtools::throwFeatureNotImplementedSQLException( "XRowUpdate::updateCharacterStream", *this, anyEx );
766 }
767}
768
769void SAL_CALL java_sql_ResultSet::updateObject( sal_Int32 columnIndex, const css::uno::Any& x )
770{
771 if(!::dbtools::implUpdateObject(this,columnIndex,x))
772 {
774 const OUString sError( aResources.getResourceStringWithSubstitution(
775 STR_UNKNOWN_COLUMN_TYPE,
776 "$position$", OUString::number(columnIndex)
777 ) );
779 }
780}
781
782
783void SAL_CALL java_sql_ResultSet::updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, sal_Int32 scale )
784{
785 // OSL_FAIL("java_sql_ResultSet::updateNumericObject: NYI");
786 try
787 {
789
790 {
791
792 // initialize temporary variable
793 // Java-Call
794 static jmethodID mID(nullptr);
795 if ( !mID )
796 {
797 static const char * const cSignature = "(ILjava/lang/Object;I)V";
798 static const char * const cMethodName = "updateObject";
799
800 obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
801 }
802
803 {
804 // convert parameter
805 double nTemp = 0.0;
806 std::unique_ptr<java_math_BigDecimal> pBigDecimal;
807 if ( x >>= nTemp)
808 {
809 pBigDecimal.reset(new java_math_BigDecimal(nTemp));
810 }
811 else
812 pBigDecimal.reset(new java_math_BigDecimal(::comphelper::getString(x)));
813
814 t.pEnv->CallVoidMethod( object, mID, columnIndex,pBigDecimal->getJavaObject(),scale);
815 ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
816 }
817 }
818 }
819 catch(const Exception&)
820 {
821 updateObject( columnIndex,x);
822 }
823}
824
826{
827 static jmethodID mID(nullptr);
828 return callIntMethod_ThrowRuntime("getConcurrency", mID);
829}
830
832{
833 static jmethodID mID(nullptr);
834 return callIntMethod_ThrowRuntime("getType",mID);
835}
836
838{
839 static jmethodID mID(nullptr);
840 return callIntMethod_ThrowRuntime("getFetchDirection", mID);
841}
842
844{
845 static jmethodID mID(nullptr);
846 return callIntMethod_ThrowRuntime("getFetchSize", mID);
847}
848
850{
851 static jmethodID mID(nullptr);
852 return callStringMethod("getCursorName",mID);
853}
854
855
857{
858 static jmethodID mID(nullptr);
859 callVoidMethodWithIntArg_ThrowRuntime("setFetchDirection", mID, _par0);
860}
861
863{
864 static jmethodID mID(nullptr);
865 callVoidMethod_ThrowSQL("refreshRow",mID);
866}
867
869{
870 static jmethodID mID(nullptr);
871 callVoidMethodWithIntArg_ThrowRuntime("setFetchSize", mID, _par0);
872}
873
875{
876 return new ::cppu::OPropertyArrayHelper
877 {
878 {
879 {
883 PropertyAttribute::READONLY
884 },
885 {
889 0
890 },
891 {
895 0
896 },
897 {
901 PropertyAttribute::READONLY
902 },
903 {
907 PropertyAttribute::READONLY
908 }
909 }
910 };
911}
912
914{
915 return *getArrayHelper();
916}
917
919 css::uno::Any & rConvertedValue,
920 css::uno::Any & rOldValue,
921 sal_Int32 nHandle,
922 const css::uno::Any& rValue )
923{
924 bool bRet = false;
925 switch(nHandle)
926 {
930 throw css::lang::IllegalArgumentException();
932 bRet = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
933 break;
935 bRet = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
936 break;
937 default:
938 break;
939 }
940 return bRet;
941}
942
943
945 sal_Int32 nHandle,
946 const css::uno::Any& rValue
947 )
948{
949 switch(nHandle)
950 {
954 throw css::uno::Exception("cannot set prop " + OUString::number(nHandle), nullptr);
957 break;
960 break;
961 default:
962 ;
963 }
964}
965
967 css::uno::Any& rValue,
968 sal_Int32 nHandle
969 ) const
970{
971 try
972 {
973 switch(nHandle)
974 {
976 rValue <<= getCursorName();
977 break;
979 rValue <<= getResultSetConcurrency();
980 break;
982 rValue <<= getResultSetType();
983 break;
985 rValue <<= getFetchDirection();
986 break;
988 rValue <<= getFetchSize();
989 break;
990 }
991 }
992 catch(const Exception&)
993 {
994 }
995}
996
997void SAL_CALL java_sql_ResultSet::acquire() noexcept
998{
999 java_sql_ResultSet_BASE::acquire();
1000}
1001
1002void SAL_CALL java_sql_ResultSet::release() noexcept
1003{
1004 java_sql_ResultSet_BASE::release();
1005}
1006
1007css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL java_sql_ResultSet::getPropertySetInfo( )
1008{
1009 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1010}
1011
1012
1013/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
void disposing(std::unique_lock< std::mutex > &rGuard)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
static void releaseRef()
Definition: Object.cxx:81
helper class for accessing resources shared by different libraries in the connectivity module
OUString getResourceStringWithSubstitution(TranslateId pResId, const char *_pAsciiPatternToReplace, const OUString &_rStringToSubstitute) const
loads a string from the shared resource file, and replaces a given ASCII pattern with a given string
static jclass st_getMyClass()
Definition: Boolean.cxx:28
jobject callObjectMethod(JNIEnv *pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
Definition: Object.cxx:404
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
sal_Int32 callIntMethodWithStringArg(const char *_pMethodName, jmethodID &_inout_MethodID, const OUString &_nArgument) const
Definition: Object.cxx:444
void callVoidMethod_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:330
sal_Int32 callIntMethodWithIntArg_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:308
void callVoidMethodWithIntArg_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:352
void callVoidMethodWithIntArg_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:363
OUString callStringMethod(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:394
jobject callObjectMethodWithIntArg(JNIEnv *pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:415
bool callBooleanMethodWithIntArg(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:266
OUString callStringMethodWithIntArg(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:424
sal_Int32 callIntMethod_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:297
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 callVoidMethod_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:341
void obtainMethodId_throwSQL(JNIEnv *_pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
Definition: Object.cxx:229
static jclass st_getMyClass()
Definition: String.cxx:31
static jclass st_getMyClass()
Definition: Timestamp.cxx:65
virtual void SAL_CALL moveToInsertRow() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual double SAL_CALL getDouble(sal_Int32 columnIndex) override
virtual void SAL_CALL moveToCurrentRow() override
virtual sal_Bool SAL_CALL isLast() override
virtual void SAL_CALL clearWarnings() override
virtual void SAL_CALL updateShort(sal_Int32 columnIndex, sal_Int16 x) override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual void SAL_CALL updateBoolean(sal_Int32 columnIndex, sal_Bool x) override
virtual jclass getMyClass() const override
virtual float SAL_CALL getFloat(sal_Int32 columnIndex) override
virtual void SAL_CALL updateTime(sal_Int32 columnIndex, const css::util::Time &x) override
virtual void SAL_CALL release() noexcept override
virtual sal_Bool SAL_CALL isAfterLast() override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes(sal_Int32 columnIndex) override
virtual void SAL_CALL updateFloat(sal_Int32 columnIndex, float x) override
virtual css::uno::Any SAL_CALL getObject(sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess > &typeMap) override
virtual sal_Bool SAL_CALL isFirst() override
virtual ~java_sql_ResultSet() override
sal_Int32 getResultSetConcurrency() const
virtual sal_Bool SAL_CALL relative(sal_Int32 rows) override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual void SAL_CALL updateInt(sal_Int32 columnIndex, sal_Int32 x) override
virtual sal_Int32 SAL_CALL getInt(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL updateNull(sal_Int32 columnIndex) override
virtual void SAL_CALL disposing() override
virtual void SAL_CALL updateObject(sal_Int32 columnIndex, const css::uno::Any &x) override
virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef(sal_Int32 columnIndex) override
virtual void SAL_CALL acquire() noexcept override
virtual sal_Bool SAL_CALL rowDeleted() override
virtual void SAL_CALL deleteRow() override
virtual sal_Int64 SAL_CALL getLong(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL rowInserted() override
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL getBoolean(sal_Int32 columnIndex) override
void setFetchSize(sal_Int32 _par0)
virtual void SAL_CALL updateNumericObject(sal_Int32 columnIndex, const css::uno::Any &x, sal_Int32 scale) override
virtual sal_Int32 SAL_CALL getRow() override
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
void setFetchDirection(sal_Int32 _par0)
virtual sal_Int8 SAL_CALL getByte(sal_Int32 columnIndex) override
virtual void SAL_CALL refreshRow() override
virtual void SAL_CALL updateString(sal_Int32 columnIndex, const OUString &x) override
virtual sal_Bool SAL_CALL absolute(sal_Int32 row) override
virtual void SAL_CALL insertRow() override
virtual void SAL_CALL updateByte(sal_Int32 columnIndex, sal_Int8 x) override
virtual void SAL_CALL updateLong(sal_Int32 columnIndex, sal_Int64 x) override
virtual void SAL_CALL cancel() override
virtual void SAL_CALL updateCharacterStream(sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
virtual css::uno::Any SAL_CALL getWarnings() override
virtual void SAL_CALL updateBinaryStream(sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream(sal_Int32 columnIndex) override
css::uno::Reference< css::uno::XInterface > m_xStatement
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual css::util::Time SAL_CALL getTime(sal_Int32 columnIndex) override
virtual void SAL_CALL beforeFirst() override
virtual sal_Bool SAL_CALL isBeforeFirst() override
virtual void SAL_CALL cancelRowUpdates() override
virtual sal_Bool SAL_CALL previous() override
virtual sal_Bool SAL_CALL last() override
virtual void SAL_CALL updateBytes(sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 > &x) override
virtual OUString SAL_CALL getString(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData() override
virtual css::util::Date SAL_CALL getDate(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL rowUpdated() override
virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob(sal_Int32 columnIndex) override
virtual void SAL_CALL close() override
virtual void SAL_CALL updateDate(sal_Int32 columnIndex, const css::util::Date &x) override
virtual sal_Bool SAL_CALL first() override
virtual void SAL_CALL updateTimestamp(sal_Int32 columnIndex, const css::util::DateTime &x) override
virtual sal_Bool SAL_CALL next() override
virtual sal_Int16 SAL_CALL getShort(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual sal_Bool SAL_CALL wasNull() override
virtual void SAL_CALL afterLast() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL updateDouble(sal_Int32 columnIndex, double x) override
virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray(sal_Int32 columnIndex) override
virtual sal_Int32 SAL_CALL findColumn(const OUString &columnName) override
virtual void SAL_CALL updateRow() override
virtual css::util::DateTime SAL_CALL getTimestamp(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement() override
static jclass st_getMyClass()
Definition: Timestamp.cxx:92
helper class to hold a local ref to a JNI object
Definition: LocalRef.hxx:42
mutable::osl::Mutex m_aMutex
css::uno::Type const & get()
const OUString & getNameByIndex(sal_Int32 _nIndex) const
Definition: propertyids.cxx:95
ULONG m_refCount
float x
std::mutex m_aMutex
IMPLEMENT_SERVICE_INFO(java_sql_ResultSet,"com.sun.star.sdbcx.JResultSet","com.sun.star.sdbc.ResultSet")
void * p
Sequence< sal_Int8 > aSeq
std::unique_ptr< sal_Int32[]> pData
@ Exception
sal_Int32 getINT32(const Any &_rAny)
jobject convertTypeMapToJavaMap(const css::uno::Reference< css::container::XNameAccess > &_rMap)
jobject createCharArrayReader(const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length)
Definition: tools.cxx:233
::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, css::sdbc::XRow, css::sdbc::XResultSetMetaDataSupplier, css::util::XCancellable, css::sdbc::XWarningsSupplier, css::sdbc::XResultSetUpdate, css::sdbc::XRowUpdate, css::sdbc::XCloseable, css::sdbc::XColumnLocate, css::lang::XServiceInfo > java_sql_ResultSet_BASE
jstring convertwchar_tToJavaString(JNIEnv *pEnv, const OUString &Temp)
Definition: tools.cxx:93
jobject createByteInputStream(const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length)
Definition: tools.cxx:206
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.
bool implUpdateObject(const Reference< XRowUpdate > &_rxUpdatedObject, const sal_Int32 _nColumnIndex, const Any &_rValue)
Definition: dbtools.cxx:1427
args
void dispose()
sal_Int32 scale
Definition: pq_statics.cxx:62
const char * columnName
Definition: pq_statics.cxx:56
#define PROPERTY_ID_RESULTSETTYPE
Definition: propertyids.hxx:44
#define PROPERTY_ID_CURSORNAME
Definition: propertyids.hxx:42
#define PROPERTY_ID_RESULTSETCONCURRENCY
Definition: propertyids.hxx:43
#define PROPERTY_ID_FETCHSIZE
Definition: propertyids.hxx:46
#define PROPERTY_ID_FETCHDIRECTION
Definition: propertyids.hxx:45
sal_Int32 nHandle
unsigned char sal_Bool
signed char sal_Int8
const SvXMLTokenMapEntry aTypes[]