LibreOffice Module ucb (master) 1
ftpresultsetbase.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <com/sun/star/sdbc/SQLException.hpp>
22#include <com/sun/star/uno/Reference.h>
23#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <utility>
27#include "ftpresultsetbase.hxx"
28
29using namespace ftp;
30using namespace com::sun::star;
31
32ResultSetBase::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 )),
38 m_nRow( -1 ),
39 m_nWasNull( true ),
40 m_sProperty( seq )
41{
42}
43
44ResultSetBase::~ResultSetBase()
45{
46}
47
48
49// XInterface
50
51void SAL_CALL
53 noexcept
54{
55 OWeakObject::acquire();
56}
57
58
59void SAL_CALL
61 noexcept
62{
63 OWeakObject::release();
64}
65
66
67uno::Any SAL_CALL
69{
71 rType,
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 );
79}
80
81
82// XComponent
83
84
85void SAL_CALL
87 const uno::Reference< lang::XEventListener >& Listener )
88{
89 osl::MutexGuard aGuard( m_aMutex );
90
94
95 m_pDisposeEventListeners->addInterface( Listener );
96}
97
98
99void SAL_CALL
101 const uno::Reference< lang::XEventListener >& Listener )
102{
103 osl::MutexGuard aGuard( m_aMutex );
104
106 m_pDisposeEventListeners->removeInterface( Listener );
107}
108
109
110void SAL_CALL
112{
113 osl::MutexGuard aGuard( m_aMutex );
114
115 lang::EventObject aEvt;
116 aEvt.Source = static_cast< lang::XComponent * >( this );
117
119 {
120 m_pDisposeEventListeners->disposeAndClear( aEvt );
121 }
122 if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
123 {
124 m_pRowCountListeners->disposeAndClear( aEvt );
125 }
126 if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
127 {
128 m_pIsFinalListeners->disposeAndClear( aEvt );
129 }
130}
131
132
133// XResultSet
134
135sal_Bool SAL_CALL
137{
138 ++m_nRow;
139 return m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
140}
141
142
143sal_Bool SAL_CALL
145{
146 return m_nRow == -1;
147}
148
149
150sal_Bool SAL_CALL
152{
153 return m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()); // Cannot happen, if m_aFolder.isOpen()
154}
155
156
157sal_Bool SAL_CALL
159{
160 return m_nRow == 0;
161}
162
163
164sal_Bool SAL_CALL
166{
167 if( m_nRow == sal::static_int_cast<sal_Int32>(m_aItems.size()) - 1 )
168 return true;
169 else
170 return false;
171}
172
173
174void SAL_CALL
176{
177 m_nRow = -1;
178}
179
180
181void SAL_CALL
183{
184 m_nRow = m_aItems.size();
185}
186
187
188sal_Bool SAL_CALL
190{
191 m_nRow = -1;
192 return next();
193}
194
195
196sal_Bool SAL_CALL
198{
199 m_nRow = m_aItems.size() - 1;
200 return true;
201}
202
203
204sal_Int32 SAL_CALL
206{
207 // Test, whether behind last row
208 if( -1 == m_nRow || m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()) )
209 return 0;
210 else
211 return m_nRow+1;
212}
213
214
215sal_Bool SAL_CALL ResultSetBase::absolute( sal_Int32 row )
216{
217 if( row >= 0 )
218 m_nRow = row - 1;
219 else
220 {
221 last();
222 m_nRow += ( row + 1 );
223 if( m_nRow < -1 )
224 m_nRow = -1;
225 }
226
227 return 0<= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
228}
229
230
231sal_Bool SAL_CALL
233{
234 if( isAfterLast() || isBeforeFirst() )
235 throw sdbc::SQLException();
236
237 if( row > 0 )
238 while( row-- )
239 next();
240 else if( row < 0 )
241 while( row++ && m_nRow > - 1 )
242 previous();
243
244 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
245}
246
247
248sal_Bool SAL_CALL
250{
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;
254
255 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
256}
257
258
259void SAL_CALL
261{
262}
263
264
265sal_Bool SAL_CALL
267{
268 return false;
269}
270
271sal_Bool SAL_CALL
273{
274 return false;
275}
276
277sal_Bool SAL_CALL
279{
280 return false;
281}
282
283
284uno::Reference< uno::XInterface > SAL_CALL
286{
287 return uno::Reference< uno::XInterface >();
288}
289
290
291// XCloseable
292
293void SAL_CALL
295{
296}
297
298
299OUString SAL_CALL
301{
302 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
303 return m_aPath[m_nRow];
304 else
305 return OUString();
306}
307
308
309uno::Reference< ucb::XContentIdentifier > SAL_CALL
311{
312 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
313 {
314 if(!m_aIdents[m_nRow].is()) {
315 OUString url = queryContentIdentifierString();
316 if(!url.isEmpty() )
318 uno::Reference< ucb::XContentIdentifier >(
319 new ::ucbhelper::ContentIdentifier(url) );
320 }
321 return m_aIdents[m_nRow];
322 }
323
324 return uno::Reference<ucb::XContentIdentifier>();
325}
326
327
328uno::Reference< ucb::XContent > SAL_CALL
330{
331 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
332 return m_xProvider->queryContent(queryContentIdentifier());
333 else
334 return uno::Reference< ucb::XContent >();
335}
336
337namespace {
338
339class XPropertySetInfoImpl
340 : public cppu::OWeakObject,
341 public beans::XPropertySetInfo
342{
343public:
344
345 explicit XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
346 : m_aSeq( aSeq )
347 {
348 }
349
350 void SAL_CALL acquire()
351 noexcept override
352 {
353 OWeakObject::acquire();
354 }
355
356
357 void SAL_CALL release()
358 noexcept override
359 {
360 OWeakObject::release();
361 }
362
363 uno::Any SAL_CALL queryInterface( const uno::Type& rType ) override
364 {
366 rType,
367 static_cast< beans::XPropertySetInfo* >(this) );
368 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
369 }
370
371 uno::Sequence< beans::Property > SAL_CALL getProperties() override
372 {
373 return m_aSeq;
374 }
375
376 beans::Property SAL_CALL getPropertyByName( const OUString& aName ) override
377 {
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))
381 return *pProp;
382 throw beans::UnknownPropertyException(aName);
383 }
384
385 sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override
386 {
387 return std::any_of(std::cbegin(m_aSeq), std::cend(m_aSeq),
388 [&Name](const beans::Property& rProp) { return Name == rProp.Name; });
389 }
390
391private:
392
393 uno::Sequence< beans::Property > m_aSeq;
394};
395
396}
397
398// XPropertySet
399uno::Reference< beans::XPropertySetInfo > SAL_CALL
401{
402 uno::Sequence< beans::Property > seq
403 {
404 { "RowCount", -1, cppu::UnoType<sal_Int32>::get(), beans::PropertyAttribute::READONLY },
405 { "IsRowCountFinal", -1, cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::READONLY }
406 };
407
408 return uno::Reference< beans::XPropertySetInfo > (
409 new XPropertySetInfoImpl( seq ) );
410}
411
412
414 const OUString& aPropertyName, const uno::Any& /*aValue*/ )
415{
416 if( aPropertyName == "IsRowCountFinal" ||
417 aPropertyName == "RowCount" )
418 return;
419
420 throw beans::UnknownPropertyException(aPropertyName);
421}
422
423
425 const OUString& PropertyName )
426{
427 if( PropertyName == "IsRowCountFinal" )
428 {
429 return uno::Any(true);
430 }
431 else if ( PropertyName == "RowCount" )
432 {
433 sal_Int32 count = m_aItems.size();
434 return uno::Any(count);
435 }
436 else
437 throw beans::UnknownPropertyException(PropertyName);
438}
439
440
442 const OUString& aPropertyName,
443 const uno::Reference< beans::XPropertyChangeListener >& xListener )
444{
445 if( aPropertyName == "IsRowCountFinal" )
446 {
447 osl::MutexGuard aGuard( m_aMutex );
448 if ( ! m_pIsFinalListeners )
451
452 m_pIsFinalListeners->addInterface( xListener );
453 }
454 else if ( aPropertyName == "RowCount" )
455 {
456 osl::MutexGuard aGuard( m_aMutex );
457 if ( ! m_pRowCountListeners )
460 m_pRowCountListeners->addInterface( xListener );
461 }
462 else
463 throw beans::UnknownPropertyException(aPropertyName);
464}
465
466
468 const OUString& aPropertyName,
469 const uno::Reference< beans::XPropertyChangeListener >& aListener )
470{
471 if( aPropertyName == "IsRowCountFinal" &&
473 {
474 osl::MutexGuard aGuard( m_aMutex );
475 m_pIsFinalListeners->removeInterface( aListener );
476 }
477 else if ( aPropertyName == "RowCount" &&
479 {
480 osl::MutexGuard aGuard( m_aMutex );
481 m_pRowCountListeners->removeInterface( aListener );
482 }
483 else
484 throw beans::UnknownPropertyException(aPropertyName);
485}
486
487
489 const OUString& /*PropertyName*/,
490 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
491{
492}
493
494
496 const OUString& /*PropertyName*/,
497 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
498{
499}
500
501
502// XResultSetMetaDataSupplier
503uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
505{
506 return new ::ucbhelper::ResultSetMetaData( m_xContext, m_sProperty );
507}
508
509
510/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
Sequence< Any > m_aSeq
css::uno::Type const & get()
virtual sal_Bool SAL_CALL isAfterLast() override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual sal_Bool SAL_CALL rowUpdated() override
virtual void SAL_CALL acquire() noexcept override
virtual sal_Bool SAL_CALL previous() override
std::vector< OUString > m_aPath
css::uno::Sequence< css::beans::Property > m_sProperty
virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData() override
std::unique_ptr< comphelper::OInterfaceContainerHelper3< css::lang::XEventListener > > m_pDisposeEventListeners
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual sal_Bool SAL_CALL next() override
virtual void SAL_CALL refreshRow() override
virtual sal_Bool SAL_CALL rowInserted() override
std::unique_ptr< comphelper::OInterfaceContainerHelper3< css::beans::XPropertyChangeListener > > m_pIsFinalListeners
virtual sal_Bool SAL_CALL relative(sal_Int32 rows) override
css::uno::Reference< css::ucb::XContentProvider > m_xProvider
virtual void SAL_CALL beforeFirst() override
virtual void SAL_CALL close() override
virtual sal_Bool SAL_CALL first() override
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL dispose() override
virtual sal_Bool SAL_CALL isLast() override
virtual OUString SAL_CALL queryContentIdentifierString() override
virtual sal_Bool SAL_CALL absolute(sal_Int32 row) override
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual sal_Bool SAL_CALL last() override
virtual sal_Bool SAL_CALL rowDeleted() override
virtual sal_Bool SAL_CALL isBeforeFirst() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement() override
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent() override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual void SAL_CALL afterLast() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL queryContentIdentifier() override
virtual sal_Bool SAL_CALL isFirst() override
virtual void SAL_CALL release() noexcept override
virtual sal_Int32 SAL_CALL getRow() override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
std::unique_ptr< comphelper::OInterfaceContainerHelper3< css::beans::XPropertyChangeListener > > m_pRowCountListeners
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
OUString aName
Sequence< sal_Int8 > aSeq
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
Definition of ftpcontentprovider.
bool hasValue()
OUString Name
unsigned char sal_Bool