xref: /aoo4110/main/ucb/source/sorter/sortdynres.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SORTDYNRES_HXX
25 #define _SORTDYNRES_HXX
26 
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/lang/XTypeProvider.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/lang/XComponent.hpp>
31 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
32 #include <com/sun/star/sdbc/XResultSet.hpp>
33 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
34 #include <com/sun/star/ucb/XDynamicResultSetListener.hpp>
35 #include <com/sun/star/ucb/ListenerAlreadySetException.hpp>
36 #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
37 #include <cppuhelper/weak.hxx>
38 #include <osl/mutex.hxx>
39 #include <ucbhelper/macros.hxx>
40 #include "sortresult.hxx"
41 
42 namespace cppu {
43 	class OInterfaceContainerHelper;
44 }
45 
46 //-----------------------------------------------------------------------------
47 
48 #define NUMBERED_SORTINGINFO		com::sun::star::ucb::NumberedSortingInfo
49 #define RUNTIMEEXCEPTION			com::sun::star::uno::RuntimeException
50 #define REFERENCE					com::sun::star::uno::Reference
51 #define SEQUENCE					com::sun::star::uno::Sequence
52 #define	EVENTOBJECT					com::sun::star::lang::EventObject
53 #define XEVENTLISTENER				com::sun::star::lang::XEventListener
54 #define XMULTISERVICEFACTORY		com::sun::star::lang::XMultiServiceFactory
55 #define XRESULTSET					com::sun::star::sdbc::XResultSet
56 #define SQLEXCEPTION				com::sun::star::sdbc::SQLException
57 #define XANYCOMPAREFACTORY			com::sun::star::ucb::XAnyCompareFactory
58 #define XDYNAMICRESULTSET			com::sun::star::ucb::XDynamicResultSet
59 #define XDYNAMICRESULTSETLISTENER	com::sun::star::ucb::XDynamicResultSetListener
60 #define LISTENERALREADYSETEXCEPTION	com::sun::star::ucb::ListenerAlreadySetException
61 
62 #define DYNAMIC_RESULTSET_SERVICE_NAME 	"com.sun.star.ucb.SortedDynamicResultSet"
63 #define DYNAMIC_RESULTSET_FACTORY_NAME 	"com.sun.star.ucb.SortedDynamicResultSetFactory"
64 
65 //-----------------------------------------------------------------------------
66 class SortedDynamicResultSetListener;
67 
68 class SortedDynamicResultSet:
69 				public cppu::OWeakObject,
70 				public com::sun::star::lang::XTypeProvider,
71 				public com::sun::star::lang::XServiceInfo,
72 				public com::sun::star::ucb::XDynamicResultSet
73 {
74 	cppu::OInterfaceContainerHelper	*mpDisposeEventListeners;
75 
76 	REFERENCE < XDYNAMICRESULTSETLISTENER >	mxListener;
77 	REFERENCE < XDYNAMICRESULTSETLISTENER > mxOwnListener;
78 
79 	REFERENCE < XRESULTSET >			mxOne;
80 	REFERENCE < XRESULTSET >			mxTwo;
81 	REFERENCE < XDYNAMICRESULTSET >		mxOriginal;
82 	SEQUENCE  < NUMBERED_SORTINGINFO >	maOptions;
83 	REFERENCE < XANYCOMPAREFACTORY >	mxCompFac;
84 	REFERENCE < XMULTISERVICEFACTORY >	mxSMgr;
85 
86 	SortedResultSet*					mpOne;
87 	SortedResultSet*					mpTwo;
88 	SortedDynamicResultSetListener*		mpOwnListener;
89 
90 	EventList							maActions;
91 	osl::Mutex							maMutex;
92 	sal_Bool							mbGotWelcome	:1;
93 	sal_Bool							mbUseOne		:1;
94 	sal_Bool							mbStatic		:1;
95 
96 private:
97 
98 	void				SendNotify();
99 
100 public:
101 	SortedDynamicResultSet( const REFERENCE < XDYNAMICRESULTSET >	 &xOriginal,
102 							const SEQUENCE  < NUMBERED_SORTINGINFO > &aOptions,
103 							const REFERENCE < XANYCOMPAREFACTORY >	 &xCompFac,
104 							const REFERENCE < XMULTISERVICEFACTORY > &xSMgr );
105 
106 	~SortedDynamicResultSet();
107 
108 	//-----------------------------------------------------------------
109 	// XInterface
110 	//-----------------------------------------------------------------
111 	XINTERFACE_DECL()
112 
113 	//-----------------------------------------------------------------
114 	// XTypeProvider
115 	//-----------------------------------------------------------------
116 	XTYPEPROVIDER_DECL()
117 
118 	//-----------------------------------------------------------------
119     // XServiceInfo
120 	//-----------------------------------------------------------------
121 	XSERVICEINFO_NOFACTORY_DECL()
122 
123 	//-----------------------------------------------------------------
124 	// XComponent
125 	//-----------------------------------------------------------------
126 	virtual void SAL_CALL
127 	dispose() throw( RUNTIME_EXCEPTION );
128 
129     virtual void SAL_CALL
130 	addEventListener( const REFERENCE< XEVENTLISTENER >& Listener )
131 		throw( RUNTIME_EXCEPTION );
132 
133     virtual void SAL_CALL
134 	removeEventListener( const REFERENCE< XEVENTLISTENER >& Listener )
135 		throw( RUNTIME_EXCEPTION );
136 
137 	//-----------------------------------------------------------------
138 	// XDynamicResultSet
139 	//-----------------------------------------------------------------
140     virtual REFERENCE< XRESULTSET > SAL_CALL
141 	getStaticResultSet(  )
142 		throw( LISTENERALREADYSETEXCEPTION, RUNTIMEEXCEPTION );
143 
144 	virtual void SAL_CALL
145 	setListener( const REFERENCE< XDYNAMICRESULTSETLISTENER >& Listener )
146 		throw( LISTENERALREADYSETEXCEPTION, RUNTIMEEXCEPTION );
147 
148 	virtual void SAL_CALL
149 	connectToCache( const REFERENCE< XDYNAMICRESULTSET > & xCache )
150 		throw( LISTENERALREADYSETEXCEPTION,
151 			   com::sun::star::ucb::AlreadyInitializedException,
152 			   com::sun::star::ucb::ServiceNotFoundException,
153 			   RUNTIMEEXCEPTION );
154 
155     virtual sal_Int16 SAL_CALL
156 	getCapabilities()
157 		throw( RUNTIMEEXCEPTION );
158 
159 	//-----------------------------------------------------------------
160 	// own methods:
161 	//-----------------------------------------------------------------
162     virtual void SAL_CALL
163 	impl_disposing( const EVENTOBJECT& Source )
164 		throw( RUNTIMEEXCEPTION );
165 
166     virtual void SAL_CALL
167 	impl_notify( const ::com::sun::star::ucb::ListEvent& Changes )
168 		throw( RUNTIMEEXCEPTION );
169 };
170 
171 //-----------------------------------------------------------------------------
172 
173 class SortedDynamicResultSetListener:
174 				public cppu::OWeakObject,
175 				public com::sun::star::ucb::XDynamicResultSetListener
176 {
177 	SortedDynamicResultSet	*mpOwner;
178 	osl::Mutex			 	maMutex;
179 
180 public:
181 	 SortedDynamicResultSetListener( SortedDynamicResultSet *mOwner );
182 	~SortedDynamicResultSetListener();
183 
184 	//-----------------------------------------------------------------
185 	// XInterface
186 	//-----------------------------------------------------------------
187 	XINTERFACE_DECL()
188 
189 	//-----------------------------------------------------------------
190 	// XEventListener ( base of XDynamicResultSetListener )
191 	//-----------------------------------------------------------------
192     virtual void SAL_CALL
193 	disposing( const EVENTOBJECT& Source )
194 		throw( RUNTIMEEXCEPTION );
195 
196 	//-----------------------------------------------------------------
197 	// XDynamicResultSetListener
198 	//-----------------------------------------------------------------
199     virtual void SAL_CALL
200 	notify( const ::com::sun::star::ucb::ListEvent& Changes )
201 		throw( RUNTIMEEXCEPTION );
202 
203 	//-----------------------------------------------------------------
204 	// own methods:
205 	//-----------------------------------------------------------------
206 	void SAL_CALL impl_OwnerDies();
207 };
208 
209 //-----------------------------------------------------------------------------
210 
211 class SortedDynamicResultSetFactory:
212 				public cppu::OWeakObject,
213 				public com::sun::star::lang::XTypeProvider,
214 				public com::sun::star::lang::XServiceInfo,
215 				public com::sun::star::ucb::XSortedDynamicResultSetFactory
216 {
217 
218 	REFERENCE< XMULTISERVICEFACTORY >	mxSMgr;
219 
220 public:
221 
222 	SortedDynamicResultSetFactory(
223 		const REFERENCE< XMULTISERVICEFACTORY > & rSMgr);
224 
225 	~SortedDynamicResultSetFactory();
226 
227 	//-----------------------------------------------------------------
228 	// XInterface
229 	//-----------------------------------------------------------------
230 	XINTERFACE_DECL()
231 
232 	//-----------------------------------------------------------------
233 	// XTypeProvider
234 	//-----------------------------------------------------------------
235 	XTYPEPROVIDER_DECL()
236 
237 	//-----------------------------------------------------------------
238     // XServiceInfo
239 	//-----------------------------------------------------------------
240 	XSERVICEINFO_DECL()
241 
242 	//-----------------------------------------------------------------
243 	// XSortedDynamicResultSetFactory
244 
245 	virtual REFERENCE< XDYNAMICRESULTSET > SAL_CALL
246 	createSortedDynamicResultSet(
247 				const REFERENCE< XDYNAMICRESULTSET > & Source,
248 				const SEQUENCE< NUMBERED_SORTINGINFO > & Info,
249 				const REFERENCE< XANYCOMPAREFACTORY > & CompareFactory )
250 		throw( RUNTIMEEXCEPTION );
251 };
252 
253 #endif
254