xref: /trunk/main/ucb/source/cacher/contentresultsetwrapper.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 _CONTENT_RESULTSET_WRAPPER_HXX
25 #define _CONTENT_RESULTSET_WRAPPER_HXX
26 
27 #include <rtl/ustring.hxx>
28 #include <ucbhelper/macros.hxx>
29 #include <osl/mutex.hxx>
30 #include <cppuhelper/weak.hxx>
31 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/sdbc/XCloseable.hpp>
33 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
34 #include <com/sun/star/sdbc/XResultSet.hpp>
35 #include <com/sun/star/sdbc/XRow.hpp>
36 #include <com/sun/star/ucb/XContentAccess.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/lang/DisposedException.hpp>
39 #include <cppuhelper/interfacecontainer.hxx>
40 
41 //=========================================================================
42 
43 class ContentResultSetWrapperListener;
44 class ContentResultSetWrapper
45                 : public cppu::OWeakObject
46                 , public com::sun::star::lang::XComponent
47                 , public com::sun::star::sdbc::XCloseable
48                 , public com::sun::star::sdbc::XResultSetMetaDataSupplier
49                 , public com::sun::star::beans::XPropertySet
50                 , public com::sun::star::ucb::XContentAccess
51                 , public com::sun::star::sdbc::XResultSet
52                 , public com::sun::star::sdbc::XRow
53 {
54 protected:
55 
56     //--------------------------------------------------------------------------
57     //class PropertyChangeListenerContainer_Impl.
58 
59     struct equalStr_Impl
60     {
operator ()ContentResultSetWrapper::equalStr_Impl61             bool operator()( const rtl::OUString& s1, const rtl::OUString& s2 ) const
62         {
63             return !!( s1 == s2 );
64         }
65     };
66 
67     struct hashStr_Impl
68     {
operator ()ContentResultSetWrapper::hashStr_Impl69         size_t operator()( const rtl::OUString& rName ) const
70         {
71             return rName.hashCode();
72         }
73     };
74 
75     typedef cppu::OMultiTypeInterfaceContainerHelperVar
76     < rtl::OUString , hashStr_Impl , equalStr_Impl >
77     PropertyChangeListenerContainer_Impl;
78     //--------------------------------------------------------------------------
79     // class ReacquireableGuard
80 
81     class ReacquireableGuard
82     {
83     protected:
84         osl::Mutex* pT;
85     public:
86 
ReacquireableGuard(osl::Mutex * t)87         ReacquireableGuard(osl::Mutex * t) : pT(t)
88         {
89             pT->acquire();
90         }
91 
ReacquireableGuard(osl::Mutex & t)92         ReacquireableGuard(osl::Mutex& t) : pT(&t)
93         {
94             pT->acquire();
95         }
96 
97         /** Releases mutex. */
~ReacquireableGuard()98         ~ReacquireableGuard()
99         {
100             if (pT)
101                 pT->release();
102         }
103 
104         /** Releases mutex. */
clear()105         void clear()
106         {
107             if(pT)
108             {
109                 pT->release();
110                 pT = NULL;
111             }
112         }
113 
114         /** Reacquire mutex. */
reacquire()115         void reacquire()
116         {
117             if(pT)
118             {
119                 pT->acquire();
120             }
121         }
122     };
123 
124     //-----------------------------------------------------------------
125     //members
126 
127     //my Mutex
128     osl::Mutex              m_aMutex;
129 
130     //different Interfaces from Origin:
131     com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet >
132                             m_xResultSetOrigin;
133     com::sun::star::uno::Reference< com::sun::star::sdbc::XRow >
134                             m_xRowOrigin; //XRow-interface from m_xOrigin
135                             //!! call impl_init_xRowOrigin() bevor you access this member
136     com::sun::star::uno::Reference< com::sun::star::ucb::XContentAccess >
137                             m_xContentAccessOrigin; //XContentAccess-interface from m_xOrigin
138                             //!! call impl_init_xContentAccessOrigin() bevor you access this member
139     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >
140                             m_xPropertySetOrigin; //XPropertySet-interface from m_xOrigin
141                             //!! call impl_init_xPropertySetOrigin() bevor you access this member
142 
143     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >
144                             m_xPropertySetInfo;
145                             //call impl_initPropertySetInfo() bevor you access this member
146 
147     sal_Int32               m_nForwardOnly;
148 
149 private:
150     com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener >
151                             m_xMyListenerImpl;
152     ContentResultSetWrapperListener*
153                             m_pMyListenerImpl;
154 
155     com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSetMetaData >
156                             m_xMetaDataFromOrigin; //XResultSetMetaData from m_xOrigin
157 
158     //management of listeners
159     sal_Bool                m_bDisposed; ///Dispose call ready.
160     sal_Bool                m_bInDispose;///In dispose call
161     osl::Mutex              m_aContainerMutex;
162     cppu::OInterfaceContainerHelper*
163                             m_pDisposeEventListeners;
164     PropertyChangeListenerContainer_Impl*
165                             m_pPropertyChangeListeners;
166     PropertyChangeListenerContainer_Impl*
167                             m_pVetoableChangeListeners;
168 
169     //-----------------------------------------------------------------
170     //methods:
171 private:
172     PropertyChangeListenerContainer_Impl* SAL_CALL
173     impl_getPropertyChangeListenerContainer();
174 
175     PropertyChangeListenerContainer_Impl* SAL_CALL
176     impl_getVetoableChangeListenerContainer();
177 
178 protected:
179     //-----------------------------------------------------------------
180 
181     ContentResultSetWrapper( com::sun::star::uno::Reference<
182                         com::sun::star::sdbc::XResultSet > xOrigin );
183 
184     virtual ~ContentResultSetWrapper();
185 
186     void SAL_CALL impl_init();
187     void SAL_CALL impl_deinit();
188 
189     //--
190 
191     void SAL_CALL impl_init_xRowOrigin();
192     void SAL_CALL impl_init_xContentAccessOrigin();
193     void SAL_CALL impl_init_xPropertySetOrigin();
194 
195     //--
196 
197     virtual void SAL_CALL impl_initPropertySetInfo(); //helping XPropertySet
198 
199     void SAL_CALL
200     impl_EnsureNotDisposed();
201 
202     void SAL_CALL
203     impl_notifyPropertyChangeListeners(
204             const com::sun::star::beans::PropertyChangeEvent& rEvt );
205 
206     void SAL_CALL
207     impl_notifyVetoableChangeListeners(
208             const com::sun::star::beans::PropertyChangeEvent& rEvt );
209 
210     sal_Bool SAL_CALL impl_isForwardOnly();
211 
212 public:
213 
214     //-----------------------------------------------------------------
215     // XInterface
216     //-----------------------------------------------------------------
217     virtual com::sun::star::uno::Any SAL_CALL
218     queryInterface( const com::sun::star::uno::Type & rType );
219 
220     //-----------------------------------------------------------------
221     // XComponent
222     //-----------------------------------------------------------------
223     virtual void SAL_CALL
224     dispose();
225 
226     virtual void SAL_CALL
227     addEventListener( const com::sun::star::uno::Reference<
228         com::sun::star::lang::XEventListener >& Listener );
229 
230     virtual void SAL_CALL
231     removeEventListener( const com::sun::star::uno::Reference<
232         com::sun::star::lang::XEventListener >& Listener );
233 
234     //-----------------------------------------------------------------
235     //XCloseable
236     //-----------------------------------------------------------------
237     virtual void SAL_CALL
238     close();
239 
240     //-----------------------------------------------------------------
241     //XResultSetMetaDataSupplier
242     //-----------------------------------------------------------------
243     virtual com::sun::star::uno::Reference<
244                 com::sun::star::sdbc::XResultSetMetaData > SAL_CALL
245     getMetaData();
246 
247     //-----------------------------------------------------------------
248     // XPropertySet
249     //-----------------------------------------------------------------
250     virtual com::sun::star::uno::Reference<
251                 com::sun::star::beans::XPropertySetInfo > SAL_CALL
252     getPropertySetInfo();
253 
254     virtual void SAL_CALL
255     setPropertyValue( const rtl::OUString& aPropertyName,
256                       const com::sun::star::uno::Any& aValue );
257 
258     virtual com::sun::star::uno::Any SAL_CALL
259     getPropertyValue( const rtl::OUString& PropertyName );
260 
261     virtual void SAL_CALL
262     addPropertyChangeListener( const rtl::OUString& aPropertyName,
263                                const com::sun::star::uno::Reference<
264                                     com::sun::star::beans::XPropertyChangeListener >& xListener );
265 
266     virtual void SAL_CALL
267     removePropertyChangeListener( const rtl::OUString& aPropertyName,
268                                   const com::sun::star::uno::Reference<
269                                     com::sun::star::beans::XPropertyChangeListener >& aListener );
270 
271     virtual void SAL_CALL
272     addVetoableChangeListener( const rtl::OUString& PropertyName,
273                                const com::sun::star::uno::Reference<
274                                     com::sun::star::beans::XVetoableChangeListener >& aListener );
275 
276     virtual void SAL_CALL
277     removeVetoableChangeListener( const rtl::OUString& PropertyName,
278                                   const com::sun::star::uno::Reference<
279                                     com::sun::star::beans::XVetoableChangeListener >& aListener );
280 
281     //-----------------------------------------------------------------
282     // own methods
283     //-----------------------------------------------------------------
284     virtual void SAL_CALL
285         impl_disposing( const com::sun::star::lang::EventObject& Source );
286 
287     virtual void SAL_CALL
288     impl_propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt );
289 
290     virtual void SAL_CALL
291     impl_vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent );
292 
293     //-----------------------------------------------------------------
294     // XContentAccess
295     //-----------------------------------------------------------------
296     virtual rtl::OUString SAL_CALL
297     queryContentIdentifierString();
298 
299     virtual com::sun::star::uno::Reference<
300                 com::sun::star::ucb::XContentIdentifier > SAL_CALL
301     queryContentIdentifier();
302 
303     virtual com::sun::star::uno::Reference<
304                 com::sun::star::ucb::XContent > SAL_CALL
305     queryContent();
306 
307     //-----------------------------------------------------------------
308     // XResultSet
309     //-----------------------------------------------------------------
310     virtual sal_Bool SAL_CALL
311     next();
312     virtual sal_Bool SAL_CALL
313     isBeforeFirst();
314     virtual sal_Bool SAL_CALL
315     isAfterLast();
316     virtual sal_Bool SAL_CALL
317     isFirst();
318     virtual sal_Bool SAL_CALL
319     isLast();
320     virtual void SAL_CALL
321     beforeFirst();
322     virtual void SAL_CALL
323     afterLast();
324     virtual sal_Bool SAL_CALL
325     first();
326     virtual sal_Bool SAL_CALL
327     last();
328     virtual sal_Int32 SAL_CALL
329     getRow();
330     virtual sal_Bool SAL_CALL
331     absolute( sal_Int32 row );
332     virtual sal_Bool SAL_CALL
333     relative( sal_Int32 rows );
334     virtual sal_Bool SAL_CALL
335     previous();
336     virtual void SAL_CALL
337     refreshRow();
338     virtual sal_Bool SAL_CALL
339     rowUpdated();
340     virtual sal_Bool SAL_CALL
341     rowInserted();
342     virtual sal_Bool SAL_CALL
343     rowDeleted();
344     virtual com::sun::star::uno::Reference<
345                 com::sun::star::uno::XInterface > SAL_CALL
346     getStatement();
347 
348     //-----------------------------------------------------------------
349     // XRow
350     //-----------------------------------------------------------------
351     virtual sal_Bool SAL_CALL
352     wasNull();
353 
354     virtual rtl::OUString SAL_CALL
355     getString( sal_Int32 columnIndex );
356 
357     virtual sal_Bool SAL_CALL
358     getBoolean( sal_Int32 columnIndex );
359 
360     virtual sal_Int8 SAL_CALL
361     getByte( sal_Int32 columnIndex );
362 
363     virtual sal_Int16 SAL_CALL
364     getShort( sal_Int32 columnIndex );
365 
366     virtual sal_Int32 SAL_CALL
367     getInt( sal_Int32 columnIndex );
368 
369     virtual sal_Int64 SAL_CALL
370     getLong( sal_Int32 columnIndex );
371 
372     virtual float SAL_CALL
373     getFloat( sal_Int32 columnIndex );
374 
375     virtual double SAL_CALL
376     getDouble( sal_Int32 columnIndex );
377 
378     virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL
379     getBytes( sal_Int32 columnIndex );
380 
381     virtual com::sun::star::util::Date SAL_CALL
382     getDate( sal_Int32 columnIndex );
383 
384     virtual com::sun::star::util::Time SAL_CALL
385     getTime( sal_Int32 columnIndex );
386 
387     virtual com::sun::star::util::DateTime SAL_CALL
388     getTimestamp( sal_Int32 columnIndex );
389 
390     virtual com::sun::star::uno::Reference<
391                 com::sun::star::io::XInputStream > SAL_CALL
392     getBinaryStream( sal_Int32 columnIndex );
393 
394     virtual com::sun::star::uno::Reference<
395                 com::sun::star::io::XInputStream > SAL_CALL
396     getCharacterStream( sal_Int32 columnIndex );
397 
398     virtual com::sun::star::uno::Any SAL_CALL
399     getObject( sal_Int32 columnIndex,
400                const com::sun::star::uno::Reference<
401                 com::sun::star::container::XNameAccess >& typeMap );
402 
403     virtual com::sun::star::uno::Reference<
404                 com::sun::star::sdbc::XRef > SAL_CALL
405     getRef( sal_Int32 columnIndex );
406 
407     virtual com::sun::star::uno::Reference<
408                 com::sun::star::sdbc::XBlob > SAL_CALL
409     getBlob( sal_Int32 columnIndex );
410 
411     virtual com::sun::star::uno::Reference<
412                 com::sun::star::sdbc::XClob > SAL_CALL
413     getClob( sal_Int32 columnIndex );
414 
415     virtual com::sun::star::uno::Reference<
416                 com::sun::star::sdbc::XArray > SAL_CALL
417     getArray( sal_Int32 columnIndex );
418 };
419 
420 //=========================================================================
421 
422 class ContentResultSetWrapperListener
423         : public cppu::OWeakObject
424         , public com::sun::star::beans::XPropertyChangeListener
425         , public com::sun::star::beans::XVetoableChangeListener
426 {
427 protected:
428     ContentResultSetWrapper*    m_pOwner;
429 
430 public:
431     ContentResultSetWrapperListener( ContentResultSetWrapper* pOwner );
432 
433     virtual ~ContentResultSetWrapperListener();
434 
435     //-----------------------------------------------------------------
436     // XInterface
437     //-----------------------------------------------------------------
438     XINTERFACE_DECL()
439 
440     //-----------------------------------------------------------------
441     //XEventListener
442     //-----------------------------------------------------------------
443     virtual void SAL_CALL
444         disposing( const com::sun::star::lang::EventObject& Source );
445 
446     //-----------------------------------------------------------------
447     //XPropertyChangeListener
448     //-----------------------------------------------------------------
449     virtual void SAL_CALL
450     propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt );
451 
452     //-----------------------------------------------------------------
453     //XVetoableChangeListener
454     //-----------------------------------------------------------------
455     virtual void SAL_CALL
456     vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent );
457 
458     //-----------------------------------------------------------------
459     // own methods:
460     void SAL_CALL impl_OwnerDies();
461 };
462 
463 #endif
464