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 
55  class CCRS_Cache
56  {
57  private:
58  std::unique_ptr<css::ucb::FetchResult>
60  css::uno::Reference< css::ucb::XContentIdentifierMapping >
62  std::unique_ptr<css::uno::Sequence< sal_Bool >> m_pMappedReminder;
63 
64  private:
67  css::uno::Any&
68  getRowAny( sal_Int32 nRow );
69 
70  void clear();
71 
72 
73  void remindMapped( sal_Int32 nRow );
74  bool isRowMapped( sal_Int32 nRow );
75  css::uno::Sequence< sal_Bool >* getMappedReminder();
76 
77  public:
78  CCRS_Cache( const css::uno::Reference<
79  css::ucb::XContentIdentifierMapping > & xMapping );
80  ~CCRS_Cache();
81 
82  void loadData(
83  const css::ucb::FetchResult& rResult );
84 
85  bool
86  hasRow( sal_Int32 nRow );
87 
88  bool
89  hasCausedException( sal_Int32 nRow );
90 
91  sal_Int32
92  getMaxRow() const;
93 
94  bool
95  hasKnownLast() const;
96 
99  const css::uno::Any&
100  getAny( sal_Int32 nRow, sal_Int32 nColumnIndex );
101 
103  OUString const &
104  getContentIdentifierString( sal_Int32 nRow );
105 
107  css::uno::Reference< css::ucb::XContentIdentifier >
108  getContentIdentifier( sal_Int32 nRow );
109 
111  css::uno::Reference< css::ucb::XContent >
112  getContent( sal_Int32 nRow );
113  };
114 
115  //members
116 
117  css::uno::Reference< css::uno::XComponentContext >
119 
120  //different Interfaces from Origin:
121  css::uno::Reference< css::ucb::XFetchProvider >
122  m_xFetchProvider; //XFetchProvider-interface from m_xOrigin
123 
124  css::uno::Reference< css::ucb::XFetchProviderForContentAccess >
125  m_xFetchProviderForContentAccess; //XFetchProviderForContentAccess-interface from m_xOrigin
126 
129 
130 
131  css::uno::Reference< css::ucb::XContentIdentifierMapping >
132  m_xContentIdentifierMapping;// can be used for remote optimized ContentAccess
133 
134  //some Properties and helping variables
135  sal_Int32 m_nRow;
136  bool m_bAfterLast; // TRUE, if m_nRow is after final count; can be TRUE without knowing the exact final count
137 
138  sal_Int32 m_nLastAppliedPos;
140 
141  sal_Int32 m_nKnownCount; // count we know from the Origin
142  bool m_bFinalCount; // TRUE if the Origin has reached final count and we got that count in m_nKnownCount
143 
144  sal_Int32 m_nFetchSize;
145  sal_Int32 m_nFetchDirection;
146 
149 
150  //cache:
155 
156 
157 private:
158 
159  //helping XPropertySet methods.
160  virtual void impl_initPropertySetInfo() override;
161 
164  bool
165  applyPositionToOrigin( sal_Int32 nRow );
166 
168  void
169  impl_fetchData( sal_Int32 nRow, sal_Int32 nCount
170  , sal_Int32 nFetchDirection );
171 
172  bool
173  impl_isKnownValidPosition( sal_Int32 nRow );
174 
175  bool
176  impl_isKnownInvalidPosition( sal_Int32 nRow );
177 
178  void
179  impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew );
180 
181  void
182  impl_changeIsRowCountFinal( bool bOld, bool bNew );
183 
184 public:
186  const css::uno::Reference< css::uno::XComponentContext > & rxContext,
187  const css::uno::Reference< css::sdbc::XResultSet > & xOrigin,
188  const css::uno::Reference< css::ucb::XContentIdentifierMapping > & xContentIdentifierMapping );
189 
190  virtual ~CachedContentResultSet() override;
191 
192 
193  // XInterface
194  virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
195  virtual void SAL_CALL acquire()
196  throw() override;
197  virtual void SAL_CALL release()
198  throw() override;
199 
200  // XTypeProvider
201 
202  virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
203  virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
204 
205  // XServiceInfo
206  virtual OUString SAL_CALL getImplementationName() override;
207  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
208  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
209 
210  // XPropertySet inherited
211 
212 
213  virtual void SAL_CALL
214  setPropertyValue( const OUString& aPropertyName,
215  const css::uno::Any& aValue ) override;
216 
217  virtual css::uno::Any SAL_CALL
218  getPropertyValue( const OUString& PropertyName ) override;
219 
220 
221  // own inherited
222 
223  virtual void
224  impl_disposing( const css::lang::EventObject& Source ) override;
225 
226  virtual void
227  impl_propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
228 
229  virtual void
230  impl_vetoableChange( const css::beans::PropertyChangeEvent& aEvent ) override;
231 
232 
233  // XContentAccess inherited
234 
235  virtual OUString SAL_CALL
236  queryContentIdentifierString() override;
237 
238  virtual css::uno::Reference<
239  css::ucb::XContentIdentifier > SAL_CALL
240  queryContentIdentifier() override;
241 
242  virtual css::uno::Reference<
243  css::ucb::XContent > SAL_CALL
244  queryContent() override;
245 
246 
247  // XResultSet inherited
248 
249  virtual sal_Bool SAL_CALL
250  next() override;
251  virtual sal_Bool SAL_CALL
252  isBeforeFirst() override;
253  virtual sal_Bool SAL_CALL
254  isAfterLast() override;
255  virtual sal_Bool SAL_CALL
256  isFirst() override;
257  virtual sal_Bool SAL_CALL
258  isLast() override;
259  virtual void SAL_CALL
260  beforeFirst() override;
261  virtual void SAL_CALL
262  afterLast() override;
263  virtual sal_Bool SAL_CALL
264  first() override;
265  virtual sal_Bool SAL_CALL
266  last() override;
267  virtual sal_Int32 SAL_CALL
268  getRow() override;
269  virtual sal_Bool SAL_CALL
270  absolute( sal_Int32 row ) override;
271  virtual sal_Bool SAL_CALL
272  relative( sal_Int32 rows ) override;
273  virtual sal_Bool SAL_CALL
274  previous() override;
275  virtual void SAL_CALL
276  refreshRow() override;
277  virtual sal_Bool SAL_CALL
278  rowUpdated() override;
279  virtual sal_Bool SAL_CALL
280  rowInserted() override;
281  virtual sal_Bool SAL_CALL
282  rowDeleted() override;
283  virtual css::uno::Reference<
284  css::uno::XInterface > SAL_CALL
285  getStatement() override;
286 
287 
288  // XRow inherited
289 
290  virtual sal_Bool SAL_CALL
291  wasNull() override;
292 
293  virtual OUString SAL_CALL
294  getString( sal_Int32 columnIndex ) override;
295 
296  virtual sal_Bool SAL_CALL
297  getBoolean( sal_Int32 columnIndex ) override;
298 
299  virtual sal_Int8 SAL_CALL
300  getByte( sal_Int32 columnIndex ) override;
301 
302  virtual sal_Int16 SAL_CALL
303  getShort( sal_Int32 columnIndex ) override;
304 
305  virtual sal_Int32 SAL_CALL
306  getInt( sal_Int32 columnIndex ) override;
307 
308  virtual sal_Int64 SAL_CALL
309  getLong( sal_Int32 columnIndex ) override;
310 
311  virtual float SAL_CALL
312  getFloat( sal_Int32 columnIndex ) override;
313 
314  virtual double SAL_CALL
315  getDouble( sal_Int32 columnIndex ) override;
316 
317  virtual css::uno::Sequence< sal_Int8 > SAL_CALL
318  getBytes( sal_Int32 columnIndex ) override;
319 
320  virtual css::util::Date SAL_CALL
321  getDate( sal_Int32 columnIndex ) override;
322 
323  virtual css::util::Time SAL_CALL
324  getTime( sal_Int32 columnIndex ) override;
325 
326  virtual css::util::DateTime SAL_CALL
327  getTimestamp( sal_Int32 columnIndex ) override;
328 
329  virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
330  getBinaryStream( sal_Int32 columnIndex ) override;
331 
332  virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
333  getCharacterStream( sal_Int32 columnIndex ) override;
334 
335  virtual css::uno::Any SAL_CALL
336  getObject( sal_Int32 columnIndex,
337  const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
338 
339  virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL
340  getRef( sal_Int32 columnIndex ) override;
341 
342  virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL
343  getBlob( sal_Int32 columnIndex ) override;
344 
345  virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL
346  getClob( sal_Int32 columnIndex ) override;
347 
348  virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL
349  getArray( sal_Int32 columnIndex ) override;
350 
351 
352  // Type Converter support
353 
354 
355 private:
357  css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
358 
359  const css::uno::Reference<
360  css::script::XTypeConverter >& getTypeConverter();
361 
362  template<typename T> T rowOriginGet(
363  T (SAL_CALL css::sdbc::XRow::* f)(sal_Int32), sal_Int32 columnIndex);
364 };
365 
366 
368  public cppu::WeakImplHelper<
369  css::lang::XServiceInfo,
370  css::ucb::XCachedContentResultSetFactory>
371 {
372  css::uno::Reference< css::uno::XComponentContext > m_xContext;
373 
374 public:
375 
376  CachedContentResultSetFactory( const css::uno::Reference< css::uno::XComponentContext > & rxContext);
377 
378  virtual ~CachedContentResultSetFactory() override;
379 
380  // XServiceInfo
381  virtual OUString SAL_CALL getImplementationName() override;
382  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
383  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
384 
385  static OUString getImplementationName_Static();
386  static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
387 
388  static css::uno::Reference< css::lang::XSingleServiceFactory >
389  createServiceFactory( const css::uno::Reference<
390  css::lang::XMultiServiceFactory >& rxServiceMgr );
391 
392  // XCachedContentResultSetFactory
393 
394  virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL
395  createCachedContentResultSet(
396  const css::uno::Reference< css::sdbc::XResultSet > & xSource,
397  const css::uno::Reference< css::ucb::XContentIdentifierMapping > & xMapping ) override;
398 };
399 
400 #endif
401 
402 /* 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