1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
{
43 class CCRS_PropertySetInfo
;
44 class CachedContentResultSet
45 : public ContentResultSetWrapper
46 , public css::lang::XTypeProvider
47 , public css::lang::XServiceInfo
55 std::unique_ptr
<css::ucb::FetchResult
>
57 css::uno::Reference
< css::ucb::XContentIdentifierMapping
>
58 m_xContentIdentifierMapping
;
59 std::unique_ptr
<css::uno::Sequence
< sal_Bool
>> m_pMappedReminder
;
62 /// @throws css::sdbc::SQLException
63 /// @throws css::uno::RuntimeException
65 getRowAny( sal_Int32 nRow
);
70 void remindMapped( sal_Int32 nRow
);
71 bool isRowMapped( sal_Int32 nRow
);
72 void clearMappedReminder();
73 css::uno::Sequence
< sal_Bool
>* getMappedReminder();
76 CCRS_Cache( const css::uno::Reference
<
77 css::ucb::XContentIdentifierMapping
> & xMapping
);
81 const css::ucb::FetchResult
& rResult
);
84 hasRow( sal_Int32 nRow
);
87 hasCausedException( sal_Int32 nRow
);
95 /// @throws css::sdbc::SQLException
96 /// @throws css::uno::RuntimeException
98 getAny( sal_Int32 nRow
, sal_Int32 nColumnIndex
);
100 /// @throws css::uno::RuntimeException
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
);
115 css::uno::Reference
< css::uno::XComponentContext
>
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
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
;
150 CCRS_Cache m_aCacheContentIdentifierString
;
151 CCRS_Cache m_aCacheContentIdentifier
;
152 CCRS_Cache m_aCacheContent
;
157 //helping XPropertySet methods.
158 virtual void impl_initPropertySetInfo() override
;
160 /// @throws css::sdbc::SQLException
161 /// @throws css::uno::RuntimeException
163 applyPositionToOrigin( sal_Int32 nRow
);
165 /// @throws css::uno::RuntimeException
167 impl_fetchData( sal_Int32 nRow
, sal_Int32 nCount
168 , sal_Int32 nFetchDirection
);
171 impl_isKnownValidPosition( sal_Int32 nRow
);
174 impl_isKnownInvalidPosition( sal_Int32 nRow
);
177 impl_changeRowCount( sal_Int32 nOld
, sal_Int32 nNew
);
180 impl_changeIsRowCountFinal( bool bOld
, bool bNew
);
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
;
192 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
193 virtual void SAL_CALL
acquire()
195 virtual void SAL_CALL
release()
200 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
201 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() override
;
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
;
222 impl_disposing( const css::lang::EventObject
& Source
) override
;
225 impl_propertyChange( const css::beans::PropertyChangeEvent
& evt
) override
;
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
249 virtual sal_Bool SAL_CALL
250 isBeforeFirst() override
;
251 virtual sal_Bool SAL_CALL
252 isAfterLast() override
;
253 virtual sal_Bool SAL_CALL
255 virtual sal_Bool SAL_CALL
257 virtual void SAL_CALL
258 beforeFirst() override
;
259 virtual void SAL_CALL
260 afterLast() override
;
261 virtual sal_Bool SAL_CALL
263 virtual sal_Bool SAL_CALL
265 virtual sal_Int32 SAL_CALL
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
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
;
288 virtual sal_Bool SAL_CALL
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
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
;
375 CachedContentResultSetFactory( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
);
377 virtual ~CachedContentResultSetFactory() override
;
381 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
382 virtual void SAL_CALL
acquire()
384 virtual void SAL_CALL
release()
388 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
389 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() override
;
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
;
413 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */