Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / include / ucbhelper / resultset.hxx
blob4f002deb9620dc478026b94c9d77bb5d2a26ce66
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 #ifndef INCLUDED_UCBHELPER_RESULTSET_HXX
21 #define INCLUDED_UCBHELPER_RESULTSET_HXX
23 #include <com/sun/star/lang/XTypeProvider.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/lang/XComponent.hpp>
26 #include <com/sun/star/ucb/ResultSetException.hpp>
27 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
28 #include <com/sun/star/ucb/XContentAccess.hpp>
29 #include <com/sun/star/sdbc/XResultSet.hpp>
30 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
31 #include <com/sun/star/sdbc/XRow.hpp>
32 #include <com/sun/star/sdbc/XCloseable.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <rtl/ref.hxx>
36 #include <salhelper/simplereferenceobject.hxx>
37 #include <cppuhelper/weak.hxx>
38 #include <ucbhelper/macros.hxx>
39 #include <ucbhelper/ucbhelperdllapi.h>
40 #include <memory>
42 namespace ucbhelper {
45 #define RESULTSET_SERVICE_NAME "com.sun.star.ucb.ContentResultSet"
48 class ResultSetDataSupplier;
49 struct ResultSet_Impl;
51 /**
52 * This is an implementation of the service com.sun.star.ucb.ContentResultSet.
53 * It can be used to implement the method XDynamicResultSet::getStaticResultSet,
54 * which needs to be implemented for instance to implement the command "open"
55 * at folder objects. This class uses a user supplied ResultSetDataSupplier
56 * object to request data on demand.
58 * @see ResultSetDataSupplier
60 class UCBHELPER_DLLPUBLIC ResultSet :
61 public cppu::OWeakObject,
62 public css::lang::XTypeProvider,
63 public css::lang::XServiceInfo,
64 public css::lang::XComponent,
65 public css::ucb::XContentAccess,
66 public css::sdbc::XResultSet,
67 public css::sdbc::XResultSetMetaDataSupplier,
68 public css::sdbc::XRow,
69 public css::sdbc::XCloseable,
70 public css::beans::XPropertySet
72 std::unique_ptr<ResultSet_Impl> m_pImpl;
74 public:
75 /**
76 * Construction.
78 * @param rxSMgr is a Service Manager.
79 * @param rProperties is a sequence of properties for that the resultset
80 * shall be able to obtain the values.
81 * @param rDataSupplier is a supplier for the resultset data.
83 ResultSet(
84 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
85 const css::uno::Sequence< css::beans::Property >& rProperties,
86 const rtl::Reference< ResultSetDataSupplier >& rDataSupplier );
87 /**
88 * Construction.
90 * @param rxSMgr is a Service Manager.
91 * @param rProperties is a sequence of properties for that the resultset
92 * shall be able to obtain the values.
93 * @param rDataSupplier is a supplier for the resultset data.
94 * @param rxEnv is the environment for interactions, progress propagation,
95 * ...
97 ResultSet(
98 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
99 const css::uno::Sequence< css::beans::Property >& rProperties,
100 const rtl::Reference< ResultSetDataSupplier >& rDataSupplier,
101 const css::uno::Reference< css::ucb::XCommandEnvironment >& rxEnv );
102 virtual ~ResultSet();
104 // XInterface
105 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType )
106 throw( css::uno::RuntimeException, std::exception ) override;
107 virtual void SAL_CALL acquire()
108 throw() override;
109 virtual void SAL_CALL release()
110 throw() override;
112 // XTypeProvider
113 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
114 getImplementationId()
115 throw( css::uno::RuntimeException, std::exception ) override;
116 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
117 getTypes()
118 throw( css::uno::RuntimeException, std::exception ) override;
120 // XServiceInfo
121 virtual OUString SAL_CALL getImplementationName()
122 throw( css::uno::RuntimeException, std::exception ) override;
123 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
124 throw( css::uno::RuntimeException, std::exception ) override;
125 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
126 throw( css::uno::RuntimeException, std::exception ) override;
128 static OUString getImplementationName_Static();
129 static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
131 // XComponent
132 virtual void SAL_CALL
133 dispose()
134 throw( css::uno::RuntimeException, std::exception ) override;
135 virtual void SAL_CALL
136 addEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener )
137 throw( css::uno::RuntimeException, std::exception ) override;
138 virtual void SAL_CALL
139 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener )
140 throw( css::uno::RuntimeException, std::exception ) override;
142 // XContentAccess
143 virtual OUString SAL_CALL
144 queryContentIdentifierString()
145 throw( css::uno::RuntimeException, std::exception ) override;
146 virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL
147 queryContentIdentifier()
148 throw( css::uno::RuntimeException, std::exception ) override;
149 virtual css::uno::Reference< css::ucb::XContent > SAL_CALL
150 queryContent()
151 throw( css::uno::RuntimeException, std::exception ) override;
153 // XResultSetMetaDataSupplier
154 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL
155 getMetaData()
156 throw( css::sdbc::SQLException,
157 css::uno::RuntimeException, std::exception ) override;
159 // XResultSet
160 virtual sal_Bool SAL_CALL
161 next()
162 throw( css::sdbc::SQLException,
163 css::uno::RuntimeException, std::exception ) override;
164 virtual sal_Bool SAL_CALL
165 isBeforeFirst()
166 throw( css::sdbc::SQLException,
167 css::uno::RuntimeException, std::exception ) override;
168 virtual sal_Bool SAL_CALL
169 isAfterLast()
170 throw( css::sdbc::SQLException,
171 css::uno::RuntimeException, std::exception ) override;
172 virtual sal_Bool SAL_CALL
173 isFirst()
174 throw( css::sdbc::SQLException,
175 css::uno::RuntimeException, std::exception ) override;
176 virtual sal_Bool SAL_CALL
177 isLast()
178 throw( css::sdbc::SQLException,
179 css::uno::RuntimeException, std::exception ) override;
180 virtual void SAL_CALL
181 beforeFirst()
182 throw( css::sdbc::SQLException,
183 css::uno::RuntimeException, std::exception ) override;
184 virtual void SAL_CALL
185 afterLast()
186 throw( css::sdbc::SQLException,
187 css::uno::RuntimeException, std::exception ) override;
188 virtual sal_Bool SAL_CALL
189 first()
190 throw( css::sdbc::SQLException,
191 css::uno::RuntimeException, std::exception ) override;
192 virtual sal_Bool SAL_CALL
193 last()
194 throw( css::sdbc::SQLException,
195 css::uno::RuntimeException, std::exception ) override;
196 virtual sal_Int32 SAL_CALL
197 getRow()
198 throw( css::sdbc::SQLException,
199 css::uno::RuntimeException, std::exception ) override;
200 virtual sal_Bool SAL_CALL
201 absolute( sal_Int32 row )
202 throw( css::sdbc::SQLException,
203 css::uno::RuntimeException, std::exception ) override;
204 virtual sal_Bool SAL_CALL
205 relative( sal_Int32 rows )
206 throw( css::sdbc::SQLException,
207 css::uno::RuntimeException, std::exception ) override;
208 virtual sal_Bool SAL_CALL
209 previous()
210 throw( css::sdbc::SQLException,
211 css::uno::RuntimeException, std::exception ) override;
212 virtual void SAL_CALL
213 refreshRow()
214 throw( css::sdbc::SQLException,
215 css::uno::RuntimeException, std::exception ) override;
216 virtual sal_Bool SAL_CALL
217 rowUpdated()
218 throw( css::sdbc::SQLException,
219 css::uno::RuntimeException, std::exception ) override;
220 virtual sal_Bool SAL_CALL
221 rowInserted()
222 throw( css::sdbc::SQLException,
223 css::uno::RuntimeException, std::exception ) override;
224 virtual sal_Bool SAL_CALL
225 rowDeleted()
226 throw( css::sdbc::SQLException,
227 css::uno::RuntimeException, std::exception ) override;
228 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
229 getStatement()
230 throw( css::sdbc::SQLException,
231 css::uno::RuntimeException, std::exception ) override;
233 // XRow
234 virtual sal_Bool SAL_CALL
235 wasNull()
236 throw( css::sdbc::SQLException,
237 css::uno::RuntimeException, std::exception ) override;
238 virtual OUString SAL_CALL
239 getString( sal_Int32 columnIndex )
240 throw( css::sdbc::SQLException,
241 css::uno::RuntimeException, std::exception ) override;
242 virtual sal_Bool SAL_CALL
243 getBoolean( sal_Int32 columnIndex )
244 throw( css::sdbc::SQLException,
245 css::uno::RuntimeException, std::exception ) override;
246 virtual sal_Int8 SAL_CALL
247 getByte( sal_Int32 columnIndex )
248 throw( css::sdbc::SQLException,
249 css::uno::RuntimeException, std::exception ) override;
250 virtual sal_Int16 SAL_CALL
251 getShort( sal_Int32 columnIndex )
252 throw( css::sdbc::SQLException,
253 css::uno::RuntimeException, std::exception ) override;
254 virtual sal_Int32 SAL_CALL
255 getInt( sal_Int32 columnIndex )
256 throw( css::sdbc::SQLException,
257 css::uno::RuntimeException, std::exception ) override;
258 virtual sal_Int64 SAL_CALL
259 getLong( sal_Int32 columnIndex )
260 throw( css::sdbc::SQLException,
261 css::uno::RuntimeException, std::exception ) override;
262 virtual float SAL_CALL
263 getFloat( sal_Int32 columnIndex )
264 throw( css::sdbc::SQLException,
265 css::uno::RuntimeException, std::exception ) override;
266 virtual double SAL_CALL
267 getDouble( sal_Int32 columnIndex )
268 throw( css::sdbc::SQLException,
269 css::uno::RuntimeException, std::exception ) override;
270 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
271 getBytes( sal_Int32 columnIndex )
272 throw( css::sdbc::SQLException,
273 css::uno::RuntimeException, std::exception ) override;
274 virtual css::util::Date SAL_CALL
275 getDate( sal_Int32 columnIndex )
276 throw( css::sdbc::SQLException,
277 css::uno::RuntimeException, std::exception ) override;
278 virtual css::util::Time SAL_CALL
279 getTime( sal_Int32 columnIndex )
280 throw( css::sdbc::SQLException,
281 css::uno::RuntimeException, std::exception ) override;
282 virtual css::util::DateTime SAL_CALL
283 getTimestamp( sal_Int32 columnIndex )
284 throw( css::sdbc::SQLException,
285 css::uno::RuntimeException, std::exception ) override;
286 virtual css::uno::Reference<
287 css::io::XInputStream > SAL_CALL
288 getBinaryStream( sal_Int32 columnIndex )
289 throw( css::sdbc::SQLException,
290 css::uno::RuntimeException, std::exception ) override;
291 virtual css::uno::Reference<
292 css::io::XInputStream > SAL_CALL
293 getCharacterStream( sal_Int32 columnIndex )
294 throw( css::sdbc::SQLException,
295 css::uno::RuntimeException, std::exception ) override;
296 virtual css::uno::Any SAL_CALL
297 getObject( sal_Int32 columnIndex,
298 const css::uno::Reference< css::container::XNameAccess >& typeMap )
299 throw( css::sdbc::SQLException,
300 css::uno::RuntimeException, std::exception ) override;
301 virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL
302 getRef( sal_Int32 columnIndex )
303 throw( css::sdbc::SQLException,
304 css::uno::RuntimeException, std::exception ) override;
305 virtual css::uno::Reference<
306 css::sdbc::XBlob > SAL_CALL
307 getBlob( sal_Int32 columnIndex )
308 throw( css::sdbc::SQLException,
309 css::uno::RuntimeException, std::exception ) override;
310 virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL
311 getClob( sal_Int32 columnIndex )
312 throw( css::sdbc::SQLException,
313 css::uno::RuntimeException, std::exception ) override;
314 virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL
315 getArray( sal_Int32 columnIndex )
316 throw( css::sdbc::SQLException,
317 css::uno::RuntimeException, std::exception ) override;
319 // XCloseable
320 virtual void SAL_CALL
321 close()
322 throw( css::sdbc::SQLException,
323 css::uno::RuntimeException, std::exception ) override;
325 // XPropertySet
326 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
327 getPropertySetInfo()
328 throw( css::uno::RuntimeException, std::exception ) override;
329 virtual void SAL_CALL
330 setPropertyValue( const OUString& aPropertyName,
331 const css::uno::Any& aValue )
332 throw( css::beans::UnknownPropertyException,
333 css::beans::PropertyVetoException,
334 css::lang::IllegalArgumentException,
335 css::lang::WrappedTargetException,
336 css::uno::RuntimeException, std::exception ) override;
337 virtual css::uno::Any SAL_CALL
338 getPropertyValue( const OUString& PropertyName )
339 throw( css::beans::UnknownPropertyException,
340 css::lang::WrappedTargetException,
341 css::uno::RuntimeException, std::exception ) override;
342 virtual void SAL_CALL
343 addPropertyChangeListener( const OUString& aPropertyName,
344 const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener )
345 throw( css::beans::UnknownPropertyException,
346 css::lang::WrappedTargetException,
347 css::uno::RuntimeException, std::exception ) override;
348 virtual void SAL_CALL
349 removePropertyChangeListener( const OUString& aPropertyName,
350 const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener )
351 throw( css::beans::UnknownPropertyException,
352 css::lang::WrappedTargetException,
353 css::uno::RuntimeException, std::exception ) override;
354 virtual void SAL_CALL
355 addVetoableChangeListener( const OUString& PropertyName,
356 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener )
357 throw( css::beans::UnknownPropertyException,
358 css::lang::WrappedTargetException,
359 css::uno::RuntimeException, std::exception ) override;
360 virtual void SAL_CALL
361 removeVetoableChangeListener( const OUString& PropertyName,
362 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener )
363 throw( css::beans::UnknownPropertyException,
364 css::lang::WrappedTargetException,
365 css::uno::RuntimeException, std::exception ) override;
368 // Non-interface methods.
372 * This method propagates property value changes to all registered
373 * listeners.
375 * @param rEvt is a property change event.
377 void propertyChanged(
378 const css::beans::PropertyChangeEvent& rEvt );
381 * This method should be called by the data supplier for the result set
382 * to indicate that there were new data obtained from the data source.
384 * @param nOld is the old count of rows; must be non-negative.
385 * @param nnew is the new count of rows; must be non-negative.
387 void rowCountChanged( sal_uInt32 nOld, sal_uInt32 nNew );
390 * This method should be called by the data supplier for the result set
391 * to indicate that there were all rows obtained from the data source.
393 void rowCountFinal();
396 * This method returns a sequence containing all properties ( not the
397 * values! ) of the result set.
399 * @return a sequence of properties.
401 const css::uno::Sequence< css::beans::Property >&
402 getProperties();
405 * This method returns the environment to use for interactions, progress
406 * propagation, ... It can by empty.
408 * @return an environment or an empty reference.
410 const css::uno::Reference< css::ucb::XCommandEnvironment >&
411 getEnvironment();
416 * This is the base class for an object that supplies data to a result set
418 * @see ResultSet
420 class ResultSetDataSupplier : public salhelper::SimpleReferenceObject
422 friend class ResultSet;
424 // No ref, otherwise we get a cyclic reference between supplier and set!
425 // Will be set from ResultSet ctor.
426 ResultSet* m_pResultSet;
428 public:
429 ResultSetDataSupplier() : m_pResultSet( nullptr ) {}
432 * This method returns the resultset this supplier belongs to.
434 * @return the resultset for that the supplier supplies data.
436 rtl::Reference< ResultSet > getResultSet() const { return m_pResultSet; }
439 * This method returns the identifier string of the content at the
440 * specified index.
442 * @param nIndex is the zero-based index within the logical data array
443 * of the supplier; must be non-negative.
444 * @return the content's identifier string.
446 virtual OUString queryContentIdentifierString( sal_uInt32 nIndex ) = 0;
449 * This method returns the identifier of the content at the specified index.
451 * @param nIndex is the zero-based index within the logical data array
452 * of the supplier; must be non-negative.
453 * @return the content's identifier.
455 virtual css::uno::Reference< css::ucb::XContentIdentifier >
456 queryContentIdentifier( sal_uInt32 nIndex ) = 0;
459 * This method returns the content at the specified index.
461 * @param nIndex is the zero-based index within the logical data array
462 * of the supplier; must be non-negative.
463 * @return the content.
465 virtual css::uno::Reference< css::ucb::XContent >
466 queryContent( sal_uInt32 nIndex ) = 0;
469 * This method returns whether there is a content at the specified index.
471 * @param nIndex is the zero-based index within the logical data array
472 * of the supplier; must be non-negative.
473 * @return true, if there is a content at the given index.
475 virtual bool getResult( sal_uInt32 nIndex ) = 0;
478 * This method returns the total count of objects in the logical data array
479 * of the supplier. The implementation of this method may be very
480 * "expensive", because it can be necessary to obtain all data in order
481 * to determine the count. Therefore the ResultSet implementation calls
482 * it very seldom.
484 * @return the total count of objects; will always be non-negative.
486 virtual sal_uInt32 totalCount() = 0;
489 * This method returns the count of objects obtained so far. There is no
490 * for the implementation to obtain all objects at once. It can obtain
491 * all data on demand.
493 * The implementation should call m_pResultSet->rowCountChanged(...)
494 * every time it has inserted a new entry in its logical result array.
496 * @return the count of objects obtained so far; will always be
497 * non-negative.
499 virtual sal_uInt32 currentCount() = 0;
502 * This method returns whether the value returned by currentCount() is
503 * "final". This is the case, if that there was all data obtained by the
504 * supplier and the current count won't increase any more.
506 * The implementation should call m_pResultSet->rowCountFinal(...) if
507 * it has inserted all entries in its logical result array.
509 * @return true, if the value returned by currentCount() won't change
510 anymore.
512 virtual bool isCountFinal() = 0;
515 * This method returns an object for accessing the property values at
516 * the specified index. The implementation may use the helper class
517 * ucb::PropertyValueSet to provide the return value.
519 * @param nIndex is the zero-based index within the logical data array
520 * of the supplier.
521 * @return the object for accessing the property values.
523 virtual css::uno::Reference< css::sdbc::XRow >
524 queryPropertyValues( sal_uInt32 nIndex ) = 0;
527 * This method is called to instruct the supplier to release the (possibly
528 * presnt) property values at the given index.
530 * @param nIndex is the zero-based index within the logical data array
531 * of the supplier.
533 virtual void releasePropertyValues( sal_uInt32 nIndex ) = 0;
536 * This method will be called by the resultset implementation in order
537 * to instruct the data supplier to release all resources it has
538 * allocated so far. In case the supplier is collecting data
539 * asynchronously, that process must be stopped.
541 virtual void close() = 0;
544 * This method will be called by the resultset implementation in order
545 * check, whether an error has occurred while collecting data. The
546 * implementation of this method must throw an exception in that case.
548 * Note: An exception thrown to indicate an error must always be thrown
549 * by the thread that created the data supplier. If the supplier collects
550 * data asynchronously ( i.e. in a separate thread ) and an error
551 * occurs, throwing of the appropriate exception must be deferred
552 * until validate() is called by the ResultSet implementation from
553 * inside the main thread.
554 * In case data are obtained synchronously, the ResultSetException can
555 * be thrown directly.
557 * @exception ResultSetException thrown, if an error has occurred
559 virtual void validate()
560 throw( css::ucb::ResultSetException ) = 0;
565 #endif /* ! INCLUDED_UCBHELPER_RESULTSET_HXX */
567 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */