1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: resultsetbase.cxx,v $
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>
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
,
51 const uno::Sequence
< beans::Property
>& seq
,
52 const uno::Sequence
< ucb::NumberedSortingInfo
>& seqSort
)
54 m_xProvider( xProvider
),
57 m_nOpenMode( nOpenMode
),
58 m_bRowCountFinal( true ),
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
;
78 ResultSetBase::acquire(
82 OWeakObject::acquire();
87 ResultSetBase::release(
91 OWeakObject::release();
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
);
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
);
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
);
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
);
174 throw( sdbc::SQLException
,
175 uno::RuntimeException
)
179 if( sal::static_int_cast
<sal_uInt32
>( m_nRow
) < m_aItems
.size() )
188 ResultSetBase::isBeforeFirst(
190 throw( sdbc::SQLException
,
191 uno::RuntimeException
)
198 ResultSetBase::isAfterLast(
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()
208 ResultSetBase::isFirst(
210 throw( sdbc::SQLException
,
211 uno::RuntimeException
)
218 ResultSetBase::isLast(
220 throw( sdbc::SQLException
,
221 uno::RuntimeException
)
223 if( sal::static_int_cast
<sal_uInt32
>( m_nRow
) == m_aItems
.size() - 1 )
231 ResultSetBase::beforeFirst(
233 throw( sdbc::SQLException
,
234 uno::RuntimeException
)
241 ResultSetBase::afterLast(
243 throw( sdbc::SQLException
,
244 uno::RuntimeException
)
246 m_nRow
= m_aItems
.size();
251 ResultSetBase::first(
253 throw( sdbc::SQLException
,
254 uno::RuntimeException
)
264 throw( sdbc::SQLException
,
265 uno::RuntimeException
)
267 m_nRow
= m_aItems
.size() - 1;
273 ResultSetBase::getRow(
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() )
286 sal_Bool SAL_CALL
ResultSetBase::absolute( sal_Int32 row
)
287 throw( sdbc::SQLException
, uno::RuntimeException
)
294 m_nRow
+= ( row
+ 1 );
299 return 0<= m_nRow
&& sal::static_int_cast
<sal_uInt32
>( m_nRow
) < m_aItems
.size();
306 ResultSetBase::relative(
308 throw( sdbc::SQLException
,
309 uno::RuntimeException
)
311 if( isAfterLast() || isBeforeFirst() )
312 throw sdbc::SQLException();
318 while( row
++ && m_nRow
> -1 )
321 return 0 <= m_nRow
&& sal::static_int_cast
<sal_uInt32
>( m_nRow
) < m_aItems
.size();
327 ResultSetBase::previous(
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();
341 ResultSetBase::refreshRow(
343 throw( sdbc::SQLException
,
344 uno::RuntimeException
)
350 ResultSetBase::rowUpdated(
352 throw( sdbc::SQLException
,
353 uno::RuntimeException
)
359 ResultSetBase::rowInserted(
361 throw( sdbc::SQLException
,
362 uno::RuntimeException
)
368 ResultSetBase::rowDeleted(
370 throw( sdbc::SQLException
,
371 uno::RuntimeException
)
377 uno::Reference
< uno::XInterface
> SAL_CALL
378 ResultSetBase::getStatement(
380 throw( sdbc::SQLException
,
381 uno::RuntimeException
)
383 uno::Reference
< uno::XInterface
> test( 0 );
391 ResultSetBase::close(
393 throw( sdbc::SQLException
,
394 uno::RuntimeException
)
399 rtl::OUString SAL_CALL
400 ResultSetBase::queryContentIdentifierString(
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
];
407 return rtl::OUString();
411 uno::Reference
< ucb::XContentIdentifier
> SAL_CALL
412 ResultSetBase::queryContentIdentifier(
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(
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() );
437 return uno::Reference
< ucb::XContent
>();
442 class XPropertySetInfoImpl
443 : public cppu::OWeakObject
,
444 public beans::XPropertySetInfo
448 XPropertySetInfoImpl( const uno::Sequence
< beans::Property
>& aSeq
)
453 void SAL_CALL
acquire( void )
456 OWeakObject::acquire();
460 void SAL_CALL
release( void )
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
)
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
)
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
)
501 uno::Sequence
< beans::Property
> m_aSeq
;
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" );
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" );
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
)
538 if( aPropertyName
== rtl::OUString::createFromAscii( "IsRowCountFinal" ) ||
539 aPropertyName
== rtl::OUString::createFromAscii( "RowCount" ) )
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" ) )
555 aAny
<<= m_bRowCountFinal
;
558 else if ( PropertyName
== rtl::OUString::createFromAscii( "RowCount" ) )
561 sal_Int32 count
= m_aItems
.size();
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
);
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
);
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
)
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
)
648 // XResultSetMetaDataSupplier
649 uno::Reference
< sdbc::XResultSetMetaData
> SAL_CALL
650 ResultSetBase::getMetaData(
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
);