xref: /trunk/main/ucb/source/sorter/sortdynres.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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();
128 
129     virtual void SAL_CALL
130     addEventListener( const REFERENCE< XEVENTLISTENER >& Listener );
131 
132     virtual void SAL_CALL
133     removeEventListener( const REFERENCE< XEVENTLISTENER >& Listener );
134 
135     //-----------------------------------------------------------------
136     // XDynamicResultSet
137     //-----------------------------------------------------------------
138     virtual REFERENCE< XRESULTSET > SAL_CALL
139     getStaticResultSet(  );
140 
141     virtual void SAL_CALL
142     setListener( const REFERENCE< XDYNAMICRESULTSETLISTENER >& Listener );
143 
144     virtual void SAL_CALL
145     connectToCache( const REFERENCE< XDYNAMICRESULTSET > & xCache );
146 
147     virtual sal_Int16 SAL_CALL
148     getCapabilities();
149 
150     //-----------------------------------------------------------------
151     // own methods:
152     //-----------------------------------------------------------------
153     virtual void SAL_CALL
154     impl_disposing( const EVENTOBJECT& Source );
155 
156     virtual void SAL_CALL
157     impl_notify( const ::com::sun::star::ucb::ListEvent& Changes );
158 };
159 
160 //-----------------------------------------------------------------------------
161 
162 class SortedDynamicResultSetListener:
163                 public cppu::OWeakObject,
164                 public com::sun::star::ucb::XDynamicResultSetListener
165 {
166     SortedDynamicResultSet  *mpOwner;
167     osl::Mutex              maMutex;
168 
169 public:
170      SortedDynamicResultSetListener( SortedDynamicResultSet *mOwner );
171     ~SortedDynamicResultSetListener();
172 
173     //-----------------------------------------------------------------
174     // XInterface
175     //-----------------------------------------------------------------
176     XINTERFACE_DECL()
177 
178     //-----------------------------------------------------------------
179     // XEventListener ( base of XDynamicResultSetListener )
180     //-----------------------------------------------------------------
181     virtual void SAL_CALL
182     disposing( const EVENTOBJECT& Source );
183 
184     //-----------------------------------------------------------------
185     // XDynamicResultSetListener
186     //-----------------------------------------------------------------
187     virtual void SAL_CALL
188     notify( const ::com::sun::star::ucb::ListEvent& Changes );
189 
190     //-----------------------------------------------------------------
191     // own methods:
192     //-----------------------------------------------------------------
193     void SAL_CALL impl_OwnerDies();
194 };
195 
196 //-----------------------------------------------------------------------------
197 
198 class SortedDynamicResultSetFactory:
199                 public cppu::OWeakObject,
200                 public com::sun::star::lang::XTypeProvider,
201                 public com::sun::star::lang::XServiceInfo,
202                 public com::sun::star::ucb::XSortedDynamicResultSetFactory
203 {
204 
205     REFERENCE< XMULTISERVICEFACTORY >   mxSMgr;
206 
207 public:
208 
209     SortedDynamicResultSetFactory(
210         const REFERENCE< XMULTISERVICEFACTORY > & rSMgr);
211 
212     ~SortedDynamicResultSetFactory();
213 
214     //-----------------------------------------------------------------
215     // XInterface
216     //-----------------------------------------------------------------
217     XINTERFACE_DECL()
218 
219     //-----------------------------------------------------------------
220     // XTypeProvider
221     //-----------------------------------------------------------------
222     XTYPEPROVIDER_DECL()
223 
224     //-----------------------------------------------------------------
225     // XServiceInfo
226     //-----------------------------------------------------------------
227     XSERVICEINFO_DECL()
228 
229     //-----------------------------------------------------------------
230     // XSortedDynamicResultSetFactory
231 
232     virtual REFERENCE< XDYNAMICRESULTSET > SAL_CALL
233     createSortedDynamicResultSet(
234                 const REFERENCE< XDYNAMICRESULTSET > & Source,
235                 const SEQUENCE< NUMBERED_SORTINGINFO > & Info,
236                 const REFERENCE< XANYCOMPAREFACTORY > & CompareFactory );
237 };
238 
239 #endif
240