1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <ucbhelper/contentidentifier.hxx>
30 #include <com/sun/star/ucb/OpenMode.hpp>
31 #include <com/sun/star/uno/Reference.h>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/ucb/ListActionType.hpp>
34 #include <com/sun/star/ucb/XSourceInitialization.hpp>
35 #include <ucbhelper/resultsetmetadata.hxx>
36 #include "ftpresultsetbase.hxx"
39 using namespace com::sun::star
;
41 ResultSetBase::ResultSetBase(
42 const uno::Reference
< lang::XMultiServiceFactory
>& xMSF
,
43 const uno::Reference
< ucb::XContentProvider
>& xProvider
,
45 const uno::Sequence
< beans::Property
>& seq
,
46 const uno::Sequence
< ucb::NumberedSortingInfo
>& seqSort
)
48 m_xProvider( xProvider
),
51 m_nOpenMode( nOpenMode
),
52 m_bRowCountFinal( true ),
54 m_sSortingInfo( seqSort
),
55 m_pDisposeEventListeners( 0 ),
56 m_pRowCountListeners( 0 ),
57 m_pIsFinalListeners( 0 )
61 ResultSetBase::~ResultSetBase()
63 delete m_pIsFinalListeners
;
64 delete m_pRowCountListeners
;
65 delete m_pDisposeEventListeners
;
72 ResultSetBase::acquire(
76 OWeakObject::acquire();
81 ResultSetBase::release(
85 OWeakObject::release();
91 ResultSetBase::queryInterface(
92 const uno::Type
& rType
)
93 throw( uno::RuntimeException
)
95 uno::Any aRet
= cppu::queryInterface(
97 (static_cast< lang::XComponent
* >(this)),
98 (static_cast< sdbc::XRow
* >(this)),
99 (static_cast< sdbc::XResultSet
* >(this)),
100 (static_cast< sdbc::XResultSetMetaDataSupplier
* >(this)),
101 (static_cast< beans::XPropertySet
* >(this)),
102 (static_cast< ucb::XContentAccess
* >(this)) );
103 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
112 ResultSetBase::addEventListener(
113 const uno::Reference
< lang::XEventListener
>& Listener
)
114 throw( uno::RuntimeException
)
116 osl::MutexGuard
aGuard( m_aMutex
);
118 if ( ! m_pDisposeEventListeners
)
119 m_pDisposeEventListeners
=
120 new cppu::OInterfaceContainerHelper( m_aMutex
);
122 m_pDisposeEventListeners
->addInterface( Listener
);
127 ResultSetBase::removeEventListener(
128 const uno::Reference
< lang::XEventListener
>& Listener
)
129 throw( uno::RuntimeException
)
131 osl::MutexGuard
aGuard( m_aMutex
);
133 if ( m_pDisposeEventListeners
)
134 m_pDisposeEventListeners
->removeInterface( Listener
);
140 ResultSetBase::dispose()
141 throw( uno::RuntimeException
)
143 osl::MutexGuard
aGuard( m_aMutex
);
145 lang::EventObject aEvt
;
146 aEvt
.Source
= static_cast< lang::XComponent
* >( this );
148 if ( m_pDisposeEventListeners
&& m_pDisposeEventListeners
->getLength() )
150 m_pDisposeEventListeners
->disposeAndClear( aEvt
);
152 if( m_pRowCountListeners
&& m_pRowCountListeners
->getLength() )
154 m_pRowCountListeners
->disposeAndClear( aEvt
);
156 if( m_pIsFinalListeners
&& m_pIsFinalListeners
->getLength() )
158 m_pIsFinalListeners
->disposeAndClear( aEvt
);
169 throw( sdbc::SQLException
,
170 uno::RuntimeException
)
173 if( ++m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
182 ResultSetBase::isBeforeFirst(
184 throw( sdbc::SQLException
,
185 uno::RuntimeException
)
192 ResultSetBase::isAfterLast(
194 throw( sdbc::SQLException
,
195 uno::RuntimeException
)
197 return m_nRow
>= sal::static_int_cast
<sal_Int32
>(m_aItems
.size()); // Cannot happen, if m_aFolder.isOpen()
202 ResultSetBase::isFirst(
204 throw( sdbc::SQLException
,
205 uno::RuntimeException
)
212 ResultSetBase::isLast(
214 throw( sdbc::SQLException
,
215 uno::RuntimeException
)
217 if( m_nRow
== sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) - 1 )
225 ResultSetBase::beforeFirst(
227 throw( sdbc::SQLException
,
228 uno::RuntimeException
)
235 ResultSetBase::afterLast(
237 throw( sdbc::SQLException
,
238 uno::RuntimeException
)
240 m_nRow
= m_aItems
.size();
245 ResultSetBase::first(
247 throw( sdbc::SQLException
,
248 uno::RuntimeException
)
258 throw( sdbc::SQLException
,
259 uno::RuntimeException
)
261 m_nRow
= m_aItems
.size() - 1;
267 ResultSetBase::getRow(
269 throw( sdbc::SQLException
,
270 uno::RuntimeException
)
272 // Test, whether behind last row
273 if( -1 == m_nRow
|| m_nRow
>= sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
280 sal_Bool SAL_CALL
ResultSetBase::absolute( sal_Int32 row
)
281 throw( sdbc::SQLException
, uno::RuntimeException
)
288 m_nRow
+= ( row
+ 1 );
293 return 0<= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size());
300 ResultSetBase::relative(
302 throw( sdbc::SQLException
,
303 uno::RuntimeException
)
305 if( isAfterLast() || isBeforeFirst() )
306 throw sdbc::SQLException();
312 while( row
++ && m_nRow
> - 1 )
315 return 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size());
321 ResultSetBase::previous(
323 throw( sdbc::SQLException
,
324 uno::RuntimeException
)
326 if( m_nRow
> sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
327 m_nRow
= m_aItems
.size(); // Correct Handling of afterLast
328 if( 0 <= m_nRow
) -- m_nRow
;
330 return 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size());
335 ResultSetBase::refreshRow(
337 throw( sdbc::SQLException
,
338 uno::RuntimeException
)
344 ResultSetBase::rowUpdated(
346 throw( sdbc::SQLException
,
347 uno::RuntimeException
)
353 ResultSetBase::rowInserted(
355 throw( sdbc::SQLException
,
356 uno::RuntimeException
)
362 ResultSetBase::rowDeleted(
364 throw( sdbc::SQLException
,
365 uno::RuntimeException
)
371 uno::Reference
< uno::XInterface
> SAL_CALL
372 ResultSetBase::getStatement(
374 throw( sdbc::SQLException
,
375 uno::RuntimeException
)
377 uno::Reference
< uno::XInterface
> test( 0 );
385 ResultSetBase::close(
387 throw( sdbc::SQLException
,
388 uno::RuntimeException
)
393 rtl::OUString SAL_CALL
394 ResultSetBase::queryContentIdentifierString(
396 throw( uno::RuntimeException
)
398 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
399 return m_aPath
[m_nRow
];
401 return rtl::OUString();
405 uno::Reference
< ucb::XContentIdentifier
> SAL_CALL
406 ResultSetBase::queryContentIdentifier(
410 uno::RuntimeException
413 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
415 if(!m_aIdents
[m_nRow
].is()) {
416 rtl::OUString url
= queryContentIdentifierString();
419 uno::Reference
< ucb::XContentIdentifier
>(
420 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
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(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(
471 (static_cast< beans::XPropertySetInfo
* >(this)) );
472 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
475 uno::Sequence
< beans::Property
> SAL_CALL
getProperties()
476 throw( uno::RuntimeException
)
481 beans::Property SAL_CALL
getPropertyByName( const ::rtl::OUString
& aName
)
482 throw( beans::UnknownPropertyException
,
483 uno::RuntimeException
)
485 for( int i
= 0; i
< m_aSeq
.getLength(); ++i
)
486 if( aName
== m_aSeq
[i
].Name
)
488 throw beans::UnknownPropertyException();
491 sal_Bool SAL_CALL
hasPropertyByName( const ::rtl::OUString
& Name
)
492 throw( uno::RuntimeException
)
494 for( int i
= 0; i
< m_aSeq
.getLength(); ++i
)
495 if( Name
== m_aSeq
[i
].Name
)
502 uno::Sequence
< beans::Property
> m_aSeq
;
508 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
509 ResultSetBase::getPropertySetInfo()
510 throw( uno::RuntimeException
)
512 uno::Sequence
< beans::Property
> seq(2);
513 seq
[0].Name
= rtl::OUString("RowCount");
515 seq
[0].Type
= getCppuType( static_cast< sal_Int32
* >(0) );
516 seq
[0].Attributes
= beans::PropertyAttribute::READONLY
;
518 seq
[1].Name
= rtl::OUString("IsRowCountFinal");
520 seq
[1].Type
= getCppuType( static_cast< sal_Bool
* >(0) );
521 seq
[1].Attributes
= beans::PropertyAttribute::READONLY
;
524 return uno::Reference
< beans::XPropertySetInfo
> (
525 new XPropertySetInfoImpl( seq
) );
530 void SAL_CALL
ResultSetBase::setPropertyValue(
531 const rtl::OUString
& aPropertyName
, const uno::Any
& /*aValue*/ )
532 throw( beans::UnknownPropertyException
,
533 beans::PropertyVetoException
,
534 lang::IllegalArgumentException
,
535 lang::WrappedTargetException
,
536 uno::RuntimeException
)
538 if( aPropertyName
== rtl::OUString("IsRowCountFinal") ||
539 aPropertyName
== rtl::OUString("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("IsRowCountFinal") )
555 aAny
<<= m_bRowCountFinal
;
558 else if ( PropertyName
== rtl::OUString("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("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("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("IsRowCountFinal") &&
607 m_pIsFinalListeners
)
609 osl::MutexGuard
aGuard( m_aMutex
);
610 m_pIsFinalListeners
->removeInterface( aListener
);
612 else if ( aPropertyName
== rtl::OUString("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
)
633 void SAL_CALL
ResultSetBase::removeVetoableChangeListener(
634 const rtl::OUString
& /*PropertyName*/,
635 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
636 throw( beans::UnknownPropertyException
,
637 lang::WrappedTargetException
,
638 uno::RuntimeException
)
644 // XResultSetMetaDataSupplier
645 uno::Reference
< sdbc::XResultSetMetaData
> SAL_CALL
646 ResultSetBase::getMetaData(
648 throw( sdbc::SQLException
,
649 uno::RuntimeException
)
651 ::ucbhelper::ResultSetMetaData
* p
=
652 new ::ucbhelper::ResultSetMetaData(
653 m_xMSF
, m_sProperty
);
654 return uno::Reference
< sdbc::XResultSetMetaData
>( p
);
660 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */