xref: /AOO41X/main/ucb/source/cacher/dynamicresultsetwrapper.hxx (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 #ifndef _DYNAMIC_RESULTSET_WRAPPER_HXX
29*cdf0e10cSrcweir #define _DYNAMIC_RESULTSET_WRAPPER_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <osl/mutex.hxx>
32*cdf0e10cSrcweir #include <osl/conditn.hxx>
33*cdf0e10cSrcweir #include <ucbhelper/macros.hxx>
34*cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
35*cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
37*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
38*cdf0e10cSrcweir #include <com/sun/star/ucb/XDynamicResultSet.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/ucb/XSourceInitialization.hpp>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #ifndef __com_sun_star_lang_DisposedException_idl__
42*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
43*cdf0e10cSrcweir #endif
44*cdf0e10cSrcweir #include <com/sun/star/ucb/XDynamicResultSetListener.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir //#define CACHED_CRS_STUB_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSetStub"
48*cdf0e10cSrcweir //#define CACHED_CRS_STUB_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetStubFactory"
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir //=========================================================================
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir class DynamicResultSetWrapperListener;
53*cdf0e10cSrcweir class DynamicResultSetWrapper
54*cdf0e10cSrcweir 				: public cppu::OWeakObject
55*cdf0e10cSrcweir 				, public com::sun::star::ucb::XDynamicResultSet
56*cdf0e10cSrcweir 				, public com::sun::star::ucb::XSourceInitialization
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir private:
59*cdf0e10cSrcweir 	//management of listeners
60*cdf0e10cSrcweir 	sal_Bool				m_bDisposed; ///Dispose call ready.
61*cdf0e10cSrcweir 	sal_Bool				m_bInDispose;///In dispose call
62*cdf0e10cSrcweir 	osl::Mutex				m_aContainerMutex;
63*cdf0e10cSrcweir 	cppu::OInterfaceContainerHelper*
64*cdf0e10cSrcweir 							m_pDisposeEventListeners;
65*cdf0e10cSrcweir protected:
66*cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener >
67*cdf0e10cSrcweir 							m_xMyListenerImpl;
68*cdf0e10cSrcweir 	DynamicResultSetWrapperListener*
69*cdf0e10cSrcweir 							m_pMyListenerImpl;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
72*cdf0e10cSrcweir 							m_xSMgr;
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 	osl::Mutex				m_aMutex;
75*cdf0e10cSrcweir 	sal_Bool				m_bStatic;
76*cdf0e10cSrcweir 	sal_Bool				m_bGotWelcome;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 	//different Interfaces from Origin:
79*cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSet >
80*cdf0e10cSrcweir 							m_xSource;
81*cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet >
82*cdf0e10cSrcweir 							m_xSourceResultOne;
83*cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet >
84*cdf0e10cSrcweir 							m_xSourceResultTwo;
85*cdf0e10cSrcweir 	//com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet >
86*cdf0e10cSrcweir 	//						m_xSourceResultCurrent;
87*cdf0e10cSrcweir 	//sal_Bool				m_bUseOne;
88*cdf0e10cSrcweir 	//
89*cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet >
90*cdf0e10cSrcweir 							m_xMyResultOne;
91*cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet >
92*cdf0e10cSrcweir 							m_xMyResultTwo;
93*cdf0e10cSrcweir 	//
94*cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener >
95*cdf0e10cSrcweir 							m_xListener;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	osl::Condition			m_aSourceSet;
98*cdf0e10cSrcweir 	osl::Condition			m_aListenerSet;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir protected:
101*cdf0e10cSrcweir 	void SAL_CALL impl_init();
102*cdf0e10cSrcweir 	void SAL_CALL impl_deinit();
103*cdf0e10cSrcweir 	void SAL_CALL
104*cdf0e10cSrcweir 	impl_EnsureNotDisposed()
105*cdf0e10cSrcweir 		throw( com::sun::star::lang::DisposedException,
106*cdf0e10cSrcweir 			   com::sun::star::uno::RuntimeException );
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	virtual void SAL_CALL
109*cdf0e10cSrcweir 	impl_InitResultSetOne( const com::sun::star::uno::Reference<
110*cdf0e10cSrcweir 				com::sun::star::sdbc::XResultSet >& xResultSet );
111*cdf0e10cSrcweir 	virtual void SAL_CALL
112*cdf0e10cSrcweir 	impl_InitResultSetTwo( const com::sun::star::uno::Reference<
113*cdf0e10cSrcweir 				com::sun::star::sdbc::XResultSet >& xResultSet );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir public:
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 	DynamicResultSetWrapper(
118*cdf0e10cSrcweir 		com::sun::star::uno::Reference<
119*cdf0e10cSrcweir 						com::sun::star::ucb::XDynamicResultSet > xOrigin
120*cdf0e10cSrcweir 		, const com::sun::star::uno::Reference<
121*cdf0e10cSrcweir 						com::sun::star::lang::XMultiServiceFactory > & xSMgr );
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 	virtual ~DynamicResultSetWrapper();
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	//-----------------------------------------------------------------
126*cdf0e10cSrcweir 	// XInterface
127*cdf0e10cSrcweir 	virtual com::sun::star::uno::Any SAL_CALL
128*cdf0e10cSrcweir 	queryInterface( const com::sun::star::uno::Type & rType )
129*cdf0e10cSrcweir 		throw( com::sun::star::uno::RuntimeException );
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	//-----------------------------------------------------------------
132*cdf0e10cSrcweir     // XDynamicResultSet
133*cdf0e10cSrcweir 	virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > SAL_CALL
134*cdf0e10cSrcweir 	getStaticResultSet()
135*cdf0e10cSrcweir 		throw( com::sun::star::ucb::ListenerAlreadySetException
136*cdf0e10cSrcweir 		, com::sun::star::uno::RuntimeException );
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	virtual void SAL_CALL
139*cdf0e10cSrcweir 	setListener( const com::sun::star::uno::Reference<
140*cdf0e10cSrcweir 		com::sun::star::ucb::XDynamicResultSetListener > & Listener )
141*cdf0e10cSrcweir 		throw( com::sun::star::ucb::ListenerAlreadySetException
142*cdf0e10cSrcweir 			, com::sun::star::uno::RuntimeException );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 	virtual void SAL_CALL
145*cdf0e10cSrcweir 	connectToCache( const com::sun::star::uno::Reference<
146*cdf0e10cSrcweir 		com::sun::star::ucb::XDynamicResultSet > & xCache )
147*cdf0e10cSrcweir 		throw( com::sun::star::ucb::ListenerAlreadySetException
148*cdf0e10cSrcweir 			, com::sun::star::ucb::AlreadyInitializedException
149*cdf0e10cSrcweir 			, com::sun::star::ucb::ServiceNotFoundException
150*cdf0e10cSrcweir 			, com::sun::star::uno::RuntimeException );
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	virtual sal_Int16 SAL_CALL
153*cdf0e10cSrcweir 	getCapabilities() throw( com::sun::star::uno::RuntimeException );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	//-----------------------------------------------------------------
156*cdf0e10cSrcweir 	// XComponent ( base of XDynamicResultSet )
157*cdf0e10cSrcweir 	virtual void SAL_CALL
158*cdf0e10cSrcweir 	dispose() throw( com::sun::star::uno::RuntimeException );
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     virtual void SAL_CALL
161*cdf0e10cSrcweir 	addEventListener( const com::sun::star::uno::Reference<
162*cdf0e10cSrcweir 		com::sun::star::lang::XEventListener >& Listener )
163*cdf0e10cSrcweir 			throw( com::sun::star::uno::RuntimeException );
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     virtual void SAL_CALL
166*cdf0e10cSrcweir 	removeEventListener( const com::sun::star::uno::Reference<
167*cdf0e10cSrcweir 		com::sun::star::lang::XEventListener >& Listener )
168*cdf0e10cSrcweir 			throw( com::sun::star::uno::RuntimeException );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	//-----------------------------------------------------------------
171*cdf0e10cSrcweir     // XSourceInitialization
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	virtual void SAL_CALL
174*cdf0e10cSrcweir 	setSource(	const com::sun::star::uno::Reference<
175*cdf0e10cSrcweir 		com::sun::star::uno::XInterface > & Source )
176*cdf0e10cSrcweir 		 throw( com::sun::star::ucb::AlreadyInitializedException
177*cdf0e10cSrcweir 				, com::sun::star::uno::RuntimeException );
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	//-----------------------------------------------------------------
180*cdf0e10cSrcweir 	// own methods:
181*cdf0e10cSrcweir     virtual void SAL_CALL
182*cdf0e10cSrcweir 	impl_disposing( const com::sun::star::lang::EventObject& Source )
183*cdf0e10cSrcweir 		throw( com::sun::star::uno::RuntimeException );
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	virtual void SAL_CALL
186*cdf0e10cSrcweir 	impl_notify( const ::com::sun::star::ucb::ListEvent& Changes )
187*cdf0e10cSrcweir 		throw( com::sun::star::uno::RuntimeException );
188*cdf0e10cSrcweir };
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir //=========================================================================
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir class DynamicResultSetWrapperListener
193*cdf0e10cSrcweir 				: public cppu::OWeakObject
194*cdf0e10cSrcweir 				, public com::sun::star::ucb::XDynamicResultSetListener
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir protected:
197*cdf0e10cSrcweir 	DynamicResultSetWrapper*	m_pOwner;
198*cdf0e10cSrcweir 	osl::Mutex					m_aMutex;
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir public:
201*cdf0e10cSrcweir 	DynamicResultSetWrapperListener( DynamicResultSetWrapper* pOwner );
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	virtual ~DynamicResultSetWrapperListener();
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 	//-----------------------------------------------------------------
206*cdf0e10cSrcweir 	// XInterface
207*cdf0e10cSrcweir 	//-----------------------------------------------------------------
208*cdf0e10cSrcweir 	XINTERFACE_DECL()
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 	//-----------------------------------------------------------------
211*cdf0e10cSrcweir 	// XEventListener ( base of XDynamicResultSetListener )
212*cdf0e10cSrcweir 	//-----------------------------------------------------------------
213*cdf0e10cSrcweir     virtual void SAL_CALL
214*cdf0e10cSrcweir 	disposing( const com::sun::star::lang::EventObject& Source )
215*cdf0e10cSrcweir 		throw( com::sun::star::uno::RuntimeException );
216*cdf0e10cSrcweir 	//-----------------------------------------------------------------
217*cdf0e10cSrcweir 	// XDynamicResultSetListener
218*cdf0e10cSrcweir     virtual void SAL_CALL
219*cdf0e10cSrcweir 	notify( const ::com::sun::star::ucb::ListEvent& Changes )
220*cdf0e10cSrcweir 		throw( com::sun::star::uno::RuntimeException );
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 	//-----------------------------------------------------------------
223*cdf0e10cSrcweir 	// own methods:
224*cdf0e10cSrcweir 	void SAL_CALL impl_OwnerDies();
225*cdf0e10cSrcweir };
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir #endif
229*cdf0e10cSrcweir 
230