update dev300-m58
[ooovba.git] / xmlhelp / source / cxxhelp / provider / resultsetbase.cxx
blob9923e1f2e25bb8a84faddecd03abb1271c1586ec
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: resultsetbase.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlhelp.hxx"
33 #include <ucbhelper/contentidentifier.hxx>
34 #include <com/sun/star/ucb/OpenMode.hpp>
35 #include <com/sun/star/uno/Reference.h>
36 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #endif
39 #include <com/sun/star/ucb/ListActionType.hpp>
40 #include <com/sun/star/ucb/XSourceInitialization.hpp>
41 #include <ucbhelper/resultsetmetadata.hxx>
43 #include "resultsetbase.hxx"
45 using namespace chelp;
46 using namespace com::sun::star;
48 ResultSetBase::ResultSetBase( const uno::Reference< lang::XMultiServiceFactory >& xMSF,
49 const uno::Reference< ucb::XContentProvider >& xProvider,
50 sal_Int32 nOpenMode,
51 const uno::Sequence< beans::Property >& seq,
52 const uno::Sequence< ucb::NumberedSortingInfo >& seqSort )
53 : m_xMSF( xMSF ),
54 m_xProvider( xProvider ),
55 m_nRow( -1 ),
56 m_nWasNull( true ),
57 m_nOpenMode( nOpenMode ),
58 m_bRowCountFinal( true ),
59 m_sProperty( seq ),
60 m_sSortingInfo( seqSort ),
61 m_pDisposeEventListeners( 0 ),
62 m_pRowCountListeners( 0 ),
63 m_pIsFinalListeners( 0 )
67 ResultSetBase::~ResultSetBase()
69 delete m_pIsFinalListeners;
70 delete m_pRowCountListeners;
71 delete m_pDisposeEventListeners;
75 // XInterface
77 void SAL_CALL
78 ResultSetBase::acquire(
79 void )
80 throw()
82 OWeakObject::acquire();
86 void SAL_CALL
87 ResultSetBase::release(
88 void )
89 throw()
91 OWeakObject::release();
96 uno::Any SAL_CALL
97 ResultSetBase::queryInterface(
98 const uno::Type& rType )
99 throw( uno::RuntimeException )
101 uno::Any aRet = cppu::queryInterface( rType,
102 SAL_STATIC_CAST( lang::XComponent*, this),
103 SAL_STATIC_CAST( sdbc::XRow*, this),
104 SAL_STATIC_CAST( sdbc::XResultSet*, this),
105 SAL_STATIC_CAST( sdbc::XResultSetMetaDataSupplier*, this),
106 SAL_STATIC_CAST( beans::XPropertySet*, this ),
107 SAL_STATIC_CAST( ucb::XContentAccess*, this) );
108 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
113 // XComponent
116 void SAL_CALL
117 ResultSetBase::addEventListener(
118 const uno::Reference< lang::XEventListener >& Listener )
119 throw( uno::RuntimeException )
121 osl::MutexGuard aGuard( m_aMutex );
123 if ( ! m_pDisposeEventListeners )
124 m_pDisposeEventListeners =
125 new cppu::OInterfaceContainerHelper( m_aMutex );
127 m_pDisposeEventListeners->addInterface( Listener );
131 void SAL_CALL
132 ResultSetBase::removeEventListener(
133 const uno::Reference< lang::XEventListener >& Listener )
134 throw( uno::RuntimeException )
136 osl::MutexGuard aGuard( m_aMutex );
138 if ( m_pDisposeEventListeners )
139 m_pDisposeEventListeners->removeInterface( Listener );
144 void SAL_CALL
145 ResultSetBase::dispose()
146 throw( uno::RuntimeException )
148 osl::MutexGuard aGuard( m_aMutex );
150 lang::EventObject aEvt;
151 aEvt.Source = static_cast< lang::XComponent * >( this );
153 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
155 m_pDisposeEventListeners->disposeAndClear( aEvt );
157 if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
159 m_pRowCountListeners->disposeAndClear( aEvt );
161 if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
163 m_pIsFinalListeners->disposeAndClear( aEvt );
169 // XResultSet
171 sal_Bool SAL_CALL
172 ResultSetBase::next(
173 void )
174 throw( sdbc::SQLException,
175 uno::RuntimeException )
177 sal_Bool test;
178 m_nRow++;
179 if( sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
180 test = true;
181 else
182 test = false;
183 return test;
187 sal_Bool SAL_CALL
188 ResultSetBase::isBeforeFirst(
189 void )
190 throw( sdbc::SQLException,
191 uno::RuntimeException )
193 return m_nRow == -1;
197 sal_Bool SAL_CALL
198 ResultSetBase::isAfterLast(
199 void )
200 throw( sdbc::SQLException,
201 uno::RuntimeException )
203 return sal::static_int_cast<sal_uInt32>( m_nRow ) >= m_aItems.size(); // Cannot happen, if m_aFolder.isOpen()
207 sal_Bool SAL_CALL
208 ResultSetBase::isFirst(
209 void )
210 throw( sdbc::SQLException,
211 uno::RuntimeException )
213 return m_nRow == 0;
217 sal_Bool SAL_CALL
218 ResultSetBase::isLast(
219 void )
220 throw( sdbc::SQLException,
221 uno::RuntimeException)
223 if( sal::static_int_cast<sal_uInt32>( m_nRow ) == m_aItems.size() - 1 )
224 return true;
225 else
226 return false;
230 void SAL_CALL
231 ResultSetBase::beforeFirst(
232 void )
233 throw( sdbc::SQLException,
234 uno::RuntimeException)
236 m_nRow = -1;
240 void SAL_CALL
241 ResultSetBase::afterLast(
242 void )
243 throw( sdbc::SQLException,
244 uno::RuntimeException )
246 m_nRow = m_aItems.size();
250 sal_Bool SAL_CALL
251 ResultSetBase::first(
252 void )
253 throw( sdbc::SQLException,
254 uno::RuntimeException)
256 m_nRow = -1;
257 return next();
261 sal_Bool SAL_CALL
262 ResultSetBase::last(
263 void )
264 throw( sdbc::SQLException,
265 uno::RuntimeException )
267 m_nRow = m_aItems.size() - 1;
268 return true;
272 sal_Int32 SAL_CALL
273 ResultSetBase::getRow(
274 void )
275 throw( sdbc::SQLException,
276 uno::RuntimeException)
278 // Test, whether behind last row
279 if( -1 == m_nRow || sal::static_int_cast<sal_uInt32>( m_nRow ) >= m_aItems.size() )
280 return 0;
281 else
282 return m_nRow+1;
286 sal_Bool SAL_CALL ResultSetBase::absolute( sal_Int32 row )
287 throw( sdbc::SQLException, uno::RuntimeException)
289 if( row >= 0 )
290 m_nRow = row - 1;
291 else
293 last();
294 m_nRow += ( row + 1 );
295 if( m_nRow < -1 )
296 m_nRow = -1;
299 return 0<= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size();
305 sal_Bool SAL_CALL
306 ResultSetBase::relative(
307 sal_Int32 row )
308 throw( sdbc::SQLException,
309 uno::RuntimeException)
311 if( isAfterLast() || isBeforeFirst() )
312 throw sdbc::SQLException();
314 if( row > 0 )
315 while( row-- )
316 next();
317 else if( row < 0 )
318 while( row++ && m_nRow > -1 )
319 previous();
321 return 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size();
326 sal_Bool SAL_CALL
327 ResultSetBase::previous(
328 void )
329 throw( sdbc::SQLException,
330 uno::RuntimeException)
332 if( sal::static_int_cast<sal_uInt32>( m_nRow ) > m_aItems.size() )
333 m_nRow = m_aItems.size(); // Correct Handling of afterLast
334 if( 0 <= m_nRow ) -- m_nRow;
336 return 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size();
340 void SAL_CALL
341 ResultSetBase::refreshRow(
342 void )
343 throw( sdbc::SQLException,
344 uno::RuntimeException)
349 sal_Bool SAL_CALL
350 ResultSetBase::rowUpdated(
351 void )
352 throw( sdbc::SQLException,
353 uno::RuntimeException )
355 return false;
358 sal_Bool SAL_CALL
359 ResultSetBase::rowInserted(
360 void )
361 throw( sdbc::SQLException,
362 uno::RuntimeException )
364 return false;
367 sal_Bool SAL_CALL
368 ResultSetBase::rowDeleted(
369 void )
370 throw( sdbc::SQLException,
371 uno::RuntimeException )
373 return false;
377 uno::Reference< uno::XInterface > SAL_CALL
378 ResultSetBase::getStatement(
379 void )
380 throw( sdbc::SQLException,
381 uno::RuntimeException )
383 uno::Reference< uno::XInterface > test( 0 );
384 return test;
388 // XCloseable
390 void SAL_CALL
391 ResultSetBase::close(
392 void )
393 throw( sdbc::SQLException,
394 uno::RuntimeException)
399 rtl::OUString SAL_CALL
400 ResultSetBase::queryContentIdentifierString(
401 void )
402 throw( uno::RuntimeException )
404 if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
405 return m_aPath[m_nRow];
406 else
407 return rtl::OUString();
411 uno::Reference< ucb::XContentIdentifier > SAL_CALL
412 ResultSetBase::queryContentIdentifier(
413 void )
414 throw( uno::RuntimeException )
416 if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
418 rtl::OUString url = queryContentIdentifierString();
419 if( ! m_aIdents[m_nRow].is() && url.getLength() )
420 m_aIdents[m_nRow] = uno::Reference< ucb::XContentIdentifier >(
421 new ::ucbhelper::ContentIdentifier( m_xMSF,url ) );
422 return m_aIdents[m_nRow];
425 return uno::Reference< ucb::XContentIdentifier >();
429 uno::Reference< ucb::XContent > SAL_CALL
430 ResultSetBase::queryContent(
431 void )
432 throw( uno::RuntimeException )
434 if( 0 <= m_nRow && sal::static_int_cast<sal_uInt32>( m_nRow ) < m_aItems.size() )
435 return m_xProvider->queryContent( queryContentIdentifier() );
436 else
437 return uno::Reference< ucb::XContent >();
442 class XPropertySetInfoImpl
443 : public cppu::OWeakObject,
444 public beans::XPropertySetInfo
446 public:
448 XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
449 : m_aSeq( aSeq )
453 void SAL_CALL acquire( void )
454 throw()
456 OWeakObject::acquire();
460 void SAL_CALL release( void )
461 throw()
463 OWeakObject::release();
466 uno::Any SAL_CALL queryInterface( const uno::Type& rType )
467 throw( uno::RuntimeException )
469 uno::Any aRet = cppu::queryInterface( rType,
470 SAL_STATIC_CAST( beans::XPropertySetInfo*, this ) );
471 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
474 uno::Sequence< beans::Property > SAL_CALL getProperties()
475 throw( uno::RuntimeException )
477 return m_aSeq;
480 beans::Property SAL_CALL getPropertyByName( const ::rtl::OUString& aName )
481 throw( beans::UnknownPropertyException,
482 uno::RuntimeException)
484 for( int i = 0; i < m_aSeq.getLength(); ++i )
485 if( aName == m_aSeq[i].Name )
486 return m_aSeq[i];
487 throw beans::UnknownPropertyException();
490 sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name )
491 throw( uno::RuntimeException )
493 for( int i = 0; i < m_aSeq.getLength(); ++i )
494 if( Name == m_aSeq[i].Name )
495 return true;
496 return false;
499 private:
501 uno::Sequence< beans::Property > m_aSeq;
506 // XPropertySet
507 uno::Reference< beans::XPropertySetInfo > SAL_CALL
508 ResultSetBase::getPropertySetInfo()
509 throw( uno::RuntimeException)
511 uno::Sequence< beans::Property > seq(2);
512 seq[0].Name = rtl::OUString::createFromAscii( "RowCount" );
513 seq[0].Handle = -1;
514 seq[0].Type = getCppuType( static_cast< sal_Int32* >(0) );
515 seq[0].Attributes = beans::PropertyAttribute::READONLY;
517 seq[1].Name = rtl::OUString::createFromAscii( "IsRowCountFinal" );
518 seq[1].Handle = -1;
519 seq[1].Type = getCppuType( static_cast< sal_Bool* >(0) );
520 seq[1].Attributes = beans::PropertyAttribute::READONLY;
523 return uno::Reference< beans::XPropertySetInfo > ( new XPropertySetInfoImpl( seq ) );
528 void SAL_CALL ResultSetBase::setPropertyValue(
529 const rtl::OUString& aPropertyName, const uno::Any& aValue )
530 throw( beans::UnknownPropertyException,
531 beans::PropertyVetoException,
532 lang::IllegalArgumentException,
533 lang::WrappedTargetException,
534 uno::RuntimeException)
536 (void)aValue;
538 if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) ||
539 aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) )
540 return;
542 throw beans::UnknownPropertyException();
546 uno::Any SAL_CALL ResultSetBase::getPropertyValue(
547 const rtl::OUString& PropertyName )
548 throw( beans::UnknownPropertyException,
549 lang::WrappedTargetException,
550 uno::RuntimeException)
552 if( PropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) )
554 uno::Any aAny;
555 aAny <<= m_bRowCountFinal;
556 return aAny;
558 else if ( PropertyName == rtl::OUString::createFromAscii( "RowCount" ) )
560 uno::Any aAny;
561 sal_Int32 count = m_aItems.size();
562 aAny <<= count;
563 return aAny;
565 else
566 throw beans::UnknownPropertyException();
570 void SAL_CALL ResultSetBase::addPropertyChangeListener(
571 const rtl::OUString& aPropertyName,
572 const uno::Reference< beans::XPropertyChangeListener >& xListener )
573 throw( beans::UnknownPropertyException,
574 lang::WrappedTargetException,
575 uno::RuntimeException)
577 if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) )
579 osl::MutexGuard aGuard( m_aMutex );
580 if ( ! m_pIsFinalListeners )
581 m_pIsFinalListeners =
582 new cppu::OInterfaceContainerHelper( m_aMutex );
584 m_pIsFinalListeners->addInterface( xListener );
586 else if ( aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) )
588 osl::MutexGuard aGuard( m_aMutex );
589 if ( ! m_pRowCountListeners )
590 m_pRowCountListeners =
591 new cppu::OInterfaceContainerHelper( m_aMutex );
592 m_pRowCountListeners->addInterface( xListener );
594 else
595 throw beans::UnknownPropertyException();
599 void SAL_CALL ResultSetBase::removePropertyChangeListener(
600 const rtl::OUString& aPropertyName,
601 const uno::Reference< beans::XPropertyChangeListener >& aListener )
602 throw( beans::UnknownPropertyException,
603 lang::WrappedTargetException,
604 uno::RuntimeException)
606 if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) &&
607 m_pIsFinalListeners )
609 osl::MutexGuard aGuard( m_aMutex );
610 m_pIsFinalListeners->removeInterface( aListener );
612 else if ( aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) &&
613 m_pRowCountListeners )
615 osl::MutexGuard aGuard( m_aMutex );
616 m_pRowCountListeners->removeInterface( aListener );
618 else
619 throw beans::UnknownPropertyException();
623 void SAL_CALL ResultSetBase::addVetoableChangeListener(
624 const rtl::OUString& PropertyName,
625 const uno::Reference< beans::XVetoableChangeListener >& aListener )
626 throw( beans::UnknownPropertyException,
627 lang::WrappedTargetException,
628 uno::RuntimeException)
630 (void)PropertyName;
631 (void)aListener;
635 void SAL_CALL ResultSetBase::removeVetoableChangeListener(
636 const rtl::OUString& PropertyName,
637 const uno::Reference< beans::XVetoableChangeListener >& aListener )
638 throw( beans::UnknownPropertyException,
639 lang::WrappedTargetException,
640 uno::RuntimeException)
642 (void)PropertyName;
643 (void)aListener;
648 // XResultSetMetaDataSupplier
649 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
650 ResultSetBase::getMetaData(
651 void )
652 throw( sdbc::SQLException,
653 uno::RuntimeException )
655 ::ucbhelper::ResultSetMetaData* p =
656 new ::ucbhelper::ResultSetMetaData(
657 m_xMSF, m_sProperty );
658 return uno::Reference< sdbc::XResultSetMetaData >( p );