Update ooo320-m1
[ooovba.git] / ucb / source / cacher / contentresultsetwrapper.cxx
blob7f1254393e881caa7e0adafa582e22c2065d5ff7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: contentresultsetwrapper.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
34 #include <contentresultsetwrapper.hxx>
35 #include <com/sun/star/sdbc/FetchDirection.hpp>
36 #include <com/sun/star/ucb/FetchError.hpp>
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #include <com/sun/star/sdbc/ResultSetType.hpp>
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <rtl/ustring.hxx>
41 #include <osl/diagnose.h>
43 using namespace com::sun::star::beans;
44 using namespace com::sun::star::lang;
45 using namespace com::sun::star::sdbc;
46 using namespace com::sun::star::ucb;
47 using namespace com::sun::star::uno;
48 using namespace com::sun::star::util;
49 using namespace cppu;
50 using namespace rtl;
52 //--------------------------------------------------------------------------
53 //--------------------------------------------------------------------------
54 // class ContentResultSetWrapper
55 //--------------------------------------------------------------------------
56 //--------------------------------------------------------------------------
58 ContentResultSetWrapper::ContentResultSetWrapper(
59 Reference< XResultSet > xOrigin )
60 : m_xResultSetOrigin( xOrigin )
61 , m_xRowOrigin( NULL )
62 , m_xContentAccessOrigin( NULL )
63 , m_xPropertySetOrigin( NULL )
64 , m_xPropertySetInfo( NULL )
65 , m_nForwardOnly( 2 )
66 , m_xMetaDataFromOrigin( NULL )
67 , m_bDisposed( sal_False )
68 , m_bInDispose( sal_False )
69 , m_pDisposeEventListeners( NULL )
70 , m_pPropertyChangeListeners( NULL )
71 , m_pVetoableChangeListeners( NULL )
73 m_pMyListenerImpl = new ContentResultSetWrapperListener( this );
74 m_xMyListenerImpl = Reference< XPropertyChangeListener >( m_pMyListenerImpl );
76 OSL_ENSURE( m_xResultSetOrigin.is(), "XResultSet is required" );
78 //!! call impl_init() at the end of constructor of derived class
82 void SAL_CALL ContentResultSetWrapper::impl_init_xRowOrigin()
85 osl::Guard< osl::Mutex > aGuard( m_aMutex );
86 if(m_xRowOrigin.is())
87 return;
90 Reference< XRow > xOrgig =
91 Reference< XRow >( m_xResultSetOrigin, UNO_QUERY );
94 osl::Guard< osl::Mutex > aGuard( m_aMutex );
95 m_xRowOrigin = xOrgig;
96 OSL_ENSURE( m_xRowOrigin.is(), "interface XRow is required" );
100 void SAL_CALL ContentResultSetWrapper::impl_init_xContentAccessOrigin()
103 osl::Guard< osl::Mutex > aGuard( m_aMutex );
104 if(m_xContentAccessOrigin.is())
105 return;
108 Reference< XContentAccess > xOrgig =
109 Reference< XContentAccess >( m_xResultSetOrigin, UNO_QUERY );
112 osl::Guard< osl::Mutex > aGuard( m_aMutex );
113 m_xContentAccessOrigin = xOrgig;
114 OSL_ENSURE( m_xContentAccessOrigin.is(), "interface XContentAccess is required" );
119 void SAL_CALL ContentResultSetWrapper::impl_init_xPropertySetOrigin()
122 osl::Guard< osl::Mutex > aGuard( m_aMutex );
123 if( m_xPropertySetOrigin.is() )
124 return;
127 Reference< XPropertySet > xOrig =
128 Reference< XPropertySet >( m_xResultSetOrigin, UNO_QUERY );
131 osl::Guard< osl::Mutex > aGuard( m_aMutex );
132 m_xPropertySetOrigin = xOrig;
133 OSL_ENSURE( m_xPropertySetOrigin.is(), "interface XPropertySet is required" );
137 void SAL_CALL ContentResultSetWrapper::impl_init()
139 //call this at the end of constructor of derived class
142 //listen to disposing from Origin:
143 Reference< XComponent > xComponentOrigin( m_xResultSetOrigin, UNO_QUERY );
144 OSL_ENSURE( xComponentOrigin.is(), "interface XComponent is required" );
145 xComponentOrigin->addEventListener( static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) );
148 ContentResultSetWrapper::~ContentResultSetWrapper()
150 //call impl_deinit() at start of destructor of derived class
152 delete m_pDisposeEventListeners;
153 delete m_pPropertyChangeListeners;
154 delete m_pVetoableChangeListeners;
157 void SAL_CALL ContentResultSetWrapper::impl_deinit()
159 //call this at start of destructor of derived class
161 m_pMyListenerImpl->impl_OwnerDies();
164 //virtual
165 void SAL_CALL ContentResultSetWrapper
166 ::impl_initPropertySetInfo()
169 osl::Guard< osl::Mutex > aGuard( m_aMutex );
170 if( m_xPropertySetInfo.is() )
171 return;
173 impl_init_xPropertySetOrigin();
174 if( !m_xPropertySetOrigin.is() )
175 return;
178 Reference< XPropertySetInfo > xOrig =
179 m_xPropertySetOrigin->getPropertySetInfo();
182 osl::Guard< osl::Mutex > aGuard( m_aMutex );
183 m_xPropertySetInfo = xOrig;
187 void SAL_CALL ContentResultSetWrapper
188 ::impl_EnsureNotDisposed()
189 throw( DisposedException, RuntimeException )
191 osl::Guard< osl::Mutex > aGuard( m_aMutex );
192 if( m_bDisposed )
193 throw DisposedException();
196 ContentResultSetWrapper::PropertyChangeListenerContainer_Impl* SAL_CALL
197 ContentResultSetWrapper
198 ::impl_getPropertyChangeListenerContainer()
200 osl::Guard< osl::Mutex > aGuard( m_aMutex );
201 if ( !m_pPropertyChangeListeners )
202 m_pPropertyChangeListeners =
203 new PropertyChangeListenerContainer_Impl( m_aContainerMutex );
204 return m_pPropertyChangeListeners;
207 ContentResultSetWrapper::PropertyChangeListenerContainer_Impl* SAL_CALL
208 ContentResultSetWrapper
209 ::impl_getVetoableChangeListenerContainer()
211 osl::Guard< osl::Mutex > aGuard( m_aMutex );
212 if ( !m_pVetoableChangeListeners )
213 m_pVetoableChangeListeners =
214 new PropertyChangeListenerContainer_Impl( m_aContainerMutex );
215 return m_pVetoableChangeListeners;
218 void SAL_CALL ContentResultSetWrapper
219 ::impl_notifyPropertyChangeListeners(
220 const PropertyChangeEvent& rEvt )
223 osl::Guard< osl::Mutex > aGuard( m_aMutex );
224 if( !m_pPropertyChangeListeners )
225 return;
228 // Notify listeners interested especially in the changed property.
229 OInterfaceContainerHelper* pContainer =
230 m_pPropertyChangeListeners->getContainer( rEvt.PropertyName );
231 if( pContainer )
233 OInterfaceIteratorHelper aIter( *pContainer );
234 while( aIter.hasMoreElements() )
236 Reference< XPropertyChangeListener > xListener(
237 aIter.next(), UNO_QUERY );
238 if( xListener.is() )
239 xListener->propertyChange( rEvt );
243 // Notify listeners interested in all properties.
244 pContainer = m_pPropertyChangeListeners->getContainer( OUString() );
245 if( pContainer )
247 OInterfaceIteratorHelper aIter( *pContainer );
248 while( aIter.hasMoreElements() )
250 Reference< XPropertyChangeListener > xListener(
251 aIter.next(), UNO_QUERY );
252 if( xListener.is() )
253 xListener->propertyChange( rEvt );
258 void SAL_CALL ContentResultSetWrapper
259 ::impl_notifyVetoableChangeListeners( const PropertyChangeEvent& rEvt )
260 throw( PropertyVetoException,
261 RuntimeException )
264 osl::Guard< osl::Mutex > aGuard( m_aMutex );
265 if( !m_pVetoableChangeListeners )
266 return;
269 // Notify listeners interested especially in the changed property.
270 OInterfaceContainerHelper* pContainer =
271 m_pVetoableChangeListeners->getContainer( rEvt.PropertyName );
272 if( pContainer )
274 OInterfaceIteratorHelper aIter( *pContainer );
275 while( aIter.hasMoreElements() )
277 Reference< XVetoableChangeListener > xListener(
278 aIter.next(), UNO_QUERY );
279 if( xListener.is() )
280 xListener->vetoableChange( rEvt );
284 // Notify listeners interested in all properties.
285 pContainer = m_pVetoableChangeListeners->getContainer( OUString() );
286 if( pContainer )
288 OInterfaceIteratorHelper aIter( *pContainer );
289 while( aIter.hasMoreElements() )
291 Reference< XVetoableChangeListener > xListener(
292 aIter.next(), UNO_QUERY );
293 if( xListener.is() )
294 xListener->vetoableChange( rEvt );
299 sal_Bool SAL_CALL ContentResultSetWrapper
300 ::impl_isForwardOnly()
302 //m_nForwardOnly == 2 -> don't know
303 //m_nForwardOnly == 1 -> YES
304 //m_nForwardOnly == 0 -> NO
306 //@todo replace this with lines in comment
307 osl::Guard< osl::Mutex > aGuard( m_aMutex );
308 m_nForwardOnly = 0;
309 return false;
313 ReacquireableGuard aGuard( m_aMutex );
314 if( m_nForwardOnly == 2 )
316 aGuard.clear();
317 if( !getPropertySetInfo().is() )
319 aGuard.reacquire();
320 m_nForwardOnly = 0;
321 return m_nForwardOnly;
323 aGuard.reacquire();
325 rtl::OUString aName = OUString::createFromAscii( "ResultSetType" );
326 //find out, if we are ForwardOnly and cache the value:
328 impl_init_xPropertySetOrigin();
329 if( !m_xPropertySetOrigin.is() )
331 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
332 m_nForwardOnly = 0;
333 return m_nForwardOnly;
336 aGuard.clear();
337 Any aAny = m_xPropertySetOrigin->getPropertyValue( aName );
339 aGuard.reacquire();
340 long nResultSetType;
341 if( ( aAny >>= nResultSetType ) &&
342 ( nResultSetType == ResultSetType::FORWARD_ONLY ) )
343 m_nForwardOnly = 1;
344 else
345 m_nForwardOnly = 0;
347 return m_nForwardOnly;
351 //--------------------------------------------------------------------------
352 // XInterface methods.
353 //--------------------------------------------------------------------------
354 //list all interfaces inclusive baseclasses of interfaces
355 QUERYINTERFACE_IMPL_START( ContentResultSetWrapper )
357 SAL_STATIC_CAST( XComponent*, this ),
358 SAL_STATIC_CAST( XCloseable*, this ),
359 SAL_STATIC_CAST( XResultSetMetaDataSupplier*, this ),
360 SAL_STATIC_CAST( XPropertySet*, this ),
362 SAL_STATIC_CAST( XContentAccess*, this ),
363 SAL_STATIC_CAST( XResultSet*, this ),
364 SAL_STATIC_CAST( XRow*, this )
366 QUERYINTERFACE_IMPL_END
368 //--------------------------------------------------------------------------
369 // XComponent methods.
370 //--------------------------------------------------------------------------
371 // virtual
372 void SAL_CALL ContentResultSetWrapper
373 ::dispose() throw( RuntimeException )
375 impl_EnsureNotDisposed();
377 ReacquireableGuard aGuard( m_aMutex );
378 if( m_bInDispose || m_bDisposed )
379 return;
380 m_bInDispose = sal_True;
382 if( m_xPropertySetOrigin.is() )
384 aGuard.clear();
387 m_xPropertySetOrigin->removePropertyChangeListener(
388 OUString(), static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) );
390 catch( Exception& )
392 OSL_ENSURE( sal_False, "could not remove PropertyChangeListener" );
396 m_xPropertySetOrigin->removeVetoableChangeListener(
397 OUString(), static_cast< XVetoableChangeListener * >( m_pMyListenerImpl ) );
399 catch( Exception& )
401 OSL_ENSURE( sal_False, "could not remove VetoableChangeListener" );
404 Reference< XComponent > xComponentOrigin( m_xResultSetOrigin, UNO_QUERY );
405 OSL_ENSURE( xComponentOrigin.is(), "interface XComponent is required" );
406 xComponentOrigin->removeEventListener( static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) );
409 aGuard.reacquire();
410 if( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
412 EventObject aEvt;
413 aEvt.Source = static_cast< XComponent * >( this );
415 aGuard.clear();
416 m_pDisposeEventListeners->disposeAndClear( aEvt );
419 aGuard.reacquire();
420 if( m_pPropertyChangeListeners )
422 EventObject aEvt;
423 aEvt.Source = static_cast< XPropertySet * >( this );
425 aGuard.clear();
426 m_pPropertyChangeListeners->disposeAndClear( aEvt );
429 aGuard.reacquire();
430 if( m_pVetoableChangeListeners )
432 EventObject aEvt;
433 aEvt.Source = static_cast< XPropertySet * >( this );
435 aGuard.clear();
436 m_pVetoableChangeListeners->disposeAndClear( aEvt );
439 aGuard.reacquire();
440 m_bDisposed = sal_True;
441 m_bInDispose = sal_False;
444 //--------------------------------------------------------------------------
445 // virtual
446 void SAL_CALL ContentResultSetWrapper
447 ::addEventListener( const Reference< XEventListener >& Listener )
448 throw( RuntimeException )
450 impl_EnsureNotDisposed();
451 osl::Guard< osl::Mutex > aGuard( m_aMutex );
453 if ( !m_pDisposeEventListeners )
454 m_pDisposeEventListeners =
455 new OInterfaceContainerHelper( m_aContainerMutex );
457 m_pDisposeEventListeners->addInterface( Listener );
460 //--------------------------------------------------------------------------
461 // virtual
462 void SAL_CALL ContentResultSetWrapper
463 ::removeEventListener( const Reference< XEventListener >& Listener )
464 throw( RuntimeException )
466 impl_EnsureNotDisposed();
467 osl::Guard< osl::Mutex > aGuard( m_aMutex );
469 if ( m_pDisposeEventListeners )
470 m_pDisposeEventListeners->removeInterface( Listener );
473 //--------------------------------------------------------------------------
474 //XCloseable methods.
475 //--------------------------------------------------------------------------
476 //virtual
477 void SAL_CALL ContentResultSetWrapper
478 ::close()
479 throw( SQLException,
480 RuntimeException )
482 impl_EnsureNotDisposed();
483 dispose();
486 //--------------------------------------------------------------------------
487 //XResultSetMetaDataSupplier methods.
488 //--------------------------------------------------------------------------
489 //virtual
490 Reference< XResultSetMetaData > SAL_CALL ContentResultSetWrapper
491 ::getMetaData()
492 throw( SQLException,
493 RuntimeException )
495 impl_EnsureNotDisposed();
497 ReacquireableGuard aGuard( m_aMutex );
498 if( !m_xMetaDataFromOrigin.is() && m_xResultSetOrigin.is() )
500 Reference< XResultSetMetaDataSupplier > xMetaDataSupplier
501 = Reference< XResultSetMetaDataSupplier >(
502 m_xResultSetOrigin, UNO_QUERY );
504 if( xMetaDataSupplier.is() )
506 aGuard.clear();
508 Reference< XResultSetMetaData > xMetaData
509 = xMetaDataSupplier->getMetaData();
511 aGuard.reacquire();
512 m_xMetaDataFromOrigin = xMetaData;
515 return m_xMetaDataFromOrigin;
519 //--------------------------------------------------------------------------
520 // XPropertySet methods.
521 //--------------------------------------------------------------------------
522 // virtual
523 Reference< XPropertySetInfo > SAL_CALL ContentResultSetWrapper
524 ::getPropertySetInfo() throw( RuntimeException )
526 impl_EnsureNotDisposed();
528 osl::Guard< osl::Mutex > aGuard( m_aMutex );
529 if( m_xPropertySetInfo.is() )
530 return m_xPropertySetInfo;
532 impl_initPropertySetInfo();
533 return m_xPropertySetInfo;
535 //--------------------------------------------------------------------------
536 // virtual
537 void SAL_CALL ContentResultSetWrapper
538 ::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
539 throw( UnknownPropertyException,
540 PropertyVetoException,
541 IllegalArgumentException,
542 WrappedTargetException,
543 RuntimeException )
545 impl_EnsureNotDisposed();
546 impl_init_xPropertySetOrigin();
547 if( !m_xPropertySetOrigin.is() )
549 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
550 throw UnknownPropertyException();
552 m_xPropertySetOrigin->setPropertyValue( rPropertyName, rValue );
555 //--------------------------------------------------------------------------
556 // virtual
557 Any SAL_CALL ContentResultSetWrapper
558 ::getPropertyValue( const OUString& rPropertyName )
559 throw( UnknownPropertyException,
560 WrappedTargetException,
561 RuntimeException )
563 impl_EnsureNotDisposed();
564 impl_init_xPropertySetOrigin();
565 if( !m_xPropertySetOrigin.is() )
567 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
568 throw UnknownPropertyException();
570 return m_xPropertySetOrigin->getPropertyValue( rPropertyName );
573 //--------------------------------------------------------------------------
574 // virtual
575 void SAL_CALL ContentResultSetWrapper
576 ::addPropertyChangeListener(
577 const OUString& aPropertyName,
578 const Reference< XPropertyChangeListener >& xListener )
579 throw( UnknownPropertyException,
580 WrappedTargetException,
581 RuntimeException )
583 impl_EnsureNotDisposed();
585 if( !getPropertySetInfo().is() )
587 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
588 throw UnknownPropertyException();
591 if( aPropertyName.getLength() )
593 m_xPropertySetInfo->getPropertyByName( aPropertyName );
594 //throws UnknownPropertyException, if so
597 impl_getPropertyChangeListenerContainer();
598 sal_Bool bNeedRegister = !m_pPropertyChangeListeners->
599 getContainedTypes().getLength();
600 m_pPropertyChangeListeners->addInterface( aPropertyName, xListener );
601 if( bNeedRegister )
603 impl_init_xPropertySetOrigin();
605 osl::Guard< osl::Mutex > aGuard( m_aMutex );
606 if( !m_xPropertySetOrigin.is() )
608 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
609 return;
614 m_xPropertySetOrigin->addPropertyChangeListener(
615 OUString(), static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) );
617 catch( Exception& rEx )
619 m_pPropertyChangeListeners->removeInterface( aPropertyName, xListener );
620 throw rEx;
625 //--------------------------------------------------------------------------
626 // virtual
627 void SAL_CALL ContentResultSetWrapper
628 ::addVetoableChangeListener(
629 const OUString& rPropertyName,
630 const Reference< XVetoableChangeListener >& xListener )
631 throw( UnknownPropertyException,
632 WrappedTargetException,
633 RuntimeException )
635 impl_EnsureNotDisposed();
637 if( !getPropertySetInfo().is() )
639 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
640 throw UnknownPropertyException();
642 if( rPropertyName.getLength() )
644 m_xPropertySetInfo->getPropertyByName( rPropertyName );
645 //throws UnknownPropertyException, if so
648 impl_getVetoableChangeListenerContainer();
649 sal_Bool bNeedRegister = !m_pVetoableChangeListeners->
650 getContainedTypes().getLength();
651 m_pVetoableChangeListeners->addInterface( rPropertyName, xListener );
652 if( bNeedRegister )
654 impl_init_xPropertySetOrigin();
656 osl::Guard< osl::Mutex > aGuard( m_aMutex );
657 if( !m_xPropertySetOrigin.is() )
659 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
660 return;
665 m_xPropertySetOrigin->addVetoableChangeListener(
666 OUString(), static_cast< XVetoableChangeListener * >( m_pMyListenerImpl ) );
668 catch( Exception& rEx )
670 m_pVetoableChangeListeners->removeInterface( rPropertyName, xListener );
671 throw rEx;
676 //--------------------------------------------------------------------------
677 // virtual
678 void SAL_CALL ContentResultSetWrapper
679 ::removePropertyChangeListener(
680 const OUString& rPropertyName,
681 const Reference< XPropertyChangeListener >& xListener )
682 throw( UnknownPropertyException,
683 WrappedTargetException,
684 RuntimeException )
686 impl_EnsureNotDisposed();
689 //noop, if no listener registered
690 osl::Guard< osl::Mutex > aGuard( m_aMutex );
691 if( !m_pPropertyChangeListeners )
692 return;
694 OInterfaceContainerHelper* pContainer =
695 m_pPropertyChangeListeners->getContainer( rPropertyName );
697 if( !pContainer )
699 if( rPropertyName.getLength() )
701 if( !getPropertySetInfo().is() )
702 throw UnknownPropertyException();
704 m_xPropertySetInfo->getPropertyByName( rPropertyName );
705 //throws UnknownPropertyException, if so
707 return; //the listener was not registered
710 m_pPropertyChangeListeners->removeInterface( rPropertyName, xListener );
712 if( !m_pPropertyChangeListeners->getContainedTypes().getLength() )
714 impl_init_xPropertySetOrigin();
716 osl::Guard< osl::Mutex > aGuard( m_aMutex );
717 if( !m_xPropertySetOrigin.is() )
719 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
720 return;
725 m_xPropertySetOrigin->removePropertyChangeListener(
726 OUString(), static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) );
728 catch( Exception& )
730 OSL_ENSURE( sal_False, "could not remove PropertyChangeListener" );
735 //--------------------------------------------------------------------------
736 // virtual
737 void SAL_CALL ContentResultSetWrapper
738 ::removeVetoableChangeListener(
739 const OUString& rPropertyName,
740 const Reference< XVetoableChangeListener >& xListener )
741 throw( UnknownPropertyException,
742 WrappedTargetException,
743 RuntimeException )
745 impl_EnsureNotDisposed();
748 //noop, if no listener registered
749 osl::Guard< osl::Mutex > aGuard( m_aMutex );
750 if( !m_pVetoableChangeListeners )
751 return;
753 OInterfaceContainerHelper* pContainer =
754 m_pVetoableChangeListeners->getContainer( rPropertyName );
756 if( !pContainer )
758 if( rPropertyName.getLength() )
760 if( !getPropertySetInfo().is() )
761 throw UnknownPropertyException();
763 m_xPropertySetInfo->getPropertyByName( rPropertyName );
764 //throws UnknownPropertyException, if so
766 return; //the listener was not registered
769 m_pVetoableChangeListeners->removeInterface( rPropertyName, xListener );
771 if( !m_pVetoableChangeListeners->getContainedTypes().getLength() )
773 impl_init_xPropertySetOrigin();
775 osl::Guard< osl::Mutex > aGuard( m_aMutex );
776 if( !m_xPropertySetOrigin.is() )
778 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
779 return;
784 m_xPropertySetOrigin->removeVetoableChangeListener(
785 OUString(), static_cast< XVetoableChangeListener * >( m_pMyListenerImpl ) );
787 catch( Exception& )
789 OSL_ENSURE( sal_False, "could not remove VetoableChangeListener" );
794 //--------------------------------------------------------------------------
795 // own methods.
796 //--------------------------------------------------------------------------
798 //virtual
799 void SAL_CALL ContentResultSetWrapper
800 ::impl_disposing( const EventObject& )
801 throw( RuntimeException )
803 impl_EnsureNotDisposed();
805 osl::Guard< osl::Mutex > aGuard( m_aMutex );
807 if( !m_xResultSetOrigin.is() )
808 return;
810 //release all references to the broadcaster:
811 m_xResultSetOrigin.clear();
812 if(m_xRowOrigin.is())
813 m_xRowOrigin.clear();
814 if(m_xContentAccessOrigin.is())
815 m_xContentAccessOrigin.clear();
816 if(m_xPropertySetOrigin.is())
817 m_xPropertySetOrigin.clear();
818 m_xMetaDataFromOrigin.clear();
819 if(m_xPropertySetInfo.is())
820 m_xPropertySetInfo.clear();
823 //virtual
824 void SAL_CALL ContentResultSetWrapper
825 ::impl_propertyChange( const PropertyChangeEvent& rEvt )
826 throw( RuntimeException )
828 impl_EnsureNotDisposed();
830 PropertyChangeEvent aEvt( rEvt );
831 aEvt.Source = static_cast< XPropertySet * >( this );
832 aEvt.Further = sal_False;
833 impl_notifyPropertyChangeListeners( aEvt );
836 //virtual
837 void SAL_CALL ContentResultSetWrapper
838 ::impl_vetoableChange( const PropertyChangeEvent& rEvt )
839 throw( PropertyVetoException,
840 RuntimeException )
842 impl_EnsureNotDisposed();
844 PropertyChangeEvent aEvt( rEvt );
845 aEvt.Source = static_cast< XPropertySet * >( this );
846 aEvt.Further = sal_False;
848 impl_notifyVetoableChangeListeners( aEvt );
851 //--------------------------------------------------------------------------
852 // XContentAccess methods. ( -- position dependent )
853 //--------------------------------------------------------------------------
855 // virtual
856 OUString SAL_CALL ContentResultSetWrapper
857 ::queryContentIdentifierString()
858 throw( RuntimeException )
860 impl_EnsureNotDisposed();
861 impl_init_xContentAccessOrigin();
862 if( !m_xContentAccessOrigin.is() )
864 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
865 throw RuntimeException();
867 return m_xContentAccessOrigin->queryContentIdentifierString();
870 //--------------------------------------------------------------------------
871 // virtual
872 Reference< XContentIdentifier > SAL_CALL ContentResultSetWrapper
873 ::queryContentIdentifier()
874 throw( RuntimeException )
876 impl_EnsureNotDisposed();
877 impl_init_xContentAccessOrigin();
878 if( !m_xContentAccessOrigin.is() )
880 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
881 throw RuntimeException();
883 return m_xContentAccessOrigin->queryContentIdentifier();
886 //--------------------------------------------------------------------------
887 // virtual
888 Reference< XContent > SAL_CALL ContentResultSetWrapper
889 ::queryContent()
890 throw( RuntimeException )
892 impl_EnsureNotDisposed();
893 impl_init_xContentAccessOrigin();
894 if( !m_xContentAccessOrigin.is() )
896 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
897 throw RuntimeException();
899 return m_xContentAccessOrigin->queryContent();
902 //-----------------------------------------------------------------
903 // XResultSet methods.
904 //-----------------------------------------------------------------
905 //virtual
907 sal_Bool SAL_CALL ContentResultSetWrapper
908 ::next()
909 throw( SQLException,
910 RuntimeException )
912 impl_EnsureNotDisposed();
914 if( !m_xResultSetOrigin.is() )
916 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
917 throw RuntimeException();
919 return m_xResultSetOrigin->next();
922 //virtual
923 sal_Bool SAL_CALL ContentResultSetWrapper
924 ::previous()
925 throw( SQLException,
926 RuntimeException )
928 impl_EnsureNotDisposed();
930 if( !m_xResultSetOrigin.is() )
932 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
933 throw RuntimeException();
935 return m_xResultSetOrigin->previous();
938 //virtual
939 sal_Bool SAL_CALL ContentResultSetWrapper
940 ::absolute( sal_Int32 row )
941 throw( SQLException,
942 RuntimeException )
944 impl_EnsureNotDisposed();
946 if( !m_xResultSetOrigin.is() )
948 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
949 throw RuntimeException();
951 return m_xResultSetOrigin->absolute( row );
954 //virtual
955 sal_Bool SAL_CALL ContentResultSetWrapper
956 ::relative( sal_Int32 rows )
957 throw( SQLException,
958 RuntimeException )
960 impl_EnsureNotDisposed();
962 if( !m_xResultSetOrigin.is() )
964 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
965 throw RuntimeException();
967 return m_xResultSetOrigin->relative( rows );
971 //virtual
972 sal_Bool SAL_CALL ContentResultSetWrapper
973 ::first()
974 throw( SQLException,
975 RuntimeException )
977 impl_EnsureNotDisposed();
979 if( !m_xResultSetOrigin.is() )
981 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
982 throw RuntimeException();
984 return m_xResultSetOrigin->first();
987 //virtual
988 sal_Bool SAL_CALL ContentResultSetWrapper
989 ::last()
990 throw( SQLException,
991 RuntimeException )
993 impl_EnsureNotDisposed();
995 if( !m_xResultSetOrigin.is() )
997 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
998 throw RuntimeException();
1000 return m_xResultSetOrigin->last();
1003 //virtual
1004 void SAL_CALL ContentResultSetWrapper
1005 ::beforeFirst()
1006 throw( SQLException,
1007 RuntimeException )
1009 impl_EnsureNotDisposed();
1011 if( !m_xResultSetOrigin.is() )
1013 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1014 throw RuntimeException();
1016 m_xResultSetOrigin->beforeFirst();
1019 //virtual
1020 void SAL_CALL ContentResultSetWrapper
1021 ::afterLast()
1022 throw( SQLException,
1023 RuntimeException )
1025 impl_EnsureNotDisposed();
1027 if( !m_xResultSetOrigin.is() )
1029 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1030 throw RuntimeException();
1032 m_xResultSetOrigin->afterLast();
1035 //virtual
1036 sal_Bool SAL_CALL ContentResultSetWrapper
1037 ::isAfterLast()
1038 throw( SQLException,
1039 RuntimeException )
1041 impl_EnsureNotDisposed();
1043 if( !m_xResultSetOrigin.is() )
1045 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1046 throw RuntimeException();
1048 return m_xResultSetOrigin->isAfterLast();
1051 //virtual
1052 sal_Bool SAL_CALL ContentResultSetWrapper
1053 ::isBeforeFirst()
1054 throw( SQLException,
1055 RuntimeException )
1057 impl_EnsureNotDisposed();
1059 if( !m_xResultSetOrigin.is() )
1061 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1062 throw RuntimeException();
1064 return m_xResultSetOrigin->isBeforeFirst();
1067 //virtual
1068 sal_Bool SAL_CALL ContentResultSetWrapper
1069 ::isFirst()
1070 throw( SQLException,
1071 RuntimeException )
1073 impl_EnsureNotDisposed();
1075 if( !m_xResultSetOrigin.is() )
1077 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1078 throw RuntimeException();
1080 return m_xResultSetOrigin->isFirst();
1083 //virtual
1084 sal_Bool SAL_CALL ContentResultSetWrapper
1085 ::isLast()
1086 throw( SQLException,
1087 RuntimeException )
1089 impl_EnsureNotDisposed();
1091 if( !m_xResultSetOrigin.is() )
1093 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1094 throw RuntimeException();
1096 return m_xResultSetOrigin->isLast();
1100 //virtual
1101 sal_Int32 SAL_CALL ContentResultSetWrapper
1102 ::getRow()
1103 throw( SQLException,
1104 RuntimeException )
1106 impl_EnsureNotDisposed();
1108 if( !m_xResultSetOrigin.is() )
1110 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1111 throw RuntimeException();
1113 return m_xResultSetOrigin->getRow();
1116 //virtual
1117 void SAL_CALL ContentResultSetWrapper
1118 ::refreshRow()
1119 throw( SQLException,
1120 RuntimeException )
1122 impl_EnsureNotDisposed();
1124 if( !m_xResultSetOrigin.is() )
1126 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1127 throw RuntimeException();
1129 m_xResultSetOrigin->refreshRow();
1132 //virtual
1133 sal_Bool SAL_CALL ContentResultSetWrapper
1134 ::rowUpdated()
1135 throw( SQLException,
1136 RuntimeException )
1138 impl_EnsureNotDisposed();
1140 if( !m_xResultSetOrigin.is() )
1142 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1143 throw RuntimeException();
1145 return m_xResultSetOrigin->rowUpdated();
1147 //virtual
1148 sal_Bool SAL_CALL ContentResultSetWrapper
1149 ::rowInserted()
1150 throw( SQLException,
1151 RuntimeException )
1153 impl_EnsureNotDisposed();
1155 if( !m_xResultSetOrigin.is() )
1157 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1158 throw RuntimeException();
1160 return m_xResultSetOrigin->rowInserted();
1163 //virtual
1164 sal_Bool SAL_CALL ContentResultSetWrapper
1165 ::rowDeleted()
1166 throw( SQLException,
1167 RuntimeException )
1169 impl_EnsureNotDisposed();
1171 if( !m_xResultSetOrigin.is() )
1173 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1174 throw RuntimeException();
1176 return m_xResultSetOrigin->rowDeleted();
1179 //virtual
1180 Reference< XInterface > SAL_CALL ContentResultSetWrapper
1181 ::getStatement()
1182 throw( SQLException,
1183 RuntimeException )
1185 impl_EnsureNotDisposed();
1186 //@todo ?return anything
1187 return Reference< XInterface >();
1190 //-----------------------------------------------------------------
1191 // XRow methods.
1192 //-----------------------------------------------------------------
1194 #define XROW_GETXXX( getXXX ) \
1195 impl_EnsureNotDisposed(); \
1196 impl_init_xRowOrigin(); \
1197 if( !m_xRowOrigin.is() ) \
1199 OSL_ENSURE( sal_False, "broadcaster was disposed already" );\
1200 throw RuntimeException(); \
1202 return m_xRowOrigin->getXXX( columnIndex );
1204 //virtual
1205 sal_Bool SAL_CALL ContentResultSetWrapper
1206 ::wasNull()
1207 throw( SQLException,
1208 RuntimeException )
1210 impl_EnsureNotDisposed();
1211 impl_init_xRowOrigin();
1212 if( !m_xRowOrigin.is() )
1214 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1215 throw RuntimeException();
1217 return m_xRowOrigin->wasNull();
1220 //virtual
1221 rtl::OUString SAL_CALL ContentResultSetWrapper
1222 ::getString( sal_Int32 columnIndex )
1223 throw( SQLException,
1224 RuntimeException )
1226 XROW_GETXXX( getString );
1229 //virtual
1230 sal_Bool SAL_CALL ContentResultSetWrapper
1231 ::getBoolean( sal_Int32 columnIndex )
1232 throw( SQLException,
1233 RuntimeException )
1235 XROW_GETXXX( getBoolean );
1238 //virtual
1239 sal_Int8 SAL_CALL ContentResultSetWrapper
1240 ::getByte( sal_Int32 columnIndex )
1241 throw( SQLException,
1242 RuntimeException )
1244 XROW_GETXXX( getByte );
1247 //virtual
1248 sal_Int16 SAL_CALL ContentResultSetWrapper
1249 ::getShort( sal_Int32 columnIndex )
1250 throw( SQLException,
1251 RuntimeException )
1253 XROW_GETXXX( getShort );
1256 //virtual
1257 sal_Int32 SAL_CALL ContentResultSetWrapper
1258 ::getInt( sal_Int32 columnIndex )
1259 throw( SQLException,
1260 RuntimeException )
1262 XROW_GETXXX( getInt );
1265 //virtual
1266 sal_Int64 SAL_CALL ContentResultSetWrapper
1267 ::getLong( sal_Int32 columnIndex )
1268 throw( SQLException,
1269 RuntimeException )
1271 XROW_GETXXX( getLong );
1274 //virtual
1275 float SAL_CALL ContentResultSetWrapper
1276 ::getFloat( sal_Int32 columnIndex )
1277 throw( SQLException,
1278 RuntimeException )
1280 XROW_GETXXX( getFloat );
1283 //virtual
1284 double SAL_CALL ContentResultSetWrapper
1285 ::getDouble( sal_Int32 columnIndex )
1286 throw( SQLException,
1287 RuntimeException )
1289 XROW_GETXXX( getDouble );
1292 //virtual
1293 Sequence< sal_Int8 > SAL_CALL ContentResultSetWrapper
1294 ::getBytes( sal_Int32 columnIndex )
1295 throw( SQLException,
1296 RuntimeException )
1298 XROW_GETXXX( getBytes );
1301 //virtual
1302 Date SAL_CALL ContentResultSetWrapper
1303 ::getDate( sal_Int32 columnIndex )
1304 throw( SQLException,
1305 RuntimeException )
1307 XROW_GETXXX( getDate );
1310 //virtual
1311 Time SAL_CALL ContentResultSetWrapper
1312 ::getTime( sal_Int32 columnIndex )
1313 throw( SQLException,
1314 RuntimeException )
1316 XROW_GETXXX( getTime );
1319 //virtual
1320 DateTime SAL_CALL ContentResultSetWrapper
1321 ::getTimestamp( sal_Int32 columnIndex )
1322 throw( SQLException,
1323 RuntimeException )
1325 XROW_GETXXX( getTimestamp );
1328 //virtual
1329 Reference< com::sun::star::io::XInputStream >
1330 SAL_CALL ContentResultSetWrapper
1331 ::getBinaryStream( sal_Int32 columnIndex )
1332 throw( SQLException,
1333 RuntimeException )
1335 XROW_GETXXX( getBinaryStream );
1338 //virtual
1339 Reference< com::sun::star::io::XInputStream >
1340 SAL_CALL ContentResultSetWrapper
1341 ::getCharacterStream( sal_Int32 columnIndex )
1342 throw( SQLException,
1343 RuntimeException )
1345 XROW_GETXXX( getCharacterStream );
1348 //virtual
1349 Any SAL_CALL ContentResultSetWrapper
1350 ::getObject( sal_Int32 columnIndex,
1351 const Reference<
1352 com::sun::star::container::XNameAccess >& typeMap )
1353 throw( SQLException,
1354 RuntimeException )
1356 //if you change this macro please pay attention to
1357 //define XROW_GETXXX, where this is similar implemented
1359 impl_EnsureNotDisposed();
1360 impl_init_xRowOrigin();
1361 if( !m_xRowOrigin.is() )
1363 OSL_ENSURE( sal_False, "broadcaster was disposed already" );
1364 throw RuntimeException();
1366 return m_xRowOrigin->getObject( columnIndex, typeMap );
1369 //virtual
1370 Reference< XRef > SAL_CALL ContentResultSetWrapper
1371 ::getRef( sal_Int32 columnIndex )
1372 throw( SQLException,
1373 RuntimeException )
1375 XROW_GETXXX( getRef );
1378 //virtual
1379 Reference< XBlob > SAL_CALL ContentResultSetWrapper
1380 ::getBlob( sal_Int32 columnIndex )
1381 throw( SQLException,
1382 RuntimeException )
1384 XROW_GETXXX( getBlob );
1387 //virtual
1388 Reference< XClob > SAL_CALL ContentResultSetWrapper
1389 ::getClob( sal_Int32 columnIndex )
1390 throw( SQLException,
1391 RuntimeException )
1393 XROW_GETXXX( getClob );
1396 //virtual
1397 Reference< XArray > SAL_CALL ContentResultSetWrapper
1398 ::getArray( sal_Int32 columnIndex )
1399 throw( SQLException,
1400 RuntimeException )
1402 XROW_GETXXX( getArray );
1405 //--------------------------------------------------------------------------
1406 //--------------------------------------------------------------------------
1407 // class ContentResultSetWrapperListener
1408 //--------------------------------------------------------------------------
1409 //--------------------------------------------------------------------------
1411 ContentResultSetWrapperListener::ContentResultSetWrapperListener(
1412 ContentResultSetWrapper* pOwner )
1413 : m_pOwner( pOwner )
1417 ContentResultSetWrapperListener::~ContentResultSetWrapperListener()
1421 //--------------------------------------------------------------------------
1422 // XInterface methods.
1423 //--------------------------------------------------------------------------
1424 //list all interfaces inclusive baseclasses of interfaces
1425 XINTERFACE_COMMON_IMPL( ContentResultSetWrapperListener )
1426 QUERYINTERFACE_IMPL_START( ContentResultSetWrapperListener )
1428 static_cast< XEventListener * >(
1429 static_cast< XPropertyChangeListener * >(this))
1430 , SAL_STATIC_CAST( XPropertyChangeListener*, this )
1431 , SAL_STATIC_CAST( XVetoableChangeListener*, this )
1433 QUERYINTERFACE_IMPL_END
1436 //--------------------------------------------------------------------------
1437 //XEventListener methods.
1438 //--------------------------------------------------------------------------
1440 //virtual
1441 void SAL_CALL ContentResultSetWrapperListener
1442 ::disposing( const EventObject& rEventObject )
1443 throw( RuntimeException )
1445 if( m_pOwner )
1446 m_pOwner->impl_disposing( rEventObject );
1449 //--------------------------------------------------------------------------
1450 //XPropertyChangeListener methods.
1451 //--------------------------------------------------------------------------
1453 //virtual
1454 void SAL_CALL ContentResultSetWrapperListener
1455 ::propertyChange( const PropertyChangeEvent& rEvt )
1456 throw( RuntimeException )
1458 if( m_pOwner )
1459 m_pOwner->impl_propertyChange( rEvt );
1462 //--------------------------------------------------------------------------
1463 //XVetoableChangeListener methods.
1464 //--------------------------------------------------------------------------
1465 //virtual
1466 void SAL_CALL ContentResultSetWrapperListener
1467 ::vetoableChange( const PropertyChangeEvent& rEvt )
1468 throw( PropertyVetoException,
1469 RuntimeException )
1471 if( m_pOwner )
1472 m_pOwner->impl_vetoableChange( rEvt );
1475 void SAL_CALL ContentResultSetWrapperListener
1476 ::impl_OwnerDies()
1478 m_pOwner = NULL;