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