xref: /trunk/main/ucb/source/cacher/cachedcontentresultset.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CACHED_CONTENT_RESULTSET_HXX
25 #define _CACHED_CONTENT_RESULTSET_HXX
26 
27 #include <contentresultsetwrapper.hxx>
28 #include <com/sun/star/lang/XTypeProvider.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/ucb/XFetchProvider.hpp>
31 #include <com/sun/star/ucb/XFetchProviderForContentAccess.hpp>
32 #include <com/sun/star/ucb/FetchResult.hpp>
33 #include <com/sun/star/ucb/XContentIdentifierMapping.hpp>
34 #include <com/sun/star/ucb/XCachedContentResultSetFactory.hpp>
35 
36 #define CACHED_CONTENT_RESULTSET_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSet"
37 #define CACHED_CONTENT_RESULTSET_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetFactory"
38 
39 //=========================================================================
40 
41 namespace com { namespace sun { namespace star { namespace script {
42     class XTypeConverter;
43 } } } }
44 
45 class CCRS_PropertySetInfo;
46 class CachedContentResultSet
47                 : public ContentResultSetWrapper
48                 , public com::sun::star::lang::XTypeProvider
49                 , public com::sun::star::lang::XServiceInfo
50 {
51     //--------------------------------------------------------------------------
52     // class CCRS_Cache
53 
54     class CCRS_Cache
55     {
56     private:
57         com::sun::star::ucb::FetchResult*           m_pResult;
58         com::sun::star::uno::Reference<
59             com::sun::star::ucb::XContentIdentifierMapping >
60                                                     m_xContentIdentifierMapping;
61         com::sun::star::uno::Sequence< sal_Bool >*  m_pMappedReminder;
62 
63     private:
64         com::sun::star::uno::Any& SAL_CALL
65         getRowAny( sal_Int32 nRow );
66 
67         void SAL_CALL clear();
68 
69 
70         void SAL_CALL remindMapped( sal_Int32 nRow );
71         sal_Bool SAL_CALL isRowMapped( sal_Int32 nRow );
72         void SAL_CALL clearMappedReminder();
73         com::sun::star::uno::Sequence< sal_Bool >* SAL_CALL getMappedReminder();
74 
75     public:
76         CCRS_Cache( const com::sun::star::uno::Reference<
77                 com::sun::star::ucb::XContentIdentifierMapping > & xMapping );
78         ~CCRS_Cache();
79 
80         void SAL_CALL loadData(
81             const com::sun::star::ucb::FetchResult& rResult );
82 
83         sal_Bool SAL_CALL
84         hasRow( sal_Int32 nRow );
85 
86         sal_Bool SAL_CALL
87         hasCausedException( sal_Int32 nRow );
88 
89         sal_Int32 SAL_CALL
90         getMaxRow();
91 
92         sal_Bool SAL_CALL
93         hasKnownLast();
94 
95         //---
96         const com::sun::star::uno::Any& SAL_CALL
97         getAny( sal_Int32 nRow, sal_Int32 nColumnIndex );
98 
99         const rtl::OUString& SAL_CALL
100         getContentIdentifierString( sal_Int32 nRow );
101 
102         const com::sun::star::uno::Reference<
103                 com::sun::star::ucb::XContentIdentifier >& SAL_CALL
104         getContentIdentifier( sal_Int32 nRow );
105 
106         const com::sun::star::uno::Reference<
107                 com::sun::star::ucb::XContent >& SAL_CALL
108         getContent( sal_Int32 nRow );
109     };
110     //-----------------------------------------------------------------
111     //members
112 
113     com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
114                             m_xSMgr;
115 
116     //different Interfaces from Origin:
117     com::sun::star::uno::Reference< com::sun::star::ucb::XFetchProvider >
118                             m_xFetchProvider; //XFetchProvider-interface from m_xOrigin
119 
120     com::sun::star::uno::Reference< com::sun::star::ucb::XFetchProviderForContentAccess >
121                             m_xFetchProviderForContentAccess; //XFetchProviderForContentAccess-interface from m_xOrigin
122 
123     //my PropertySetInfo
124     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >
125                             m_xMyPropertySetInfo;//holds m_pMyPropSetInfo alive
126     CCRS_PropertySetInfo*   m_pMyPropSetInfo;
127 
128 
129     //
130     com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifierMapping >
131                             m_xContentIdentifierMapping;// can be used for remote optimized ContentAccess
132 
133     //some Properties and helping variables
134     sal_Int32               m_nRow;
135     sal_Bool                m_bAfterLast; // TRUE, if m_nRow is after final count; can be TRUE without knowing the exact final count
136 
137     sal_Int32               m_nLastAppliedPos;
138     sal_Bool                m_bAfterLastApplied;
139 
140     sal_Int32               m_nKnownCount; // count we know from the Origin
141     sal_Bool                m_bFinalCount; // TRUE if the Origin has reached final count and we got that count in m_nKnownCount
142 
143     sal_Int32               m_nFetchSize;
144     sal_Int32               m_nFetchDirection;
145 
146     sal_Bool                m_bLastReadWasFromCache;
147     sal_Bool                m_bLastCachedReadWasNull;
148 
149     //cache:
150     CCRS_Cache              m_aCache;
151     CCRS_Cache              m_aCacheContentIdentifierString;
152     CCRS_Cache              m_aCacheContentIdentifier;
153     CCRS_Cache              m_aCacheContent;
154 
155 
156 private:
157     //-----------------------------------------------------------------
158     //helping XPropertySet methods.
159     virtual void SAL_CALL impl_initPropertySetInfo();
160 
161 
162     //-----------------------------------------------------------------
163     sal_Bool SAL_CALL
164     applyPositionToOrigin( sal_Int32 nRow );
165 
166     void SAL_CALL
167     impl_fetchData( sal_Int32 nRow, sal_Int32 nCount
168                     , sal_Int32 nFetchDirection );
169 
170     sal_Bool SAL_CALL
171     impl_isKnownValidPosition( sal_Int32 nRow );
172 
173     sal_Bool SAL_CALL
174     impl_isKnownInvalidPosition( sal_Int32 nRow );
175 
176     void SAL_CALL
177     impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew );
178 
179     void SAL_CALL
180     impl_changeIsRowCountFinal( sal_Bool bOld, sal_Bool bNew );
181 
182 public:
183     CachedContentResultSet(
184                         const com::sun::star::uno::Reference<
185                             com::sun::star::lang::XMultiServiceFactory > &
186                                 xSMgr,
187                         const com::sun::star::uno::Reference<
188                             com::sun::star::sdbc::XResultSet > & xOrigin,
189                         const com::sun::star::uno::Reference<
190                             com::sun::star::ucb::XContentIdentifierMapping > &
191                                 xContentIdentifierMapping );
192 
193     virtual ~CachedContentResultSet();
194 
195     //-----------------------------------------------------------------
196     // XInterface inherited
197     //-----------------------------------------------------------------
198     XINTERFACE_DECL()
199     //-----------------------------------------------------------------
200     // XTypeProvider
201     //-----------------------------------------------------------------
202     XTYPEPROVIDER_DECL()
203     //-----------------------------------------------------------------
204     // XServiceInfo
205     //-----------------------------------------------------------------
206     XSERVICEINFO_NOFACTORY_DECL()
207 
208     //-----------------------------------------------------------------
209     // XPropertySet inherited
210     //-----------------------------------------------------------------
211 
212     virtual void SAL_CALL
213     setPropertyValue( const rtl::OUString& aPropertyName,
214                       const com::sun::star::uno::Any& aValue );
215 
216     virtual com::sun::star::uno::Any SAL_CALL
217     getPropertyValue( const rtl::OUString& PropertyName );
218 
219     //-----------------------------------------------------------------
220     // own inherited
221     //-----------------------------------------------------------------
222     virtual void SAL_CALL
223     impl_disposing( const com::sun::star::lang::EventObject& Source );
224 
225     virtual void SAL_CALL
226     impl_propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt );
227 
228     virtual void SAL_CALL
229     impl_vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent );
230 
231     //-----------------------------------------------------------------
232     // XContentAccess inherited
233     //-----------------------------------------------------------------
234     virtual rtl::OUString SAL_CALL
235     queryContentIdentifierString();
236 
237     virtual com::sun::star::uno::Reference<
238                 com::sun::star::ucb::XContentIdentifier > SAL_CALL
239     queryContentIdentifier();
240 
241     virtual com::sun::star::uno::Reference<
242                 com::sun::star::ucb::XContent > SAL_CALL
243     queryContent();
244 
245     //-----------------------------------------------------------------
246     // XResultSet inherited
247     //-----------------------------------------------------------------
248     virtual sal_Bool SAL_CALL
249     next();
250     virtual sal_Bool SAL_CALL
251     isBeforeFirst();
252     virtual sal_Bool SAL_CALL
253     isAfterLast();
254     virtual sal_Bool SAL_CALL
255     isFirst();
256     virtual sal_Bool SAL_CALL
257     isLast();
258     virtual void SAL_CALL
259     beforeFirst();
260     virtual void SAL_CALL
261     afterLast();
262     virtual sal_Bool SAL_CALL
263     first();
264     virtual sal_Bool SAL_CALL
265     last();
266     virtual sal_Int32 SAL_CALL
267     getRow();
268     virtual sal_Bool SAL_CALL
269     absolute( sal_Int32 row );
270     virtual sal_Bool SAL_CALL
271     relative( sal_Int32 rows );
272     virtual sal_Bool SAL_CALL
273     previous();
274     virtual void SAL_CALL
275     refreshRow();
276     virtual sal_Bool SAL_CALL
277     rowUpdated();
278     virtual sal_Bool SAL_CALL
279     rowInserted();
280     virtual sal_Bool SAL_CALL
281     rowDeleted();
282     virtual com::sun::star::uno::Reference<
283                 com::sun::star::uno::XInterface > SAL_CALL
284     getStatement();
285 
286     //-----------------------------------------------------------------
287     // XRow inherited
288     //-----------------------------------------------------------------
289     virtual sal_Bool SAL_CALL
290     wasNull();
291 
292     virtual rtl::OUString SAL_CALL
293     getString( sal_Int32 columnIndex );
294 
295     virtual sal_Bool SAL_CALL
296     getBoolean( sal_Int32 columnIndex );
297 
298     virtual sal_Int8 SAL_CALL
299     getByte( sal_Int32 columnIndex );
300 
301     virtual sal_Int16 SAL_CALL
302     getShort( sal_Int32 columnIndex );
303 
304     virtual sal_Int32 SAL_CALL
305     getInt( sal_Int32 columnIndex );
306 
307     virtual sal_Int64 SAL_CALL
308     getLong( sal_Int32 columnIndex );
309 
310     virtual float SAL_CALL
311     getFloat( sal_Int32 columnIndex );
312 
313     virtual double SAL_CALL
314     getDouble( sal_Int32 columnIndex );
315 
316     virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL
317     getBytes( sal_Int32 columnIndex );
318 
319     virtual com::sun::star::util::Date SAL_CALL
320     getDate( sal_Int32 columnIndex );
321 
322     virtual com::sun::star::util::Time SAL_CALL
323     getTime( sal_Int32 columnIndex );
324 
325     virtual com::sun::star::util::DateTime SAL_CALL
326     getTimestamp( sal_Int32 columnIndex );
327 
328     virtual com::sun::star::uno::Reference<
329                 com::sun::star::io::XInputStream > SAL_CALL
330     getBinaryStream( sal_Int32 columnIndex );
331 
332     virtual com::sun::star::uno::Reference<
333                 com::sun::star::io::XInputStream > SAL_CALL
334     getCharacterStream( sal_Int32 columnIndex );
335 
336     virtual com::sun::star::uno::Any SAL_CALL
337     getObject( sal_Int32 columnIndex,
338                const com::sun::star::uno::Reference<
339                 com::sun::star::container::XNameAccess >& typeMap );
340 
341     virtual com::sun::star::uno::Reference<
342                 com::sun::star::sdbc::XRef > SAL_CALL
343     getRef( sal_Int32 columnIndex );
344 
345     virtual com::sun::star::uno::Reference<
346                 com::sun::star::sdbc::XBlob > SAL_CALL
347     getBlob( sal_Int32 columnIndex );
348 
349     virtual com::sun::star::uno::Reference<
350                 com::sun::star::sdbc::XClob > SAL_CALL
351     getClob( sal_Int32 columnIndex );
352 
353     virtual com::sun::star::uno::Reference<
354                 com::sun::star::sdbc::XArray > SAL_CALL
355     getArray( sal_Int32 columnIndex );
356 
357     //-----------------------------------------------------------------
358     // Type Converter support
359     //-----------------------------------------------------------------
360 
361 private:
362     sal_Bool m_bTriedToGetTypeConverter;
363     com::sun::star::uno::Reference<
364         com::sun::star::script::XTypeConverter > m_xTypeConverter;
365 
366     const com::sun::star::uno::Reference<
367         com::sun::star::script::XTypeConverter >& getTypeConverter();
368 };
369 
370 //=========================================================================
371 
372 class CachedContentResultSetFactory
373                 : public cppu::OWeakObject
374                 , public com::sun::star::lang::XTypeProvider
375                 , public com::sun::star::lang::XServiceInfo
376                 , public com::sun::star::ucb::XCachedContentResultSetFactory
377 {
378 protected:
379     com::sun::star::uno::Reference<
380         com::sun::star::lang::XMultiServiceFactory >    m_xSMgr;
381 
382 public:
383 
384     CachedContentResultSetFactory(
385         const com::sun::star::uno::Reference<
386         com::sun::star::lang::XMultiServiceFactory > & rSMgr);
387 
388     virtual ~CachedContentResultSetFactory();
389 
390     //-----------------------------------------------------------------
391     // XInterface
392     XINTERFACE_DECL()
393 
394     //-----------------------------------------------------------------
395     // XTypeProvider
396     XTYPEPROVIDER_DECL()
397 
398     //-----------------------------------------------------------------
399     // XServiceInfo
400     XSERVICEINFO_DECL()
401 
402     //-----------------------------------------------------------------
403     // XCachedContentResultSetFactory
404 
405     virtual com::sun::star::uno::Reference<
406                 com::sun::star::sdbc::XResultSet > SAL_CALL
407     createCachedContentResultSet(
408             const com::sun::star::uno::Reference<
409                 com::sun::star::sdbc::XResultSet > & xSource,
410             const com::sun::star::uno::Reference<
411                 com::sun::star::ucb::XContentIdentifierMapping > & xMapping );
412 };
413 
414 #endif
415