Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / ucb / source / cacher / cachedcontentresultset.hxx
blob3e450f4d01ea588671bffa3da05793c250464686
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_UCB_SOURCE_CACHER_CACHEDCONTENTRESULTSET_HXX
21 #define INCLUDED_UCB_SOURCE_CACHER_CACHEDCONTENTRESULTSET_HXX
23 #include "contentresultsetwrapper.hxx"
24 #include <com/sun/star/uno/XComponentContext.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/lang/XTypeProvider.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
29 #include <com/sun/star/ucb/XFetchProvider.hpp>
30 #include <com/sun/star/ucb/XFetchProviderForContentAccess.hpp>
31 #include <com/sun/star/ucb/FetchResult.hpp>
32 #include <com/sun/star/ucb/XContentIdentifierMapping.hpp>
33 #include <com/sun/star/ucb/XCachedContentResultSetFactory.hpp>
34 #include <cppuhelper/implbase.hxx>
35 #include <rtl/ref.hxx>
37 #include <memory>
39 #define CACHED_CONTENT_RESULTSET_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSet"
40 #define CACHED_CONTENT_RESULTSET_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetFactory"
43 namespace com { namespace sun { namespace star { namespace script {
44 class XTypeConverter;
45 } } } }
47 class CCRS_PropertySetInfo;
48 class CachedContentResultSet
49 : public ContentResultSetWrapper
50 , public css::lang::XTypeProvider
51 , public css::lang::XServiceInfo
54 // class CCRS_Cache
56 class CCRS_Cache
58 private:
59 std::unique_ptr<css::ucb::FetchResult>
60 m_pResult;
61 css::uno::Reference< css::ucb::XContentIdentifierMapping >
62 m_xContentIdentifierMapping;
63 std::unique_ptr<css::uno::Sequence< sal_Bool >> m_pMappedReminder;
65 private:
66 /// @throws css::sdbc::SQLException
67 /// @throws css::uno::RuntimeException
68 css::uno::Any&
69 getRowAny( sal_Int32 nRow );
71 void clear();
74 void remindMapped( sal_Int32 nRow );
75 bool isRowMapped( sal_Int32 nRow );
76 void clearMappedReminder();
77 css::uno::Sequence< sal_Bool >* getMappedReminder();
79 public:
80 CCRS_Cache( const css::uno::Reference<
81 css::ucb::XContentIdentifierMapping > & xMapping );
82 ~CCRS_Cache();
84 void loadData(
85 const css::ucb::FetchResult& rResult );
87 bool
88 hasRow( sal_Int32 nRow );
90 bool
91 hasCausedException( sal_Int32 nRow );
93 sal_Int32
94 getMaxRow() const;
96 bool
97 hasKnownLast() const;
99 /// @throws css::sdbc::SQLException
100 /// @throws css::uno::RuntimeException
101 const css::uno::Any&
102 getAny( sal_Int32 nRow, sal_Int32 nColumnIndex );
104 /// @throws css::uno::RuntimeException
105 OUString const &
106 getContentIdentifierString( sal_Int32 nRow );
108 /// @throws css::uno::RuntimeException
109 css::uno::Reference< css::ucb::XContentIdentifier >
110 getContentIdentifier( sal_Int32 nRow );
112 /// @throws css::uno::RuntimeException
113 css::uno::Reference< css::ucb::XContent >
114 getContent( sal_Int32 nRow );
117 //members
119 css::uno::Reference< css::uno::XComponentContext >
120 m_xContext;
122 //different Interfaces from Origin:
123 css::uno::Reference< css::ucb::XFetchProvider >
124 m_xFetchProvider; //XFetchProvider-interface from m_xOrigin
126 css::uno::Reference< css::ucb::XFetchProviderForContentAccess >
127 m_xFetchProviderForContentAccess; //XFetchProviderForContentAccess-interface from m_xOrigin
129 rtl::Reference< CCRS_PropertySetInfo >
130 m_xMyPropertySetInfo;
133 css::uno::Reference< css::ucb::XContentIdentifierMapping >
134 m_xContentIdentifierMapping;// can be used for remote optimized ContentAccess
136 //some Properties and helping variables
137 sal_Int32 m_nRow;
138 bool m_bAfterLast; // TRUE, if m_nRow is after final count; can be TRUE without knowing the exact final count
140 sal_Int32 m_nLastAppliedPos;
141 bool m_bAfterLastApplied;
143 sal_Int32 m_nKnownCount; // count we know from the Origin
144 bool m_bFinalCount; // TRUE if the Origin has reached final count and we got that count in m_nKnownCount
146 sal_Int32 m_nFetchSize;
147 sal_Int32 m_nFetchDirection;
149 bool m_bLastReadWasFromCache;
150 bool m_bLastCachedReadWasNull;
152 //cache:
153 CCRS_Cache m_aCache;
154 CCRS_Cache m_aCacheContentIdentifierString;
155 CCRS_Cache m_aCacheContentIdentifier;
156 CCRS_Cache m_aCacheContent;
159 private:
161 //helping XPropertySet methods.
162 virtual void impl_initPropertySetInfo() override;
164 /// @throws css::sdbc::SQLException
165 /// @throws css::uno::RuntimeException
166 bool
167 applyPositionToOrigin( sal_Int32 nRow );
169 /// @throws css::uno::RuntimeException
170 void
171 impl_fetchData( sal_Int32 nRow, sal_Int32 nCount
172 , sal_Int32 nFetchDirection );
174 bool
175 impl_isKnownValidPosition( sal_Int32 nRow );
177 bool
178 impl_isKnownInvalidPosition( sal_Int32 nRow );
180 void
181 impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew );
183 void
184 impl_changeIsRowCountFinal( bool bOld, bool bNew );
186 public:
187 CachedContentResultSet(
188 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
189 const css::uno::Reference< css::sdbc::XResultSet > & xOrigin,
190 const css::uno::Reference< css::ucb::XContentIdentifierMapping > & xContentIdentifierMapping );
192 virtual ~CachedContentResultSet() override;
195 // XInterface
196 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
197 virtual void SAL_CALL acquire()
198 throw() override;
199 virtual void SAL_CALL release()
200 throw() override;
202 // XTypeProvider
204 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
205 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
207 // XServiceInfo
208 virtual OUString SAL_CALL getImplementationName() override;
209 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
210 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
212 // XPropertySet inherited
215 virtual void SAL_CALL
216 setPropertyValue( const OUString& aPropertyName,
217 const css::uno::Any& aValue ) override;
219 virtual css::uno::Any SAL_CALL
220 getPropertyValue( const OUString& PropertyName ) override;
223 // own inherited
225 virtual void
226 impl_disposing( const css::lang::EventObject& Source ) override;
228 virtual void
229 impl_propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
231 virtual void
232 impl_vetoableChange( const css::beans::PropertyChangeEvent& aEvent ) override;
235 // XContentAccess inherited
237 virtual OUString SAL_CALL
238 queryContentIdentifierString() override;
240 virtual css::uno::Reference<
241 css::ucb::XContentIdentifier > SAL_CALL
242 queryContentIdentifier() override;
244 virtual css::uno::Reference<
245 css::ucb::XContent > SAL_CALL
246 queryContent() override;
249 // XResultSet inherited
251 virtual sal_Bool SAL_CALL
252 next() override;
253 virtual sal_Bool SAL_CALL
254 isBeforeFirst() override;
255 virtual sal_Bool SAL_CALL
256 isAfterLast() override;
257 virtual sal_Bool SAL_CALL
258 isFirst() override;
259 virtual sal_Bool SAL_CALL
260 isLast() override;
261 virtual void SAL_CALL
262 beforeFirst() override;
263 virtual void SAL_CALL
264 afterLast() override;
265 virtual sal_Bool SAL_CALL
266 first() override;
267 virtual sal_Bool SAL_CALL
268 last() override;
269 virtual sal_Int32 SAL_CALL
270 getRow() override;
271 virtual sal_Bool SAL_CALL
272 absolute( sal_Int32 row ) override;
273 virtual sal_Bool SAL_CALL
274 relative( sal_Int32 rows ) override;
275 virtual sal_Bool SAL_CALL
276 previous() override;
277 virtual void SAL_CALL
278 refreshRow() override;
279 virtual sal_Bool SAL_CALL
280 rowUpdated() override;
281 virtual sal_Bool SAL_CALL
282 rowInserted() override;
283 virtual sal_Bool SAL_CALL
284 rowDeleted() override;
285 virtual css::uno::Reference<
286 css::uno::XInterface > SAL_CALL
287 getStatement() override;
290 // XRow inherited
292 virtual sal_Bool SAL_CALL
293 wasNull() override;
295 virtual OUString SAL_CALL
296 getString( sal_Int32 columnIndex ) override;
298 virtual sal_Bool SAL_CALL
299 getBoolean( sal_Int32 columnIndex ) override;
301 virtual sal_Int8 SAL_CALL
302 getByte( sal_Int32 columnIndex ) override;
304 virtual sal_Int16 SAL_CALL
305 getShort( sal_Int32 columnIndex ) override;
307 virtual sal_Int32 SAL_CALL
308 getInt( sal_Int32 columnIndex ) override;
310 virtual sal_Int64 SAL_CALL
311 getLong( sal_Int32 columnIndex ) override;
313 virtual float SAL_CALL
314 getFloat( sal_Int32 columnIndex ) override;
316 virtual double SAL_CALL
317 getDouble( sal_Int32 columnIndex ) override;
319 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
320 getBytes( sal_Int32 columnIndex ) override;
322 virtual css::util::Date SAL_CALL
323 getDate( sal_Int32 columnIndex ) override;
325 virtual css::util::Time SAL_CALL
326 getTime( sal_Int32 columnIndex ) override;
328 virtual css::util::DateTime SAL_CALL
329 getTimestamp( sal_Int32 columnIndex ) override;
331 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
332 getBinaryStream( sal_Int32 columnIndex ) override;
334 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
335 getCharacterStream( sal_Int32 columnIndex ) override;
337 virtual css::uno::Any SAL_CALL
338 getObject( sal_Int32 columnIndex,
339 const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
341 virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL
342 getRef( sal_Int32 columnIndex ) override;
344 virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL
345 getBlob( sal_Int32 columnIndex ) override;
347 virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL
348 getClob( sal_Int32 columnIndex ) override;
350 virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL
351 getArray( sal_Int32 columnIndex ) override;
354 // Type Converter support
357 private:
358 bool m_bTriedToGetTypeConverter;
359 css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
361 const css::uno::Reference<
362 css::script::XTypeConverter >& getTypeConverter();
364 template<typename T> T rowOriginGet(
365 T (SAL_CALL css::sdbc::XRow::* f)(sal_Int32), sal_Int32 columnIndex);
369 class CachedContentResultSetFactory final :
370 public cppu::WeakImplHelper<
371 css::lang::XServiceInfo,
372 css::ucb::XCachedContentResultSetFactory>
374 css::uno::Reference< css::uno::XComponentContext > m_xContext;
376 public:
378 CachedContentResultSetFactory( const css::uno::Reference< css::uno::XComponentContext > & rxContext);
380 virtual ~CachedContentResultSetFactory() override;
382 // XServiceInfo
383 virtual OUString SAL_CALL getImplementationName() override;
384 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
385 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
387 static OUString getImplementationName_Static();
388 static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
390 static css::uno::Reference< css::lang::XSingleServiceFactory >
391 createServiceFactory( const css::uno::Reference<
392 css::lang::XMultiServiceFactory >& rxServiceMgr );
394 // XCachedContentResultSetFactory
396 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL
397 createCachedContentResultSet(
398 const css::uno::Reference< css::sdbc::XResultSet > & xSource,
399 const css::uno::Reference< css::ucb::XContentIdentifierMapping > & xMapping ) override;
402 #endif
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */