Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / ucbhelper / resultset.hxx
bloba71afddabb5fd88eb9916ec05a9d7730e1441fa8
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() override;
104 // XInterface
105 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
106 virtual void SAL_CALL acquire()
107 throw() override;
108 virtual void SAL_CALL release()
109 throw() override;
111 // XTypeProvider
112 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
113 getImplementationId() override;
114 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
115 getTypes() override;
117 // XServiceInfo
118 virtual OUString SAL_CALL getImplementationName() override;
119 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
120 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
122 // XComponent
123 virtual void SAL_CALL
124 dispose() override;
125 virtual void SAL_CALL
126 addEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
127 virtual void SAL_CALL
128 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
130 // XContentAccess
131 virtual OUString SAL_CALL
132 queryContentIdentifierString() override;
133 virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL
134 queryContentIdentifier() override;
135 virtual css::uno::Reference< css::ucb::XContent > SAL_CALL
136 queryContent() override;
138 // XResultSetMetaDataSupplier
139 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL
140 getMetaData() override;
142 // XResultSet
143 virtual sal_Bool SAL_CALL
144 next() override;
145 virtual sal_Bool SAL_CALL
146 isBeforeFirst() override;
147 virtual sal_Bool SAL_CALL
148 isAfterLast() override;
149 virtual sal_Bool SAL_CALL
150 isFirst() override;
151 virtual sal_Bool SAL_CALL
152 isLast() override;
153 virtual void SAL_CALL
154 beforeFirst() override;
155 virtual void SAL_CALL
156 afterLast() override;
157 virtual sal_Bool SAL_CALL
158 first() override;
159 virtual sal_Bool SAL_CALL
160 last() override;
161 virtual sal_Int32 SAL_CALL
162 getRow() override;
163 virtual sal_Bool SAL_CALL
164 absolute( sal_Int32 row ) override;
165 virtual sal_Bool SAL_CALL
166 relative( sal_Int32 rows ) override;
167 virtual sal_Bool SAL_CALL
168 previous() override;
169 virtual void SAL_CALL
170 refreshRow() override;
171 virtual sal_Bool SAL_CALL
172 rowUpdated() override;
173 virtual sal_Bool SAL_CALL
174 rowInserted() override;
175 virtual sal_Bool SAL_CALL
176 rowDeleted() override;
177 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
178 getStatement() override;
180 // XRow
181 virtual sal_Bool SAL_CALL
182 wasNull() override;
183 virtual OUString SAL_CALL
184 getString( sal_Int32 columnIndex ) override;
185 virtual sal_Bool SAL_CALL
186 getBoolean( sal_Int32 columnIndex ) override;
187 virtual sal_Int8 SAL_CALL
188 getByte( sal_Int32 columnIndex ) override;
189 virtual sal_Int16 SAL_CALL
190 getShort( sal_Int32 columnIndex ) override;
191 virtual sal_Int32 SAL_CALL
192 getInt( sal_Int32 columnIndex ) override;
193 virtual sal_Int64 SAL_CALL
194 getLong( sal_Int32 columnIndex ) override;
195 virtual float SAL_CALL
196 getFloat( sal_Int32 columnIndex ) override;
197 virtual double SAL_CALL
198 getDouble( sal_Int32 columnIndex ) override;
199 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
200 getBytes( sal_Int32 columnIndex ) override;
201 virtual css::util::Date SAL_CALL
202 getDate( sal_Int32 columnIndex ) override;
203 virtual css::util::Time SAL_CALL
204 getTime( sal_Int32 columnIndex ) override;
205 virtual css::util::DateTime SAL_CALL
206 getTimestamp( sal_Int32 columnIndex ) override;
207 virtual css::uno::Reference<
208 css::io::XInputStream > SAL_CALL
209 getBinaryStream( sal_Int32 columnIndex ) override;
210 virtual css::uno::Reference<
211 css::io::XInputStream > SAL_CALL
212 getCharacterStream( sal_Int32 columnIndex ) override;
213 virtual css::uno::Any SAL_CALL
214 getObject( sal_Int32 columnIndex,
215 const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
216 virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL
217 getRef( sal_Int32 columnIndex ) override;
218 virtual css::uno::Reference<
219 css::sdbc::XBlob > SAL_CALL
220 getBlob( sal_Int32 columnIndex ) override;
221 virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL
222 getClob( sal_Int32 columnIndex ) override;
223 virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL
224 getArray( sal_Int32 columnIndex ) override;
226 // XCloseable
227 virtual void SAL_CALL
228 close() override;
230 // XPropertySet
231 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
232 getPropertySetInfo() override;
233 virtual void SAL_CALL
234 setPropertyValue( const OUString& aPropertyName,
235 const css::uno::Any& aValue ) override;
236 virtual css::uno::Any SAL_CALL
237 getPropertyValue( const OUString& PropertyName ) override;
238 virtual void SAL_CALL
239 addPropertyChangeListener( const OUString& aPropertyName,
240 const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
241 virtual void SAL_CALL
242 removePropertyChangeListener( const OUString& aPropertyName,
243 const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
244 virtual void SAL_CALL
245 addVetoableChangeListener( const OUString& PropertyName,
246 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
247 virtual void SAL_CALL
248 removeVetoableChangeListener( const OUString& PropertyName,
249 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
252 // Non-interface methods.
256 * This method propagates property value changes to all registered
257 * listeners.
259 * @param rEvt is a property change event.
261 void propertyChanged(
262 const css::beans::PropertyChangeEvent& rEvt );
265 * This method should be called by the data supplier for the result set
266 * to indicate that there were new data obtained from the data source.
268 * @param nOld is the old count of rows; must be non-negative.
269 * @param nnew is the new count of rows; must be non-negative.
271 void rowCountChanged( sal_uInt32 nOld, sal_uInt32 nNew );
274 * This method should be called by the data supplier for the result set
275 * to indicate that there were all rows obtained from the data source.
277 void rowCountFinal();
280 * This method returns a sequence containing all properties ( not the
281 * values! ) of the result set.
283 * @return a sequence of properties.
285 const css::uno::Sequence< css::beans::Property >&
286 getProperties();
289 * This method returns the environment to use for interactions, progress
290 * propagation, ... It can by empty.
292 * @return an environment or an empty reference.
294 const css::uno::Reference< css::ucb::XCommandEnvironment >&
295 getEnvironment();
300 * This is the base class for an object that supplies data to a result set
302 * @see ResultSet
304 class ResultSetDataSupplier : public salhelper::SimpleReferenceObject
306 friend class ResultSet;
308 // No ref, otherwise we get a cyclic reference between supplier and set!
309 // Will be set from ResultSet ctor.
310 ResultSet* m_pResultSet;
312 public:
313 ResultSetDataSupplier() : m_pResultSet( nullptr ) {}
316 * This method returns the resultset this supplier belongs to.
318 * @return the resultset for that the supplier supplies data.
320 rtl::Reference< ResultSet > getResultSet() const { return m_pResultSet; }
323 * This method returns the identifier string of the content at the
324 * specified index.
326 * @param nIndex is the zero-based index within the logical data array
327 * of the supplier; must be non-negative.
328 * @return the content's identifier string.
330 virtual OUString queryContentIdentifierString( sal_uInt32 nIndex ) = 0;
333 * This method returns the identifier of the content at the specified index.
335 * @param nIndex is the zero-based index within the logical data array
336 * of the supplier; must be non-negative.
337 * @return the content's identifier.
339 virtual css::uno::Reference< css::ucb::XContentIdentifier >
340 queryContentIdentifier( sal_uInt32 nIndex ) = 0;
343 * This method returns the content at the specified index.
345 * @param nIndex is the zero-based index within the logical data array
346 * of the supplier; must be non-negative.
347 * @return the content.
349 virtual css::uno::Reference< css::ucb::XContent >
350 queryContent( sal_uInt32 nIndex ) = 0;
353 * This method returns whether there is a content at the specified index.
355 * @param nIndex is the zero-based index within the logical data array
356 * of the supplier; must be non-negative.
357 * @return true, if there is a content at the given index.
359 virtual bool getResult( sal_uInt32 nIndex ) = 0;
362 * This method returns the total count of objects in the logical data array
363 * of the supplier. The implementation of this method may be very
364 * "expensive", because it can be necessary to obtain all data in order
365 * to determine the count. Therefore the ResultSet implementation calls
366 * it very seldom.
368 * @return the total count of objects; will always be non-negative.
370 virtual sal_uInt32 totalCount() = 0;
373 * This method returns the count of objects obtained so far. There is no
374 * for the implementation to obtain all objects at once. It can obtain
375 * all data on demand.
377 * The implementation should call m_pResultSet->rowCountChanged(...)
378 * every time it has inserted a new entry in its logical result array.
380 * @return the count of objects obtained so far; will always be
381 * non-negative.
383 virtual sal_uInt32 currentCount() = 0;
386 * This method returns whether the value returned by currentCount() is
387 * "final". This is the case, if that there was all data obtained by the
388 * supplier and the current count won't increase any more.
390 * The implementation should call m_pResultSet->rowCountFinal(...) if
391 * it has inserted all entries in its logical result array.
393 * @return true, if the value returned by currentCount() won't change
394 anymore.
396 virtual bool isCountFinal() = 0;
399 * This method returns an object for accessing the property values at
400 * the specified index. The implementation may use the helper class
401 * ucb::PropertyValueSet to provide the return value.
403 * @param nIndex is the zero-based index within the logical data array
404 * of the supplier.
405 * @return the object for accessing the property values.
407 virtual css::uno::Reference< css::sdbc::XRow >
408 queryPropertyValues( sal_uInt32 nIndex ) = 0;
411 * This method is called to instruct the supplier to release the (possibly
412 * presnt) property values at the given index.
414 * @param nIndex is the zero-based index within the logical data array
415 * of the supplier.
417 virtual void releasePropertyValues( sal_uInt32 nIndex ) = 0;
420 * This method will be called by the resultset implementation in order
421 * to instruct the data supplier to release all resources it has
422 * allocated so far. In case the supplier is collecting data
423 * asynchronously, that process must be stopped.
425 virtual void close() = 0;
428 * This method will be called by the resultset implementation in order
429 * check, whether an error has occurred while collecting data. The
430 * implementation of this method must throw an exception in that case.
432 * Note: An exception thrown to indicate an error must always be thrown
433 * by the thread that created the data supplier. If the supplier collects
434 * data asynchronously ( i.e. in a separate thread ) and an error
435 * occurs, throwing of the appropriate exception must be deferred
436 * until validate() is called by the ResultSet implementation from
437 * inside the main thread.
438 * In case data are obtained synchronously, the ResultSetException can
439 * be thrown directly.
441 * @exception ResultSetException thrown, if an error has occurred
443 virtual void validate() = 0;
448 #endif /* ! INCLUDED_UCBHELPER_RESULTSET_HXX */
450 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */