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 #ifndef INCLUDED_UCB_SOURCE_CACHER_CACHEDCONTENTRESULTSET_HXX
21 #define INCLUDED_UCB_SOURCE_CACHER_CACHEDCONTENTRESULTSET_HXX
22 
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>
36 
37 #include <memory>
38 
39 #define CACHED_CONTENT_RESULTSET_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSet"
40 #define CACHED_CONTENT_RESULTSET_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetFactory"
41 
42 
43 namespace com { namespace sun { namespace star { namespace script {
44  class XTypeConverter;
45 } } } }
46 
50  , public css::lang::XTypeProvider
51  , public css::lang::XServiceInfo
52 {
53 
54  // class CCRS_Cache
55 
56  class CCRS_Cache
57  {
58  private:
59  std::unique_ptr<css::ucb::FetchResult>
61  css::uno::Reference< css::ucb::XContentIdentifierMapping >
63  std::unique_ptr<css::uno::Sequence< sal_Bool >> m_pMappedReminder;
64 
65  private:
68  css::uno::Any&
69  getRowAny( sal_Int32 nRow );
70 
71  void clear();
72 
73 
74  void remindMapped( sal_Int32 nRow );
75  bool isRowMapped( sal_Int32 nRow );
76  void clearMappedReminder();
77  css::uno::Sequence< sal_Bool >* getMappedReminder();
78 
79  public:
80  CCRS_Cache( const css::uno::Reference<
81  css::ucb::XContentIdentifierMapping > & xMapping );
82  ~CCRS_Cache();
83 
84  void loadData(
85  const css::ucb::FetchResult& rResult );
86 
87  bool
88  hasRow( sal_Int32 nRow );
89 
90  bool
91  hasCausedException( sal_Int32 nRow );
92 
93  sal_Int32
94  getMaxRow() const;
95 
96  bool
97  hasKnownLast() const;
98 
101  const css::uno::Any&
102  getAny( sal_Int32 nRow, sal_Int32 nColumnIndex );
103 
105  OUString const &
106  getContentIdentifierString( sal_Int32 nRow );
107 
109  css::uno::Reference< css::ucb::XContentIdentifier >
110  getContentIdentifier( sal_Int32 nRow );
111 
113  css::uno::Reference< css::ucb::XContent >
114  getContent( sal_Int32 nRow );
115  };
116 
117  //members
118 
119  css::uno::Reference< css::uno::XComponentContext >
121 
122  //different Interfaces from Origin:
123  css::uno::Reference< css::ucb::XFetchProvider >
124  m_xFetchProvider; //XFetchProvider-interface from m_xOrigin
125 
126  css::uno::Reference< css::ucb::XFetchProviderForContentAccess >
127  m_xFetchProviderForContentAccess; //XFetchProviderForContentAccess-interface from m_xOrigin
128 
131 
132 
133  css::uno::Reference< css::ucb::XContentIdentifierMapping >
134  m_xContentIdentifierMapping;// can be used for remote optimized ContentAccess
135 
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
139 
140  sal_Int32 m_nLastAppliedPos;
142 
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
145 
146  sal_Int32 m_nFetchSize;
147  sal_Int32 m_nFetchDirection;
148 
151 
152  //cache:
157 
158 
159 private:
160 
161  //helping XPropertySet methods.
162  virtual void impl_initPropertySetInfo() override;
163 
166  bool
167  applyPositionToOrigin( sal_Int32 nRow );
168 
170  void
171  impl_fetchData( sal_Int32 nRow, sal_Int32 nCount
172  , sal_Int32 nFetchDirection );
173 
174  bool
175  impl_isKnownValidPosition( sal_Int32 nRow );
176 
177  bool
178  impl_isKnownInvalidPosition( sal_Int32 nRow );
179 
180  void
181  impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew );
182 
183  void
184  impl_changeIsRowCountFinal( bool bOld, bool bNew );
185 
186 public:
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 );
191 
192  virtual ~CachedContentResultSet() override;
193 
194 
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;
201 
202  // XTypeProvider
203 
204  virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
205  virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
206 
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;
211 
212  // XPropertySet inherited
213 
214 
215  virtual void SAL_CALL
216  setPropertyValue( const OUString& aPropertyName,
217  const css::uno::Any& aValue ) override;
218 
219  virtual css::uno::Any SAL_CALL
220  getPropertyValue( const OUString& PropertyName ) override;
221 
222 
223  // own inherited
224 
225  virtual void
226  impl_disposing( const css::lang::EventObject& Source ) override;
227 
228  virtual void
229  impl_propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
230 
231  virtual void
232  impl_vetoableChange( const css::beans::PropertyChangeEvent& aEvent ) override;
233 
234 
235  // XContentAccess inherited
236 
237  virtual OUString SAL_CALL
238  queryContentIdentifierString() override;
239 
240  virtual css::uno::Reference<
241  css::ucb::XContentIdentifier > SAL_CALL
242  queryContentIdentifier() override;
243 
244  virtual css::uno::Reference<
245  css::ucb::XContent > SAL_CALL
246  queryContent() override;
247 
248 
249  // XResultSet inherited
250 
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;
288 
289 
290  // XRow inherited
291 
292  virtual sal_Bool SAL_CALL
293  wasNull() override;
294 
295  virtual OUString SAL_CALL
296  getString( sal_Int32 columnIndex ) override;
297 
298  virtual sal_Bool SAL_CALL
299  getBoolean( sal_Int32 columnIndex ) override;
300 
301  virtual sal_Int8 SAL_CALL
302  getByte( sal_Int32 columnIndex ) override;
303 
304  virtual sal_Int16 SAL_CALL
305  getShort( sal_Int32 columnIndex ) override;
306 
307  virtual sal_Int32 SAL_CALL
308  getInt( sal_Int32 columnIndex ) override;
309 
310  virtual sal_Int64 SAL_CALL
311  getLong( sal_Int32 columnIndex ) override;
312 
313  virtual float SAL_CALL
314  getFloat( sal_Int32 columnIndex ) override;
315 
316  virtual double SAL_CALL
317  getDouble( sal_Int32 columnIndex ) override;
318 
319  virtual css::uno::Sequence< sal_Int8 > SAL_CALL
320  getBytes( sal_Int32 columnIndex ) override;
321 
322  virtual css::util::Date SAL_CALL
323  getDate( sal_Int32 columnIndex ) override;
324 
325  virtual css::util::Time SAL_CALL
326  getTime( sal_Int32 columnIndex ) override;
327 
328  virtual css::util::DateTime SAL_CALL
329  getTimestamp( sal_Int32 columnIndex ) override;
330 
331  virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
332  getBinaryStream( sal_Int32 columnIndex ) override;
333 
334  virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
335  getCharacterStream( sal_Int32 columnIndex ) override;
336 
337  virtual css::uno::Any SAL_CALL
338  getObject( sal_Int32 columnIndex,
339  const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
340 
341  virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL
342  getRef( sal_Int32 columnIndex ) override;
343 
344  virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL
345  getBlob( sal_Int32 columnIndex ) override;
346 
347  virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL
348  getClob( sal_Int32 columnIndex ) override;
349 
350  virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL
351  getArray( sal_Int32 columnIndex ) override;
352 
353 
354  // Type Converter support
355 
356 
357 private:
359  css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
360 
361  const css::uno::Reference<
362  css::script::XTypeConverter >& getTypeConverter();
363 
364  template<typename T> T rowOriginGet(
365  T (SAL_CALL css::sdbc::XRow::* f)(sal_Int32), sal_Int32 columnIndex);
366 };
367 
368 
370  public cppu::WeakImplHelper<
371  css::lang::XServiceInfo,
372  css::ucb::XCachedContentResultSetFactory>
373 {
374  css::uno::Reference< css::uno::XComponentContext > m_xContext;
375 
376 public:
377 
378  CachedContentResultSetFactory( const css::uno::Reference< css::uno::XComponentContext > & rxContext);
379 
380  virtual ~CachedContentResultSetFactory() override;
381 
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;
386 
387  static OUString getImplementationName_Static();
388  static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
389 
390  static css::uno::Reference< css::lang::XSingleServiceFactory >
391  createServiceFactory( const css::uno::Reference<
392  css::lang::XMultiServiceFactory >& rxServiceMgr );
393 
394  // XCachedContentResultSetFactory
395 
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;
400 };
401 
402 #endif
403 
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL afterLast() override
Type
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL queryContentIdentifier() override
virtual sal_Bool SAL_CALL isBeforeFirst() override
virtual void SAL_CALL acquire() override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual void impl_initPropertySetInfo() override
css::uno::Any & getRowAny(sal_Int32 nRow)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob(sal_Int32 columnIndex) override
virtual sal_Int32 SAL_CALL getRow() override
css::uno::Sequence< sal_Bool > * getMappedReminder()
signed char sal_Int8
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual float SAL_CALL getFloat(sal_Int32 columnIndex) override
css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter
bool impl_isKnownInvalidPosition(sal_Int32 nRow)
virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray(sal_Int32 columnIndex) override
css::uno::Reference< css::ucb::XContentIdentifierMapping > m_xContentIdentifierMapping
sal_Int16 script
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
rtl::Reference< CCRS_PropertySetInfo > m_xMyPropertySetInfo
void loadData(const css::ucb::FetchResult &rResult)
T rowOriginGet(T(SAL_CALL css::sdbc::XRow::*f)(sal_Int32), sal_Int32 columnIndex)
bool applyPositionToOrigin(sal_Int32 nRow)
const css::uno::Any & getAny(sal_Int32 nRow, sal_Int32 nColumnIndex)
std::unique_ptr< css::ucb::FetchResult > m_pResult
const css::uno::Reference< css::script::XTypeConverter > & getTypeConverter()
virtual void SAL_CALL release() override
virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef(sal_Int32 columnIndex) override
css::uno::Reference< css::ucb::XFetchProvider > m_xFetchProvider
virtual void SAL_CALL beforeFirst() override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual sal_Bool SAL_CALL last() override
virtual OUString SAL_CALL getString(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream(sal_Int32 columnIndex) override
virtual void impl_vetoableChange(const css::beans::PropertyChangeEvent &aEvent) override
virtual sal_Bool SAL_CALL rowInserted() override
virtual double SAL_CALL getDouble(sal_Int32 columnIndex) override
virtual sal_Int64 SAL_CALL getLong(sal_Int32 columnIndex) override
void impl_fetchData(sal_Int32 nRow, sal_Int32 nCount, sal_Int32 nFetchDirection)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual sal_Bool SAL_CALL isLast() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement() override
css::uno::Reference< css::ucb::XFetchProviderForContentAccess > m_xFetchProviderForContentAccess
css::uno::Reference< css::ucb::XContentIdentifierMapping > m_xContentIdentifierMapping
virtual OUString SAL_CALL getImplementationName() override
virtual OUString SAL_CALL queryContentIdentifierString() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual sal_Bool SAL_CALL getBoolean(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL absolute(sal_Int32 row) override
OUString const & getContentIdentifierString(sal_Int32 nRow)
virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob(sal_Int32 columnIndex) override
unsigned char sal_Bool
void impl_changeRowCount(sal_Int32 nOld, sal_Int32 nNew)
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual sal_Int32 SAL_CALL getInt(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL isAfterLast() override
bool impl_isKnownValidPosition(sal_Int32 nRow)
css::uno::Reference< css::ucb::XContent > getContent(sal_Int32 nRow)
std::unique_ptr< css::uno::Sequence< sal_Bool > > m_pMappedReminder
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL next() override
css::uno::Reference< css::ucb::XContentIdentifier > getContentIdentifier(sal_Int32 nRow)
virtual void impl_disposing(const css::lang::EventObject &Source) override
virtual void SAL_CALL refreshRow() override
virtual css::util::Time SAL_CALL getTime(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL previous() override
CCRS_Cache(const css::uno::Reference< css::ucb::XContentIdentifierMapping > &xMapping)
virtual sal_Bool SAL_CALL rowDeleted() override
virtual sal_Bool SAL_CALL isFirst() override
virtual css::util::Date SAL_CALL getDate(sal_Int32 columnIndex) override
virtual void impl_propertyChange(const css::beans::PropertyChangeEvent &evt) override
virtual css::util::DateTime SAL_CALL getTimestamp(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL wasNull() override
virtual css::uno::Any SAL_CALL getObject(sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess > &typeMap) override
virtual ~CachedContentResultSet() override
virtual sal_Bool SAL_CALL first() override
virtual sal_Int8 SAL_CALL getByte(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL relative(sal_Int32 rows) override
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent() override
virtual sal_Int16 SAL_CALL getShort(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL rowUpdated() 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_changeIsRowCountFinal(bool bOld, bool bNew)
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes(sal_Int32 columnIndex) override