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/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>
32 
33 #include <memory>
34 
35 #define CACHED_CONTENT_RESULTSET_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSet"
36 #define CACHED_CONTENT_RESULTSET_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetFactory"
37 
38 
39 namespace com { namespace sun { namespace star { namespace script {
40  class XTypeConverter;
41 } } } }
42 
46  , public css::lang::XTypeProvider
47  , public css::lang::XServiceInfo
48 {
49 
50  // class CCRS_Cache
51 
52  class CCRS_Cache
53  {
54  private:
55  std::unique_ptr<css::ucb::FetchResult>
57  css::uno::Reference< css::ucb::XContentIdentifierMapping >
59  std::unique_ptr<css::uno::Sequence< sal_Bool >> m_pMappedReminder;
60 
61  private:
64  css::uno::Any&
65  getRowAny( sal_Int32 nRow );
66 
67  void clear();
68 
69 
70  void remindMapped( sal_Int32 nRow );
71  bool isRowMapped( sal_Int32 nRow );
72  void clearMappedReminder();
73  css::uno::Sequence< sal_Bool >* getMappedReminder();
74 
75  public:
76  CCRS_Cache( const css::uno::Reference<
77  css::ucb::XContentIdentifierMapping > & xMapping );
78  ~CCRS_Cache();
79 
80  void loadData(
81  const css::ucb::FetchResult& rResult );
82 
83  bool
84  hasRow( sal_Int32 nRow );
85 
86  bool
87  hasCausedException( sal_Int32 nRow );
88 
89  sal_Int32
90  getMaxRow();
91 
92  bool
93  hasKnownLast();
94 
97  const css::uno::Any&
98  getAny( sal_Int32 nRow, sal_Int32 nColumnIndex );
99 
101  OUString const &
102  getContentIdentifierString( sal_Int32 nRow );
103 
105  css::uno::Reference< css::ucb::XContentIdentifier >
106  getContentIdentifier( sal_Int32 nRow );
107 
109  css::uno::Reference< css::ucb::XContent >
110  getContent( sal_Int32 nRow );
111  };
112 
113  //members
114 
115  css::uno::Reference< css::uno::XComponentContext >
117 
118  //different Interfaces from Origin:
119  css::uno::Reference< css::ucb::XFetchProvider >
120  m_xFetchProvider; //XFetchProvider-interface from m_xOrigin
121 
122  css::uno::Reference< css::ucb::XFetchProviderForContentAccess >
123  m_xFetchProviderForContentAccess; //XFetchProviderForContentAccess-interface from m_xOrigin
124 
127 
128 
129  css::uno::Reference< css::ucb::XContentIdentifierMapping >
130  m_xContentIdentifierMapping;// can be used for remote optimized ContentAccess
131 
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
135 
136  sal_Int32 m_nLastAppliedPos;
138 
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
141 
142  sal_Int32 m_nFetchSize;
143  sal_Int32 m_nFetchDirection;
144 
147 
148  //cache:
153 
154 
155 private:
156 
157  //helping XPropertySet methods.
158  virtual void impl_initPropertySetInfo() override;
159 
162  bool
163  applyPositionToOrigin( sal_Int32 nRow );
164 
166  void
167  impl_fetchData( sal_Int32 nRow, sal_Int32 nCount
168  , sal_Int32 nFetchDirection );
169 
170  bool
171  impl_isKnownValidPosition( sal_Int32 nRow );
172 
173  bool
174  impl_isKnownInvalidPosition( sal_Int32 nRow );
175 
176  void
177  impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew );
178 
179  void
180  impl_changeIsRowCountFinal( bool bOld, bool bNew );
181 
182 public:
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 );
187 
188  virtual ~CachedContentResultSet() override;
189 
190 
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;
197 
198  // XTypeProvider
199 
200  virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
201  virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
202 
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;
207 
208  // XPropertySet inherited
209 
210 
211  virtual void SAL_CALL
212  setPropertyValue( const OUString& aPropertyName,
213  const css::uno::Any& aValue ) override;
214 
215  virtual css::uno::Any SAL_CALL
216  getPropertyValue( const OUString& PropertyName ) override;
217 
218 
219  // own inherited
220 
221  virtual void
222  impl_disposing( const css::lang::EventObject& Source ) override;
223 
224  virtual void
225  impl_propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
226 
227  virtual void
228  impl_vetoableChange( const css::beans::PropertyChangeEvent& aEvent ) override;
229 
230 
231  // XContentAccess inherited
232 
233  virtual OUString SAL_CALL
234  queryContentIdentifierString() override;
235 
236  virtual css::uno::Reference<
237  css::ucb::XContentIdentifier > SAL_CALL
238  queryContentIdentifier() override;
239 
240  virtual css::uno::Reference<
241  css::ucb::XContent > SAL_CALL
242  queryContent() override;
243 
244 
245  // XResultSet inherited
246 
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;
284 
285 
286  // XRow inherited
287 
288  virtual sal_Bool SAL_CALL
289  wasNull() override;
290 
291  virtual OUString SAL_CALL
292  getString( sal_Int32 columnIndex ) override;
293 
294  virtual sal_Bool SAL_CALL
295  getBoolean( sal_Int32 columnIndex ) override;
296 
297  virtual sal_Int8 SAL_CALL
298  getByte( sal_Int32 columnIndex ) override;
299 
300  virtual sal_Int16 SAL_CALL
301  getShort( sal_Int32 columnIndex ) override;
302 
303  virtual sal_Int32 SAL_CALL
304  getInt( sal_Int32 columnIndex ) override;
305 
306  virtual sal_Int64 SAL_CALL
307  getLong( sal_Int32 columnIndex ) override;
308 
309  virtual float SAL_CALL
310  getFloat( sal_Int32 columnIndex ) override;
311 
312  virtual double SAL_CALL
313  getDouble( sal_Int32 columnIndex ) override;
314 
315  virtual css::uno::Sequence< sal_Int8 > SAL_CALL
316  getBytes( sal_Int32 columnIndex ) override;
317 
318  virtual css::util::Date SAL_CALL
319  getDate( sal_Int32 columnIndex ) override;
320 
321  virtual css::util::Time SAL_CALL
322  getTime( sal_Int32 columnIndex ) override;
323 
324  virtual css::util::DateTime SAL_CALL
325  getTimestamp( sal_Int32 columnIndex ) override;
326 
327  virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
328  getBinaryStream( sal_Int32 columnIndex ) override;
329 
330  virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
331  getCharacterStream( sal_Int32 columnIndex ) override;
332 
333  virtual css::uno::Any SAL_CALL
334  getObject( sal_Int32 columnIndex,
335  const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
336 
337  virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL
338  getRef( sal_Int32 columnIndex ) override;
339 
340  virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL
341  getBlob( sal_Int32 columnIndex ) override;
342 
343  virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL
344  getClob( sal_Int32 columnIndex ) override;
345 
346  virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL
347  getArray( sal_Int32 columnIndex ) override;
348 
349 
350  // Type Converter support
351 
352 
353 private:
355  css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
356 
357  const css::uno::Reference<
358  css::script::XTypeConverter >& getTypeConverter();
359 
360  template<typename T> T rowOriginGet(
361  T (SAL_CALL css::sdbc::XRow::* f)(sal_Int32), sal_Int32 columnIndex);
362 };
363 
364 
366  : public cppu::OWeakObject
367  , public css::lang::XTypeProvider
368  , public css::lang::XServiceInfo
369  , public css::ucb::XCachedContentResultSetFactory
370 {
371  css::uno::Reference< css::uno::XComponentContext > m_xContext;
372 
373 public:
374 
375  CachedContentResultSetFactory( const css::uno::Reference< css::uno::XComponentContext > & rxContext);
376 
377  virtual ~CachedContentResultSetFactory() override;
378 
379 
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;
386 
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;
390 
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;
395 
396  static OUString getImplementationName_Static();
397  static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
398 
399  static css::uno::Reference< css::lang::XSingleServiceFactory >
400  createServiceFactory( const css::uno::Reference<
401  css::lang::XMultiServiceFactory >& rxServiceMgr );
402 
403  // XCachedContentResultSetFactory
404 
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;
409 };
410 
411 #endif
412 
413 /* 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