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: ftpresultsetbase.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_ucb.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>
42 #include "ftpresultsetbase.hxx"
45 using namespace com::sun::star
;
47 ResultSetBase::ResultSetBase(
48 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(
103 SAL_STATIC_CAST( lang::XComponent
*, this),
104 SAL_STATIC_CAST( sdbc::XRow
*, this),
105 SAL_STATIC_CAST( sdbc::XResultSet
*, this),
106 SAL_STATIC_CAST( sdbc::XResultSetMetaDataSupplier
*, this),
107 SAL_STATIC_CAST( beans::XPropertySet
*, this ),
108 SAL_STATIC_CAST( ucb::XContentAccess
*, this) );
109 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
118 ResultSetBase::addEventListener(
119 const uno::Reference
< lang::XEventListener
>& Listener
)
120 throw( uno::RuntimeException
)
122 osl::MutexGuard
aGuard( m_aMutex
);
124 if ( ! m_pDisposeEventListeners
)
125 m_pDisposeEventListeners
=
126 new cppu::OInterfaceContainerHelper( m_aMutex
);
128 m_pDisposeEventListeners
->addInterface( Listener
);
133 ResultSetBase::removeEventListener(
134 const uno::Reference
< lang::XEventListener
>& Listener
)
135 throw( uno::RuntimeException
)
137 osl::MutexGuard
aGuard( m_aMutex
);
139 if ( m_pDisposeEventListeners
)
140 m_pDisposeEventListeners
->removeInterface( Listener
);
146 ResultSetBase::dispose()
147 throw( uno::RuntimeException
)
149 osl::MutexGuard
aGuard( m_aMutex
);
151 lang::EventObject aEvt
;
152 aEvt
.Source
= static_cast< lang::XComponent
* >( this );
154 if ( m_pDisposeEventListeners
&& m_pDisposeEventListeners
->getLength() )
156 m_pDisposeEventListeners
->disposeAndClear( aEvt
);
158 if( m_pRowCountListeners
&& m_pRowCountListeners
->getLength() )
160 m_pRowCountListeners
->disposeAndClear( aEvt
);
162 if( m_pIsFinalListeners
&& m_pIsFinalListeners
->getLength() )
164 m_pIsFinalListeners
->disposeAndClear( aEvt
);
175 throw( sdbc::SQLException
,
176 uno::RuntimeException
)
179 if( ++m_nRow
< sal::static_int_cast
<sal_Int32
>(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 m_nRow
>= sal::static_int_cast
<sal_Int32
>(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( m_nRow
== sal::static_int_cast
<sal_Int32
>(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
|| m_nRow
>= sal::static_int_cast
<sal_Int32
>(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
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(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
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size());
327 ResultSetBase::previous(
329 throw( sdbc::SQLException
,
330 uno::RuntimeException
)
332 if( m_nRow
> sal::static_int_cast
<sal_Int32
>(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
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(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
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
405 return m_aPath
[m_nRow
];
407 return rtl::OUString();
411 uno::Reference
< ucb::XContentIdentifier
> SAL_CALL
412 ResultSetBase::queryContentIdentifier(
416 uno::RuntimeException
419 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
421 if(!m_aIdents
[m_nRow
].is()) {
422 rtl::OUString url
= queryContentIdentifierString();
425 uno::Reference
< ucb::XContentIdentifier
>(
426 new ::ucbhelper::ContentIdentifier(m_xMSF
,url
) );
428 return m_aIdents
[m_nRow
];
431 return uno::Reference
<ucb::XContentIdentifier
>();
435 uno::Reference
< ucb::XContent
> SAL_CALL
436 ResultSetBase::queryContent(
438 throw( uno::RuntimeException
)
440 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
441 return m_xProvider
->queryContent(queryContentIdentifier());
443 return uno::Reference
< ucb::XContent
>();
448 class XPropertySetInfoImpl
449 : public cppu::OWeakObject
,
450 public beans::XPropertySetInfo
454 XPropertySetInfoImpl( const uno::Sequence
< beans::Property
>& aSeq
)
459 void SAL_CALL
acquire( void )
462 OWeakObject::acquire();
466 void SAL_CALL
release( void )
469 OWeakObject::release();
472 uno::Any SAL_CALL
queryInterface( const uno::Type
& rType
)
473 throw( uno::RuntimeException
)
475 uno::Any aRet
= cppu::queryInterface(
477 SAL_STATIC_CAST( beans::XPropertySetInfo
*, this ) );
478 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
481 uno::Sequence
< beans::Property
> SAL_CALL
getProperties()
482 throw( uno::RuntimeException
)
487 beans::Property SAL_CALL
getPropertyByName( const ::rtl::OUString
& aName
)
488 throw( beans::UnknownPropertyException
,
489 uno::RuntimeException
)
491 for( int i
= 0; i
< m_aSeq
.getLength(); ++i
)
492 if( aName
== m_aSeq
[i
].Name
)
494 throw beans::UnknownPropertyException();
497 sal_Bool SAL_CALL
hasPropertyByName( const ::rtl::OUString
& Name
)
498 throw( uno::RuntimeException
)
500 for( int i
= 0; i
< m_aSeq
.getLength(); ++i
)
501 if( Name
== m_aSeq
[i
].Name
)
508 uno::Sequence
< beans::Property
> m_aSeq
;
514 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
515 ResultSetBase::getPropertySetInfo()
516 throw( uno::RuntimeException
)
518 uno::Sequence
< beans::Property
> seq(2);
519 seq
[0].Name
= rtl::OUString::createFromAscii( "RowCount" );
521 seq
[0].Type
= getCppuType( static_cast< sal_Int32
* >(0) );
522 seq
[0].Attributes
= beans::PropertyAttribute::READONLY
;
524 seq
[1].Name
= rtl::OUString::createFromAscii( "IsRowCountFinal" );
526 seq
[1].Type
= getCppuType( static_cast< sal_Bool
* >(0) );
527 seq
[1].Attributes
= beans::PropertyAttribute::READONLY
;
530 return uno::Reference
< beans::XPropertySetInfo
> (
531 new XPropertySetInfoImpl( seq
) );
536 void SAL_CALL
ResultSetBase::setPropertyValue(
537 const rtl::OUString
& aPropertyName
, const uno::Any
& /*aValue*/ )
538 throw( beans::UnknownPropertyException
,
539 beans::PropertyVetoException
,
540 lang::IllegalArgumentException
,
541 lang::WrappedTargetException
,
542 uno::RuntimeException
)
544 if( aPropertyName
== rtl::OUString::createFromAscii( "IsRowCountFinal" ) ||
545 aPropertyName
== rtl::OUString::createFromAscii( "RowCount" ) )
548 throw beans::UnknownPropertyException();
552 uno::Any SAL_CALL
ResultSetBase::getPropertyValue(
553 const rtl::OUString
& PropertyName
)
554 throw( beans::UnknownPropertyException
,
555 lang::WrappedTargetException
,
556 uno::RuntimeException
)
558 if( PropertyName
== rtl::OUString::createFromAscii( "IsRowCountFinal" ) )
561 aAny
<<= m_bRowCountFinal
;
564 else if ( PropertyName
== rtl::OUString::createFromAscii( "RowCount" ) )
567 sal_Int32 count
= m_aItems
.size();
572 throw beans::UnknownPropertyException();
576 void SAL_CALL
ResultSetBase::addPropertyChangeListener(
577 const rtl::OUString
& aPropertyName
,
578 const uno::Reference
< beans::XPropertyChangeListener
>& xListener
)
579 throw( beans::UnknownPropertyException
,
580 lang::WrappedTargetException
,
581 uno::RuntimeException
)
583 if( aPropertyName
== rtl::OUString::createFromAscii( "IsRowCountFinal" ) )
585 osl::MutexGuard
aGuard( m_aMutex
);
586 if ( ! m_pIsFinalListeners
)
587 m_pIsFinalListeners
=
588 new cppu::OInterfaceContainerHelper( m_aMutex
);
590 m_pIsFinalListeners
->addInterface( xListener
);
592 else if ( aPropertyName
== rtl::OUString::createFromAscii( "RowCount" ) )
594 osl::MutexGuard
aGuard( m_aMutex
);
595 if ( ! m_pRowCountListeners
)
596 m_pRowCountListeners
=
597 new cppu::OInterfaceContainerHelper( m_aMutex
);
598 m_pRowCountListeners
->addInterface( xListener
);
601 throw beans::UnknownPropertyException();
605 void SAL_CALL
ResultSetBase::removePropertyChangeListener(
606 const rtl::OUString
& aPropertyName
,
607 const uno::Reference
< beans::XPropertyChangeListener
>& aListener
)
608 throw( beans::UnknownPropertyException
,
609 lang::WrappedTargetException
,
610 uno::RuntimeException
)
612 if( aPropertyName
== rtl::OUString::createFromAscii( "IsRowCountFinal" ) &&
613 m_pIsFinalListeners
)
615 osl::MutexGuard
aGuard( m_aMutex
);
616 m_pIsFinalListeners
->removeInterface( aListener
);
618 else if ( aPropertyName
== rtl::OUString::createFromAscii( "RowCount" ) &&
619 m_pRowCountListeners
)
621 osl::MutexGuard
aGuard( m_aMutex
);
622 m_pRowCountListeners
->removeInterface( aListener
);
625 throw beans::UnknownPropertyException();
629 void SAL_CALL
ResultSetBase::addVetoableChangeListener(
630 const rtl::OUString
& /*PropertyName*/,
631 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
632 throw( beans::UnknownPropertyException
,
633 lang::WrappedTargetException
,
634 uno::RuntimeException
)
639 void SAL_CALL
ResultSetBase::removeVetoableChangeListener(
640 const rtl::OUString
& /*PropertyName*/,
641 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
642 throw( beans::UnknownPropertyException
,
643 lang::WrappedTargetException
,
644 uno::RuntimeException
)
650 // XResultSetMetaDataSupplier
651 uno::Reference
< sdbc::XResultSetMetaData
> SAL_CALL
652 ResultSetBase::getMetaData(
654 throw( sdbc::SQLException
,
655 uno::RuntimeException
)
657 ::ucbhelper::ResultSetMetaData
* p
=
658 new ::ucbhelper::ResultSetMetaData(
659 m_xMSF
, m_sProperty
);
660 return uno::Reference
< sdbc::XResultSetMetaData
>( p
);