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/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>
39 #define CACHED_CONTENT_RESULTSET_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSet"
40 #define CACHED_CONTENT_RESULTSET_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetFactory"
43 namespace com
{ namespace sun
{ namespace star
{ namespace script
{
47 class CCRS_PropertySetInfo
;
48 class CachedContentResultSet
49 : public ContentResultSetWrapper
50 , public css::lang::XTypeProvider
51 , public css::lang::XServiceInfo
59 std::unique_ptr
<css::ucb::FetchResult
>
61 css::uno::Reference
< css::ucb::XContentIdentifierMapping
>
62 m_xContentIdentifierMapping
;
63 std::unique_ptr
<css::uno::Sequence
< sal_Bool
>> m_pMappedReminder
;
66 /// @throws css::sdbc::SQLException
67 /// @throws css::uno::RuntimeException
69 getRowAny( sal_Int32 nRow
);
74 void remindMapped( sal_Int32 nRow
);
75 bool isRowMapped( sal_Int32 nRow
);
76 void clearMappedReminder();
77 css::uno::Sequence
< sal_Bool
>* getMappedReminder();
80 CCRS_Cache( const css::uno::Reference
<
81 css::ucb::XContentIdentifierMapping
> & xMapping
);
85 const css::ucb::FetchResult
& rResult
);
88 hasRow( sal_Int32 nRow
);
91 hasCausedException( sal_Int32 nRow
);
99 /// @throws css::sdbc::SQLException
100 /// @throws css::uno::RuntimeException
102 getAny( sal_Int32 nRow
, sal_Int32 nColumnIndex
);
104 /// @throws css::uno::RuntimeException
106 getContentIdentifierString( sal_Int32 nRow
);
108 /// @throws css::uno::RuntimeException
109 css::uno::Reference
< css::ucb::XContentIdentifier
>
110 getContentIdentifier( sal_Int32 nRow
);
112 /// @throws css::uno::RuntimeException
113 css::uno::Reference
< css::ucb::XContent
>
114 getContent( sal_Int32 nRow
);
119 css::uno::Reference
< css::uno::XComponentContext
>
122 //different Interfaces from Origin:
123 css::uno::Reference
< css::ucb::XFetchProvider
>
124 m_xFetchProvider
; //XFetchProvider-interface from m_xOrigin
126 css::uno::Reference
< css::ucb::XFetchProviderForContentAccess
>
127 m_xFetchProviderForContentAccess
; //XFetchProviderForContentAccess-interface from m_xOrigin
129 rtl::Reference
< CCRS_PropertySetInfo
>
130 m_xMyPropertySetInfo
;
133 css::uno::Reference
< css::ucb::XContentIdentifierMapping
>
134 m_xContentIdentifierMapping
;// can be used for remote optimized ContentAccess
136 //some Properties and helping variables
138 bool m_bAfterLast
; // TRUE, if m_nRow is after final count; can be TRUE without knowing the exact final count
140 sal_Int32 m_nLastAppliedPos
;
141 bool m_bAfterLastApplied
;
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
146 sal_Int32 m_nFetchSize
;
147 sal_Int32 m_nFetchDirection
;
149 bool m_bLastReadWasFromCache
;
150 bool m_bLastCachedReadWasNull
;
154 CCRS_Cache m_aCacheContentIdentifierString
;
155 CCRS_Cache m_aCacheContentIdentifier
;
156 CCRS_Cache m_aCacheContent
;
161 //helping XPropertySet methods.
162 virtual void impl_initPropertySetInfo() override
;
164 /// @throws css::sdbc::SQLException
165 /// @throws css::uno::RuntimeException
167 applyPositionToOrigin( sal_Int32 nRow
);
169 /// @throws css::uno::RuntimeException
171 impl_fetchData( sal_Int32 nRow
, sal_Int32 nCount
172 , sal_Int32 nFetchDirection
);
175 impl_isKnownValidPosition( sal_Int32 nRow
);
178 impl_isKnownInvalidPosition( sal_Int32 nRow
);
181 impl_changeRowCount( sal_Int32 nOld
, sal_Int32 nNew
);
184 impl_changeIsRowCountFinal( bool bOld
, bool bNew
);
187 CachedContentResultSet(
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
);
192 virtual ~CachedContentResultSet() override
;
196 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
197 virtual void SAL_CALL
acquire()
199 virtual void SAL_CALL
release()
204 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
205 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() override
;
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
;
212 // XPropertySet inherited
215 virtual void SAL_CALL
216 setPropertyValue( const OUString
& aPropertyName
,
217 const css::uno::Any
& aValue
) override
;
219 virtual css::uno::Any SAL_CALL
220 getPropertyValue( const OUString
& PropertyName
) override
;
226 impl_disposing( const css::lang::EventObject
& Source
) override
;
229 impl_propertyChange( const css::beans::PropertyChangeEvent
& evt
) override
;
232 impl_vetoableChange( const css::beans::PropertyChangeEvent
& aEvent
) override
;
235 // XContentAccess inherited
237 virtual OUString SAL_CALL
238 queryContentIdentifierString() override
;
240 virtual css::uno::Reference
<
241 css::ucb::XContentIdentifier
> SAL_CALL
242 queryContentIdentifier() override
;
244 virtual css::uno::Reference
<
245 css::ucb::XContent
> SAL_CALL
246 queryContent() override
;
249 // XResultSet inherited
251 virtual sal_Bool SAL_CALL
253 virtual sal_Bool SAL_CALL
254 isBeforeFirst() override
;
255 virtual sal_Bool SAL_CALL
256 isAfterLast() override
;
257 virtual sal_Bool SAL_CALL
259 virtual sal_Bool SAL_CALL
261 virtual void SAL_CALL
262 beforeFirst() override
;
263 virtual void SAL_CALL
264 afterLast() override
;
265 virtual sal_Bool SAL_CALL
267 virtual sal_Bool SAL_CALL
269 virtual sal_Int32 SAL_CALL
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
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
;
292 virtual sal_Bool SAL_CALL
295 virtual OUString SAL_CALL
296 getString( sal_Int32 columnIndex
) override
;
298 virtual sal_Bool SAL_CALL
299 getBoolean( sal_Int32 columnIndex
) override
;
301 virtual sal_Int8 SAL_CALL
302 getByte( sal_Int32 columnIndex
) override
;
304 virtual sal_Int16 SAL_CALL
305 getShort( sal_Int32 columnIndex
) override
;
307 virtual sal_Int32 SAL_CALL
308 getInt( sal_Int32 columnIndex
) override
;
310 virtual sal_Int64 SAL_CALL
311 getLong( sal_Int32 columnIndex
) override
;
313 virtual float SAL_CALL
314 getFloat( sal_Int32 columnIndex
) override
;
316 virtual double SAL_CALL
317 getDouble( sal_Int32 columnIndex
) override
;
319 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
320 getBytes( sal_Int32 columnIndex
) override
;
322 virtual css::util::Date SAL_CALL
323 getDate( sal_Int32 columnIndex
) override
;
325 virtual css::util::Time SAL_CALL
326 getTime( sal_Int32 columnIndex
) override
;
328 virtual css::util::DateTime SAL_CALL
329 getTimestamp( sal_Int32 columnIndex
) override
;
331 virtual css::uno::Reference
< css::io::XInputStream
> SAL_CALL
332 getBinaryStream( sal_Int32 columnIndex
) override
;
334 virtual css::uno::Reference
< css::io::XInputStream
> SAL_CALL
335 getCharacterStream( sal_Int32 columnIndex
) override
;
337 virtual css::uno::Any SAL_CALL
338 getObject( sal_Int32 columnIndex
,
339 const css::uno::Reference
< css::container::XNameAccess
>& typeMap
) override
;
341 virtual css::uno::Reference
< css::sdbc::XRef
> SAL_CALL
342 getRef( sal_Int32 columnIndex
) override
;
344 virtual css::uno::Reference
< css::sdbc::XBlob
> SAL_CALL
345 getBlob( sal_Int32 columnIndex
) override
;
347 virtual css::uno::Reference
< css::sdbc::XClob
> SAL_CALL
348 getClob( sal_Int32 columnIndex
) override
;
350 virtual css::uno::Reference
< css::sdbc::XArray
> SAL_CALL
351 getArray( sal_Int32 columnIndex
) override
;
354 // Type Converter support
358 bool m_bTriedToGetTypeConverter
;
359 css::uno::Reference
< css::script::XTypeConverter
> m_xTypeConverter
;
361 const css::uno::Reference
<
362 css::script::XTypeConverter
>& getTypeConverter();
364 template<typename T
> T
rowOriginGet(
365 T (SAL_CALL
css::sdbc::XRow::* f
)(sal_Int32
), sal_Int32 columnIndex
);
369 class CachedContentResultSetFactory final
:
370 public cppu::WeakImplHelper
<
371 css::lang::XServiceInfo
,
372 css::ucb::XCachedContentResultSetFactory
>
374 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
378 CachedContentResultSetFactory( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
);
380 virtual ~CachedContentResultSetFactory() override
;
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
;
387 static OUString
getImplementationName_Static();
388 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static();
390 static css::uno::Reference
< css::lang::XSingleServiceFactory
>
391 createServiceFactory( const css::uno::Reference
<
392 css::lang::XMultiServiceFactory
>& rxServiceMgr
);
394 // XCachedContentResultSetFactory
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
;
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */