Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef _SORTRESULT_HXX
21 : : #define _SORTRESULT_HXX
22 : :
23 : : #include <com/sun/star/beans/XPropertySet.hpp>
24 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 : : #include <com/sun/star/lang/XTypeProvider.hpp>
26 : : #include <com/sun/star/lang/XServiceInfo.hpp>
27 : : #include <com/sun/star/lang/XComponent.hpp>
28 : : #include <com/sun/star/sdbc/XCloseable.hpp>
29 : : #include <com/sun/star/sdbc/XResultSet.hpp>
30 : : #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
31 : : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
32 : : #include <com/sun/star/sdbc/XRow.hpp>
33 : : #include <com/sun/star/ucb/XContentAccess.hpp>
34 : : #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
35 : : #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
36 : : #include <com/sun/star/ucb/ListAction.hpp>
37 : : #include <cppuhelper/weak.hxx>
38 : : #include <osl/mutex.hxx>
39 : :
40 : : #include <deque>
41 : : #include <ucbhelper/macros.hxx>
42 : :
43 : : namespace cppu {
44 : : class OInterfaceContainerHelper;
45 : : }
46 : :
47 : : //-----------------------------------------------------------------------------
48 : : struct SortInfo;
49 : : struct SortListData;
50 : : class SRSPropertySetInfo;
51 : : class PropertyChangeListeners_Impl;
52 : :
53 : : //-----------------------------------------------------------------------------
54 : : class SortedEntryList
55 : : {
56 : : std::deque < SortListData* > maData;
57 : :
58 : : public:
59 : 146 : SortedEntryList(){}
60 [ + - ]: 146 : ~SortedEntryList(){ Clear(); }
61 : :
62 : 1330 : sal_uInt32 Count() const { return (sal_uInt32) maData.size(); }
63 : :
64 : : void Clear();
65 : : void Insert( SortListData *pEntry, long nPos );
66 : : SortListData* Remove( long nPos );
67 : : SortListData* GetData( long nPos );
68 : :
69 : : long operator [] ( long nPos ) const;
70 : : };
71 : :
72 : : //-----------------------------------------------------------------------------
73 : : #define LISTACTION com::sun::star::ucb::ListAction
74 : :
75 : : class EventList
76 : : {
77 : : std::deque < LISTACTION* > maData;
78 : :
79 : : public:
80 : 146 : EventList(){}
81 [ + - ]: 146 : ~EventList(){ Clear(); }
82 : :
83 : 0 : sal_uInt32 Count() { return (sal_uInt32) maData.size(); }
84 : :
85 : : void AddEvent( long nType, long nPos, long nCount );
86 : 0 : void Insert( LISTACTION *pAction ) { maData.push_back( pAction ); }
87 : : void Clear();
88 : 0 : LISTACTION* GetAction( long nIndex ) { return maData[ nIndex ]; }
89 : : };
90 : :
91 : : //-----------------------------------------------------------------------------
92 : :
93 : : class SimpleList
94 : : {
95 : : std::deque < void* > maData;
96 : :
97 : : public:
98 : 292 : SimpleList(){}
99 : 292 : ~SimpleList(){ Clear(); }
100 : :
101 : 0 : sal_uInt32 Count() { return (sal_uInt32) maData.size(); }
102 : 438 : void Clear() { maData.clear(); }
103 : :
104 : : void Remove( sal_uInt32 nPos );
105 : : void Remove( void* pData );
106 : :
107 : 0 : void Append( void* pData )
108 : 0 : { maData.push_back( pData ); }
109 : : void Insert( void* pData, sal_uInt32 nPos );
110 : : void* GetObject( sal_uInt32 nPos ) const;
111 : : void Replace( void* pData, sal_uInt32 nPos );
112 : : };
113 : :
114 : : //-----------------------------------------------------------------------------
115 : :
116 : : #define PROPERTYCHANGEEVENT com::sun::star::beans::PropertyChangeEvent
117 : : #define RUNTIME_EXCEPTION com::sun::star::uno::RuntimeException
118 : : #define REFERENCE com::sun::star::uno::Reference
119 : : #define SEQUENCE com::sun::star::uno::Sequence
120 : : #define XEVENTLISTENER com::sun::star::lang::XEventListener
121 : : #define XRESULTSET com::sun::star::sdbc::XResultSet
122 : : #define SQLEXCEPTION com::sun::star::sdbc::SQLException
123 : : #define XRESULTSETMETADATA com::sun::star::sdbc::XResultSetMetaData
124 : : #define NUMBERED_SORTINGINFO com::sun::star::ucb::NumberedSortingInfo
125 : : #define XANYCOMPAREFACTORY com::sun::star::ucb::XAnyCompareFactory
126 : :
127 : : #define RESULTSET_SERVICE_NAME "com.sun.star.ucb.SortedResultSet"
128 : :
129 : : //-----------------------------------------------------------------------------
130 : :
131 : : class SortedResultSet:
132 : : public cppu::OWeakObject,
133 : : public com::sun::star::lang::XTypeProvider,
134 : : public com::sun::star::lang::XServiceInfo,
135 : : public com::sun::star::lang::XComponent,
136 : : public com::sun::star::ucb::XContentAccess,
137 : : public XRESULTSET,
138 : : public com::sun::star::sdbc::XRow,
139 : : public com::sun::star::sdbc::XCloseable,
140 : : public com::sun::star::sdbc::XResultSetMetaDataSupplier,
141 : : public com::sun::star::beans::XPropertySet
142 : : {
143 : : cppu::OInterfaceContainerHelper *mpDisposeEventListeners;
144 : : PropertyChangeListeners_Impl *mpPropChangeListeners;
145 : : PropertyChangeListeners_Impl *mpVetoChangeListeners;
146 : :
147 : : REFERENCE < XRESULTSET > mxOriginal;
148 : : REFERENCE < XRESULTSET > mxOther;
149 : :
150 : : SRSPropertySetInfo* mpPropSetInfo;
151 : : SortInfo* mpSortInfo;
152 : : osl::Mutex maMutex;
153 : : SortedEntryList maS2O; // maps the sorted entries to the original ones
154 : : SimpleList maO2S; // maps the original Entries to the sorted ones
155 : : SimpleList maModList; // keeps track of modified entries
156 : : long mnLastSort; // index of the last sorted entry;
157 : : long mnCurEntry; // index of the current entry
158 : : long mnCount; // total count of the elements
159 : : sal_Bool mbIsCopy;
160 : :
161 : :
162 : : private:
163 : :
164 : : long FindPos( SortListData *pEntry, long nStart, long nEnd )
165 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
166 : : long Compare( SortListData *pOne,
167 : : SortListData *pTwo )
168 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
169 : : void BuildSortInfo( REFERENCE< XRESULTSET > aResult,
170 : : const SEQUENCE < NUMBERED_SORTINGINFO > &xSortInfo,
171 : : const REFERENCE< XANYCOMPAREFACTORY > &xCompFac );
172 : : long CompareImpl( REFERENCE < XRESULTSET > xResultOne,
173 : : REFERENCE < XRESULTSET > xResultTwo,
174 : : long nIndexOne, long nIndexTwo,
175 : : SortInfo* pSortInfo )
176 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
177 : : long CompareImpl( REFERENCE < XRESULTSET > xResultOne,
178 : : REFERENCE < XRESULTSET > xResultTwo,
179 : : long nIndexOne, long nIndexTwo )
180 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
181 : : void PropertyChanged( const PROPERTYCHANGEEVENT& rEvt );
182 : :
183 : : public:
184 : : SortedResultSet( REFERENCE< XRESULTSET > aResult );
185 : : ~SortedResultSet();
186 : :
187 : 0 : const SortedEntryList* GetS2OList() const { return &maS2O; }
188 : 0 : const SimpleList* GetO2SList() const { return &maO2S; }
189 : 0 : REFERENCE < XRESULTSET > GetResultSet() const { return mxOriginal; }
190 : 0 : SortInfo* GetSortInfo() const { return mpSortInfo; }
191 : 0 : long GetCount() const { return mnCount; }
192 : :
193 : : void CopyData( SortedResultSet* pSource );
194 : : void Initialize( const SEQUENCE < NUMBERED_SORTINGINFO > &xSortInfo,
195 : : const REFERENCE< XANYCOMPAREFACTORY > &xCompFac );
196 : : void CheckProperties( long nOldCount, sal_Bool bWasFinal );
197 : :
198 : : void InsertNew( long nPos, long nCount );
199 : : void SetChanged( long nPos, long nCount );
200 : : void Remove( long nPos, long nCount, EventList *pList );
201 : : void Move( long nPos, long nCount, long nOffset );
202 : :
203 : : void ResortModified( EventList* pList );
204 : : void ResortNew( EventList* pList );
205 : :
206 : : // XInterface
207 : : XINTERFACE_DECL()
208 : :
209 : : // XTypeProvider
210 : : XTYPEPROVIDER_DECL()
211 : :
212 : : // XServiceInfo
213 : : XSERVICEINFO_NOFACTORY_DECL()
214 : :
215 : : // XComponent
216 : : virtual void SAL_CALL
217 : : dispose() throw( RUNTIME_EXCEPTION );
218 : :
219 : : virtual void SAL_CALL
220 : : addEventListener( const REFERENCE< XEVENTLISTENER >& Listener )
221 : : throw( RUNTIME_EXCEPTION );
222 : :
223 : : virtual void SAL_CALL
224 : : removeEventListener( const REFERENCE< XEVENTLISTENER >& Listener )
225 : : throw( RUNTIME_EXCEPTION );
226 : :
227 : : // XContentAccess
228 : : virtual rtl::OUString SAL_CALL
229 : : queryContentIdentifierString()
230 : : throw( RUNTIME_EXCEPTION );
231 : : virtual REFERENCE<
232 : : com::sun::star::ucb::XContentIdentifier > SAL_CALL
233 : : queryContentIdentifier()
234 : : throw( RUNTIME_EXCEPTION );
235 : : virtual REFERENCE<
236 : : com::sun::star::ucb::XContent > SAL_CALL
237 : : queryContent()
238 : : throw( RUNTIME_EXCEPTION );
239 : :
240 : : // XResultSet
241 : : virtual sal_Bool SAL_CALL
242 : : next()
243 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
244 : : virtual sal_Bool SAL_CALL
245 : : isBeforeFirst()
246 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
247 : : virtual sal_Bool SAL_CALL
248 : : isAfterLast()
249 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
250 : : virtual sal_Bool SAL_CALL
251 : : isFirst()
252 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
253 : : virtual sal_Bool SAL_CALL
254 : : isLast()
255 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
256 : : virtual void SAL_CALL
257 : : beforeFirst()
258 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
259 : : virtual void SAL_CALL
260 : : afterLast()
261 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
262 : : virtual sal_Bool SAL_CALL
263 : : first()
264 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
265 : : virtual sal_Bool SAL_CALL
266 : : last()
267 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
268 : : virtual sal_Int32 SAL_CALL
269 : : getRow()
270 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
271 : : virtual sal_Bool SAL_CALL
272 : : absolute( sal_Int32 row )
273 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
274 : : virtual sal_Bool SAL_CALL
275 : : relative( sal_Int32 rows )
276 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
277 : : virtual sal_Bool SAL_CALL
278 : : previous()
279 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
280 : : virtual void SAL_CALL
281 : : refreshRow()
282 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
283 : : virtual sal_Bool SAL_CALL
284 : : rowUpdated()
285 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
286 : : virtual sal_Bool SAL_CALL
287 : : rowInserted()
288 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
289 : : virtual sal_Bool SAL_CALL
290 : : rowDeleted()
291 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
292 : : virtual REFERENCE<
293 : : com::sun::star::uno::XInterface > SAL_CALL
294 : : getStatement()
295 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
296 : :
297 : : // XRow
298 : : virtual sal_Bool SAL_CALL
299 : : wasNull() throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
300 : :
301 : : virtual rtl::OUString SAL_CALL
302 : : getString( sal_Int32 columnIndex )
303 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
304 : :
305 : : virtual sal_Bool SAL_CALL
306 : : getBoolean( sal_Int32 columnIndex )
307 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
308 : :
309 : : virtual sal_Int8 SAL_CALL
310 : : getByte( sal_Int32 columnIndex )
311 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
312 : :
313 : : virtual sal_Int16 SAL_CALL
314 : : getShort( sal_Int32 columnIndex )
315 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
316 : :
317 : : virtual sal_Int32 SAL_CALL
318 : : getInt( sal_Int32 columnIndex )
319 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
320 : :
321 : : virtual sal_Int64 SAL_CALL
322 : : getLong( sal_Int32 columnIndex )
323 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
324 : :
325 : : virtual float SAL_CALL
326 : : getFloat( sal_Int32 columnIndex )
327 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
328 : :
329 : : virtual double SAL_CALL
330 : : getDouble( sal_Int32 columnIndex )
331 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
332 : :
333 : : virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL
334 : : getBytes( sal_Int32 columnIndex )
335 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
336 : :
337 : : virtual com::sun::star::util::Date SAL_CALL
338 : : getDate( sal_Int32 columnIndex )
339 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
340 : :
341 : : virtual com::sun::star::util::Time SAL_CALL
342 : : getTime( sal_Int32 columnIndex )
343 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
344 : :
345 : : virtual com::sun::star::util::DateTime SAL_CALL
346 : : getTimestamp( sal_Int32 columnIndex )
347 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
348 : :
349 : : virtual REFERENCE<
350 : : com::sun::star::io::XInputStream > SAL_CALL
351 : : getBinaryStream( sal_Int32 columnIndex )
352 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
353 : :
354 : : virtual REFERENCE<
355 : : com::sun::star::io::XInputStream > SAL_CALL
356 : : getCharacterStream( sal_Int32 columnIndex )
357 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
358 : :
359 : : virtual com::sun::star::uno::Any SAL_CALL
360 : : getObject( sal_Int32 columnIndex,
361 : : const REFERENCE<
362 : : com::sun::star::container::XNameAccess >& typeMap )
363 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
364 : : virtual REFERENCE<
365 : : com::sun::star::sdbc::XRef > SAL_CALL
366 : : getRef( sal_Int32 columnIndex )
367 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
368 : : virtual REFERENCE<
369 : : com::sun::star::sdbc::XBlob > SAL_CALL
370 : : getBlob( sal_Int32 columnIndex )
371 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
372 : : virtual REFERENCE<
373 : : com::sun::star::sdbc::XClob > SAL_CALL
374 : : getClob( sal_Int32 columnIndex )
375 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
376 : : virtual REFERENCE<
377 : : com::sun::star::sdbc::XArray > SAL_CALL
378 : : getArray( sal_Int32 columnIndex )
379 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
380 : :
381 : : // XCloseable
382 : : virtual void SAL_CALL
383 : : close()
384 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
385 : :
386 : : // XResultSetMetaDataSupplier
387 : : virtual REFERENCE< XRESULTSETMETADATA > SAL_CALL
388 : : getMetaData()
389 : : throw( SQLEXCEPTION, RUNTIME_EXCEPTION );
390 : :
391 : :
392 : : // XPropertySet
393 : : virtual REFERENCE<
394 : : com::sun::star::beans::XPropertySetInfo > SAL_CALL
395 : : getPropertySetInfo()
396 : : throw( RUNTIME_EXCEPTION );
397 : :
398 : : virtual void SAL_CALL
399 : : setPropertyValue( const rtl::OUString& PropertyName,
400 : : const com::sun::star::uno::Any& Value )
401 : : throw( com::sun::star::beans::UnknownPropertyException,
402 : : com::sun::star::beans::PropertyVetoException,
403 : : com::sun::star::lang::IllegalArgumentException,
404 : : com::sun::star::lang::WrappedTargetException,
405 : : RUNTIME_EXCEPTION );
406 : :
407 : : virtual com::sun::star::uno::Any SAL_CALL
408 : : getPropertyValue( const rtl::OUString& PropertyName )
409 : : throw( com::sun::star::beans::UnknownPropertyException,
410 : : com::sun::star::lang::WrappedTargetException,
411 : : RUNTIME_EXCEPTION );
412 : :
413 : : virtual void SAL_CALL
414 : : addPropertyChangeListener( const rtl::OUString& PropertyName,
415 : : const REFERENCE<
416 : : com::sun::star::beans::XPropertyChangeListener >& Listener )
417 : : throw( com::sun::star::beans::UnknownPropertyException,
418 : : com::sun::star::lang::WrappedTargetException,
419 : : RUNTIME_EXCEPTION );
420 : :
421 : : virtual void SAL_CALL
422 : : removePropertyChangeListener( const rtl::OUString& PropertyName,
423 : : const REFERENCE<
424 : : com::sun::star::beans::XPropertyChangeListener >& Listener )
425 : : throw( com::sun::star::beans::UnknownPropertyException,
426 : : com::sun::star::lang::WrappedTargetException,
427 : : RUNTIME_EXCEPTION );
428 : :
429 : : virtual void SAL_CALL
430 : : addVetoableChangeListener( const rtl::OUString& PropertyName,
431 : : const REFERENCE<
432 : : com::sun::star::beans::XVetoableChangeListener >& Listener )
433 : : throw( com::sun::star::beans::UnknownPropertyException,
434 : : com::sun::star::lang::WrappedTargetException,
435 : : RUNTIME_EXCEPTION );
436 : :
437 : : virtual void SAL_CALL
438 : : removeVetoableChangeListener( const rtl::OUString& PropertyName,
439 : : const REFERENCE<
440 : : com::sun::star::beans::XVetoableChangeListener >& aListener )
441 : : throw( com::sun::star::beans::UnknownPropertyException,
442 : : com::sun::star::lang::WrappedTargetException,
443 : : RUNTIME_EXCEPTION );
444 : : };
445 : :
446 : : #endif
447 : :
448 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|