Line data Source code
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 : #ifndef _RESULTSETBASE_HXX
20 : #define _RESULTSETBASE_HXX
21 :
22 : #include <vector>
23 : #include <cppuhelper/weak.hxx>
24 : #include <cppuhelper/interfacecontainer.hxx>
25 : #include <com/sun/star/lang/XComponent.hpp>
26 : #include <com/sun/star/ucb/XContentAccess.hpp>
27 : #include <com/sun/star/sdbc/XCloseable.hpp>
28 : #include <com/sun/star/beans/XPropertySet.hpp>
29 : #include <com/sun/star/sdbc/XResultSet.hpp>
30 : #include <com/sun/star/sdbc/XRow.hpp>
31 : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
32 : #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
33 : #include <com/sun/star/ucb/XContentProvider.hpp>
34 : #include <com/sun/star/ucb/XContentIdentifier.hpp>
35 : #include <com/sun/star/uno/XComponentContext.hpp>
36 : #include <com/sun/star/beans/Property.hpp>
37 :
38 :
39 : namespace chelp {
40 :
41 : class ResultSetBase
42 : : public cppu::OWeakObject,
43 : public com::sun::star::lang::XComponent,
44 : public com::sun::star::sdbc::XRow,
45 : public com::sun::star::sdbc::XResultSet,
46 : public com::sun::star::sdbc::XCloseable,
47 : public com::sun::star::sdbc::XResultSetMetaDataSupplier,
48 : public com::sun::star::beans::XPropertySet,
49 : public com::sun::star::ucb::XContentAccess
50 : {
51 : public:
52 :
53 : ResultSetBase( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext,
54 : const com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider >& xProvider,
55 : sal_Int32 nOpenMode,
56 : const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& seq,
57 : const com::sun::star::uno::Sequence< com::sun::star::ucb::NumberedSortingInfo >& seqSort );
58 :
59 : virtual ~ResultSetBase();
60 :
61 : // XInterface
62 : virtual com::sun::star::uno::Any SAL_CALL
63 : queryInterface(
64 : const com::sun::star::uno::Type& aType )
65 : throw( com::sun::star::uno::RuntimeException);
66 :
67 : virtual void SAL_CALL
68 : acquire(
69 : void )
70 : throw();
71 :
72 : virtual void SAL_CALL
73 : release(
74 : void )
75 : throw();
76 :
77 : // XComponent
78 : virtual void SAL_CALL
79 : dispose(
80 : void )
81 : throw( com::sun::star::uno::RuntimeException );
82 :
83 : virtual void SAL_CALL
84 : addEventListener(
85 : const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& xListener )
86 : throw( com::sun::star::uno::RuntimeException );
87 :
88 : virtual void SAL_CALL
89 : removeEventListener( const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& aListener )
90 : throw( com::sun::star::uno::RuntimeException );
91 :
92 :
93 : // XRow
94 : virtual sal_Bool SAL_CALL
95 0 : wasNull(
96 : void )
97 : throw( com::sun::star::sdbc::SQLException,
98 : com::sun::star::uno::RuntimeException )
99 : {
100 0 : if( 0<= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
101 0 : m_nWasNull = m_aItems[m_nRow]->wasNull();
102 : else
103 0 : m_nWasNull = true;
104 0 : return m_nWasNull;
105 : }
106 :
107 : virtual OUString SAL_CALL
108 0 : getString(
109 : sal_Int32 columnIndex )
110 : throw( com::sun::star::sdbc::SQLException,
111 : com::sun::star::uno::RuntimeException)
112 : {
113 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
114 0 : return m_aItems[m_nRow]->getString( columnIndex );
115 : else
116 0 : return OUString();
117 : }
118 :
119 : virtual sal_Bool SAL_CALL
120 0 : getBoolean(
121 : sal_Int32 columnIndex )
122 : throw( com::sun::star::sdbc::SQLException,
123 : com::sun::star::uno::RuntimeException)
124 : {
125 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
126 0 : return m_aItems[m_nRow]->getBoolean( columnIndex );
127 : else
128 0 : return false;
129 : }
130 :
131 : virtual sal_Int8 SAL_CALL
132 0 : getByte(
133 : sal_Int32 columnIndex )
134 : throw( com::sun::star::sdbc::SQLException,
135 : com::sun::star::uno::RuntimeException)
136 : {
137 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
138 0 : return m_aItems[m_nRow]->getByte( columnIndex );
139 : else
140 0 : return sal_Int8( 0 );
141 : }
142 :
143 : virtual sal_Int16 SAL_CALL
144 0 : getShort(
145 : sal_Int32 columnIndex )
146 : throw(
147 : com::sun::star::sdbc::SQLException,
148 : com::sun::star::uno::RuntimeException)
149 : {
150 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
151 0 : return m_aItems[m_nRow]->getShort( columnIndex );
152 : else
153 0 : return sal_Int16( 0 );
154 : }
155 :
156 : virtual sal_Int32 SAL_CALL
157 0 : getInt(
158 : sal_Int32 columnIndex )
159 : throw( com::sun::star::sdbc::SQLException,
160 : com::sun::star::uno::RuntimeException )
161 : {
162 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
163 0 : return m_aItems[m_nRow]->getInt( columnIndex );
164 : else
165 0 : return sal_Int32( 0 );
166 : }
167 :
168 : virtual sal_Int64 SAL_CALL
169 0 : getLong(
170 : sal_Int32 columnIndex )
171 : throw( com::sun::star::sdbc::SQLException,
172 : com::sun::star::uno::RuntimeException)
173 : {
174 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
175 0 : return m_aItems[m_nRow]->getLong( columnIndex );
176 : else
177 0 : return sal_Int64( 0 );
178 : }
179 :
180 : virtual float SAL_CALL
181 0 : getFloat(
182 : sal_Int32 columnIndex )
183 : throw( com::sun::star::sdbc::SQLException,
184 : com::sun::star::uno::RuntimeException )
185 : {
186 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
187 0 : return m_aItems[m_nRow]->getFloat( columnIndex );
188 : else
189 0 : return float( 0 );
190 : }
191 :
192 : virtual double SAL_CALL
193 0 : getDouble(
194 : sal_Int32 columnIndex )
195 : throw( com::sun::star::sdbc::SQLException,
196 : com::sun::star::uno::RuntimeException )
197 : {
198 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
199 0 : return m_aItems[m_nRow]->getDouble( columnIndex );
200 : else
201 0 : return double( 0 );
202 : }
203 :
204 : virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL
205 0 : getBytes(
206 : sal_Int32 columnIndex )
207 : throw( com::sun::star::sdbc::SQLException,
208 : com::sun::star::uno::RuntimeException )
209 : {
210 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
211 0 : return m_aItems[m_nRow]->getBytes( columnIndex );
212 : else
213 0 : return com::sun::star::uno::Sequence< sal_Int8 >();
214 : }
215 :
216 : virtual com::sun::star::util::Date SAL_CALL
217 0 : getDate(
218 : sal_Int32 columnIndex )
219 : throw( com::sun::star::sdbc::SQLException,
220 : com::sun::star::uno::RuntimeException)
221 : {
222 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
223 0 : return m_aItems[m_nRow]->getDate( columnIndex );
224 : else
225 0 : return com::sun::star::util::Date();
226 : }
227 :
228 : virtual com::sun::star::util::Time SAL_CALL
229 0 : getTime(
230 : sal_Int32 columnIndex )
231 : throw( com::sun::star::sdbc::SQLException,
232 : com::sun::star::uno::RuntimeException)
233 : {
234 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
235 0 : return m_aItems[m_nRow]->getTime( columnIndex );
236 : else
237 0 : return com::sun::star::util::Time();
238 : }
239 :
240 : virtual com::sun::star::util::DateTime SAL_CALL
241 0 : getTimestamp(
242 : sal_Int32 columnIndex )
243 : throw( com::sun::star::sdbc::SQLException,
244 : com::sun::star::uno::RuntimeException)
245 : {
246 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
247 0 : return m_aItems[m_nRow]->getTimestamp( columnIndex );
248 : else
249 0 : return com::sun::star::util::DateTime();
250 : }
251 :
252 : virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL
253 0 : getBinaryStream(
254 : sal_Int32 columnIndex )
255 : throw( com::sun::star::sdbc::SQLException,
256 : com::sun::star::uno::RuntimeException)
257 : {
258 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
259 0 : return m_aItems[m_nRow]->getBinaryStream( columnIndex );
260 : else
261 0 : return com::sun::star::uno::Reference< com::sun::star::io::XInputStream >();
262 : }
263 :
264 : virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL
265 0 : getCharacterStream(
266 : sal_Int32 columnIndex )
267 : throw( com::sun::star::sdbc::SQLException,
268 : com::sun::star::uno::RuntimeException)
269 : {
270 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
271 0 : return m_aItems[m_nRow]->getCharacterStream( columnIndex );
272 : else
273 0 : return com::sun::star::uno::Reference< com::sun::star::io::XInputStream >();
274 : }
275 :
276 : virtual com::sun::star::uno::Any SAL_CALL
277 0 : getObject(
278 : sal_Int32 columnIndex,
279 : const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& typeMap )
280 : throw( com::sun::star::sdbc::SQLException,
281 : com::sun::star::uno::RuntimeException)
282 : {
283 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
284 0 : return m_aItems[m_nRow]->getObject( columnIndex,typeMap );
285 : else
286 0 : return com::sun::star::uno::Any();
287 : }
288 :
289 : virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XRef > SAL_CALL
290 0 : getRef(
291 : sal_Int32 columnIndex )
292 : throw( com::sun::star::sdbc::SQLException,
293 : com::sun::star::uno::RuntimeException)
294 : {
295 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
296 0 : return m_aItems[m_nRow]->getRef( columnIndex );
297 : else
298 0 : return com::sun::star::uno::Reference< com::sun::star::sdbc::XRef >();
299 : }
300 :
301 : virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XBlob > SAL_CALL
302 0 : getBlob(
303 : sal_Int32 columnIndex )
304 : throw( com::sun::star::sdbc::SQLException,
305 : com::sun::star::uno::RuntimeException)
306 : {
307 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
308 0 : return m_aItems[m_nRow]->getBlob( columnIndex );
309 : else
310 0 : return com::sun::star::uno::Reference< com::sun::star::sdbc::XBlob >();
311 : }
312 :
313 : virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XClob > SAL_CALL
314 0 : getClob(
315 : sal_Int32 columnIndex )
316 : throw( com::sun::star::sdbc::SQLException,
317 : com::sun::star::uno::RuntimeException)
318 : {
319 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
320 0 : return m_aItems[m_nRow]->getClob( columnIndex );
321 : else
322 0 : return com::sun::star::uno::Reference< com::sun::star::sdbc::XClob >();
323 : }
324 :
325 : virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XArray > SAL_CALL
326 0 : getArray(
327 : sal_Int32 columnIndex )
328 : throw( com::sun::star::sdbc::SQLException,
329 : com::sun::star::uno::RuntimeException)
330 : {
331 0 : if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
332 0 : return m_aItems[m_nRow]->getArray( columnIndex );
333 : else
334 0 : return com::sun::star::uno::Reference< com::sun::star::sdbc::XArray >();
335 : }
336 :
337 :
338 : // XResultSet
339 :
340 : virtual sal_Bool SAL_CALL
341 : next(
342 : void )
343 : throw( com::sun::star::sdbc::SQLException,
344 : com::sun::star::uno::RuntimeException);
345 :
346 : virtual sal_Bool SAL_CALL
347 : isBeforeFirst(
348 : void )
349 : throw( com::sun::star::sdbc::SQLException,
350 : com::sun::star::uno::RuntimeException);
351 :
352 : virtual sal_Bool SAL_CALL
353 : isAfterLast(
354 : void )
355 : throw( com::sun::star::sdbc::SQLException,
356 : com::sun::star::uno::RuntimeException);
357 :
358 : virtual sal_Bool SAL_CALL
359 : isFirst(
360 : void )
361 : throw( com::sun::star::sdbc::SQLException,
362 : com::sun::star::uno::RuntimeException);
363 :
364 : virtual sal_Bool SAL_CALL
365 : isLast(
366 : void )
367 : throw( com::sun::star::sdbc::SQLException,
368 : com::sun::star::uno::RuntimeException);
369 :
370 : virtual void SAL_CALL
371 : beforeFirst(
372 : void )
373 : throw( com::sun::star::sdbc::SQLException,
374 : com::sun::star::uno::RuntimeException);
375 :
376 : virtual void SAL_CALL
377 : afterLast(
378 : void )
379 : throw( com::sun::star::sdbc::SQLException,
380 : com::sun::star::uno::RuntimeException);
381 :
382 : virtual sal_Bool SAL_CALL
383 : first(
384 : void )
385 : throw( com::sun::star::sdbc::SQLException,
386 : com::sun::star::uno::RuntimeException);
387 :
388 : virtual sal_Bool SAL_CALL
389 : last(
390 : void )
391 : throw( com::sun::star::sdbc::SQLException,
392 : com::sun::star::uno::RuntimeException);
393 :
394 : virtual sal_Int32 SAL_CALL
395 : getRow(
396 : void )
397 : throw( com::sun::star::sdbc::SQLException,
398 : com::sun::star::uno::RuntimeException);
399 :
400 : virtual sal_Bool SAL_CALL
401 : absolute(
402 : sal_Int32 row )
403 : throw( com::sun::star::sdbc::SQLException,
404 : com::sun::star::uno::RuntimeException);
405 :
406 : virtual sal_Bool SAL_CALL
407 : relative(
408 : sal_Int32 rows )
409 : throw( com::sun::star::sdbc::SQLException,
410 : com::sun::star::uno::RuntimeException);
411 :
412 : virtual sal_Bool SAL_CALL
413 : previous(
414 : void )
415 : throw( com::sun::star::sdbc::SQLException,
416 : com::sun::star::uno::RuntimeException);
417 :
418 : virtual void SAL_CALL
419 : refreshRow(
420 : void )
421 : throw( com::sun::star::sdbc::SQLException,
422 : com::sun::star::uno::RuntimeException);
423 :
424 : virtual sal_Bool SAL_CALL
425 : rowUpdated(
426 : void )
427 : throw( com::sun::star::sdbc::SQLException,
428 : com::sun::star::uno::RuntimeException);
429 :
430 : virtual sal_Bool SAL_CALL
431 : rowInserted(
432 : void )
433 : throw( com::sun::star::sdbc::SQLException,
434 : com::sun::star::uno::RuntimeException);
435 :
436 : virtual sal_Bool SAL_CALL
437 : rowDeleted(
438 : void )
439 : throw( com::sun::star::sdbc::SQLException,
440 : com::sun::star::uno::RuntimeException);
441 :
442 :
443 : virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL
444 : getStatement(
445 : void )
446 : throw( com::sun::star::sdbc::SQLException,
447 : com::sun::star::uno::RuntimeException);
448 :
449 : // XCloseable
450 :
451 : virtual void SAL_CALL
452 : close(
453 : void )
454 : throw( com::sun::star::sdbc::SQLException,
455 : com::sun::star::uno::RuntimeException);
456 :
457 : // XContentAccess
458 :
459 : virtual OUString SAL_CALL
460 : queryContentIdentifierString(
461 : void )
462 : throw( com::sun::star::uno::RuntimeException );
463 :
464 : virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > SAL_CALL
465 : queryContentIdentifier(
466 : void )
467 : throw( com::sun::star::uno::RuntimeException );
468 :
469 : virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > SAL_CALL
470 : queryContent(
471 : void )
472 : throw( com::sun::star::uno::RuntimeException );
473 :
474 : // XResultSetMetaDataSupplier
475 : virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSetMetaData > SAL_CALL
476 : getMetaData(
477 : void )
478 : throw( com::sun::star::sdbc::SQLException,
479 : com::sun::star::uno::RuntimeException);
480 :
481 :
482 : // XPropertySet
483 : virtual com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL
484 : getPropertySetInfo()
485 : throw( com::sun::star::uno::RuntimeException);
486 :
487 : virtual void SAL_CALL setPropertyValue(
488 : const OUString& aPropertyName,
489 : const com::sun::star::uno::Any& aValue )
490 : throw( com::sun::star::beans::UnknownPropertyException,
491 : com::sun::star::beans::PropertyVetoException,
492 : com::sun::star::lang::IllegalArgumentException,
493 : com::sun::star::lang::WrappedTargetException,
494 : com::sun::star::uno::RuntimeException);
495 :
496 : virtual com::sun::star::uno::Any SAL_CALL
497 : getPropertyValue(
498 : const OUString& PropertyName )
499 : throw( com::sun::star::beans::UnknownPropertyException,
500 : com::sun::star::lang::WrappedTargetException,
501 : com::sun::star::uno::RuntimeException);
502 :
503 : virtual void SAL_CALL
504 : addPropertyChangeListener(
505 : const OUString& aPropertyName,
506 : const com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener >& xListener )
507 : throw( com::sun::star::beans::UnknownPropertyException,
508 : com::sun::star::lang::WrappedTargetException,
509 : com::sun::star::uno::RuntimeException);
510 :
511 : virtual void SAL_CALL
512 : removePropertyChangeListener(
513 : const OUString& aPropertyName,
514 : const com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener >& aListener )
515 : throw( com::sun::star::beans::UnknownPropertyException,
516 : com::sun::star::lang::WrappedTargetException,
517 : com::sun::star::uno::RuntimeException);
518 :
519 : virtual void SAL_CALL
520 : addVetoableChangeListener(
521 : const OUString& PropertyName,
522 : const com::sun::star::uno::Reference< com::sun::star::beans::XVetoableChangeListener >& aListener )
523 : throw( com::sun::star::beans::UnknownPropertyException,
524 : com::sun::star::lang::WrappedTargetException,
525 : com::sun::star::uno::RuntimeException);
526 :
527 : virtual void SAL_CALL removeVetoableChangeListener(
528 : const OUString& PropertyName,
529 : const com::sun::star::uno::Reference< com::sun::star::beans::XVetoableChangeListener >& aListener )
530 : throw( com::sun::star::beans::UnknownPropertyException,
531 : com::sun::star::lang::WrappedTargetException,
532 : com::sun::star::uno::RuntimeException);
533 :
534 : protected:
535 :
536 : com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
537 : com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider > m_xProvider;
538 : sal_Int32 m_nRow;
539 : bool m_nWasNull;
540 : sal_Int32 m_nOpenMode;
541 : bool m_bRowCountFinal;
542 :
543 : typedef std::vector< com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > > IdentSet;
544 : typedef std::vector< com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > > ItemSet;
545 : typedef std::vector< OUString > PathSet;
546 :
547 : IdentSet m_aIdents;
548 : ItemSet m_aItems;
549 : PathSet m_aPath;
550 :
551 : com::sun::star::uno::Sequence< com::sun::star::beans::Property > m_sProperty;
552 : com::sun::star::uno::Sequence< com::sun::star::ucb::NumberedSortingInfo > m_sSortingInfo;
553 :
554 : osl::Mutex m_aMutex;
555 : cppu::OInterfaceContainerHelper* m_pDisposeEventListeners;
556 :
557 : cppu::OInterfaceContainerHelper* m_pRowCountListeners;
558 : cppu::OInterfaceContainerHelper* m_pIsFinalListeners;
559 : };
560 :
561 :
562 : } // end namespace fileaccess
563 :
564 :
565 : #endif
566 :
567 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|