1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <ucbhelper/contentidentifier.hxx>
21 #include <com/sun/star/sdbc/SQLException.hpp>
22 #include <com/sun/star/uno/Reference.h>
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
24 #include <ucbhelper/resultsetmetadata.hxx>
25 #include <cppuhelper/queryinterface.hxx>
27 #include "ftpresultsetbase.hxx"
30 using namespace com::sun::star
;
32 ResultSetBase::ResultSetBase(
33 uno::Reference
< uno::XComponentContext
> xContext
,
34 uno::Reference
< ucb::XContentProvider
> xProvider
,
35 const uno::Sequence
< beans::Property
>& seq
)
36 : m_xContext(std::move( xContext
)),
37 m_xProvider(std::move( xProvider
)),
44 ResultSetBase::~ResultSetBase()
52 ResultSetBase::acquire()
55 OWeakObject::acquire();
60 ResultSetBase::release()
63 OWeakObject::release();
68 ResultSetBase::queryInterface( const uno::Type
& rType
)
70 uno::Any aRet
= cppu::queryInterface(
72 static_cast< lang::XComponent
* >(this),
73 static_cast< sdbc::XRow
* >(this),
74 static_cast< sdbc::XResultSet
* >(this),
75 static_cast< sdbc::XResultSetMetaDataSupplier
* >(this),
76 static_cast< beans::XPropertySet
* >(this),
77 static_cast< ucb::XContentAccess
* >(this) );
78 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
86 ResultSetBase::addEventListener(
87 const uno::Reference
< lang::XEventListener
>& Listener
)
89 osl::MutexGuard
aGuard( m_aMutex
);
91 if ( ! m_pDisposeEventListeners
)
92 m_pDisposeEventListeners
.reset(
93 new comphelper::OInterfaceContainerHelper3
<lang::XEventListener
>( m_aMutex
) );
95 m_pDisposeEventListeners
->addInterface( Listener
);
100 ResultSetBase::removeEventListener(
101 const uno::Reference
< lang::XEventListener
>& Listener
)
103 osl::MutexGuard
aGuard( m_aMutex
);
105 if ( m_pDisposeEventListeners
)
106 m_pDisposeEventListeners
->removeInterface( Listener
);
111 ResultSetBase::dispose()
113 osl::MutexGuard
aGuard( m_aMutex
);
115 lang::EventObject aEvt
;
116 aEvt
.Source
= static_cast< lang::XComponent
* >( this );
118 if ( m_pDisposeEventListeners
&& m_pDisposeEventListeners
->getLength() )
120 m_pDisposeEventListeners
->disposeAndClear( aEvt
);
122 if( m_pRowCountListeners
&& m_pRowCountListeners
->getLength() )
124 m_pRowCountListeners
->disposeAndClear( aEvt
);
126 if( m_pIsFinalListeners
&& m_pIsFinalListeners
->getLength() )
128 m_pIsFinalListeners
->disposeAndClear( aEvt
);
136 ResultSetBase::next()
139 return m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size());
144 ResultSetBase::isBeforeFirst()
151 ResultSetBase::isAfterLast()
153 return m_nRow
>= sal::static_int_cast
<sal_Int32
>(m_aItems
.size()); // Cannot happen, if m_aFolder.isOpen()
158 ResultSetBase::isFirst()
165 ResultSetBase::isLast()
167 if( m_nRow
== sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) - 1 )
175 ResultSetBase::beforeFirst()
182 ResultSetBase::afterLast()
184 m_nRow
= m_aItems
.size();
189 ResultSetBase::first()
197 ResultSetBase::last()
199 m_nRow
= m_aItems
.size() - 1;
205 ResultSetBase::getRow()
207 // Test, whether behind last row
208 if( -1 == m_nRow
|| m_nRow
>= sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
215 sal_Bool SAL_CALL
ResultSetBase::absolute( sal_Int32 row
)
222 m_nRow
+= ( row
+ 1 );
227 return 0<= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size());
232 ResultSetBase::relative( sal_Int32 row
)
234 if( isAfterLast() || isBeforeFirst() )
235 throw sdbc::SQLException();
241 while( row
++ && m_nRow
> - 1 )
244 return 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size());
249 ResultSetBase::previous()
251 if( m_nRow
> sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
252 m_nRow
= m_aItems
.size(); // Correct Handling of afterLast
253 if( 0 <= m_nRow
) -- m_nRow
;
255 return 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size());
260 ResultSetBase::refreshRow()
266 ResultSetBase::rowUpdated()
272 ResultSetBase::rowInserted()
278 ResultSetBase::rowDeleted()
284 uno::Reference
< uno::XInterface
> SAL_CALL
285 ResultSetBase::getStatement()
287 return uno::Reference
< uno::XInterface
>();
294 ResultSetBase::close()
300 ResultSetBase::queryContentIdentifierString()
302 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
303 return m_aPath
[m_nRow
];
309 uno::Reference
< ucb::XContentIdentifier
> SAL_CALL
310 ResultSetBase::queryContentIdentifier()
312 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
314 if(!m_aIdents
[m_nRow
].is()) {
315 OUString url
= queryContentIdentifierString();
318 uno::Reference
< ucb::XContentIdentifier
>(
319 new ::ucbhelper::ContentIdentifier(url
) );
321 return m_aIdents
[m_nRow
];
324 return uno::Reference
<ucb::XContentIdentifier
>();
328 uno::Reference
< ucb::XContent
> SAL_CALL
329 ResultSetBase::queryContent()
331 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
332 return m_xProvider
->queryContent(queryContentIdentifier());
334 return uno::Reference
< ucb::XContent
>();
339 class XPropertySetInfoImpl
340 : public cppu::OWeakObject
,
341 public beans::XPropertySetInfo
345 explicit XPropertySetInfoImpl( const uno::Sequence
< beans::Property
>& aSeq
)
350 void SAL_CALL
acquire()
353 OWeakObject::acquire();
357 void SAL_CALL
release()
360 OWeakObject::release();
363 uno::Any SAL_CALL
queryInterface( const uno::Type
& rType
) override
365 uno::Any aRet
= cppu::queryInterface(
367 static_cast< beans::XPropertySetInfo
* >(this) );
368 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
371 uno::Sequence
< beans::Property
> SAL_CALL
getProperties() override
376 beans::Property SAL_CALL
getPropertyByName( const OUString
& aName
) override
378 auto pProp
= std::find_if(std::cbegin(m_aSeq
), std::cend(m_aSeq
),
379 [&aName
](const beans::Property
& rProp
) { return aName
== rProp
.Name
; });
380 if (pProp
!= std::cend(m_aSeq
))
382 throw beans::UnknownPropertyException(aName
);
385 sal_Bool SAL_CALL
hasPropertyByName( const OUString
& Name
) override
387 return std::any_of(std::cbegin(m_aSeq
), std::cend(m_aSeq
),
388 [&Name
](const beans::Property
& rProp
) { return Name
== rProp
.Name
; });
393 uno::Sequence
< beans::Property
> m_aSeq
;
399 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
400 ResultSetBase::getPropertySetInfo()
402 uno::Sequence
< beans::Property
> seq
404 { "RowCount", -1, cppu::UnoType
<sal_Int32
>::get(), beans::PropertyAttribute::READONLY
},
405 { "IsRowCountFinal", -1, cppu::UnoType
<sal_Bool
>::get(), beans::PropertyAttribute::READONLY
}
408 return uno::Reference
< beans::XPropertySetInfo
> (
409 new XPropertySetInfoImpl( seq
) );
413 void SAL_CALL
ResultSetBase::setPropertyValue(
414 const OUString
& aPropertyName
, const uno::Any
& /*aValue*/ )
416 if( aPropertyName
== "IsRowCountFinal" ||
417 aPropertyName
== "RowCount" )
420 throw beans::UnknownPropertyException(aPropertyName
);
424 uno::Any SAL_CALL
ResultSetBase::getPropertyValue(
425 const OUString
& PropertyName
)
427 if( PropertyName
== "IsRowCountFinal" )
429 return uno::Any(true);
431 else if ( PropertyName
== "RowCount" )
433 sal_Int32 count
= m_aItems
.size();
434 return uno::Any(count
);
437 throw beans::UnknownPropertyException(PropertyName
);
441 void SAL_CALL
ResultSetBase::addPropertyChangeListener(
442 const OUString
& aPropertyName
,
443 const uno::Reference
< beans::XPropertyChangeListener
>& xListener
)
445 if( aPropertyName
== "IsRowCountFinal" )
447 osl::MutexGuard
aGuard( m_aMutex
);
448 if ( ! m_pIsFinalListeners
)
449 m_pIsFinalListeners
.reset(
450 new comphelper::OInterfaceContainerHelper3
<beans::XPropertyChangeListener
>( m_aMutex
) );
452 m_pIsFinalListeners
->addInterface( xListener
);
454 else if ( aPropertyName
== "RowCount" )
456 osl::MutexGuard
aGuard( m_aMutex
);
457 if ( ! m_pRowCountListeners
)
458 m_pRowCountListeners
.reset(
459 new comphelper::OInterfaceContainerHelper3
<beans::XPropertyChangeListener
>( m_aMutex
) );
460 m_pRowCountListeners
->addInterface( xListener
);
463 throw beans::UnknownPropertyException(aPropertyName
);
467 void SAL_CALL
ResultSetBase::removePropertyChangeListener(
468 const OUString
& aPropertyName
,
469 const uno::Reference
< beans::XPropertyChangeListener
>& aListener
)
471 if( aPropertyName
== "IsRowCountFinal" &&
472 m_pIsFinalListeners
)
474 osl::MutexGuard
aGuard( m_aMutex
);
475 m_pIsFinalListeners
->removeInterface( aListener
);
477 else if ( aPropertyName
== "RowCount" &&
478 m_pRowCountListeners
)
480 osl::MutexGuard
aGuard( m_aMutex
);
481 m_pRowCountListeners
->removeInterface( aListener
);
484 throw beans::UnknownPropertyException(aPropertyName
);
488 void SAL_CALL
ResultSetBase::addVetoableChangeListener(
489 const OUString
& /*PropertyName*/,
490 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
495 void SAL_CALL
ResultSetBase::removeVetoableChangeListener(
496 const OUString
& /*PropertyName*/,
497 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
502 // XResultSetMetaDataSupplier
503 uno::Reference
< sdbc::XResultSetMetaData
> SAL_CALL
504 ResultSetBase::getMetaData()
506 return new ::ucbhelper::ResultSetMetaData( m_xContext
, m_sProperty
);
510 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */