1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sortresult.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SORTRESULT_HXX
32 #define _SORTRESULT_HXX
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/lang/XTypeProvider.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/lang/XComponent.hpp>
39 #include <com/sun/star/sdbc/XCloseable.hpp>
40 #include <com/sun/star/sdbc/XResultSet.hpp>
41 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
42 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
43 #include <com/sun/star/sdbc/XRow.hpp>
44 #include <com/sun/star/ucb/XContentAccess.hpp>
45 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
46 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
47 #include <com/sun/star/ucb/ListAction.hpp>
48 #include <cppuhelper/weak.hxx>
49 #include <osl/mutex.hxx>
52 #include <ucbhelper/macros.hxx>
55 class OInterfaceContainerHelper
;
58 //-----------------------------------------------------------------------------
61 class SRSPropertySetInfo
;
62 class PropertyChangeListeners_Impl
;
64 //-----------------------------------------------------------------------------
67 std::deque
< SortListData
* > maData
;
71 ~SortedEntryList(){ Clear(); }
73 sal_uInt32
Count() const { return (sal_uInt32
) maData
.size(); }
76 void Insert( SortListData
*pEntry
, long nPos
);
77 SortListData
* Remove( long nPos
);
78 SortListData
* GetData( long nPos
);
80 long operator [] ( long nPos
) const;
83 //-----------------------------------------------------------------------------
84 #define LISTACTION com::sun::star::ucb::ListAction
88 std::deque
< LISTACTION
* > maData
;
92 ~EventList(){ Clear(); }
94 sal_uInt32
Count() { return (sal_uInt32
) maData
.size(); }
96 void AddEvent( long nType
, long nPos
, long nCount
);
97 void Insert( LISTACTION
*pAction
) { maData
.push_back( pAction
); }
99 LISTACTION
* GetAction( long nIndex
) { return maData
[ nIndex
]; }
102 //-----------------------------------------------------------------------------
106 std::deque
< void* > maData
;
110 ~SimpleList(){ Clear(); }
112 sal_uInt32
Count() { return (sal_uInt32
) maData
.size(); }
113 void Clear() { maData
.clear(); }
115 void Remove( sal_uInt32 nPos
);
116 void Remove( void* pData
);
118 void Append( void* pData
)
119 { maData
.push_back( pData
); }
120 void Insert( void* pData
, sal_uInt32 nPos
);
121 void* GetObject( sal_uInt32 nPos
) const;
122 void Replace( void* pData
, sal_uInt32 nPos
);
125 //-----------------------------------------------------------------------------
127 #define PROPERTYCHANGEEVENT com::sun::star::beans::PropertyChangeEvent
128 #define RUNTIME_EXCEPTION com::sun::star::uno::RuntimeException
129 #define REFERENCE com::sun::star::uno::Reference
130 #define SEQUENCE com::sun::star::uno::Sequence
131 #define XEVENTLISTENER com::sun::star::lang::XEventListener
132 #define XRESULTSET com::sun::star::sdbc::XResultSet
133 #define SQLEXCEPTION com::sun::star::sdbc::SQLException
134 #define XRESULTSETMETADATA com::sun::star::sdbc::XResultSetMetaData
135 #define NUMBERED_SORTINGINFO com::sun::star::ucb::NumberedSortingInfo
136 #define XANYCOMPAREFACTORY com::sun::star::ucb::XAnyCompareFactory
138 #define RESULTSET_SERVICE_NAME "com.sun.star.ucb.SortedResultSet"
140 //-----------------------------------------------------------------------------
142 class SortedResultSet
:
143 public cppu::OWeakObject
,
144 public com::sun::star::lang::XTypeProvider
,
145 public com::sun::star::lang::XServiceInfo
,
146 public com::sun::star::lang::XComponent
,
147 public com::sun::star::ucb::XContentAccess
,
149 public com::sun::star::sdbc::XRow
,
150 public com::sun::star::sdbc::XCloseable
,
151 public com::sun::star::sdbc::XResultSetMetaDataSupplier
,
152 public com::sun::star::beans::XPropertySet
154 cppu::OInterfaceContainerHelper
*mpDisposeEventListeners
;
155 PropertyChangeListeners_Impl
*mpPropChangeListeners
;
156 PropertyChangeListeners_Impl
*mpVetoChangeListeners
;
158 REFERENCE
< XRESULTSET
> mxOriginal
;
159 REFERENCE
< XRESULTSET
> mxOther
;
161 SRSPropertySetInfo
* mpPropSetInfo
;
162 SortInfo
* mpSortInfo
;
164 SortedEntryList maS2O
; // maps the sorted entries to the original ones
165 SimpleList maO2S
; // maps the original Entries to the sorted ones
166 SimpleList maModList
; // keeps track of modified entries
167 long mnLastSort
; // index of the last sorted entry;
168 long mnCurEntry
; // index of the current entry
169 long mnCount
; // total count of the elements
175 long FindPos( SortListData
*pEntry
, long nStart
, long nEnd
)
176 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
177 long Compare( SortListData
*pOne
,
179 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
180 void BuildSortInfo( REFERENCE
< XRESULTSET
> aResult
,
181 const SEQUENCE
< NUMBERED_SORTINGINFO
> &xSortInfo
,
182 const REFERENCE
< XANYCOMPAREFACTORY
> &xCompFac
);
183 long CompareImpl( REFERENCE
< XRESULTSET
> xResultOne
,
184 REFERENCE
< XRESULTSET
> xResultTwo
,
185 long nIndexOne
, long nIndexTwo
,
186 SortInfo
* pSortInfo
)
187 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
188 long CompareImpl( REFERENCE
< XRESULTSET
> xResultOne
,
189 REFERENCE
< XRESULTSET
> xResultTwo
,
190 long nIndexOne
, long nIndexTwo
)
191 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
192 void PropertyChanged( const PROPERTYCHANGEEVENT
& rEvt
);
195 SortedResultSet( REFERENCE
< XRESULTSET
> aResult
);
198 const SortedEntryList
* GetS2OList() const { return &maS2O
; }
199 const SimpleList
* GetO2SList() const { return &maO2S
; }
200 REFERENCE
< XRESULTSET
> GetResultSet() const { return mxOriginal
; }
201 SortInfo
* GetSortInfo() const { return mpSortInfo
; }
202 long GetCount() const { return mnCount
; }
204 void CopyData( SortedResultSet
* pSource
);
205 void Initialize( const SEQUENCE
< NUMBERED_SORTINGINFO
> &xSortInfo
,
206 const REFERENCE
< XANYCOMPAREFACTORY
> &xCompFac
);
207 void CheckProperties( long nOldCount
, sal_Bool bWasFinal
);
209 void InsertNew( long nPos
, long nCount
);
210 void SetChanged( long nPos
, long nCount
);
211 void Remove( long nPos
, long nCount
, EventList
*pList
);
212 void Move( long nPos
, long nCount
, long nOffset
);
214 void ResortModified( EventList
* pList
);
215 void ResortNew( EventList
* pList
);
224 XSERVICEINFO_NOFACTORY_DECL()
227 virtual void SAL_CALL
228 dispose() throw( RUNTIME_EXCEPTION
);
230 virtual void SAL_CALL
231 addEventListener( const REFERENCE
< XEVENTLISTENER
>& Listener
)
232 throw( RUNTIME_EXCEPTION
);
234 virtual void SAL_CALL
235 removeEventListener( const REFERENCE
< XEVENTLISTENER
>& Listener
)
236 throw( RUNTIME_EXCEPTION
);
239 virtual rtl::OUString SAL_CALL
240 queryContentIdentifierString()
241 throw( RUNTIME_EXCEPTION
);
243 com::sun::star::ucb::XContentIdentifier
> SAL_CALL
244 queryContentIdentifier()
245 throw( RUNTIME_EXCEPTION
);
247 com::sun::star::ucb::XContent
> SAL_CALL
249 throw( RUNTIME_EXCEPTION
);
252 virtual sal_Bool SAL_CALL
254 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
255 virtual sal_Bool SAL_CALL
257 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
258 virtual sal_Bool SAL_CALL
260 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
261 virtual sal_Bool SAL_CALL
263 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
264 virtual sal_Bool SAL_CALL
266 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
267 virtual void SAL_CALL
269 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
270 virtual void SAL_CALL
272 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
273 virtual sal_Bool SAL_CALL
275 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
276 virtual sal_Bool SAL_CALL
278 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
279 virtual sal_Int32 SAL_CALL
281 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
282 virtual sal_Bool SAL_CALL
283 absolute( sal_Int32 row
)
284 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
285 virtual sal_Bool SAL_CALL
286 relative( sal_Int32 rows
)
287 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
288 virtual sal_Bool SAL_CALL
290 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
291 virtual void SAL_CALL
293 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
294 virtual sal_Bool SAL_CALL
296 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
297 virtual sal_Bool SAL_CALL
299 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
300 virtual sal_Bool SAL_CALL
302 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
304 com::sun::star::uno::XInterface
> SAL_CALL
306 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
309 virtual sal_Bool SAL_CALL
310 wasNull() throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
312 virtual rtl::OUString SAL_CALL
313 getString( sal_Int32 columnIndex
)
314 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
316 virtual sal_Bool SAL_CALL
317 getBoolean( sal_Int32 columnIndex
)
318 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
320 virtual sal_Int8 SAL_CALL
321 getByte( sal_Int32 columnIndex
)
322 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
324 virtual sal_Int16 SAL_CALL
325 getShort( sal_Int32 columnIndex
)
326 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
328 virtual sal_Int32 SAL_CALL
329 getInt( sal_Int32 columnIndex
)
330 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
332 virtual sal_Int64 SAL_CALL
333 getLong( sal_Int32 columnIndex
)
334 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
336 virtual float SAL_CALL
337 getFloat( sal_Int32 columnIndex
)
338 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
340 virtual double SAL_CALL
341 getDouble( sal_Int32 columnIndex
)
342 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
344 virtual com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
345 getBytes( sal_Int32 columnIndex
)
346 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
348 virtual com::sun::star::util::Date SAL_CALL
349 getDate( sal_Int32 columnIndex
)
350 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
352 virtual com::sun::star::util::Time SAL_CALL
353 getTime( sal_Int32 columnIndex
)
354 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
356 virtual com::sun::star::util::DateTime SAL_CALL
357 getTimestamp( sal_Int32 columnIndex
)
358 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
361 com::sun::star::io::XInputStream
> SAL_CALL
362 getBinaryStream( sal_Int32 columnIndex
)
363 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
366 com::sun::star::io::XInputStream
> SAL_CALL
367 getCharacterStream( sal_Int32 columnIndex
)
368 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
370 virtual com::sun::star::uno::Any SAL_CALL
371 getObject( sal_Int32 columnIndex
,
373 com::sun::star::container::XNameAccess
>& typeMap
)
374 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
376 com::sun::star::sdbc::XRef
> SAL_CALL
377 getRef( sal_Int32 columnIndex
)
378 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
380 com::sun::star::sdbc::XBlob
> SAL_CALL
381 getBlob( sal_Int32 columnIndex
)
382 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
384 com::sun::star::sdbc::XClob
> SAL_CALL
385 getClob( sal_Int32 columnIndex
)
386 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
388 com::sun::star::sdbc::XArray
> SAL_CALL
389 getArray( sal_Int32 columnIndex
)
390 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
393 virtual void SAL_CALL
395 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
397 // XResultSetMetaDataSupplier
398 virtual REFERENCE
< XRESULTSETMETADATA
> SAL_CALL
400 throw( SQLEXCEPTION
, RUNTIME_EXCEPTION
);
405 com::sun::star::beans::XPropertySetInfo
> SAL_CALL
407 throw( RUNTIME_EXCEPTION
);
409 virtual void SAL_CALL
410 setPropertyValue( const rtl::OUString
& PropertyName
,
411 const com::sun::star::uno::Any
& Value
)
412 throw( com::sun::star::beans::UnknownPropertyException
,
413 com::sun::star::beans::PropertyVetoException
,
414 com::sun::star::lang::IllegalArgumentException
,
415 com::sun::star::lang::WrappedTargetException
,
418 virtual com::sun::star::uno::Any SAL_CALL
419 getPropertyValue( const rtl::OUString
& PropertyName
)
420 throw( com::sun::star::beans::UnknownPropertyException
,
421 com::sun::star::lang::WrappedTargetException
,
424 virtual void SAL_CALL
425 addPropertyChangeListener( const rtl::OUString
& PropertyName
,
427 com::sun::star::beans::XPropertyChangeListener
>& Listener
)
428 throw( com::sun::star::beans::UnknownPropertyException
,
429 com::sun::star::lang::WrappedTargetException
,
432 virtual void SAL_CALL
433 removePropertyChangeListener( const rtl::OUString
& PropertyName
,
435 com::sun::star::beans::XPropertyChangeListener
>& Listener
)
436 throw( com::sun::star::beans::UnknownPropertyException
,
437 com::sun::star::lang::WrappedTargetException
,
440 virtual void SAL_CALL
441 addVetoableChangeListener( const rtl::OUString
& PropertyName
,
443 com::sun::star::beans::XVetoableChangeListener
>& Listener
)
444 throw( com::sun::star::beans::UnknownPropertyException
,
445 com::sun::star::lang::WrappedTargetException
,
448 virtual void SAL_CALL
449 removeVetoableChangeListener( const rtl::OUString
& PropertyName
,
451 com::sun::star::beans::XVetoableChangeListener
>& aListener
)
452 throw( com::sun::star::beans::UnknownPropertyException
,
453 com::sun::star::lang::WrappedTargetException
,