LibreOffice Module ucb (master) 1
cachedcontentresultset.hxx
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
20#pragma once
21
23#include <com/sun/star/uno/XComponentContext.hpp>
24#include <com/sun/star/lang/XTypeProvider.hpp>
25#include <com/sun/star/lang/XServiceInfo.hpp>
26#include <com/sun/star/ucb/XFetchProvider.hpp>
27#include <com/sun/star/ucb/XFetchProviderForContentAccess.hpp>
28#include <com/sun/star/ucb/FetchResult.hpp>
29#include <com/sun/star/ucb/XContentIdentifierMapping.hpp>
30#include <com/sun/star/ucb/XCachedContentResultSetFactory.hpp>
32#include <rtl/ref.hxx>
33
34#include <optional>
35
36namespace com::sun::star::script {
37 class XTypeConverter;
38}
39
43 , public css::lang::XTypeProvider
44 , public css::lang::XServiceInfo
45{
46
47
49 {
50 private:
51 std::optional<css::ucb::FetchResult>
53 css::uno::Reference< css::ucb::XContentIdentifierMapping >
55 std::optional<css::uno::Sequence< sal_Bool >> m_pMappedReminder;
56
57 private:
60 css::uno::Any&
61 getRowAny( sal_Int32 nRow );
62
63 void clear();
64
65
66 void remindMapped( sal_Int32 nRow );
67 bool isRowMapped( sal_Int32 nRow );
68 css::uno::Sequence< sal_Bool >& getMappedReminder();
69
70 public:
71 CCRS_Cache( const css::uno::Reference<
72 css::ucb::XContentIdentifierMapping > & xMapping );
74
75 void loadData(
76 const css::ucb::FetchResult& rResult );
77
78 bool
79 hasRow( sal_Int32 nRow ) const;
80
81 bool
82 hasCausedException( sal_Int32 nRow ) const;
83
84 sal_Int32
85 getMaxRow() const;
86
87 bool
88 hasKnownLast() const;
89
92 const css::uno::Any&
93 getAny( sal_Int32 nRow, sal_Int32 nColumnIndex );
94
96 OUString const &
97 getContentIdentifierString( sal_Int32 nRow );
98
100 css::uno::Reference< css::ucb::XContentIdentifier >
101 getContentIdentifier( sal_Int32 nRow );
102
104 css::uno::Reference< css::ucb::XContent >
105 getContent( sal_Int32 nRow );
106 };
107
108 //members
109
110 css::uno::Reference< css::uno::XComponentContext >
112
113 //different Interfaces from Origin:
114 css::uno::Reference< css::ucb::XFetchProvider >
115 m_xFetchProvider; //XFetchProvider-interface from m_xOrigin
116
117 css::uno::Reference< css::ucb::XFetchProviderForContentAccess >
118 m_xFetchProviderForContentAccess; //XFetchProviderForContentAccess-interface from m_xOrigin
119
122
123
124 css::uno::Reference< css::ucb::XContentIdentifierMapping >
125 m_xContentIdentifierMapping;// can be used for remote optimized ContentAccess
126
127 //some Properties and helping variables
128 sal_Int32 m_nRow;
129 bool m_bAfterLast; // TRUE, if m_nRow is after final count; can be TRUE without knowing the exact final count
130
133
134 sal_Int32 m_nKnownCount; // count we know from the Origin
135 bool m_bFinalCount; // TRUE if the Origin has reached final count and we got that count in m_nKnownCount
136
137 sal_Int32 m_nFetchSize;
139
142
143 //cache:
148
149
150private:
151
152 //helping XPropertySet methods.
153 virtual void impl_initPropertySetInfo(std::unique_lock<std::mutex>& rGuard) override;
154
157 bool
158 applyPositionToOrigin( std::unique_lock<std::mutex>& rGuard, sal_Int32 nRow );
159
161 void
162 impl_fetchData( std::unique_lock<std::mutex>& rGuard, sal_Int32 nRow, sal_Int32 nCount
163 , sal_Int32 nFetchDirection );
164
165 bool
166 impl_isKnownValidPosition( std::unique_lock<std::mutex>& rGuard, sal_Int32 nRow ) const;
167
168 bool
169 impl_isKnownInvalidPosition( std::unique_lock<std::mutex>& rGuard, sal_Int32 nRow ) const;
170
171 void
172 impl_changeRowCount( std::unique_lock<std::mutex>& rGuard, sal_Int32 nOld, sal_Int32 nNew );
173
174 void
175 impl_changeIsRowCountFinal( std::unique_lock<std::mutex>& rGuard, bool bOld, bool bNew );
176
177public:
179 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
180 const css::uno::Reference< css::sdbc::XResultSet > & xOrigin,
181 const css::uno::Reference< css::ucb::XContentIdentifierMapping > & xContentIdentifierMapping );
182
183 virtual ~CachedContentResultSet() override;
184
185
186 // XInterface
187 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
188 virtual void SAL_CALL acquire()
189 noexcept override;
190 virtual void SAL_CALL release()
191 noexcept override;
192
193 // XTypeProvider
194
195 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
196 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
197
198 // XServiceInfo
199 virtual OUString SAL_CALL getImplementationName() override;
200 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
201 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
202
203 // XPropertySet inherited
204
205
206 virtual void
207 setPropertyValueImpl( std::unique_lock<std::mutex>& rGuard, const OUString& aPropertyName,
208 const css::uno::Any& aValue ) override;
209
210 virtual css::uno::Any SAL_CALL
211 getPropertyValue( const OUString& PropertyName ) override;
212
213
214 // own inherited
215
216 virtual void
217 impl_disposing( const css::lang::EventObject& Source ) override;
218
219 virtual void
220 impl_propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
221
222 virtual void
223 impl_vetoableChange( const css::beans::PropertyChangeEvent& aEvent ) override;
224
225
226 // XContentAccess inherited
227
228 virtual OUString
229 queryContentIdentifierStringImpl(std::unique_lock<std::mutex>& rGuard) override;
230
231 virtual css::uno::Reference<
232 css::ucb::XContentIdentifier > SAL_CALL
233 queryContentIdentifier() override;
234
235 virtual css::uno::Reference<
236 css::ucb::XContent > SAL_CALL
237 queryContent() override;
238
239
240 // XResultSet inherited
241
242 virtual sal_Bool SAL_CALL
243 next() override;
244 virtual sal_Bool SAL_CALL
245 isBeforeFirst() override;
246 virtual sal_Bool SAL_CALL
247 isAfterLast() override;
248 virtual sal_Bool SAL_CALL
249 isFirst() override;
250 virtual sal_Bool SAL_CALL
251 isLast() override;
252 virtual void SAL_CALL
253 beforeFirst() override;
254 virtual void SAL_CALL
255 afterLast() override;
256 virtual sal_Bool SAL_CALL
257 first() override;
258 virtual sal_Bool SAL_CALL
259 last() override;
260 virtual sal_Int32 SAL_CALL
261 getRow() override;
262 virtual sal_Bool SAL_CALL
263 absolute( sal_Int32 row ) override;
264 virtual sal_Bool SAL_CALL
265 relative( sal_Int32 rows ) override;
266 virtual sal_Bool SAL_CALL
267 previous() override;
268 virtual void SAL_CALL
269 refreshRow() override;
270 virtual sal_Bool SAL_CALL
271 rowUpdated() override;
272 virtual sal_Bool SAL_CALL
273 rowInserted() override;
274 virtual sal_Bool SAL_CALL
275 rowDeleted() override;
276 virtual css::uno::Reference<
277 css::uno::XInterface > SAL_CALL
278 getStatement() override;
279
280
281 // XRow inherited
282
283 virtual sal_Bool SAL_CALL
284 wasNull() override;
285
286 virtual OUString SAL_CALL
287 getString( sal_Int32 columnIndex ) override;
288
289 virtual sal_Bool SAL_CALL
290 getBoolean( sal_Int32 columnIndex ) override;
291
292 virtual sal_Int8 SAL_CALL
293 getByte( sal_Int32 columnIndex ) override;
294
295 virtual sal_Int16 SAL_CALL
296 getShort( sal_Int32 columnIndex ) override;
297
298 virtual sal_Int32 SAL_CALL
299 getInt( sal_Int32 columnIndex ) override;
300
301 virtual sal_Int64 SAL_CALL
302 getLong( sal_Int32 columnIndex ) override;
303
304 virtual float SAL_CALL
305 getFloat( sal_Int32 columnIndex ) override;
306
307 virtual double SAL_CALL
308 getDouble( sal_Int32 columnIndex ) override;
309
310 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
311 getBytes( sal_Int32 columnIndex ) override;
312
313 virtual css::util::Date SAL_CALL
314 getDate( sal_Int32 columnIndex ) override;
315
316 virtual css::util::Time SAL_CALL
317 getTime( sal_Int32 columnIndex ) override;
318
319 virtual css::util::DateTime SAL_CALL
320 getTimestamp( sal_Int32 columnIndex ) override;
321
322 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
323 getBinaryStream( sal_Int32 columnIndex ) override;
324
325 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
326 getCharacterStream( sal_Int32 columnIndex ) override;
327
328 virtual css::uno::Any SAL_CALL
329 getObject( sal_Int32 columnIndex,
330 const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
331
332 virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL
333 getRef( sal_Int32 columnIndex ) override;
334
335 virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL
336 getBlob( sal_Int32 columnIndex ) override;
337
338 virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL
339 getClob( sal_Int32 columnIndex ) override;
340
341 virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL
342 getArray( sal_Int32 columnIndex ) override;
343
344
345 // Type Converter support
346
347
348private:
350 css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
351
352 const css::uno::Reference<
353 css::script::XTypeConverter >& getTypeConverter(std::unique_lock<std::mutex>& rGuard);
354
355 template<typename T> T rowOriginGet(
356 T (SAL_CALL css::sdbc::XRow::* f)(sal_Int32), sal_Int32 columnIndex);
357};
358
359
361 public cppu::WeakImplHelper<
362 css::lang::XServiceInfo,
363 css::ucb::XCachedContentResultSetFactory>
364{
365 css::uno::Reference< css::uno::XComponentContext > m_xContext;
366
367public:
368
369 CachedContentResultSetFactory( const css::uno::Reference< css::uno::XComponentContext > & rxContext);
370
371 virtual ~CachedContentResultSetFactory() override;
372
373 // XServiceInfo
374 virtual OUString SAL_CALL getImplementationName() override;
375 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
376 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
377
378 // XCachedContentResultSetFactory
379
380 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL
381 createCachedContentResultSet(
382 const css::uno::Reference< css::sdbc::XResultSet > & xSource,
383 const css::uno::Reference< css::ucb::XContentIdentifierMapping > & xMapping ) override;
384};
385
386/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XComponentContext > m_xContext
const css::uno::Any & getAny(sal_Int32 nRow, sal_Int32 nColumnIndex)
bool hasCausedException(sal_Int32 nRow) const
css::uno::Any & getRowAny(sal_Int32 nRow)
CCRS_Cache(const css::uno::Reference< css::ucb::XContentIdentifierMapping > &xMapping)
css::uno::Sequence< sal_Bool > & getMappedReminder()
css::uno::Reference< css::ucb::XContentIdentifierMapping > m_xContentIdentifierMapping
void loadData(const css::ucb::FetchResult &rResult)
css::uno::Reference< css::ucb::XContentIdentifier > getContentIdentifier(sal_Int32 nRow)
css::uno::Reference< css::ucb::XContent > getContent(sal_Int32 nRow)
std::optional< css::uno::Sequence< sal_Bool > > m_pMappedReminder
std::optional< css::ucb::FetchResult > m_pResult
OUString const & getContentIdentifierString(sal_Int32 nRow)
virtual ~CachedContentResultSet() override
const css::uno::Reference< css::script::XTypeConverter > & getTypeConverter(std::unique_lock< std::mutex > &rGuard)
virtual void impl_propertyChange(const css::beans::PropertyChangeEvent &evt) override
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL queryContentIdentifier() override
virtual css::util::Date SAL_CALL getDate(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
bool impl_isKnownValidPosition(std::unique_lock< std::mutex > &rGuard, sal_Int32 nRow) const
bool impl_isKnownInvalidPosition(std::unique_lock< std::mutex > &rGuard, sal_Int32 nRow) const
virtual OUString queryContentIdentifierStringImpl(std::unique_lock< std::mutex > &rGuard) override
virtual float SAL_CALL getFloat(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL rowInserted() override
virtual css::util::DateTime SAL_CALL getTimestamp(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL getBoolean(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL first() override
virtual sal_Bool SAL_CALL last() override
CachedContentResultSet(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::sdbc::XResultSet > &xOrigin, const css::uno::Reference< css::ucb::XContentIdentifierMapping > &xContentIdentifierMapping)
void impl_fetchData(std::unique_lock< std::mutex > &rGuard, sal_Int32 nRow, sal_Int32 nCount, sal_Int32 nFetchDirection)
virtual sal_Bool SAL_CALL isBeforeFirst() override
virtual sal_Int16 SAL_CALL getShort(sal_Int32 columnIndex) override
virtual css::uno::Any SAL_CALL getObject(sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess > &typeMap) override
virtual void SAL_CALL release() noexcept override
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual double SAL_CALL getDouble(sal_Int32 columnIndex) override
virtual css::util::Time SAL_CALL getTime(sal_Int32 columnIndex) override
virtual void setPropertyValueImpl(std::unique_lock< std::mutex > &rGuard, const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter
virtual sal_Int32 SAL_CALL getInt(sal_Int32 columnIndex) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void impl_vetoableChange(const css::beans::PropertyChangeEvent &aEvent) override
virtual sal_Bool SAL_CALL next() override
virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray(sal_Int32 columnIndex) override
virtual OUString SAL_CALL getString(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL isFirst() override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
void impl_changeIsRowCountFinal(std::unique_lock< std::mutex > &rGuard, bool bOld, bool bNew)
css::uno::Reference< css::ucb::XFetchProvider > m_xFetchProvider
virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob(sal_Int32 columnIndex) override
virtual void SAL_CALL afterLast() override
virtual sal_Int64 SAL_CALL getLong(sal_Int32 columnIndex) override
virtual void SAL_CALL refreshRow() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement() override
T rowOriginGet(T(SAL_CALL css::sdbc::XRow::*f)(sal_Int32), sal_Int32 columnIndex)
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual void SAL_CALL beforeFirst() override
virtual sal_Bool SAL_CALL isLast() override
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL isAfterLast() override
bool applyPositionToOrigin(std::unique_lock< std::mutex > &rGuard, sal_Int32 nRow)
virtual OUString SAL_CALL getImplementationName() override
void impl_changeRowCount(std::unique_lock< std::mutex > &rGuard, sal_Int32 nOld, sal_Int32 nNew)
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL wasNull() override
virtual void SAL_CALL acquire() noexcept override
virtual sal_Int32 SAL_CALL getRow() override
virtual sal_Bool SAL_CALL rowDeleted() override
virtual sal_Bool SAL_CALL absolute(sal_Int32 row) override
virtual void impl_disposing(const css::lang::EventObject &Source) override
virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL previous() override
virtual void impl_initPropertySetInfo(std::unique_lock< std::mutex > &rGuard) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual sal_Bool SAL_CALL rowUpdated() override
css::uno::Reference< css::ucb::XContentIdentifierMapping > m_xContentIdentifierMapping
virtual sal_Bool SAL_CALL relative(sal_Int32 rows) override
css::uno::Reference< css::ucb::XFetchProviderForContentAccess > m_xFetchProviderForContentAccess
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob(sal_Int32 columnIndex) override
rtl::Reference< CCRS_PropertySetInfo > m_xMyPropertySetInfo
virtual sal_Int8 SAL_CALL getByte(sal_Int32 columnIndex) override
Type
unsigned char sal_Bool
signed char sal_Int8