xref: /AOO42X/main/ucb/source/cacher/dynamicresultsetwrapper.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_ucb.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <dynamicresultsetwrapper.hxx>
32*cdf0e10cSrcweir #include <ucbhelper/macros.hxx>
33*cdf0e10cSrcweir #include <osl/diagnose.h>
34*cdf0e10cSrcweir #include <rtl/ustring.hxx>
35*cdf0e10cSrcweir #include <com/sun/star/ucb/ListActionType.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir using namespace com::sun::star::lang;
40*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
41*cdf0e10cSrcweir using namespace com::sun::star::ucb;
42*cdf0e10cSrcweir using namespace com::sun::star::uno;
43*cdf0e10cSrcweir using namespace cppu;
44*cdf0e10cSrcweir using namespace rtl;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir //--------------------------------------------------------------------------
47*cdf0e10cSrcweir //--------------------------------------------------------------------------
48*cdf0e10cSrcweir // class DynamicResultSetWrapper
49*cdf0e10cSrcweir //--------------------------------------------------------------------------
50*cdf0e10cSrcweir //--------------------------------------------------------------------------
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir DynamicResultSetWrapper::DynamicResultSetWrapper(
53*cdf0e10cSrcweir                     Reference< XDynamicResultSet > xOrigin
54*cdf0e10cSrcweir                     , const Reference< XMultiServiceFactory > & xSMgr )
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir                 : m_bDisposed( sal_False )
57*cdf0e10cSrcweir                 , m_bInDispose( sal_False )
58*cdf0e10cSrcweir                 , m_pDisposeEventListeners( NULL )
59*cdf0e10cSrcweir                 , m_xSMgr( xSMgr )
60*cdf0e10cSrcweir                 , m_bStatic( sal_False )
61*cdf0e10cSrcweir                 , m_bGotWelcome( sal_False )
62*cdf0e10cSrcweir                 , m_xSource( xOrigin )
63*cdf0e10cSrcweir                 , m_xSourceResultOne( NULL )
64*cdf0e10cSrcweir                 , m_xSourceResultTwo( NULL )
65*cdf0e10cSrcweir             //  , m_xSourceResultCurrent( NULL )
66*cdf0e10cSrcweir             //  , m_bUseOne( NULL )
67*cdf0e10cSrcweir                 , m_xMyResultOne( NULL )
68*cdf0e10cSrcweir                 , m_xMyResultTwo( NULL )
69*cdf0e10cSrcweir                 , m_xListener( NULL )
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir     m_pMyListenerImpl = new DynamicResultSetWrapperListener( this );
72*cdf0e10cSrcweir     m_xMyListenerImpl = Reference< XDynamicResultSetListener >( m_pMyListenerImpl );
73*cdf0e10cSrcweir     //call impl_init() at the end of constructor of derived class
74*cdf0e10cSrcweir };
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper::impl_init()
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     //call this at the end of constructor of derived class
79*cdf0e10cSrcweir     //
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     Reference< XDynamicResultSet > xSource = NULL;
82*cdf0e10cSrcweir     {
83*cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
84*cdf0e10cSrcweir         xSource = m_xSource;
85*cdf0e10cSrcweir         m_xSource = NULL;
86*cdf0e10cSrcweir     }
87*cdf0e10cSrcweir     if( xSource.is() )
88*cdf0e10cSrcweir         setSource( xSource );
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir DynamicResultSetWrapper::~DynamicResultSetWrapper()
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir     //call impl_deinit() at start of destructor of derived class
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir     delete m_pDisposeEventListeners;
96*cdf0e10cSrcweir };
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper::impl_deinit()
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir     //call this at start of destructor of derived class
101*cdf0e10cSrcweir     //
102*cdf0e10cSrcweir     m_pMyListenerImpl->impl_OwnerDies();
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper
106*cdf0e10cSrcweir ::impl_EnsureNotDisposed()
107*cdf0e10cSrcweir     throw( DisposedException, RuntimeException )
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
110*cdf0e10cSrcweir     if( m_bDisposed )
111*cdf0e10cSrcweir         throw DisposedException();
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir //virtual
115*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper
116*cdf0e10cSrcweir ::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet )
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
119*cdf0e10cSrcweir     OSL_ENSURE( !m_xSourceResultOne.is(), "Source ResultSet One is set already" );
120*cdf0e10cSrcweir     m_xSourceResultOne = xResultSet;
121*cdf0e10cSrcweir     m_xMyResultOne = xResultSet;
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir //virtual
125*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper
126*cdf0e10cSrcweir ::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet )
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
129*cdf0e10cSrcweir     OSL_ENSURE( !m_xSourceResultTwo.is(), "Source ResultSet Two is set already" );
130*cdf0e10cSrcweir     m_xSourceResultTwo = xResultSet;
131*cdf0e10cSrcweir     m_xMyResultTwo = xResultSet;
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir //--------------------------------------------------------------------------
135*cdf0e10cSrcweir // XInterface methods.
136*cdf0e10cSrcweir //--------------------------------------------------------------------------
137*cdf0e10cSrcweir //list all interfaces inclusive baseclasses of interfaces
138*cdf0e10cSrcweir QUERYINTERFACE_IMPL_START( DynamicResultSetWrapper )
139*cdf0e10cSrcweir     SAL_STATIC_CAST( XComponent*, this ) //base of XDynamicResultSet
140*cdf0e10cSrcweir     , SAL_STATIC_CAST( XDynamicResultSet*, this )
141*cdf0e10cSrcweir     , SAL_STATIC_CAST( XSourceInitialization*, this )
142*cdf0e10cSrcweir QUERYINTERFACE_IMPL_END
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir //--------------------------------------------------------------------------
145*cdf0e10cSrcweir // XComponent methods.
146*cdf0e10cSrcweir //--------------------------------------------------------------------------
147*cdf0e10cSrcweir // virtual
148*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper
149*cdf0e10cSrcweir     ::dispose() throw( RuntimeException )
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir     impl_EnsureNotDisposed();
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     Reference< XComponent > xSourceComponent;
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir         osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
156*cdf0e10cSrcweir         if( m_bInDispose || m_bDisposed )
157*cdf0e10cSrcweir             return;
158*cdf0e10cSrcweir         m_bInDispose = sal_True;
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir         xSourceComponent = Reference< XComponent >(m_xSource, UNO_QUERY);
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir         if( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
163*cdf0e10cSrcweir         {
164*cdf0e10cSrcweir             EventObject aEvt;
165*cdf0e10cSrcweir             aEvt.Source = static_cast< XComponent * >( this );
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir             aGuard.clear();
168*cdf0e10cSrcweir             m_pDisposeEventListeners->disposeAndClear( aEvt );
169*cdf0e10cSrcweir         }
170*cdf0e10cSrcweir     }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     /* //@todo ?? ( only if java collection needs to long )
173*cdf0e10cSrcweir     if( xSourceComponent.is() )
174*cdf0e10cSrcweir         xSourceComponent->dispose();
175*cdf0e10cSrcweir     */
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
178*cdf0e10cSrcweir     m_bDisposed = sal_True;
179*cdf0e10cSrcweir     m_bInDispose = sal_False;
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir //--------------------------------------------------------------------------
183*cdf0e10cSrcweir // virtual
184*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper
185*cdf0e10cSrcweir     ::addEventListener( const Reference< XEventListener >& Listener )
186*cdf0e10cSrcweir     throw( RuntimeException )
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir     impl_EnsureNotDisposed();
189*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     if ( !m_pDisposeEventListeners )
192*cdf0e10cSrcweir         m_pDisposeEventListeners =
193*cdf0e10cSrcweir                     new OInterfaceContainerHelper( m_aContainerMutex );
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir     m_pDisposeEventListeners->addInterface( Listener );
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir //--------------------------------------------------------------------------
199*cdf0e10cSrcweir // virtual
200*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper
201*cdf0e10cSrcweir     ::removeEventListener( const Reference< XEventListener >& Listener )
202*cdf0e10cSrcweir     throw( RuntimeException )
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir     impl_EnsureNotDisposed();
205*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     if ( m_pDisposeEventListeners )
208*cdf0e10cSrcweir         m_pDisposeEventListeners->removeInterface( Listener );
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir //--------------------------------------------------------------------------
212*cdf0e10cSrcweir // own methods
213*cdf0e10cSrcweir //--------------------------------------------------------------------------
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir //virtual
216*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper
217*cdf0e10cSrcweir     ::impl_disposing( const EventObject& )
218*cdf0e10cSrcweir     throw( RuntimeException )
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir     impl_EnsureNotDisposed();
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir     if( !m_xSource.is() )
225*cdf0e10cSrcweir         return;
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir     //release all references to the broadcaster:
228*cdf0e10cSrcweir     m_xSource.clear();
229*cdf0e10cSrcweir     m_xSourceResultOne.clear();//?? or only when not static??
230*cdf0e10cSrcweir     m_xSourceResultTwo.clear();//??
231*cdf0e10cSrcweir     //@todo m_xMyResultOne.clear(); ???
232*cdf0e10cSrcweir     //@todo m_xMyResultTwo.clear(); ???
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir //virtual
236*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper
237*cdf0e10cSrcweir     ::impl_notify( const ListEvent& Changes )
238*cdf0e10cSrcweir     throw( RuntimeException )
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir     impl_EnsureNotDisposed();
241*cdf0e10cSrcweir     //@todo
242*cdf0e10cSrcweir     /*
243*cdf0e10cSrcweir     <p>The Listener is allowed to blockade this call, until he really want to go
244*cdf0e10cSrcweir     to the new version. The only situation, where the listener has to return the
245*cdf0e10cSrcweir     update call at once is, while he disposes his broadcaster or while he is
246*cdf0e10cSrcweir     removing himsef as listener (otherwise you deadlock)!!!
247*cdf0e10cSrcweir     */
248*cdf0e10cSrcweir     // handle the actions in the list
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     ListEvent aNewEvent;
251*cdf0e10cSrcweir     aNewEvent.Source = static_cast< XDynamicResultSet * >( this );
252*cdf0e10cSrcweir     aNewEvent.Changes = Changes.Changes;
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir     {
255*cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
256*cdf0e10cSrcweir         for( long i=0; !m_bGotWelcome && i<Changes.Changes.getLength(); i++ )
257*cdf0e10cSrcweir         {
258*cdf0e10cSrcweir             ListAction& rAction = aNewEvent.Changes[i];
259*cdf0e10cSrcweir             switch( rAction.ListActionType )
260*cdf0e10cSrcweir             {
261*cdf0e10cSrcweir                 case ListActionType::WELCOME:
262*cdf0e10cSrcweir                 {
263*cdf0e10cSrcweir                     WelcomeDynamicResultSetStruct aWelcome;
264*cdf0e10cSrcweir                     if( rAction.ActionInfo >>= aWelcome )
265*cdf0e10cSrcweir                     {
266*cdf0e10cSrcweir                         impl_InitResultSetOne( aWelcome.Old );
267*cdf0e10cSrcweir                         impl_InitResultSetTwo( aWelcome.New );
268*cdf0e10cSrcweir                         m_bGotWelcome = sal_True;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir                         aWelcome.Old = m_xMyResultOne;
271*cdf0e10cSrcweir                         aWelcome.New = m_xMyResultTwo;
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir                          rAction.ActionInfo <<= aWelcome;
274*cdf0e10cSrcweir                     }
275*cdf0e10cSrcweir                     else
276*cdf0e10cSrcweir                     {
277*cdf0e10cSrcweir                         OSL_ENSURE( sal_False, "ListActionType was WELCOME but ActionInfo didn't contain a WelcomeDynamicResultSetStruct" );
278*cdf0e10cSrcweir                         //throw RuntimeException();
279*cdf0e10cSrcweir                     }
280*cdf0e10cSrcweir                     break;
281*cdf0e10cSrcweir                 }
282*cdf0e10cSrcweir             }
283*cdf0e10cSrcweir         }
284*cdf0e10cSrcweir         OSL_ENSURE( m_bGotWelcome, "first notification was without WELCOME" );
285*cdf0e10cSrcweir     }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir     if( !m_xListener.is() )
288*cdf0e10cSrcweir         m_aListenerSet.wait();
289*cdf0e10cSrcweir     m_xListener->notify( aNewEvent );
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     /*
292*cdf0e10cSrcweir     m_bUseOne = !m_bUseOne;
293*cdf0e10cSrcweir     if( m_bUseOne )
294*cdf0e10cSrcweir         m_xSourceResultCurrent = m_xSourceResultOne;
295*cdf0e10cSrcweir     else
296*cdf0e10cSrcweir         m_xSourceResultCurrent = m_xSourceResultTwo;
297*cdf0e10cSrcweir     */
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir //--------------------------------------------------------------------------
301*cdf0e10cSrcweir // XSourceInitialization
302*cdf0e10cSrcweir //--------------------------------------------------------------------------
303*cdf0e10cSrcweir //virtual
304*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper
305*cdf0e10cSrcweir     ::setSource( const Reference< XInterface > & Source )
306*cdf0e10cSrcweir     throw( AlreadyInitializedException, RuntimeException )
307*cdf0e10cSrcweir {
308*cdf0e10cSrcweir     impl_EnsureNotDisposed();
309*cdf0e10cSrcweir     {
310*cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
311*cdf0e10cSrcweir         if( m_xSource.is() )
312*cdf0e10cSrcweir         {
313*cdf0e10cSrcweir             throw AlreadyInitializedException();
314*cdf0e10cSrcweir         }
315*cdf0e10cSrcweir     }
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir     Reference< XDynamicResultSet > xSourceDynamic( Source, UNO_QUERY );
318*cdf0e10cSrcweir     OSL_ENSURE( xSourceDynamic.is(),
319*cdf0e10cSrcweir         "the given source is not of required type XDynamicResultSet" );
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     Reference< XDynamicResultSetListener > xListener = NULL;
322*cdf0e10cSrcweir     Reference< XDynamicResultSetListener > xMyListenerImpl = NULL;
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir     sal_Bool bStatic = sal_False;
325*cdf0e10cSrcweir     {
326*cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
327*cdf0e10cSrcweir         m_xSource = xSourceDynamic;
328*cdf0e10cSrcweir         xListener = m_xListener;
329*cdf0e10cSrcweir         bStatic = m_bStatic;
330*cdf0e10cSrcweir         xMyListenerImpl = m_xMyListenerImpl;
331*cdf0e10cSrcweir     }
332*cdf0e10cSrcweir     if( xListener.is() )
333*cdf0e10cSrcweir         xSourceDynamic->setListener( m_xMyListenerImpl );
334*cdf0e10cSrcweir     else if( bStatic )
335*cdf0e10cSrcweir     {
336*cdf0e10cSrcweir         Reference< XComponent > xSourceComponent( Source, UNO_QUERY );
337*cdf0e10cSrcweir         xSourceComponent->addEventListener( Reference< XEventListener > ::query( xMyListenerImpl ) );
338*cdf0e10cSrcweir     }
339*cdf0e10cSrcweir     m_aSourceSet.set();
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir //--------------------------------------------------------------------------
343*cdf0e10cSrcweir // XDynamicResultSet
344*cdf0e10cSrcweir //--------------------------------------------------------------------------
345*cdf0e10cSrcweir //virtual
346*cdf0e10cSrcweir Reference< XResultSet > SAL_CALL DynamicResultSetWrapper
347*cdf0e10cSrcweir     ::getStaticResultSet()
348*cdf0e10cSrcweir     throw( ListenerAlreadySetException, RuntimeException )
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir     impl_EnsureNotDisposed();
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     Reference< XDynamicResultSet > xSource = NULL;
353*cdf0e10cSrcweir     Reference< XEventListener > xMyListenerImpl = NULL;
354*cdf0e10cSrcweir     {
355*cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
356*cdf0e10cSrcweir         if( m_xListener.is() )
357*cdf0e10cSrcweir             throw ListenerAlreadySetException();
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir         xSource = m_xSource;
360*cdf0e10cSrcweir         m_bStatic = sal_True;
361*cdf0e10cSrcweir         xMyListenerImpl = Reference< XEventListener > ::query( m_xMyListenerImpl );
362*cdf0e10cSrcweir     }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir     if( xSource.is() )
365*cdf0e10cSrcweir     {
366*cdf0e10cSrcweir         Reference< XComponent > xSourceComponent( xSource, UNO_QUERY );
367*cdf0e10cSrcweir         xSourceComponent->addEventListener( xMyListenerImpl );
368*cdf0e10cSrcweir     }
369*cdf0e10cSrcweir     if( !xSource.is() )
370*cdf0e10cSrcweir         m_aSourceSet.wait();
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir     Reference< XResultSet > xResultSet = xSource->getStaticResultSet();
374*cdf0e10cSrcweir     impl_InitResultSetOne( xResultSet );
375*cdf0e10cSrcweir     return m_xMyResultOne;
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir //virtual
379*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper
380*cdf0e10cSrcweir     ::setListener( const Reference<
381*cdf0e10cSrcweir     XDynamicResultSetListener > & Listener )
382*cdf0e10cSrcweir     throw( ListenerAlreadySetException, RuntimeException )
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir     impl_EnsureNotDisposed();
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir     Reference< XDynamicResultSet > xSource = NULL;
387*cdf0e10cSrcweir     Reference< XDynamicResultSetListener > xMyListenerImpl = NULL;
388*cdf0e10cSrcweir     {
389*cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
390*cdf0e10cSrcweir         if( m_xListener.is() )
391*cdf0e10cSrcweir             throw ListenerAlreadySetException();
392*cdf0e10cSrcweir         if( m_bStatic )
393*cdf0e10cSrcweir             throw ListenerAlreadySetException();
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir         m_xListener = Listener;
396*cdf0e10cSrcweir         addEventListener( Reference< XEventListener >::query( Listener ) );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir         xSource = m_xSource;
399*cdf0e10cSrcweir         xMyListenerImpl = m_xMyListenerImpl;
400*cdf0e10cSrcweir     }
401*cdf0e10cSrcweir     if ( xSource.is() )
402*cdf0e10cSrcweir         xSource->setListener( xMyListenerImpl );
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir     m_aListenerSet.set();
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir //virtual
408*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapper
409*cdf0e10cSrcweir     ::connectToCache( const Reference< XDynamicResultSet > & xCache )
410*cdf0e10cSrcweir     throw( ListenerAlreadySetException, AlreadyInitializedException, ServiceNotFoundException, RuntimeException )
411*cdf0e10cSrcweir {
412*cdf0e10cSrcweir     impl_EnsureNotDisposed();
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir     if( m_xListener.is() )
415*cdf0e10cSrcweir         throw ListenerAlreadySetException();
416*cdf0e10cSrcweir     if( m_bStatic )
417*cdf0e10cSrcweir         throw ListenerAlreadySetException();
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir     Reference< XSourceInitialization > xTarget( xCache, UNO_QUERY );
420*cdf0e10cSrcweir     OSL_ENSURE( xTarget.is(), "The given Target dosn't have the required interface 'XSourceInitialization'" );
421*cdf0e10cSrcweir     if( xTarget.is() && m_xSMgr.is() )
422*cdf0e10cSrcweir     {
423*cdf0e10cSrcweir         //@todo m_aSourceSet.wait();?
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir         Reference< XCachedDynamicResultSetStubFactory > xStubFactory;
426*cdf0e10cSrcweir         try
427*cdf0e10cSrcweir         {
428*cdf0e10cSrcweir             xStubFactory = Reference< XCachedDynamicResultSetStubFactory >(
429*cdf0e10cSrcweir                 m_xSMgr->createInstance(
430*cdf0e10cSrcweir                     OUString::createFromAscii(
431*cdf0e10cSrcweir                         "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ) ),
432*cdf0e10cSrcweir                 UNO_QUERY );
433*cdf0e10cSrcweir         }
434*cdf0e10cSrcweir         catch ( Exception const & )
435*cdf0e10cSrcweir         {
436*cdf0e10cSrcweir         }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir         if( xStubFactory.is() )
439*cdf0e10cSrcweir         {
440*cdf0e10cSrcweir             xStubFactory->connectToCache(
441*cdf0e10cSrcweir                   this, xCache, Sequence< NumberedSortingInfo > (), NULL );
442*cdf0e10cSrcweir             return;
443*cdf0e10cSrcweir         }
444*cdf0e10cSrcweir     }
445*cdf0e10cSrcweir     OSL_ENSURE( sal_False, "could not connect to cache" );
446*cdf0e10cSrcweir     throw ServiceNotFoundException();
447*cdf0e10cSrcweir }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir //virtual
450*cdf0e10cSrcweir sal_Int16 SAL_CALL DynamicResultSetWrapper
451*cdf0e10cSrcweir     ::getCapabilities()
452*cdf0e10cSrcweir     throw( RuntimeException )
453*cdf0e10cSrcweir {
454*cdf0e10cSrcweir     impl_EnsureNotDisposed();
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir     m_aSourceSet.wait();
457*cdf0e10cSrcweir     Reference< XDynamicResultSet > xSource = NULL;
458*cdf0e10cSrcweir     {
459*cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
460*cdf0e10cSrcweir         xSource = m_xSource;
461*cdf0e10cSrcweir     }
462*cdf0e10cSrcweir     return xSource->getCapabilities();
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir //--------------------------------------------------------------------------
466*cdf0e10cSrcweir //--------------------------------------------------------------------------
467*cdf0e10cSrcweir // class DynamicResultSetWrapperListener
468*cdf0e10cSrcweir //--------------------------------------------------------------------------
469*cdf0e10cSrcweir //--------------------------------------------------------------------------
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir DynamicResultSetWrapperListener::DynamicResultSetWrapperListener(
472*cdf0e10cSrcweir         DynamicResultSetWrapper* pOwner )
473*cdf0e10cSrcweir         : m_pOwner( pOwner )
474*cdf0e10cSrcweir {
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir }
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir DynamicResultSetWrapperListener::~DynamicResultSetWrapperListener()
479*cdf0e10cSrcweir {
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir }
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir //--------------------------------------------------------------------------
484*cdf0e10cSrcweir // XInterface methods.
485*cdf0e10cSrcweir //--------------------------------------------------------------------------
486*cdf0e10cSrcweir //list all interfaces inclusive baseclasses of interfaces
487*cdf0e10cSrcweir XINTERFACE_IMPL_2( DynamicResultSetWrapperListener
488*cdf0e10cSrcweir                    , XDynamicResultSetListener
489*cdf0e10cSrcweir                    , XEventListener //base of XDynamicResultSetListener
490*cdf0e10cSrcweir                    );
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir //--------------------------------------------------------------------------
493*cdf0e10cSrcweir // XDynamicResultSetListener methods:
494*cdf0e10cSrcweir //--------------------------------------------------------------------------
495*cdf0e10cSrcweir //virtual
496*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapperListener
497*cdf0e10cSrcweir     ::disposing( const EventObject& rEventObject )
498*cdf0e10cSrcweir     throw( RuntimeException )
499*cdf0e10cSrcweir {
500*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir     if( m_pOwner )
503*cdf0e10cSrcweir         m_pOwner->impl_disposing( rEventObject );
504*cdf0e10cSrcweir }
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir //virtual
507*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapperListener
508*cdf0e10cSrcweir     ::notify( const ListEvent& Changes )
509*cdf0e10cSrcweir     throw( RuntimeException )
510*cdf0e10cSrcweir {
511*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir     if( m_pOwner )
514*cdf0e10cSrcweir         m_pOwner->impl_notify( Changes );
515*cdf0e10cSrcweir }
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir //--------------------------------------------------------------------------
518*cdf0e10cSrcweir // own methods:
519*cdf0e10cSrcweir //--------------------------------------------------------------------------
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir void SAL_CALL DynamicResultSetWrapperListener
522*cdf0e10cSrcweir     ::impl_OwnerDies()
523*cdf0e10cSrcweir {
524*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir     m_pOwner = NULL;
527*cdf0e10cSrcweir }
528*cdf0e10cSrcweir 
529