lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / ucb / source / cacher / cachedcontentresultset.hxx
blob174fb91ff5683370d92a10e8adeaa0face0990c0
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/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 <rtl/ref.hxx>
33 #include <memory>
35 #define CACHED_CONTENT_RESULTSET_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSet"
36 #define CACHED_CONTENT_RESULTSET_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetFactory"
39 namespace com { namespace sun { namespace star { namespace script {
40 class XTypeConverter;
41 } } } }
43 class CCRS_PropertySetInfo;
44 class CachedContentResultSet
45 : public ContentResultSetWrapper
46 , public css::lang::XTypeProvider
47 , public css::lang::XServiceInfo
50 // class CCRS_Cache
52 class CCRS_Cache
54 private:
55 std::unique_ptr<css::ucb::FetchResult>
56 m_pResult;
57 css::uno::Reference< css::ucb::XContentIdentifierMapping >
58 m_xContentIdentifierMapping;
59 std::unique_ptr<css::uno::Sequence< sal_Bool >> m_pMappedReminder;
61 private:
62 /// @throws css::sdbc::SQLException
63 /// @throws css::uno::RuntimeException
64 css::uno::Any&
65 getRowAny( sal_Int32 nRow );
67 void clear();
70 void remindMapped( sal_Int32 nRow );
71 bool isRowMapped( sal_Int32 nRow );
72 void clearMappedReminder();
73 css::uno::Sequence< sal_Bool >* getMappedReminder();
75 public:
76 CCRS_Cache( const css::uno::Reference<
77 css::ucb::XContentIdentifierMapping > & xMapping );
78 ~CCRS_Cache();
80 void loadData(
81 const css::ucb::FetchResult& rResult );
83 bool
84 hasRow( sal_Int32 nRow );
86 bool
87 hasCausedException( sal_Int32 nRow );
89 sal_Int32
90 getMaxRow();
92 bool
93 hasKnownLast();
95 /// @throws css::sdbc::SQLException
96 /// @throws css::uno::RuntimeException
97 const css::uno::Any&
98 getAny( sal_Int32 nRow, sal_Int32 nColumnIndex );
100 /// @throws css::uno::RuntimeException
101 OUString const &
102 getContentIdentifierString( sal_Int32 nRow );
104 /// @throws css::uno::RuntimeException
105 css::uno::Reference< css::ucb::XContentIdentifier >
106 getContentIdentifier( sal_Int32 nRow );
108 /// @throws css::uno::RuntimeException
109 css::uno::Reference< css::ucb::XContent >
110 getContent( sal_Int32 nRow );
113 //members
115 css::uno::Reference< css::uno::XComponentContext >
116 m_xContext;
118 //different Interfaces from Origin:
119 css::uno::Reference< css::ucb::XFetchProvider >
120 m_xFetchProvider; //XFetchProvider-interface from m_xOrigin
122 css::uno::Reference< css::ucb::XFetchProviderForContentAccess >
123 m_xFetchProviderForContentAccess; //XFetchProviderForContentAccess-interface from m_xOrigin
125 rtl::Reference< CCRS_PropertySetInfo >
126 m_xMyPropertySetInfo;
129 css::uno::Reference< css::ucb::XContentIdentifierMapping >
130 m_xContentIdentifierMapping;// can be used for remote optimized ContentAccess
132 //some Properties and helping variables
133 sal_Int32 m_nRow;
134 bool m_bAfterLast; // TRUE, if m_nRow is after final count; can be TRUE without knowing the exact final count
136 sal_Int32 m_nLastAppliedPos;
137 bool m_bAfterLastApplied;
139 sal_Int32 m_nKnownCount; // count we know from the Origin
140 bool m_bFinalCount; // TRUE if the Origin has reached final count and we got that count in m_nKnownCount
142 sal_Int32 m_nFetchSize;
143 sal_Int32 m_nFetchDirection;
145 bool m_bLastReadWasFromCache;
146 bool m_bLastCachedReadWasNull;
148 //cache:
149 CCRS_Cache m_aCache;
150 CCRS_Cache m_aCacheContentIdentifierString;
151 CCRS_Cache m_aCacheContentIdentifier;
152 CCRS_Cache m_aCacheContent;
155 private:
157 //helping XPropertySet methods.
158 virtual void impl_initPropertySetInfo() override;
160 /// @throws css::sdbc::SQLException
161 /// @throws css::uno::RuntimeException
162 bool
163 applyPositionToOrigin( sal_Int32 nRow );
165 /// @throws css::uno::RuntimeException
166 void
167 impl_fetchData( sal_Int32 nRow, sal_Int32 nCount
168 , sal_Int32 nFetchDirection );
170 bool
171 impl_isKnownValidPosition( sal_Int32 nRow );
173 bool
174 impl_isKnownInvalidPosition( sal_Int32 nRow );
176 void
177 impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew );
179 void
180 impl_changeIsRowCountFinal( bool bOld, bool bNew );
182 public:
183 CachedContentResultSet(
184 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
185 const css::uno::Reference< css::sdbc::XResultSet > & xOrigin,
186 const css::uno::Reference< css::ucb::XContentIdentifierMapping > & xContentIdentifierMapping );
188 virtual ~CachedContentResultSet() override;
191 // XInterface
192 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
193 virtual void SAL_CALL acquire()
194 throw() override;
195 virtual void SAL_CALL release()
196 throw() override;
198 // XTypeProvider
200 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
201 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
203 // XServiceInfo
204 virtual OUString SAL_CALL getImplementationName() override;
205 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
206 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
208 // XPropertySet inherited
211 virtual void SAL_CALL
212 setPropertyValue( const OUString& aPropertyName,
213 const css::uno::Any& aValue ) override;
215 virtual css::uno::Any SAL_CALL
216 getPropertyValue( const OUString& PropertyName ) override;
219 // own inherited
221 virtual void
222 impl_disposing( const css::lang::EventObject& Source ) override;
224 virtual void
225 impl_propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
227 virtual void
228 impl_vetoableChange( const css::beans::PropertyChangeEvent& aEvent ) override;
231 // XContentAccess inherited
233 virtual OUString SAL_CALL
234 queryContentIdentifierString() override;
236 virtual css::uno::Reference<
237 css::ucb::XContentIdentifier > SAL_CALL
238 queryContentIdentifier() override;
240 virtual css::uno::Reference<
241 css::ucb::XContent > SAL_CALL
242 queryContent() override;
245 // XResultSet inherited
247 virtual sal_Bool SAL_CALL
248 next() override;
249 virtual sal_Bool SAL_CALL
250 isBeforeFirst() override;
251 virtual sal_Bool SAL_CALL
252 isAfterLast() override;
253 virtual sal_Bool SAL_CALL
254 isFirst() override;
255 virtual sal_Bool SAL_CALL
256 isLast() override;
257 virtual void SAL_CALL
258 beforeFirst() override;
259 virtual void SAL_CALL
260 afterLast() override;
261 virtual sal_Bool SAL_CALL
262 first() override;
263 virtual sal_Bool SAL_CALL
264 last() override;
265 virtual sal_Int32 SAL_CALL
266 getRow() override;
267 virtual sal_Bool SAL_CALL
268 absolute( sal_Int32 row ) override;
269 virtual sal_Bool SAL_CALL
270 relative( sal_Int32 rows ) override;
271 virtual sal_Bool SAL_CALL
272 previous() override;
273 virtual void SAL_CALL
274 refreshRow() override;
275 virtual sal_Bool SAL_CALL
276 rowUpdated() override;
277 virtual sal_Bool SAL_CALL
278 rowInserted() override;
279 virtual sal_Bool SAL_CALL
280 rowDeleted() override;
281 virtual css::uno::Reference<
282 css::uno::XInterface > SAL_CALL
283 getStatement() override;
286 // XRow inherited
288 virtual sal_Bool SAL_CALL
289 wasNull() override;
291 virtual OUString SAL_CALL
292 getString( sal_Int32 columnIndex ) override;
294 virtual sal_Bool SAL_CALL
295 getBoolean( sal_Int32 columnIndex ) override;
297 virtual sal_Int8 SAL_CALL
298 getByte( sal_Int32 columnIndex ) override;
300 virtual sal_Int16 SAL_CALL
301 getShort( sal_Int32 columnIndex ) override;
303 virtual sal_Int32 SAL_CALL
304 getInt( sal_Int32 columnIndex ) override;
306 virtual sal_Int64 SAL_CALL
307 getLong( sal_Int32 columnIndex ) override;
309 virtual float SAL_CALL
310 getFloat( sal_Int32 columnIndex ) override;
312 virtual double SAL_CALL
313 getDouble( sal_Int32 columnIndex ) override;
315 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
316 getBytes( sal_Int32 columnIndex ) override;
318 virtual css::util::Date SAL_CALL
319 getDate( sal_Int32 columnIndex ) override;
321 virtual css::util::Time SAL_CALL
322 getTime( sal_Int32 columnIndex ) override;
324 virtual css::util::DateTime SAL_CALL
325 getTimestamp( sal_Int32 columnIndex ) override;
327 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
328 getBinaryStream( sal_Int32 columnIndex ) override;
330 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
331 getCharacterStream( sal_Int32 columnIndex ) override;
333 virtual css::uno::Any SAL_CALL
334 getObject( sal_Int32 columnIndex,
335 const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
337 virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL
338 getRef( sal_Int32 columnIndex ) override;
340 virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL
341 getBlob( sal_Int32 columnIndex ) override;
343 virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL
344 getClob( sal_Int32 columnIndex ) override;
346 virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL
347 getArray( sal_Int32 columnIndex ) override;
350 // Type Converter support
353 private:
354 bool m_bTriedToGetTypeConverter;
355 css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
357 const css::uno::Reference<
358 css::script::XTypeConverter >& getTypeConverter();
360 template<typename T> T rowOriginGet(
361 T (SAL_CALL css::sdbc::XRow::* f)(sal_Int32), sal_Int32 columnIndex);
365 class CachedContentResultSetFactory final
366 : public cppu::OWeakObject
367 , public css::lang::XTypeProvider
368 , public css::lang::XServiceInfo
369 , public css::ucb::XCachedContentResultSetFactory
371 css::uno::Reference< css::uno::XComponentContext > m_xContext;
373 public:
375 CachedContentResultSetFactory( const css::uno::Reference< css::uno::XComponentContext > & rxContext);
377 virtual ~CachedContentResultSetFactory() override;
380 // XInterface
381 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
382 virtual void SAL_CALL acquire()
383 throw() override;
384 virtual void SAL_CALL release()
385 throw() override;
387 // XTypeProvider
388 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
389 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
391 // XServiceInfo
392 virtual OUString SAL_CALL getImplementationName() override;
393 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
394 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
396 static OUString getImplementationName_Static();
397 static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
399 static css::uno::Reference< css::lang::XSingleServiceFactory >
400 createServiceFactory( const css::uno::Reference<
401 css::lang::XMultiServiceFactory >& rxServiceMgr );
403 // XCachedContentResultSetFactory
405 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL
406 createCachedContentResultSet(
407 const css::uno::Reference< css::sdbc::XResultSet > & xSource,
408 const css::uno::Reference< css::ucb::XContentIdentifierMapping > & xMapping ) override;
411 #endif
413 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */