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