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