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