bump product version to 7.6.3.2-android
[LibreOffice.git] / ucb / source / cacher / cachedcontentresultset.hxx
blob4bca955ee76e9f4102534e34d00f5efc4225a7d8
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 #pragma once
22 #include "contentresultsetwrapper.hxx"
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>
31 #include <cppuhelper/implbase.hxx>
32 #include <rtl/ref.hxx>
34 #include <optional>
36 namespace com::sun::star::script {
37 class XTypeConverter;
40 class CCRS_PropertySetInfo;
41 class CachedContentResultSet
42 : public ContentResultSetWrapper
43 , public css::lang::XTypeProvider
44 , public css::lang::XServiceInfo
48 class CCRS_Cache
50 private:
51 std::optional<css::ucb::FetchResult>
52 m_pResult;
53 css::uno::Reference< css::ucb::XContentIdentifierMapping >
54 m_xContentIdentifierMapping;
55 std::optional<css::uno::Sequence< sal_Bool >> m_pMappedReminder;
57 private:
58 /// @throws css::sdbc::SQLException
59 /// @throws css::uno::RuntimeException
60 css::uno::Any&
61 getRowAny( sal_Int32 nRow );
63 void clear();
66 void remindMapped( sal_Int32 nRow );
67 bool isRowMapped( sal_Int32 nRow );
68 css::uno::Sequence< sal_Bool >& getMappedReminder();
70 public:
71 CCRS_Cache( const css::uno::Reference<
72 css::ucb::XContentIdentifierMapping > & xMapping );
73 ~CCRS_Cache();
75 void loadData(
76 const css::ucb::FetchResult& rResult );
78 bool
79 hasRow( sal_Int32 nRow ) const;
81 bool
82 hasCausedException( sal_Int32 nRow ) const;
84 sal_Int32
85 getMaxRow() const;
87 bool
88 hasKnownLast() const;
90 /// @throws css::sdbc::SQLException
91 /// @throws css::uno::RuntimeException
92 const css::uno::Any&
93 getAny( sal_Int32 nRow, sal_Int32 nColumnIndex );
95 /// @throws css::uno::RuntimeException
96 OUString const &
97 getContentIdentifierString( sal_Int32 nRow );
99 /// @throws css::uno::RuntimeException
100 css::uno::Reference< css::ucb::XContentIdentifier >
101 getContentIdentifier( sal_Int32 nRow );
103 /// @throws css::uno::RuntimeException
104 css::uno::Reference< css::ucb::XContent >
105 getContent( sal_Int32 nRow );
108 //members
110 css::uno::Reference< css::uno::XComponentContext >
111 m_xContext;
113 //different Interfaces from Origin:
114 css::uno::Reference< css::ucb::XFetchProvider >
115 m_xFetchProvider; //XFetchProvider-interface from m_xOrigin
117 css::uno::Reference< css::ucb::XFetchProviderForContentAccess >
118 m_xFetchProviderForContentAccess; //XFetchProviderForContentAccess-interface from m_xOrigin
120 rtl::Reference< CCRS_PropertySetInfo >
121 m_xMyPropertySetInfo;
124 css::uno::Reference< css::ucb::XContentIdentifierMapping >
125 m_xContentIdentifierMapping;// can be used for remote optimized ContentAccess
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
131 sal_Int32 m_nLastAppliedPos;
132 bool m_bAfterLastApplied;
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
137 sal_Int32 m_nFetchSize;
138 sal_Int32 m_nFetchDirection;
140 bool m_bLastReadWasFromCache;
141 bool m_bLastCachedReadWasNull;
143 //cache:
144 CCRS_Cache m_aCache;
145 CCRS_Cache m_aCacheContentIdentifierString;
146 CCRS_Cache m_aCacheContentIdentifier;
147 CCRS_Cache m_aCacheContent;
150 private:
152 //helping XPropertySet methods.
153 virtual void impl_initPropertySetInfo(std::unique_lock<std::mutex>& rGuard) override;
155 /// @throws css::sdbc::SQLException
156 /// @throws css::uno::RuntimeException
157 bool
158 applyPositionToOrigin( std::unique_lock<std::mutex>& rGuard, sal_Int32 nRow );
160 /// @throws css::uno::RuntimeException
161 void
162 impl_fetchData( std::unique_lock<std::mutex>& rGuard, sal_Int32 nRow, sal_Int32 nCount
163 , sal_Int32 nFetchDirection );
165 bool
166 impl_isKnownValidPosition( std::unique_lock<std::mutex>& rGuard, sal_Int32 nRow ) const;
168 bool
169 impl_isKnownInvalidPosition( std::unique_lock<std::mutex>& rGuard, sal_Int32 nRow ) const;
171 void
172 impl_changeRowCount( std::unique_lock<std::mutex>& rGuard, sal_Int32 nOld, sal_Int32 nNew );
174 void
175 impl_changeIsRowCountFinal( std::unique_lock<std::mutex>& rGuard, bool bOld, bool bNew );
177 public:
178 CachedContentResultSet(
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 );
183 virtual ~CachedContentResultSet() override;
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;
193 // XTypeProvider
195 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
196 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
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;
203 // XPropertySet inherited
206 virtual void
207 setPropertyValueImpl( std::unique_lock<std::mutex>& rGuard, const OUString& aPropertyName,
208 const css::uno::Any& aValue ) override;
210 virtual css::uno::Any SAL_CALL
211 getPropertyValue( const OUString& PropertyName ) override;
214 // own inherited
216 virtual void
217 impl_disposing( const css::lang::EventObject& Source ) override;
219 virtual void
220 impl_propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
222 virtual void
223 impl_vetoableChange( const css::beans::PropertyChangeEvent& aEvent ) override;
226 // XContentAccess inherited
228 virtual OUString
229 queryContentIdentifierStringImpl(std::unique_lock<std::mutex>& rGuard) override;
231 virtual css::uno::Reference<
232 css::ucb::XContentIdentifier > SAL_CALL
233 queryContentIdentifier() override;
235 virtual css::uno::Reference<
236 css::ucb::XContent > SAL_CALL
237 queryContent() override;
240 // XResultSet inherited
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;
281 // XRow inherited
283 virtual sal_Bool SAL_CALL
284 wasNull() override;
286 virtual OUString SAL_CALL
287 getString( sal_Int32 columnIndex ) override;
289 virtual sal_Bool SAL_CALL
290 getBoolean( sal_Int32 columnIndex ) override;
292 virtual sal_Int8 SAL_CALL
293 getByte( sal_Int32 columnIndex ) override;
295 virtual sal_Int16 SAL_CALL
296 getShort( sal_Int32 columnIndex ) override;
298 virtual sal_Int32 SAL_CALL
299 getInt( sal_Int32 columnIndex ) override;
301 virtual sal_Int64 SAL_CALL
302 getLong( sal_Int32 columnIndex ) override;
304 virtual float SAL_CALL
305 getFloat( sal_Int32 columnIndex ) override;
307 virtual double SAL_CALL
308 getDouble( sal_Int32 columnIndex ) override;
310 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
311 getBytes( sal_Int32 columnIndex ) override;
313 virtual css::util::Date SAL_CALL
314 getDate( sal_Int32 columnIndex ) override;
316 virtual css::util::Time SAL_CALL
317 getTime( sal_Int32 columnIndex ) override;
319 virtual css::util::DateTime SAL_CALL
320 getTimestamp( sal_Int32 columnIndex ) override;
322 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
323 getBinaryStream( sal_Int32 columnIndex ) override;
325 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
326 getCharacterStream( sal_Int32 columnIndex ) override;
328 virtual css::uno::Any SAL_CALL
329 getObject( sal_Int32 columnIndex,
330 const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
332 virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL
333 getRef( sal_Int32 columnIndex ) override;
335 virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL
336 getBlob( sal_Int32 columnIndex ) override;
338 virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL
339 getClob( sal_Int32 columnIndex ) override;
341 virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL
342 getArray( sal_Int32 columnIndex ) override;
345 // Type Converter support
348 private:
349 bool m_bTriedToGetTypeConverter;
350 css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
352 const css::uno::Reference<
353 css::script::XTypeConverter >& getTypeConverter(std::unique_lock<std::mutex>& rGuard);
355 template<typename T> T rowOriginGet(
356 T (SAL_CALL css::sdbc::XRow::* f)(sal_Int32), sal_Int32 columnIndex);
360 class CachedContentResultSetFactory final :
361 public cppu::WeakImplHelper<
362 css::lang::XServiceInfo,
363 css::ucb::XCachedContentResultSetFactory>
365 css::uno::Reference< css::uno::XComponentContext > m_xContext;
367 public:
369 CachedContentResultSetFactory( const css::uno::Reference< css::uno::XComponentContext > & rxContext);
371 virtual ~CachedContentResultSetFactory() override;
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;
378 // XCachedContentResultSetFactory
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;
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */