1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _SORTRESULT_HXX
21 #define _SORTRESULT_HXX
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>
41 #include <ucbhelper/macros.hxx>
44 class OInterfaceContainerHelper
;
47 //-----------------------------------------------------------------------------
50 class SRSPropertySetInfo
;
51 class PropertyChangeListeners_Impl
;
53 //-----------------------------------------------------------------------------
56 std::deque
< SortListData
* > maData
;
60 ~SortedEntryList(){ Clear(); }
62 sal_uInt32
Count() const { return (sal_uInt32
) maData
.size(); }
65 void Insert( SortListData
*pEntry
, long nPos
);
66 SortListData
* Remove( long nPos
);
67 SortListData
* GetData( long nPos
);
69 long operator [] ( long nPos
) const;
72 //-----------------------------------------------------------------------------
76 std::deque
< css::ucb::ListAction
* > maData
;
80 ~EventList(){ Clear(); }
82 sal_uInt32
Count() { return (sal_uInt32
) maData
.size(); }
84 void AddEvent( long nType
, long nPos
, long nCount
);
85 void Insert( css::ucb::ListAction
*pAction
) { maData
.push_back( pAction
); }
87 css::ucb::ListAction
* GetAction( long nIndex
) { return maData
[ nIndex
]; }
90 //-----------------------------------------------------------------------------
94 std::deque
< void* > maData
;
98 ~SimpleList(){ Clear(); }
100 sal_uInt32
Count() { return (sal_uInt32
) maData
.size(); }
101 void Clear() { maData
.clear(); }
103 void Remove( sal_uInt32 nPos
);
104 void Remove( void* pData
);
106 void Append( void* pData
)
107 { maData
.push_back( pData
); }
108 void Insert( void* pData
, sal_uInt32 nPos
);
109 void* GetObject( sal_uInt32 nPos
) const;
110 void Replace( void* pData
, sal_uInt32 nPos
);
113 //-----------------------------------------------------------------------------
115 #define RESULTSET_SERVICE_NAME "com.sun.star.ucb.SortedResultSet"
117 //-----------------------------------------------------------------------------
119 class SortedResultSet
:
120 public cppu::OWeakObject
,
121 public css::lang::XTypeProvider
,
122 public css::lang::XServiceInfo
,
123 public css::lang::XComponent
,
124 public css::ucb::XContentAccess
,
125 public css::sdbc::XResultSet
,
126 public css::sdbc::XRow
,
127 public css::sdbc::XCloseable
,
128 public css::sdbc::XResultSetMetaDataSupplier
,
129 public css::beans::XPropertySet
131 cppu::OInterfaceContainerHelper
*mpDisposeEventListeners
;
132 PropertyChangeListeners_Impl
*mpPropChangeListeners
;
133 PropertyChangeListeners_Impl
*mpVetoChangeListeners
;
135 css::uno::Reference
< css::sdbc::XResultSet
> mxOriginal
;
136 css::uno::Reference
< css::sdbc::XResultSet
> mxOther
;
138 SRSPropertySetInfo
* mpPropSetInfo
;
139 SortInfo
* mpSortInfo
;
141 SortedEntryList maS2O
; // maps the sorted entries to the original ones
142 SimpleList maO2S
; // maps the original Entries to the sorted ones
143 SimpleList maModList
; // keeps track of modified entries
144 long mnLastSort
; // index of the last sorted entry;
145 long mnCurEntry
; // index of the current entry
146 long mnCount
; // total count of the elements
152 long FindPos( SortListData
*pEntry
, long nStart
, long nEnd
)
153 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
154 long Compare( SortListData
*pOne
,
156 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
157 void BuildSortInfo( css::uno::Reference
< css::sdbc::XResultSet
> aResult
,
158 const css::uno::Sequence
< css::ucb::NumberedSortingInfo
> &xSortInfo
,
159 const css::uno::Reference
< css::ucb::XAnyCompareFactory
> &xCompFac
);
160 long CompareImpl( css::uno::Reference
< css::sdbc::XResultSet
> xResultOne
,
161 css::uno::Reference
< css::sdbc::XResultSet
> xResultTwo
,
162 long nIndexOne
, long nIndexTwo
,
163 SortInfo
* pSortInfo
)
164 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
165 long CompareImpl( css::uno::Reference
< css::sdbc::XResultSet
> xResultOne
,
166 css::uno::Reference
< css::sdbc::XResultSet
> xResultTwo
,
167 long nIndexOne
, long nIndexTwo
)
168 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
169 void PropertyChanged( const css::beans::PropertyChangeEvent
& rEvt
);
172 SortedResultSet( css::uno::Reference
< css::sdbc::XResultSet
> aResult
);
175 const SortedEntryList
* GetS2OList() const { return &maS2O
; }
176 const SimpleList
* GetO2SList() const { return &maO2S
; }
177 css::uno::Reference
< css::sdbc::XResultSet
> GetResultSet() const { return mxOriginal
; }
178 SortInfo
* GetSortInfo() const { return mpSortInfo
; }
179 long GetCount() const { return mnCount
; }
181 void CopyData( SortedResultSet
* pSource
);
182 void Initialize( const css::uno::Sequence
< css::ucb::NumberedSortingInfo
> &xSortInfo
,
183 const css::uno::Reference
< css::ucb::XAnyCompareFactory
> &xCompFac
);
184 void CheckProperties( long nOldCount
, sal_Bool bWasFinal
);
186 void InsertNew( long nPos
, long nCount
);
187 void SetChanged( long nPos
, long nCount
);
188 void Remove( long nPos
, long nCount
, EventList
*pList
);
189 void Move( long nPos
, long nCount
, long nOffset
);
191 void ResortModified( EventList
* pList
);
192 void ResortNew( EventList
* pList
);
201 XSERVICEINFO_NOFACTORY_DECL()
204 virtual void SAL_CALL
205 dispose() throw( css::uno::RuntimeException
);
207 virtual void SAL_CALL
208 addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
)
209 throw( css::uno::RuntimeException
);
211 virtual void SAL_CALL
212 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
)
213 throw( css::uno::RuntimeException
);
216 virtual OUString SAL_CALL
217 queryContentIdentifierString()
218 throw( css::uno::RuntimeException
);
219 virtual css::uno::Reference
<
220 css::ucb::XContentIdentifier
> SAL_CALL
221 queryContentIdentifier()
222 throw( css::uno::RuntimeException
);
223 virtual css::uno::Reference
<
224 css::ucb::XContent
> SAL_CALL
226 throw( css::uno::RuntimeException
);
229 virtual sal_Bool SAL_CALL
231 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
232 virtual sal_Bool SAL_CALL
234 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
235 virtual sal_Bool SAL_CALL
237 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
238 virtual sal_Bool SAL_CALL
240 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
241 virtual sal_Bool SAL_CALL
243 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
244 virtual void SAL_CALL
246 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
247 virtual void SAL_CALL
249 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
250 virtual sal_Bool SAL_CALL
252 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
253 virtual sal_Bool SAL_CALL
255 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
256 virtual sal_Int32 SAL_CALL
258 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
259 virtual sal_Bool SAL_CALL
260 absolute( sal_Int32 row
)
261 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
262 virtual sal_Bool SAL_CALL
263 relative( sal_Int32 rows
)
264 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
265 virtual sal_Bool SAL_CALL
267 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
268 virtual void SAL_CALL
270 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
271 virtual sal_Bool SAL_CALL
273 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
274 virtual sal_Bool SAL_CALL
276 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
277 virtual sal_Bool SAL_CALL
279 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
280 virtual css::uno::Reference
<
281 css::uno::XInterface
> SAL_CALL
283 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
286 virtual sal_Bool SAL_CALL
287 wasNull() throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
289 virtual OUString SAL_CALL
290 getString( sal_Int32 columnIndex
)
291 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
293 virtual sal_Bool SAL_CALL
294 getBoolean( sal_Int32 columnIndex
)
295 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
297 virtual sal_Int8 SAL_CALL
298 getByte( sal_Int32 columnIndex
)
299 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
301 virtual sal_Int16 SAL_CALL
302 getShort( sal_Int32 columnIndex
)
303 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
305 virtual sal_Int32 SAL_CALL
306 getInt( sal_Int32 columnIndex
)
307 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
309 virtual sal_Int64 SAL_CALL
310 getLong( sal_Int32 columnIndex
)
311 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
313 virtual float SAL_CALL
314 getFloat( sal_Int32 columnIndex
)
315 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
317 virtual double SAL_CALL
318 getDouble( sal_Int32 columnIndex
)
319 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
321 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
322 getBytes( sal_Int32 columnIndex
)
323 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
325 virtual css::util::Date SAL_CALL
326 getDate( sal_Int32 columnIndex
)
327 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
329 virtual css::util::Time SAL_CALL
330 getTime( sal_Int32 columnIndex
)
331 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
333 virtual css::util::DateTime SAL_CALL
334 getTimestamp( sal_Int32 columnIndex
)
335 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
337 virtual css::uno::Reference
<
338 css::io::XInputStream
> SAL_CALL
339 getBinaryStream( sal_Int32 columnIndex
)
340 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
342 virtual css::uno::Reference
<
343 css::io::XInputStream
> SAL_CALL
344 getCharacterStream( sal_Int32 columnIndex
)
345 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
347 virtual css::uno::Any SAL_CALL
348 getObject( sal_Int32 columnIndex
,
349 const css::uno::Reference
<
350 css::container::XNameAccess
>& typeMap
)
351 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
352 virtual css::uno::Reference
<
353 css::sdbc::XRef
> SAL_CALL
354 getRef( sal_Int32 columnIndex
)
355 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
356 virtual css::uno::Reference
<
357 css::sdbc::XBlob
> SAL_CALL
358 getBlob( sal_Int32 columnIndex
)
359 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
360 virtual css::uno::Reference
<
361 css::sdbc::XClob
> SAL_CALL
362 getClob( sal_Int32 columnIndex
)
363 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
364 virtual css::uno::Reference
<
365 css::sdbc::XArray
> SAL_CALL
366 getArray( sal_Int32 columnIndex
)
367 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
370 virtual void SAL_CALL
372 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
374 // XResultSetMetaDataSupplier
375 virtual css::uno::Reference
< css::sdbc::XResultSetMetaData
> SAL_CALL
377 throw( css::sdbc::SQLException
, css::uno::RuntimeException
);
381 virtual css::uno::Reference
<
382 css::beans::XPropertySetInfo
> SAL_CALL
384 throw( css::uno::RuntimeException
);
386 virtual void SAL_CALL
387 setPropertyValue( const OUString
& PropertyName
,
388 const css::uno::Any
& Value
)
389 throw( css::beans::UnknownPropertyException
,
390 css::beans::PropertyVetoException
,
391 css::lang::IllegalArgumentException
,
392 css::lang::WrappedTargetException
,
393 css::uno::RuntimeException
);
395 virtual css::uno::Any SAL_CALL
396 getPropertyValue( const OUString
& PropertyName
)
397 throw( css::beans::UnknownPropertyException
,
398 css::lang::WrappedTargetException
,
399 css::uno::RuntimeException
);
401 virtual void SAL_CALL
402 addPropertyChangeListener( const OUString
& PropertyName
,
403 const css::uno::Reference
<
404 css::beans::XPropertyChangeListener
>& Listener
)
405 throw( css::beans::UnknownPropertyException
,
406 css::lang::WrappedTargetException
,
407 css::uno::RuntimeException
);
409 virtual void SAL_CALL
410 removePropertyChangeListener( const OUString
& PropertyName
,
411 const css::uno::Reference
<
412 css::beans::XPropertyChangeListener
>& Listener
)
413 throw( css::beans::UnknownPropertyException
,
414 css::lang::WrappedTargetException
,
415 css::uno::RuntimeException
);
417 virtual void SAL_CALL
418 addVetoableChangeListener( const OUString
& PropertyName
,
419 const css::uno::Reference
<
420 css::beans::XVetoableChangeListener
>& Listener
)
421 throw( css::beans::UnknownPropertyException
,
422 css::lang::WrappedTargetException
,
423 css::uno::RuntimeException
);
425 virtual void SAL_CALL
426 removeVetoableChangeListener( const OUString
& PropertyName
,
427 const css::uno::Reference
<
428 css::beans::XVetoableChangeListener
>& aListener
)
429 throw( css::beans::UnknownPropertyException
,
430 css::lang::WrappedTargetException
,
431 css::uno::RuntimeException
);
436 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */