bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / ucp / ftp / ftpresultsetbase.cxx
blob66af1c4a8479318f589684c47eb17393ed3a48c7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include "ftpresultsetbase.hxx"
28 using namespace ftp;
29 using namespace com::sun::star;
31 ResultSetBase::ResultSetBase(
32 const uno::Reference< uno::XComponentContext >& rxContext,
33 const uno::Reference< ucb::XContentProvider >& xProvider,
34 const uno::Sequence< beans::Property >& seq )
35 : m_xContext( rxContext ),
36 m_xProvider( xProvider ),
37 m_nRow( -1 ),
38 m_nWasNull( true ),
39 m_sProperty( seq )
43 ResultSetBase::~ResultSetBase()
48 // XInterface
50 void SAL_CALL
51 ResultSetBase::acquire()
52 noexcept
54 OWeakObject::acquire();
58 void SAL_CALL
59 ResultSetBase::release()
60 noexcept
62 OWeakObject::release();
66 uno::Any SAL_CALL
67 ResultSetBase::queryInterface( const uno::Type& rType )
69 uno::Any aRet = cppu::queryInterface(
70 rType,
71 static_cast< lang::XComponent* >(this),
72 static_cast< sdbc::XRow* >(this),
73 static_cast< sdbc::XResultSet* >(this),
74 static_cast< sdbc::XResultSetMetaDataSupplier* >(this),
75 static_cast< beans::XPropertySet* >(this),
76 static_cast< ucb::XContentAccess* >(this) );
77 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
81 // XComponent
84 void SAL_CALL
85 ResultSetBase::addEventListener(
86 const uno::Reference< lang::XEventListener >& Listener )
88 osl::MutexGuard aGuard( m_aMutex );
90 if ( ! m_pDisposeEventListeners )
91 m_pDisposeEventListeners.reset(
92 new comphelper::OInterfaceContainerHelper2( m_aMutex ) );
94 m_pDisposeEventListeners->addInterface( Listener );
98 void SAL_CALL
99 ResultSetBase::removeEventListener(
100 const uno::Reference< lang::XEventListener >& Listener )
102 osl::MutexGuard aGuard( m_aMutex );
104 if ( m_pDisposeEventListeners )
105 m_pDisposeEventListeners->removeInterface( Listener );
109 void SAL_CALL
110 ResultSetBase::dispose()
112 osl::MutexGuard aGuard( m_aMutex );
114 lang::EventObject aEvt;
115 aEvt.Source = static_cast< lang::XComponent * >( this );
117 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
119 m_pDisposeEventListeners->disposeAndClear( aEvt );
121 if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
123 m_pRowCountListeners->disposeAndClear( aEvt );
125 if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
127 m_pIsFinalListeners->disposeAndClear( aEvt );
132 // XResultSet
134 sal_Bool SAL_CALL
135 ResultSetBase::next()
137 ++m_nRow;
138 return m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
142 sal_Bool SAL_CALL
143 ResultSetBase::isBeforeFirst()
145 return m_nRow == -1;
149 sal_Bool SAL_CALL
150 ResultSetBase::isAfterLast()
152 return m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()); // Cannot happen, if m_aFolder.isOpen()
156 sal_Bool SAL_CALL
157 ResultSetBase::isFirst()
159 return m_nRow == 0;
163 sal_Bool SAL_CALL
164 ResultSetBase::isLast()
166 if( m_nRow == sal::static_int_cast<sal_Int32>(m_aItems.size()) - 1 )
167 return true;
168 else
169 return false;
173 void SAL_CALL
174 ResultSetBase::beforeFirst()
176 m_nRow = -1;
180 void SAL_CALL
181 ResultSetBase::afterLast()
183 m_nRow = m_aItems.size();
187 sal_Bool SAL_CALL
188 ResultSetBase::first()
190 m_nRow = -1;
191 return next();
195 sal_Bool SAL_CALL
196 ResultSetBase::last()
198 m_nRow = m_aItems.size() - 1;
199 return true;
203 sal_Int32 SAL_CALL
204 ResultSetBase::getRow()
206 // Test, whether behind last row
207 if( -1 == m_nRow || m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()) )
208 return 0;
209 else
210 return m_nRow+1;
214 sal_Bool SAL_CALL ResultSetBase::absolute( sal_Int32 row )
216 if( row >= 0 )
217 m_nRow = row - 1;
218 else
220 last();
221 m_nRow += ( row + 1 );
222 if( m_nRow < -1 )
223 m_nRow = -1;
226 return 0<= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
230 sal_Bool SAL_CALL
231 ResultSetBase::relative( sal_Int32 row )
233 if( isAfterLast() || isBeforeFirst() )
234 throw sdbc::SQLException();
236 if( row > 0 )
237 while( row-- )
238 next();
239 else if( row < 0 )
240 while( row++ && m_nRow > - 1 )
241 previous();
243 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
247 sal_Bool SAL_CALL
248 ResultSetBase::previous()
250 if( m_nRow > sal::static_int_cast<sal_Int32>(m_aItems.size()) )
251 m_nRow = m_aItems.size(); // Correct Handling of afterLast
252 if( 0 <= m_nRow ) -- m_nRow;
254 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
258 void SAL_CALL
259 ResultSetBase::refreshRow()
264 sal_Bool SAL_CALL
265 ResultSetBase::rowUpdated()
267 return false;
270 sal_Bool SAL_CALL
271 ResultSetBase::rowInserted()
273 return false;
276 sal_Bool SAL_CALL
277 ResultSetBase::rowDeleted()
279 return false;
283 uno::Reference< uno::XInterface > SAL_CALL
284 ResultSetBase::getStatement()
286 return uno::Reference< uno::XInterface >();
290 // XCloseable
292 void SAL_CALL
293 ResultSetBase::close()
298 OUString SAL_CALL
299 ResultSetBase::queryContentIdentifierString()
301 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
302 return m_aPath[m_nRow];
303 else
304 return OUString();
308 uno::Reference< ucb::XContentIdentifier > SAL_CALL
309 ResultSetBase::queryContentIdentifier()
311 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
313 if(!m_aIdents[m_nRow].is()) {
314 OUString url = queryContentIdentifierString();
315 if(!url.isEmpty() )
316 m_aIdents[m_nRow] =
317 uno::Reference< ucb::XContentIdentifier >(
318 new ::ucbhelper::ContentIdentifier(url) );
320 return m_aIdents[m_nRow];
323 return uno::Reference<ucb::XContentIdentifier>();
327 uno::Reference< ucb::XContent > SAL_CALL
328 ResultSetBase::queryContent()
330 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
331 return m_xProvider->queryContent(queryContentIdentifier());
332 else
333 return uno::Reference< ucb::XContent >();
336 namespace {
338 class XPropertySetInfoImpl
339 : public cppu::OWeakObject,
340 public beans::XPropertySetInfo
342 public:
344 explicit XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
345 : m_aSeq( aSeq )
349 void SAL_CALL acquire()
350 noexcept override
352 OWeakObject::acquire();
356 void SAL_CALL release()
357 noexcept override
359 OWeakObject::release();
362 uno::Any SAL_CALL queryInterface( const uno::Type& rType ) override
364 uno::Any aRet = cppu::queryInterface(
365 rType,
366 static_cast< beans::XPropertySetInfo* >(this) );
367 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
370 uno::Sequence< beans::Property > SAL_CALL getProperties() override
372 return m_aSeq;
375 beans::Property SAL_CALL getPropertyByName( const OUString& aName ) override
377 auto pProp = std::find_if(m_aSeq.begin(), m_aSeq.end(),
378 [&aName](const beans::Property& rProp) { return aName == rProp.Name; });
379 if (pProp != m_aSeq.end())
380 return *pProp;
381 throw beans::UnknownPropertyException(aName);
384 sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override
386 return std::any_of(m_aSeq.begin(), m_aSeq.end(),
387 [&Name](const beans::Property& rProp) { return Name == rProp.Name; });
390 private:
392 uno::Sequence< beans::Property > m_aSeq;
397 // XPropertySet
398 uno::Reference< beans::XPropertySetInfo > SAL_CALL
399 ResultSetBase::getPropertySetInfo()
401 uno::Sequence< beans::Property > seq
403 { "RowCount", -1, cppu::UnoType<sal_Int32>::get(), beans::PropertyAttribute::READONLY },
404 { "IsRowCountFinal", -1, cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::READONLY }
407 return uno::Reference< beans::XPropertySetInfo > (
408 new XPropertySetInfoImpl( seq ) );
412 void SAL_CALL ResultSetBase::setPropertyValue(
413 const OUString& aPropertyName, const uno::Any& /*aValue*/ )
415 if( aPropertyName == "IsRowCountFinal" ||
416 aPropertyName == "RowCount" )
417 return;
419 throw beans::UnknownPropertyException(aPropertyName);
423 uno::Any SAL_CALL ResultSetBase::getPropertyValue(
424 const OUString& PropertyName )
426 if( PropertyName == "IsRowCountFinal" )
428 return uno::Any(true);
430 else if ( PropertyName == "RowCount" )
432 sal_Int32 count = m_aItems.size();
433 return uno::Any(count);
435 else
436 throw beans::UnknownPropertyException(PropertyName);
440 void SAL_CALL ResultSetBase::addPropertyChangeListener(
441 const OUString& aPropertyName,
442 const uno::Reference< beans::XPropertyChangeListener >& xListener )
444 if( aPropertyName == "IsRowCountFinal" )
446 osl::MutexGuard aGuard( m_aMutex );
447 if ( ! m_pIsFinalListeners )
448 m_pIsFinalListeners.reset(
449 new comphelper::OInterfaceContainerHelper2( m_aMutex ) );
451 m_pIsFinalListeners->addInterface( xListener );
453 else if ( aPropertyName == "RowCount" )
455 osl::MutexGuard aGuard( m_aMutex );
456 if ( ! m_pRowCountListeners )
457 m_pRowCountListeners.reset(
458 new comphelper::OInterfaceContainerHelper2( m_aMutex ) );
459 m_pRowCountListeners->addInterface( xListener );
461 else
462 throw beans::UnknownPropertyException(aPropertyName);
466 void SAL_CALL ResultSetBase::removePropertyChangeListener(
467 const OUString& aPropertyName,
468 const uno::Reference< beans::XPropertyChangeListener >& aListener )
470 if( aPropertyName == "IsRowCountFinal" &&
471 m_pIsFinalListeners )
473 osl::MutexGuard aGuard( m_aMutex );
474 m_pIsFinalListeners->removeInterface( aListener );
476 else if ( aPropertyName == "RowCount" &&
477 m_pRowCountListeners )
479 osl::MutexGuard aGuard( m_aMutex );
480 m_pRowCountListeners->removeInterface( aListener );
482 else
483 throw beans::UnknownPropertyException(aPropertyName);
487 void SAL_CALL ResultSetBase::addVetoableChangeListener(
488 const OUString& /*PropertyName*/,
489 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
494 void SAL_CALL ResultSetBase::removeVetoableChangeListener(
495 const OUString& /*PropertyName*/,
496 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
501 // XResultSetMetaDataSupplier
502 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
503 ResultSetBase::getMetaData()
505 return new ::ucbhelper::ResultSetMetaData( m_xContext, m_sProperty );
509 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */