xref: /aoo41x/main/ucb/source/sorter/sortresult.cxx (revision 2f86921c)
1*2f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2f86921cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2f86921cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2f86921cSAndrew Rist  * distributed with this work for additional information
6*2f86921cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2f86921cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2f86921cSAndrew Rist  * "License"); you may not use this file except in compliance
9*2f86921cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2f86921cSAndrew Rist  *
11*2f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2f86921cSAndrew Rist  *
13*2f86921cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2f86921cSAndrew Rist  * software distributed under the License is distributed on an
15*2f86921cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2f86921cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2f86921cSAndrew Rist  * specific language governing permissions and limitations
18*2f86921cSAndrew Rist  * under the License.
19*2f86921cSAndrew Rist  *
20*2f86921cSAndrew Rist  *************************************************************/
21*2f86921cSAndrew Rist 
22*2f86921cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <vector>
28cdf0e10cSrcweir #include <sortresult.hxx>
29cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
30cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
32cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
33cdf0e10cSrcweir #include <com/sun/star/ucb/ListActionType.hpp>
34cdf0e10cSrcweir #include <com/sun/star/ucb/XAnyCompare.hpp>
35cdf0e10cSrcweir #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
36cdf0e10cSrcweir #include <osl/diagnose.h>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //-----------------------------------------------------------------------------
39cdf0e10cSrcweir using namespace com::sun::star::beans;
40cdf0e10cSrcweir using namespace com::sun::star::container;
41cdf0e10cSrcweir using namespace com::sun::star::io;
42cdf0e10cSrcweir using namespace com::sun::star::lang;
43cdf0e10cSrcweir using namespace com::sun::star::sdbc;
44cdf0e10cSrcweir using namespace com::sun::star::ucb;
45cdf0e10cSrcweir using namespace com::sun::star::uno;
46cdf0e10cSrcweir using namespace com::sun::star::util;
47cdf0e10cSrcweir using namespace cppu;
48cdf0e10cSrcweir using namespace rtl;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //=========================================================================
51cdf0e10cSrcweir 
52cdf0e10cSrcweir //  The mutex to synchronize access to containers.
getContainerMutex()53cdf0e10cSrcweir static osl::Mutex& getContainerMutex()
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     static osl::Mutex* pMutex = NULL;
56cdf0e10cSrcweir     if( !pMutex )
57cdf0e10cSrcweir     {
58cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
59cdf0e10cSrcweir         if( !pMutex )
60cdf0e10cSrcweir         {
61cdf0e10cSrcweir             static osl::Mutex aMutex;
62cdf0e10cSrcweir             pMutex = &aMutex;
63cdf0e10cSrcweir         }
64cdf0e10cSrcweir     }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     return *pMutex;
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir //==========================================================================
70cdf0e10cSrcweir 
71cdf0e10cSrcweir struct SortInfo
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     sal_Bool    mbUseOwnCompare;
74cdf0e10cSrcweir     sal_Bool    mbAscending;
75cdf0e10cSrcweir     sal_Bool    mbCaseSensitive;
76cdf0e10cSrcweir     sal_Int32   mnColumn;
77cdf0e10cSrcweir     sal_Int32   mnType;
78cdf0e10cSrcweir     SortInfo*   mpNext;
79cdf0e10cSrcweir     Reference < XAnyCompare >   mxCompareFunction;
80cdf0e10cSrcweir };
81cdf0e10cSrcweir 
82cdf0e10cSrcweir //-----------------------------------------------------------------------------
83cdf0e10cSrcweir 
84cdf0e10cSrcweir struct SortListData
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     sal_Bool    mbModified;
87cdf0e10cSrcweir     long        mnCurPos;
88cdf0e10cSrcweir     long        mnOldPos;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir                 SortListData( long nPos, sal_Bool bModified = sal_False );
91cdf0e10cSrcweir };
92cdf0e10cSrcweir 
93cdf0e10cSrcweir //============================================================================
94cdf0e10cSrcweir //
95cdf0e10cSrcweir // class SRSPropertySetInfo.
96cdf0e10cSrcweir //
97cdf0e10cSrcweir //============================================================================
98cdf0e10cSrcweir 
99cdf0e10cSrcweir class SRSPropertySetInfo :
100cdf0e10cSrcweir                 public OWeakObject,
101cdf0e10cSrcweir                 public XTypeProvider,
102cdf0e10cSrcweir                 public XPropertySetInfo
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     Property    maProps[2];
105cdf0e10cSrcweir 
106cdf0e10cSrcweir private:
107cdf0e10cSrcweir 
108cdf0e10cSrcweir public:
109cdf0e10cSrcweir                 SRSPropertySetInfo();
110cdf0e10cSrcweir     virtual     ~SRSPropertySetInfo();
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     // XInterface
113cdf0e10cSrcweir     XINTERFACE_DECL()
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     // XTypeProvider
116cdf0e10cSrcweir     XTYPEPROVIDER_DECL()
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     // XPropertySetInfo
119cdf0e10cSrcweir     virtual Sequence< Property > SAL_CALL getProperties()
120cdf0e10cSrcweir         throw( RuntimeException );
121cdf0e10cSrcweir     virtual Property SAL_CALL getPropertyByName( const OUString& aName )
122cdf0e10cSrcweir         throw( UnknownPropertyException, RuntimeException );
123cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name )
124cdf0e10cSrcweir         throw( RuntimeException );
125cdf0e10cSrcweir };
126cdf0e10cSrcweir 
127cdf0e10cSrcweir //=========================================================================
128cdf0e10cSrcweir //
129cdf0e10cSrcweir // PropertyChangeListenerContainer_Impl.
130cdf0e10cSrcweir //
131cdf0e10cSrcweir //=========================================================================
132cdf0e10cSrcweir 
133cdf0e10cSrcweir struct equalStr_Impl
134cdf0e10cSrcweir {
operator ()equalStr_Impl135cdf0e10cSrcweir     bool operator()( const OUString& s1, const OUString& s2 ) const
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         return !!( s1 == s2 );
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir };
140cdf0e10cSrcweir 
141cdf0e10cSrcweir struct hashStr_Impl
142cdf0e10cSrcweir {
operator ()hashStr_Impl143cdf0e10cSrcweir     size_t operator()( const OUString& rName ) const
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         return rName.hashCode();
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir };
148cdf0e10cSrcweir 
149cdf0e10cSrcweir typedef OMultiTypeInterfaceContainerHelperVar
150cdf0e10cSrcweir <
151cdf0e10cSrcweir     OUString,
152cdf0e10cSrcweir     hashStr_Impl,
153cdf0e10cSrcweir     equalStr_Impl
154cdf0e10cSrcweir > PropertyChangeListenerContainer_Impl;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir //=========================================================================
157cdf0e10cSrcweir //
158cdf0e10cSrcweir // class PropertyChangeListeners_Impl
159cdf0e10cSrcweir //
160cdf0e10cSrcweir //=========================================================================
161cdf0e10cSrcweir 
162cdf0e10cSrcweir class PropertyChangeListeners_Impl : public PropertyChangeListenerContainer_Impl
163cdf0e10cSrcweir {
164cdf0e10cSrcweir public:
PropertyChangeListeners_Impl()165cdf0e10cSrcweir     PropertyChangeListeners_Impl()
166cdf0e10cSrcweir     : PropertyChangeListenerContainer_Impl( getContainerMutex() ) {}
167cdf0e10cSrcweir };
168cdf0e10cSrcweir 
169cdf0e10cSrcweir //==========================================================================
SortedResultSet(Reference<XResultSet> aResult)170cdf0e10cSrcweir SortedResultSet::SortedResultSet( Reference< XResultSet > aResult )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir     mpDisposeEventListeners = NULL;
173cdf0e10cSrcweir     mpPropChangeListeners   = NULL;
174cdf0e10cSrcweir     mpVetoChangeListeners   = NULL;
175cdf0e10cSrcweir     mpPropSetInfo           = NULL;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     mxOriginal  = aResult;
178cdf0e10cSrcweir     mpSortInfo  = NULL;
179cdf0e10cSrcweir     mnLastSort  = 0;
180cdf0e10cSrcweir     mnCurEntry  = 0;
181cdf0e10cSrcweir     mnCount     = 0;
182cdf0e10cSrcweir     mbIsCopy    = sal_False;
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir //--------------------------------------------------------------------------
~SortedResultSet()186cdf0e10cSrcweir SortedResultSet::~SortedResultSet()
187cdf0e10cSrcweir {
188cdf0e10cSrcweir     mxOriginal.clear();
189cdf0e10cSrcweir     mxOther.clear();
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     if ( !mbIsCopy )
192cdf0e10cSrcweir     {
193cdf0e10cSrcweir         SortInfo *pInfo = mpSortInfo;
194cdf0e10cSrcweir         while ( pInfo )
195cdf0e10cSrcweir         {
196cdf0e10cSrcweir             mpSortInfo = pInfo->mpNext;
197cdf0e10cSrcweir             delete pInfo;
198cdf0e10cSrcweir             pInfo = mpSortInfo;
199cdf0e10cSrcweir         }
200cdf0e10cSrcweir     }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     mpSortInfo = NULL;
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     if ( mpPropSetInfo )
205cdf0e10cSrcweir         mpPropSetInfo->release();
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     delete mpPropChangeListeners;
208cdf0e10cSrcweir     delete mpVetoChangeListeners;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir //--------------------------------------------------------------------------
212cdf0e10cSrcweir // XInterface methods.
213cdf0e10cSrcweir //--------------------------------------------------------------------------
214cdf0e10cSrcweir 
215cdf0e10cSrcweir XINTERFACE_IMPL_9( SortedResultSet,
216cdf0e10cSrcweir                    XTypeProvider,
217cdf0e10cSrcweir                    XServiceInfo,
218cdf0e10cSrcweir                    XComponent,
219cdf0e10cSrcweir                    XContentAccess,
220cdf0e10cSrcweir                    XResultSet,
221cdf0e10cSrcweir                    XRow,
222cdf0e10cSrcweir                    XCloseable,
223cdf0e10cSrcweir                    XResultSetMetaDataSupplier,
224cdf0e10cSrcweir                    XPropertySet );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir //--------------------------------------------------------------------------
227cdf0e10cSrcweir // XTypeProvider methods.
228cdf0e10cSrcweir //--------------------------------------------------------------------------
229cdf0e10cSrcweir 
230cdf0e10cSrcweir XTYPEPROVIDER_IMPL_9( SortedResultSet,
231cdf0e10cSrcweir                       XTypeProvider,
232cdf0e10cSrcweir                       XServiceInfo,
233cdf0e10cSrcweir                       XComponent,
234cdf0e10cSrcweir                       XContentAccess,
235cdf0e10cSrcweir                       XResultSet,
236cdf0e10cSrcweir                       XRow,
237cdf0e10cSrcweir                       XCloseable,
238cdf0e10cSrcweir                       XResultSetMetaDataSupplier,
239cdf0e10cSrcweir                       XPropertySet );
240cdf0e10cSrcweir 
241cdf0e10cSrcweir //--------------------------------------------------------------------------
242cdf0e10cSrcweir // XServiceInfo methods.
243cdf0e10cSrcweir //--------------------------------------------------------------------------
244cdf0e10cSrcweir 
245cdf0e10cSrcweir XSERVICEINFO_NOFACTORY_IMPL_1( SortedResultSet,
246cdf0e10cSrcweir                                OUString::createFromAscii(
247cdf0e10cSrcweir                                 "com.sun.star.comp.ucb.SortedResultSet" ),
248cdf0e10cSrcweir                                OUString::createFromAscii(
249cdf0e10cSrcweir                                 RESULTSET_SERVICE_NAME ) );
250cdf0e10cSrcweir 
251cdf0e10cSrcweir //--------------------------------------------------------------------------
252cdf0e10cSrcweir // XComponent methods.
253cdf0e10cSrcweir //--------------------------------------------------------------------------
dispose()254cdf0e10cSrcweir void SAL_CALL SortedResultSet::dispose()
255cdf0e10cSrcweir     throw( RuntimeException )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     if ( mpDisposeEventListeners && mpDisposeEventListeners->getLength() )
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         EventObject aEvt;
262cdf0e10cSrcweir         aEvt.Source = static_cast< XComponent * >( this );
263cdf0e10cSrcweir         mpDisposeEventListeners->disposeAndClear( aEvt );
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     if ( mpPropChangeListeners )
267cdf0e10cSrcweir     {
268cdf0e10cSrcweir         EventObject aEvt;
269cdf0e10cSrcweir         aEvt.Source = static_cast< XPropertySet * >( this );
270cdf0e10cSrcweir         mpPropChangeListeners->disposeAndClear( aEvt );
271cdf0e10cSrcweir     }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir     if ( mpVetoChangeListeners )
274cdf0e10cSrcweir     {
275cdf0e10cSrcweir         EventObject aEvt;
276cdf0e10cSrcweir         aEvt.Source = static_cast< XPropertySet * >( this );
277cdf0e10cSrcweir         mpVetoChangeListeners->disposeAndClear( aEvt );
278cdf0e10cSrcweir     }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir     mxOriginal.clear();
281cdf0e10cSrcweir     mxOther.clear();
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir //--------------------------------------------------------------------------
addEventListener(const Reference<XEventListener> & Listener)285cdf0e10cSrcweir void SAL_CALL SortedResultSet::addEventListener(
286cdf0e10cSrcweir                             const Reference< XEventListener >& Listener )
287cdf0e10cSrcweir     throw( RuntimeException )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     if ( !mpDisposeEventListeners )
292cdf0e10cSrcweir         mpDisposeEventListeners =
293cdf0e10cSrcweir                     new OInterfaceContainerHelper( getContainerMutex() );
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     mpDisposeEventListeners->addInterface( Listener );
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir //--------------------------------------------------------------------------
removeEventListener(const Reference<XEventListener> & Listener)299cdf0e10cSrcweir void SAL_CALL SortedResultSet::removeEventListener(
300cdf0e10cSrcweir                             const Reference< XEventListener >& Listener )
301cdf0e10cSrcweir     throw( RuntimeException )
302cdf0e10cSrcweir {
303cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
304cdf0e10cSrcweir 
305cdf0e10cSrcweir     if ( mpDisposeEventListeners )
306cdf0e10cSrcweir         mpDisposeEventListeners->removeInterface( Listener );
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir //--------------------------------------------------------------------------
310cdf0e10cSrcweir // XContentAccess methods.
311cdf0e10cSrcweir //--------------------------------------------------------------------------
312cdf0e10cSrcweir 
313cdf0e10cSrcweir OUString SAL_CALL
queryContentIdentifierString()314cdf0e10cSrcweir SortedResultSet::queryContentIdentifierString()
315cdf0e10cSrcweir     throw( RuntimeException )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
318cdf0e10cSrcweir     return Reference< XContentAccess >::query(mxOriginal)->queryContentIdentifierString();
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir //--------------------------------------------------------------------------
322cdf0e10cSrcweir Reference< XContentIdentifier > SAL_CALL
queryContentIdentifier()323cdf0e10cSrcweir SortedResultSet::queryContentIdentifier()
324cdf0e10cSrcweir     throw( RuntimeException )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
327cdf0e10cSrcweir     return Reference< XContentAccess >::query(mxOriginal)->queryContentIdentifier();
328cdf0e10cSrcweir }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir //--------------------------------------------------------------------------
331cdf0e10cSrcweir Reference< XContent > SAL_CALL
queryContent()332cdf0e10cSrcweir SortedResultSet::queryContent()
333cdf0e10cSrcweir     throw( RuntimeException )
334cdf0e10cSrcweir {
335cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
336cdf0e10cSrcweir     return Reference< XContentAccess >::query(mxOriginal)->queryContent();
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 
340cdf0e10cSrcweir //--------------------------------------------------------------------------
341cdf0e10cSrcweir // XResultSet methods.
342cdf0e10cSrcweir //--------------------------------------------------------------------------
next()343cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::next()
344cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     mnCurEntry++;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     if ( mnCurEntry > 0 )
351cdf0e10cSrcweir     {
352cdf0e10cSrcweir         if ( mnCurEntry <= mnCount )
353cdf0e10cSrcweir         {
354cdf0e10cSrcweir             sal_Int32 nIndex = maS2O[ mnCurEntry ];
355cdf0e10cSrcweir             return mxOriginal->absolute( nIndex );
356cdf0e10cSrcweir         }
357cdf0e10cSrcweir         else
358cdf0e10cSrcweir         {
359cdf0e10cSrcweir             mnCurEntry = mnCount + 1;
360cdf0e10cSrcweir         }
361cdf0e10cSrcweir     }
362cdf0e10cSrcweir     return sal_False;
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
365cdf0e10cSrcweir //-------------------------------------------------------------------------
isBeforeFirst()366cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::isBeforeFirst()
367cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
368cdf0e10cSrcweir {
369cdf0e10cSrcweir     if ( mnCurEntry )
370cdf0e10cSrcweir         return sal_False;
371cdf0e10cSrcweir     else
372cdf0e10cSrcweir         return sal_True;
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir //-------------------------------------------------------------------------
isAfterLast()376cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::isAfterLast()
377cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
378cdf0e10cSrcweir {
379cdf0e10cSrcweir     if ( mnCurEntry > mnCount )
380cdf0e10cSrcweir         return sal_True;
381cdf0e10cSrcweir     else
382cdf0e10cSrcweir         return sal_False;
383cdf0e10cSrcweir }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir //-------------------------------------------------------------------------
isFirst()386cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::isFirst()
387cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir     if ( mnCurEntry == 1 )
390cdf0e10cSrcweir         return sal_True;
391cdf0e10cSrcweir     else
392cdf0e10cSrcweir         return sal_False;
393cdf0e10cSrcweir }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir //-------------------------------------------------------------------------
isLast()396cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::isLast()
397cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir     if ( mnCurEntry == mnCount )
400cdf0e10cSrcweir         return sal_True;
401cdf0e10cSrcweir     else
402cdf0e10cSrcweir         return sal_False;
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir //-------------------------------------------------------------------------
beforeFirst()406cdf0e10cSrcweir void SAL_CALL SortedResultSet::beforeFirst()
407cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
408cdf0e10cSrcweir {
409cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
410cdf0e10cSrcweir     mnCurEntry = 0;
411cdf0e10cSrcweir     mxOriginal->beforeFirst();
412cdf0e10cSrcweir }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir //-------------------------------------------------------------------------
afterLast()415cdf0e10cSrcweir void SAL_CALL SortedResultSet::afterLast()
416cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
417cdf0e10cSrcweir {
418cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
419cdf0e10cSrcweir     mnCurEntry = mnCount+1;
420cdf0e10cSrcweir     mxOriginal->afterLast();
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir //-------------------------------------------------------------------------
first()424cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::first()
425cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
426cdf0e10cSrcweir {
427cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
428cdf0e10cSrcweir 
429cdf0e10cSrcweir     if ( mnCount )
430cdf0e10cSrcweir     {
431cdf0e10cSrcweir         mnCurEntry = 1;
432cdf0e10cSrcweir         sal_Int32 nIndex = maS2O[ mnCurEntry ];
433cdf0e10cSrcweir         return mxOriginal->absolute( nIndex );
434cdf0e10cSrcweir     }
435cdf0e10cSrcweir     else
436cdf0e10cSrcweir     {
437cdf0e10cSrcweir         mnCurEntry = 0;
438cdf0e10cSrcweir         return sal_False;
439cdf0e10cSrcweir     }
440cdf0e10cSrcweir }
441cdf0e10cSrcweir 
442cdf0e10cSrcweir //-------------------------------------------------------------------------
last()443cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::last()
444cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
445cdf0e10cSrcweir {
446cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
447cdf0e10cSrcweir 
448cdf0e10cSrcweir     if ( mnCount )
449cdf0e10cSrcweir     {
450cdf0e10cSrcweir         mnCurEntry = mnCount;
451cdf0e10cSrcweir         sal_Int32 nIndex = maS2O[ mnCurEntry ];
452cdf0e10cSrcweir         return mxOriginal->absolute( nIndex );
453cdf0e10cSrcweir     }
454cdf0e10cSrcweir     else
455cdf0e10cSrcweir     {
456cdf0e10cSrcweir         mnCurEntry = 0;
457cdf0e10cSrcweir         return sal_False;
458cdf0e10cSrcweir     }
459cdf0e10cSrcweir }
460cdf0e10cSrcweir 
461cdf0e10cSrcweir //-------------------------------------------------------------------------
getRow()462cdf0e10cSrcweir sal_Int32 SAL_CALL SortedResultSet::getRow()
463cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
464cdf0e10cSrcweir {
465cdf0e10cSrcweir     return mnCurEntry;
466cdf0e10cSrcweir }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir //-------------------------------------------------------------------------
469cdf0e10cSrcweir /**
470cdf0e10cSrcweir  moves the cursor to the given row number in the result set.
471cdf0e10cSrcweir  <p>If the row number is positive, the cursor moves to the given row
472cdf0e10cSrcweir  number with respect to the beginning of the result set. The first
473cdf0e10cSrcweir  row is row 1, the second is row 2, and so on.
474cdf0e10cSrcweir  <p>If the given row number is negative, the cursor moves to an
475cdf0e10cSrcweir  absolute row position with respect to the end of the result set.
476cdf0e10cSrcweir  For example, calling <code>moveToPosition(-1)</code> positions the
477cdf0e10cSrcweir  cursor on the last row, <code>moveToPosition(-2)</code> indicates the
478cdf0e10cSrcweir  next-to-last row, and so on.
479cdf0e10cSrcweir  <p>An attempt to position the cursor beyond the first/last row in the
480cdf0e10cSrcweir  result set leaves the cursor before/after the first/last row,
481cdf0e10cSrcweir  respectively.
482cdf0e10cSrcweir  <p>Note: Calling <code>moveToPosition(1)</code> is the same
483cdf0e10cSrcweir  as calling <code>moveToFirst()</code>. Calling
484cdf0e10cSrcweir  <code>moveToPosition(-1)</code> is the same as calling
485cdf0e10cSrcweir  <code>moveToLast()</code>.
486cdf0e10cSrcweir  @param row
487cdf0e10cSrcweir     is the number of rows to move. Could be negative.
488cdf0e10cSrcweir  @returns
489cdf0e10cSrcweir     <TRUE/> if the cursor is on a row; <FALSE/> otherwise
490cdf0e10cSrcweir  @throws SQLException
491cdf0e10cSrcweir     if a database access error occurs or if row is 0, or the result set
492cdf0e10cSrcweir     type is FORWARD_ONLY.
493cdf0e10cSrcweir  */
absolute(sal_Int32 row)494cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::absolute( sal_Int32 row )
495cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
496cdf0e10cSrcweir {
497cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
498cdf0e10cSrcweir 
499cdf0e10cSrcweir     sal_Int32 nIndex;
500cdf0e10cSrcweir 
501cdf0e10cSrcweir     if ( row > 0 )
502cdf0e10cSrcweir     {
503cdf0e10cSrcweir         if ( row <= mnCount )
504cdf0e10cSrcweir         {
505cdf0e10cSrcweir             mnCurEntry = row;
506cdf0e10cSrcweir             nIndex = maS2O[ mnCurEntry ];
507cdf0e10cSrcweir             return mxOriginal->absolute( nIndex );
508cdf0e10cSrcweir         }
509cdf0e10cSrcweir         else
510cdf0e10cSrcweir         {
511cdf0e10cSrcweir             mnCurEntry = mnCount + 1;
512cdf0e10cSrcweir             return sal_False;
513cdf0e10cSrcweir         }
514cdf0e10cSrcweir     }
515cdf0e10cSrcweir     else if ( row == 0 )
516cdf0e10cSrcweir     {
517cdf0e10cSrcweir         throw SQLException();
518cdf0e10cSrcweir     }
519cdf0e10cSrcweir     else
520cdf0e10cSrcweir     {
521cdf0e10cSrcweir         if ( mnCount + row + 1 > 0 )
522cdf0e10cSrcweir         {
523cdf0e10cSrcweir             mnCurEntry = mnCount + row + 1;
524cdf0e10cSrcweir             nIndex = maS2O[ mnCurEntry ];
525cdf0e10cSrcweir             return mxOriginal->absolute( nIndex );
526cdf0e10cSrcweir         }
527cdf0e10cSrcweir         else
528cdf0e10cSrcweir         {
529cdf0e10cSrcweir             mnCurEntry = 0;
530cdf0e10cSrcweir             return sal_False;
531cdf0e10cSrcweir         }
532cdf0e10cSrcweir     }
533cdf0e10cSrcweir }
534cdf0e10cSrcweir 
535cdf0e10cSrcweir //-------------------------------------------------------------------------
536cdf0e10cSrcweir /**
537cdf0e10cSrcweir  moves the cursor a relative number of rows, either positive or negative.
538cdf0e10cSrcweir  <p>
539cdf0e10cSrcweir  Attempting to move beyond the first/last row in the result set positions
540cdf0e10cSrcweir  the cursor before/after the first/last row. Calling
541cdf0e10cSrcweir  <code>moveRelative(0)</code> is valid, but does not change the cursor
542cdf0e10cSrcweir  position.
543cdf0e10cSrcweir  <p>Note: Calling <code>moveRelative(1)</code> is different from calling
544cdf0e10cSrcweir  <code>moveNext()</code> because is makes sense to call
545cdf0e10cSrcweir  <code>moveNext()</code> when there is no current row, for example,
546cdf0e10cSrcweir  when the cursor is positioned before the first row or after the last
547cdf0e10cSrcweir  row of the result set.
548cdf0e10cSrcweir  @param rows
549cdf0e10cSrcweir     is the number of rows to move. Could be negative.
550cdf0e10cSrcweir  @returns
551cdf0e10cSrcweir     <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off
552cdf0e10cSrcweir     the result set.
553cdf0e10cSrcweir  @throws SQLException
554cdf0e10cSrcweir     if a database access error occurs or if there is no
555cdf0e10cSrcweir     current row, or the result set type is FORWARD_ONLY.
556cdf0e10cSrcweir  */
relative(sal_Int32 rows)557cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::relative( sal_Int32 rows )
558cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
559cdf0e10cSrcweir {
560cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
561cdf0e10cSrcweir 
562cdf0e10cSrcweir     if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
563cdf0e10cSrcweir     {
564cdf0e10cSrcweir         throw SQLException();
565cdf0e10cSrcweir     }
566cdf0e10cSrcweir 
567cdf0e10cSrcweir     if ( rows == 0 )
568cdf0e10cSrcweir         return sal_True;
569cdf0e10cSrcweir 
570cdf0e10cSrcweir     sal_Int32 nTmp = mnCurEntry + rows;
571cdf0e10cSrcweir 
572cdf0e10cSrcweir     if ( nTmp <= 0 )
573cdf0e10cSrcweir     {
574cdf0e10cSrcweir         mnCurEntry = 0;
575cdf0e10cSrcweir         return sal_False;
576cdf0e10cSrcweir     }
577cdf0e10cSrcweir     else if ( nTmp > mnCount )
578cdf0e10cSrcweir     {
579cdf0e10cSrcweir         mnCurEntry = mnCount + 1;
580cdf0e10cSrcweir         return sal_False;
581cdf0e10cSrcweir     }
582cdf0e10cSrcweir     else
583cdf0e10cSrcweir     {
584cdf0e10cSrcweir         mnCurEntry = nTmp;
585cdf0e10cSrcweir         nTmp = maS2O[ mnCurEntry ];
586cdf0e10cSrcweir         return mxOriginal->absolute( nTmp );
587cdf0e10cSrcweir     }
588cdf0e10cSrcweir }
589cdf0e10cSrcweir 
590cdf0e10cSrcweir //-------------------------------------------------------------------------
591cdf0e10cSrcweir /**
592cdf0e10cSrcweir  moves the cursor to the previous row in the result set.
593cdf0e10cSrcweir  <p>Note: <code>previous()</code> is not the same as
594cdf0e10cSrcweir  <code>relative(-1)</code> because it makes sense to call
595cdf0e10cSrcweir  <code>previous()</code> when there is no current row.
596cdf0e10cSrcweir  @returns <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off
597cdf0e10cSrcweir     the result set.
598cdf0e10cSrcweir  @throws SQLException
599cdf0e10cSrcweir     if a database access error occurs or the result set type
600cdf0e10cSrcweir     is FORWARD_ONLY.
601cdf0e10cSrcweir  */
previous()602cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::previous()
603cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
604cdf0e10cSrcweir {
605cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
606cdf0e10cSrcweir 
607cdf0e10cSrcweir     mnCurEntry -= 1;
608cdf0e10cSrcweir 
609cdf0e10cSrcweir     if ( mnCurEntry > 0 )
610cdf0e10cSrcweir     {
611cdf0e10cSrcweir         if ( mnCurEntry <= mnCount )
612cdf0e10cSrcweir         {
613cdf0e10cSrcweir             sal_Int32 nIndex = maS2O[ mnCurEntry ];
614cdf0e10cSrcweir             return mxOriginal->absolute( nIndex );
615cdf0e10cSrcweir         }
616cdf0e10cSrcweir     }
617cdf0e10cSrcweir     else
618cdf0e10cSrcweir         mnCurEntry = 0;
619cdf0e10cSrcweir 
620cdf0e10cSrcweir     return sal_False;
621cdf0e10cSrcweir }
622cdf0e10cSrcweir 
623cdf0e10cSrcweir //-------------------------------------------------------------------------
refreshRow()624cdf0e10cSrcweir void SAL_CALL SortedResultSet::refreshRow()
625cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
626cdf0e10cSrcweir {
627cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
628cdf0e10cSrcweir 
629cdf0e10cSrcweir     if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
630cdf0e10cSrcweir     {
631cdf0e10cSrcweir         throw SQLException();
632cdf0e10cSrcweir     }
633cdf0e10cSrcweir 
634cdf0e10cSrcweir     mxOriginal->refreshRow();
635cdf0e10cSrcweir }
636cdf0e10cSrcweir 
637cdf0e10cSrcweir //-------------------------------------------------------------------------
rowUpdated()638cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::rowUpdated()
639cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
640cdf0e10cSrcweir {
641cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
642cdf0e10cSrcweir 
643cdf0e10cSrcweir     if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
644cdf0e10cSrcweir     {
645cdf0e10cSrcweir         throw SQLException();
646cdf0e10cSrcweir     }
647cdf0e10cSrcweir 
648cdf0e10cSrcweir     return mxOriginal->rowUpdated();
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir //-------------------------------------------------------------------------
rowInserted()652cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::rowInserted()
653cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
654cdf0e10cSrcweir {
655cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
656cdf0e10cSrcweir 
657cdf0e10cSrcweir     if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
658cdf0e10cSrcweir     {
659cdf0e10cSrcweir         throw SQLException();
660cdf0e10cSrcweir     }
661cdf0e10cSrcweir 
662cdf0e10cSrcweir     return mxOriginal->rowInserted();
663cdf0e10cSrcweir }
664cdf0e10cSrcweir 
665cdf0e10cSrcweir //-------------------------------------------------------------------------
rowDeleted()666cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::rowDeleted()
667cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
668cdf0e10cSrcweir {
669cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
672cdf0e10cSrcweir     {
673cdf0e10cSrcweir         throw SQLException();
674cdf0e10cSrcweir     }
675cdf0e10cSrcweir 
676cdf0e10cSrcweir     return mxOriginal->rowDeleted();
677cdf0e10cSrcweir }
678cdf0e10cSrcweir 
679cdf0e10cSrcweir //-------------------------------------------------------------------------
getStatement()680cdf0e10cSrcweir Reference< XInterface > SAL_CALL SortedResultSet::getStatement()
681cdf0e10cSrcweir     throw ( SQLException, RuntimeException )
682cdf0e10cSrcweir {
683cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
684cdf0e10cSrcweir 
685cdf0e10cSrcweir     if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
686cdf0e10cSrcweir     {
687cdf0e10cSrcweir         throw SQLException();
688cdf0e10cSrcweir     }
689cdf0e10cSrcweir 
690cdf0e10cSrcweir     return mxOriginal->getStatement();
691cdf0e10cSrcweir }
692cdf0e10cSrcweir 
693cdf0e10cSrcweir //--------------------------------------------------------------------------
694cdf0e10cSrcweir // XRow methods.
695cdf0e10cSrcweir //--------------------------------------------------------------------------
696cdf0e10cSrcweir 
wasNull()697cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::wasNull()
698cdf0e10cSrcweir     throw( SQLException, RuntimeException )
699cdf0e10cSrcweir {
700cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
701cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->wasNull();
702cdf0e10cSrcweir }
703cdf0e10cSrcweir 
704cdf0e10cSrcweir //-------------------------------------------------------------------------
getString(sal_Int32 columnIndex)705cdf0e10cSrcweir OUString SAL_CALL SortedResultSet::getString( sal_Int32 columnIndex )
706cdf0e10cSrcweir     throw( SQLException, RuntimeException )
707cdf0e10cSrcweir {
708cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
709cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getString( columnIndex );
710cdf0e10cSrcweir }
711cdf0e10cSrcweir 
712cdf0e10cSrcweir //-------------------------------------------------------------------------
getBoolean(sal_Int32 columnIndex)713cdf0e10cSrcweir sal_Bool SAL_CALL SortedResultSet::getBoolean( sal_Int32 columnIndex )
714cdf0e10cSrcweir     throw( SQLException, RuntimeException )
715cdf0e10cSrcweir {
716cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
717cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getBoolean( columnIndex );
718cdf0e10cSrcweir }
719cdf0e10cSrcweir 
720cdf0e10cSrcweir //-------------------------------------------------------------------------
getByte(sal_Int32 columnIndex)721cdf0e10cSrcweir sal_Int8 SAL_CALL SortedResultSet::getByte( sal_Int32 columnIndex )
722cdf0e10cSrcweir     throw( SQLException, RuntimeException )
723cdf0e10cSrcweir {
724cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
725cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getByte( columnIndex );
726cdf0e10cSrcweir }
727cdf0e10cSrcweir 
728cdf0e10cSrcweir //-------------------------------------------------------------------------
getShort(sal_Int32 columnIndex)729cdf0e10cSrcweir sal_Int16 SAL_CALL SortedResultSet::getShort( sal_Int32 columnIndex )
730cdf0e10cSrcweir     throw( SQLException, RuntimeException )
731cdf0e10cSrcweir {
732cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
733cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getShort( columnIndex );
734cdf0e10cSrcweir }
735cdf0e10cSrcweir 
736cdf0e10cSrcweir //-------------------------------------------------------------------------
getInt(sal_Int32 columnIndex)737cdf0e10cSrcweir sal_Int32 SAL_CALL SortedResultSet::getInt( sal_Int32 columnIndex )
738cdf0e10cSrcweir     throw( SQLException, RuntimeException )
739cdf0e10cSrcweir {
740cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
741cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getInt( columnIndex );
742cdf0e10cSrcweir }
743cdf0e10cSrcweir //-------------------------------------------------------------------------
getLong(sal_Int32 columnIndex)744cdf0e10cSrcweir sal_Int64 SAL_CALL SortedResultSet::getLong( sal_Int32 columnIndex )
745cdf0e10cSrcweir     throw( SQLException, RuntimeException )
746cdf0e10cSrcweir {
747cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
748cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getLong( columnIndex );
749cdf0e10cSrcweir }
750cdf0e10cSrcweir 
751cdf0e10cSrcweir //-------------------------------------------------------------------------
getFloat(sal_Int32 columnIndex)752cdf0e10cSrcweir float SAL_CALL SortedResultSet::getFloat( sal_Int32 columnIndex )
753cdf0e10cSrcweir     throw( SQLException, RuntimeException )
754cdf0e10cSrcweir {
755cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
756cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getFloat( columnIndex );
757cdf0e10cSrcweir }
758cdf0e10cSrcweir 
759cdf0e10cSrcweir //-------------------------------------------------------------------------
getDouble(sal_Int32 columnIndex)760cdf0e10cSrcweir double SAL_CALL SortedResultSet::getDouble( sal_Int32 columnIndex )
761cdf0e10cSrcweir     throw( SQLException, RuntimeException )
762cdf0e10cSrcweir {
763cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
764cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getDouble( columnIndex );
765cdf0e10cSrcweir }
766cdf0e10cSrcweir 
767cdf0e10cSrcweir //-------------------------------------------------------------------------
getBytes(sal_Int32 columnIndex)768cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL SortedResultSet::getBytes( sal_Int32 columnIndex )
769cdf0e10cSrcweir     throw( SQLException, RuntimeException )
770cdf0e10cSrcweir {
771cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
772cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getBytes( columnIndex );
773cdf0e10cSrcweir }
774cdf0e10cSrcweir 
775cdf0e10cSrcweir //-------------------------------------------------------------------------
getDate(sal_Int32 columnIndex)776cdf0e10cSrcweir Date SAL_CALL SortedResultSet::getDate( sal_Int32 columnIndex )
777cdf0e10cSrcweir     throw( SQLException, RuntimeException )
778cdf0e10cSrcweir {
779cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
780cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getDate( columnIndex );
781cdf0e10cSrcweir }
782cdf0e10cSrcweir 
783cdf0e10cSrcweir //-------------------------------------------------------------------------
getTime(sal_Int32 columnIndex)784cdf0e10cSrcweir Time SAL_CALL SortedResultSet::getTime( sal_Int32 columnIndex )
785cdf0e10cSrcweir     throw( SQLException, RuntimeException )
786cdf0e10cSrcweir {
787cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
788cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getTime( columnIndex );
789cdf0e10cSrcweir }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir //-------------------------------------------------------------------------
getTimestamp(sal_Int32 columnIndex)792cdf0e10cSrcweir DateTime SAL_CALL SortedResultSet::getTimestamp( sal_Int32 columnIndex )
793cdf0e10cSrcweir     throw( SQLException, RuntimeException )
794cdf0e10cSrcweir {
795cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
796cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getTimestamp( columnIndex );
797cdf0e10cSrcweir }
798cdf0e10cSrcweir 
799cdf0e10cSrcweir //-------------------------------------------------------------------------
800cdf0e10cSrcweir Reference< XInputStream > SAL_CALL
getBinaryStream(sal_Int32 columnIndex)801cdf0e10cSrcweir SortedResultSet::getBinaryStream( sal_Int32 columnIndex )
802cdf0e10cSrcweir     throw( SQLException, RuntimeException )
803cdf0e10cSrcweir {
804cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
805cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getBinaryStream( columnIndex );
806cdf0e10cSrcweir }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir //-------------------------------------------------------------------------
809cdf0e10cSrcweir Reference< XInputStream > SAL_CALL
getCharacterStream(sal_Int32 columnIndex)810cdf0e10cSrcweir SortedResultSet::getCharacterStream( sal_Int32 columnIndex )
811cdf0e10cSrcweir     throw( SQLException, RuntimeException )
812cdf0e10cSrcweir {
813cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
814cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getCharacterStream( columnIndex );
815cdf0e10cSrcweir }
816cdf0e10cSrcweir 
817cdf0e10cSrcweir //-------------------------------------------------------------------------
getObject(sal_Int32 columnIndex,const Reference<XNameAccess> & typeMap)818cdf0e10cSrcweir Any SAL_CALL SortedResultSet::getObject( sal_Int32 columnIndex,
819cdf0e10cSrcweir                        const Reference< XNameAccess >& typeMap )
820cdf0e10cSrcweir     throw( SQLException, RuntimeException )
821cdf0e10cSrcweir {
822cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
823cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getObject( columnIndex,
824cdf0e10cSrcweir                                                             typeMap);
825cdf0e10cSrcweir }
826cdf0e10cSrcweir 
827cdf0e10cSrcweir //-------------------------------------------------------------------------
getRef(sal_Int32 columnIndex)828cdf0e10cSrcweir Reference< XRef > SAL_CALL SortedResultSet::getRef( sal_Int32 columnIndex )
829cdf0e10cSrcweir     throw( SQLException, RuntimeException )
830cdf0e10cSrcweir {
831cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
832cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getRef( columnIndex );
833cdf0e10cSrcweir }
834cdf0e10cSrcweir 
835cdf0e10cSrcweir //-------------------------------------------------------------------------
getBlob(sal_Int32 columnIndex)836cdf0e10cSrcweir Reference< XBlob > SAL_CALL SortedResultSet::getBlob( sal_Int32 columnIndex )
837cdf0e10cSrcweir     throw( SQLException, RuntimeException )
838cdf0e10cSrcweir {
839cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
840cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getBlob( columnIndex );
841cdf0e10cSrcweir }
842cdf0e10cSrcweir 
843cdf0e10cSrcweir //-------------------------------------------------------------------------
getClob(sal_Int32 columnIndex)844cdf0e10cSrcweir Reference< XClob > SAL_CALL SortedResultSet::getClob( sal_Int32 columnIndex )
845cdf0e10cSrcweir     throw( SQLException, RuntimeException )
846cdf0e10cSrcweir {
847cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
848cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getClob( columnIndex );
849cdf0e10cSrcweir }
850cdf0e10cSrcweir 
851cdf0e10cSrcweir //-------------------------------------------------------------------------
getArray(sal_Int32 columnIndex)852cdf0e10cSrcweir Reference< XArray > SAL_CALL SortedResultSet::getArray( sal_Int32 columnIndex )
853cdf0e10cSrcweir     throw( SQLException, RuntimeException )
854cdf0e10cSrcweir {
855cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
856cdf0e10cSrcweir     return Reference< XRow >::query(mxOriginal)->getArray( columnIndex );
857cdf0e10cSrcweir }
858cdf0e10cSrcweir 
859cdf0e10cSrcweir 
860cdf0e10cSrcweir //--------------------------------------------------------------------------
861cdf0e10cSrcweir // XCloseable methods.
862cdf0e10cSrcweir //--------------------------------------------------------------------------
863cdf0e10cSrcweir 
close()864cdf0e10cSrcweir void SAL_CALL SortedResultSet::close()
865cdf0e10cSrcweir     throw( SQLException, RuntimeException )
866cdf0e10cSrcweir {
867cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
868cdf0e10cSrcweir     Reference< XCloseable >::query(mxOriginal)->close();
869cdf0e10cSrcweir }
870cdf0e10cSrcweir 
871cdf0e10cSrcweir //--------------------------------------------------------------------------
872cdf0e10cSrcweir // XResultSetMetaDataSupplier methods.
873cdf0e10cSrcweir //--------------------------------------------------------------------------
874cdf0e10cSrcweir 
getMetaData()875cdf0e10cSrcweir Reference< XResultSetMetaData > SAL_CALL SortedResultSet::getMetaData()
876cdf0e10cSrcweir     throw( SQLException, RuntimeException )
877cdf0e10cSrcweir {
878cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
879cdf0e10cSrcweir     return Reference< XResultSetMetaDataSupplier >::query(mxOriginal)->getMetaData();
880cdf0e10cSrcweir }
881cdf0e10cSrcweir 
882cdf0e10cSrcweir 
883cdf0e10cSrcweir //--------------------------------------------------------------------------
884cdf0e10cSrcweir // XPropertySet methods.
885cdf0e10cSrcweir //--------------------------------------------------------------------------
886cdf0e10cSrcweir 
887cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL
getPropertySetInfo()888cdf0e10cSrcweir SortedResultSet::getPropertySetInfo() throw( RuntimeException )
889cdf0e10cSrcweir {
890cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
891cdf0e10cSrcweir 
892cdf0e10cSrcweir     if ( !mpPropSetInfo )
893cdf0e10cSrcweir     {
894cdf0e10cSrcweir         mpPropSetInfo = new SRSPropertySetInfo();
895cdf0e10cSrcweir         mpPropSetInfo->acquire();
896cdf0e10cSrcweir     }
897cdf0e10cSrcweir 
898cdf0e10cSrcweir     return Reference< XPropertySetInfo >( mpPropSetInfo );
899cdf0e10cSrcweir }
900cdf0e10cSrcweir 
901cdf0e10cSrcweir //--------------------------------------------------------------------------
setPropertyValue(const OUString & PropertyName,const Any &)902cdf0e10cSrcweir void SAL_CALL SortedResultSet::setPropertyValue(
903cdf0e10cSrcweir                         const OUString& PropertyName,
904cdf0e10cSrcweir                         const Any& )
905cdf0e10cSrcweir     throw( UnknownPropertyException,
906cdf0e10cSrcweir            PropertyVetoException,
907cdf0e10cSrcweir            IllegalArgumentException,
908cdf0e10cSrcweir            WrappedTargetException,
909cdf0e10cSrcweir            RuntimeException )
910cdf0e10cSrcweir {
911cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
912cdf0e10cSrcweir 
913cdf0e10cSrcweir     if ( ( PropertyName.compareToAscii( "RowCount" ) == 0 ) ||
914cdf0e10cSrcweir          ( PropertyName.compareToAscii( "IsRowCountFinal" ) == 0 ) )
915cdf0e10cSrcweir         throw IllegalArgumentException();
916cdf0e10cSrcweir     else
917cdf0e10cSrcweir         throw UnknownPropertyException();
918cdf0e10cSrcweir }
919cdf0e10cSrcweir 
920cdf0e10cSrcweir //--------------------------------------------------------------------------
getPropertyValue(const OUString & PropertyName)921cdf0e10cSrcweir Any SAL_CALL SortedResultSet::getPropertyValue( const OUString& PropertyName )
922cdf0e10cSrcweir     throw( UnknownPropertyException,
923cdf0e10cSrcweir            WrappedTargetException,
924cdf0e10cSrcweir            RuntimeException )
925cdf0e10cSrcweir {
926cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
927cdf0e10cSrcweir 
928cdf0e10cSrcweir     Any aRet;
929cdf0e10cSrcweir 
930cdf0e10cSrcweir     if ( PropertyName.compareToAscii( "RowCount" ) == 0 )
931cdf0e10cSrcweir     {
932cdf0e10cSrcweir         aRet <<= maS2O.Count();
933cdf0e10cSrcweir     }
934cdf0e10cSrcweir     else if ( PropertyName.compareToAscii( "IsRowCountFinal" ) == 0 )
935cdf0e10cSrcweir     {
936cdf0e10cSrcweir         sal_uInt32  nOrgCount = 0;
937cdf0e10cSrcweir         sal_Bool    bOrgFinal = false;
938cdf0e10cSrcweir         Any         aOrgRet;
939cdf0e10cSrcweir 
940cdf0e10cSrcweir         aRet <<= (sal_Bool) sal_False;
941cdf0e10cSrcweir 
942cdf0e10cSrcweir         aOrgRet = Reference< XPropertySet >::query(mxOriginal)->
943cdf0e10cSrcweir                         getPropertyValue( PropertyName );
944cdf0e10cSrcweir         aOrgRet >>= bOrgFinal;
945cdf0e10cSrcweir 
946cdf0e10cSrcweir         if ( bOrgFinal )
947cdf0e10cSrcweir         {
948cdf0e10cSrcweir             aOrgRet = Reference< XPropertySet >::query(mxOriginal)->
949cdf0e10cSrcweir                 getPropertyValue( OUString::createFromAscii( "RowCount" ) );
950cdf0e10cSrcweir             aOrgRet >>= nOrgCount;
951cdf0e10cSrcweir             if ( nOrgCount == maS2O.Count() )
952cdf0e10cSrcweir                 aRet <<= (sal_Bool) sal_True;
953cdf0e10cSrcweir         }
954cdf0e10cSrcweir     }
955cdf0e10cSrcweir     else
956cdf0e10cSrcweir         throw UnknownPropertyException();
957cdf0e10cSrcweir 
958cdf0e10cSrcweir     return aRet;
959cdf0e10cSrcweir }
960cdf0e10cSrcweir 
961cdf0e10cSrcweir //--------------------------------------------------------------------------
addPropertyChangeListener(const OUString & PropertyName,const Reference<XPropertyChangeListener> & Listener)962cdf0e10cSrcweir void SAL_CALL SortedResultSet::addPropertyChangeListener(
963cdf0e10cSrcweir                         const OUString& PropertyName,
964cdf0e10cSrcweir                         const Reference< XPropertyChangeListener >& Listener )
965cdf0e10cSrcweir     throw( UnknownPropertyException,
966cdf0e10cSrcweir            WrappedTargetException,
967cdf0e10cSrcweir            RuntimeException )
968cdf0e10cSrcweir {
969cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
970cdf0e10cSrcweir 
971cdf0e10cSrcweir     if ( !mpPropChangeListeners )
972cdf0e10cSrcweir         mpPropChangeListeners =
973cdf0e10cSrcweir                     new PropertyChangeListeners_Impl();
974cdf0e10cSrcweir 
975cdf0e10cSrcweir     mpPropChangeListeners->addInterface( PropertyName, Listener );
976cdf0e10cSrcweir }
977cdf0e10cSrcweir 
978cdf0e10cSrcweir //--------------------------------------------------------------------------
removePropertyChangeListener(const OUString & PropertyName,const Reference<XPropertyChangeListener> & Listener)979cdf0e10cSrcweir void SAL_CALL SortedResultSet::removePropertyChangeListener(
980cdf0e10cSrcweir                         const OUString& PropertyName,
981cdf0e10cSrcweir                         const Reference< XPropertyChangeListener >& Listener )
982cdf0e10cSrcweir     throw( UnknownPropertyException,
983cdf0e10cSrcweir            WrappedTargetException,
984cdf0e10cSrcweir            RuntimeException )
985cdf0e10cSrcweir {
986cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
987cdf0e10cSrcweir 
988cdf0e10cSrcweir     if ( mpPropChangeListeners )
989cdf0e10cSrcweir         mpPropChangeListeners->removeInterface( PropertyName, Listener );
990cdf0e10cSrcweir }
991cdf0e10cSrcweir 
992cdf0e10cSrcweir //--------------------------------------------------------------------------
addVetoableChangeListener(const OUString & PropertyName,const Reference<XVetoableChangeListener> & Listener)993cdf0e10cSrcweir void SAL_CALL SortedResultSet::addVetoableChangeListener(
994cdf0e10cSrcweir                         const OUString& PropertyName,
995cdf0e10cSrcweir                         const Reference< XVetoableChangeListener >& Listener )
996cdf0e10cSrcweir     throw( UnknownPropertyException,
997cdf0e10cSrcweir            WrappedTargetException,
998cdf0e10cSrcweir            RuntimeException )
999cdf0e10cSrcweir {
1000cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir     if ( !mpVetoChangeListeners )
1003cdf0e10cSrcweir         mpVetoChangeListeners =
1004cdf0e10cSrcweir                     new PropertyChangeListeners_Impl();
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir     mpVetoChangeListeners->addInterface( PropertyName, Listener );
1007cdf0e10cSrcweir }
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir //--------------------------------------------------------------------------
removeVetoableChangeListener(const OUString & PropertyName,const Reference<XVetoableChangeListener> & Listener)1010cdf0e10cSrcweir void SAL_CALL SortedResultSet::removeVetoableChangeListener(
1011cdf0e10cSrcweir                         const OUString& PropertyName,
1012cdf0e10cSrcweir                         const Reference< XVetoableChangeListener >& Listener )
1013cdf0e10cSrcweir     throw( UnknownPropertyException,
1014cdf0e10cSrcweir            WrappedTargetException,
1015cdf0e10cSrcweir            RuntimeException )
1016cdf0e10cSrcweir {
1017cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir     if ( mpVetoChangeListeners )
1020cdf0e10cSrcweir         mpVetoChangeListeners->removeInterface( PropertyName, Listener );
1021cdf0e10cSrcweir }
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir //--------------------------------------------------------------------------
1024cdf0e10cSrcweir // private methods
1025cdf0e10cSrcweir //--------------------------------------------------------------------------
CompareImpl(Reference<XResultSet> xResultOne,Reference<XResultSet> xResultTwo,long nIndexOne,long nIndexTwo,SortInfo * pSortInfo)1026cdf0e10cSrcweir long SortedResultSet::CompareImpl( Reference < XResultSet > xResultOne,
1027cdf0e10cSrcweir                                    Reference < XResultSet > xResultTwo,
1028cdf0e10cSrcweir                                    long nIndexOne, long nIndexTwo,
1029cdf0e10cSrcweir                                    SortInfo* pSortInfo )
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir     throw( SQLException, RuntimeException )
1032cdf0e10cSrcweir {
1033cdf0e10cSrcweir     Reference < XRow > xRowOne = Reference< XRow >::query( xResultOne );
1034cdf0e10cSrcweir     Reference < XRow > xRowTwo = Reference< XRow >::query( xResultTwo );
1035cdf0e10cSrcweir 
1036cdf0e10cSrcweir     long nCompare = 0;
1037cdf0e10cSrcweir     long nColumn = pSortInfo->mnColumn;
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir     switch ( pSortInfo->mnType )
1040cdf0e10cSrcweir     {
1041cdf0e10cSrcweir         case DataType::BIT :
1042cdf0e10cSrcweir         case DataType::TINYINT :
1043cdf0e10cSrcweir         case DataType::SMALLINT :
1044cdf0e10cSrcweir         case DataType::INTEGER :
1045cdf0e10cSrcweir             {
1046cdf0e10cSrcweir                 sal_Int32 aOne = 0;
1047cdf0e10cSrcweir 				sal_Int32 aTwo = 0;
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir                 if ( xResultOne->absolute( nIndexOne ) )
1050cdf0e10cSrcweir                     aOne = xRowOne->getInt( nColumn );
1051cdf0e10cSrcweir                 if ( xResultTwo->absolute( nIndexTwo ) )
1052cdf0e10cSrcweir                     aTwo = xRowTwo->getInt( nColumn );
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir                 if ( aOne < aTwo )
1055cdf0e10cSrcweir                     nCompare = -1;
1056cdf0e10cSrcweir                 else if ( aOne == aTwo )
1057cdf0e10cSrcweir                     nCompare = 0;
1058cdf0e10cSrcweir                 else
1059cdf0e10cSrcweir                     nCompare = 1;
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir                 break;
1062cdf0e10cSrcweir             }
1063cdf0e10cSrcweir         case DataType::BIGINT :
1064cdf0e10cSrcweir             {
1065cdf0e10cSrcweir                 sal_Int64 aOne = 0;
1066cdf0e10cSrcweir 				sal_Int64 aTwo = 0;
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir                 if ( xResultOne->absolute( nIndexOne ) )
1069cdf0e10cSrcweir                     aOne = xRowOne->getLong( nColumn );
1070cdf0e10cSrcweir                 if ( xResultTwo->absolute( nIndexTwo ) )
1071cdf0e10cSrcweir                     aTwo = xRowTwo->getLong( nColumn );
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir                 if ( aOne < aTwo )
1074cdf0e10cSrcweir                     nCompare = -1;
1075cdf0e10cSrcweir                 else if ( aOne == aTwo )
1076cdf0e10cSrcweir                     nCompare = 0;
1077cdf0e10cSrcweir                 else
1078cdf0e10cSrcweir                     nCompare = 1;
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir                 break;
1081cdf0e10cSrcweir             }
1082cdf0e10cSrcweir         case DataType::CHAR :
1083cdf0e10cSrcweir         case DataType::VARCHAR :
1084cdf0e10cSrcweir         case DataType::LONGVARCHAR :
1085cdf0e10cSrcweir             {
1086cdf0e10cSrcweir                 OUString aOne, aTwo;
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir                 if ( xResultOne->absolute( nIndexOne ) )
1089cdf0e10cSrcweir                     aOne = xRowOne->getString( nColumn );
1090cdf0e10cSrcweir                 if ( xResultTwo->absolute( nIndexTwo ) )
1091cdf0e10cSrcweir                     aTwo = xRowTwo->getString( nColumn );
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir                 if ( ! pSortInfo->mbCaseSensitive )
1094cdf0e10cSrcweir                 {
1095cdf0e10cSrcweir                     aOne = aOne.toAsciiLowerCase();
1096cdf0e10cSrcweir                     aTwo = aTwo.toAsciiLowerCase();
1097cdf0e10cSrcweir                 }
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir                 nCompare = aOne.compareTo( aTwo );
1100cdf0e10cSrcweir                 break;
1101cdf0e10cSrcweir             }
1102cdf0e10cSrcweir         case DataType::DATE :
1103cdf0e10cSrcweir             {
1104cdf0e10cSrcweir                 Date aOne, aTwo;
1105cdf0e10cSrcweir                 sal_Int32   nTmp;
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir                 if ( xResultOne->absolute( nIndexOne ) )
1108cdf0e10cSrcweir                     aOne = xRowOne->getDate( nColumn );
1109cdf0e10cSrcweir                 if ( xResultTwo->absolute( nIndexTwo ) )
1110cdf0e10cSrcweir                     aTwo = xRowTwo->getDate( nColumn );
1111cdf0e10cSrcweir 
1112cdf0e10cSrcweir                 nTmp = (sal_Int32) aTwo.Year - (sal_Int32) aOne.Year;
1113cdf0e10cSrcweir                 if ( !nTmp ) {
1114cdf0e10cSrcweir                     nTmp = (sal_Int32) aTwo.Month - (sal_Int32) aOne.Month;
1115cdf0e10cSrcweir                 if ( !nTmp )
1116cdf0e10cSrcweir                     nTmp = (sal_Int32) aTwo.Day - (sal_Int32) aOne.Day;
1117cdf0e10cSrcweir                 }
1118cdf0e10cSrcweir 
1119cdf0e10cSrcweir                 if ( nTmp < 0 )
1120cdf0e10cSrcweir                     nCompare = -1;
1121cdf0e10cSrcweir                 else if ( nTmp == 0 )
1122cdf0e10cSrcweir                     nCompare = 0;
1123cdf0e10cSrcweir                 else
1124cdf0e10cSrcweir                     nCompare = 1;
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir                 break;
1127cdf0e10cSrcweir             }
1128cdf0e10cSrcweir         case DataType::TIME :
1129cdf0e10cSrcweir             {
1130cdf0e10cSrcweir                 Time aOne, aTwo;
1131cdf0e10cSrcweir                 sal_Int32   nTmp;
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir                 if ( xResultOne->absolute( nIndexOne ) )
1134cdf0e10cSrcweir                     aOne = xRowOne->getTime( nColumn );
1135cdf0e10cSrcweir                 if ( xResultTwo->absolute( nIndexTwo ) )
1136cdf0e10cSrcweir                     aTwo = xRowTwo->getTime( nColumn );
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir                 nTmp = (sal_Int32) aTwo.Hours - (sal_Int32) aOne.Hours;
1139cdf0e10cSrcweir                 if ( !nTmp ) {
1140cdf0e10cSrcweir                     nTmp = (sal_Int32) aTwo.Minutes - (sal_Int32) aOne.Minutes;
1141cdf0e10cSrcweir                 if ( !nTmp ) {
1142cdf0e10cSrcweir                     nTmp = (sal_Int32) aTwo.Seconds - (sal_Int32) aOne.Seconds;
1143cdf0e10cSrcweir                 if ( !nTmp )
1144cdf0e10cSrcweir                     nTmp = (sal_Int32) aTwo.HundredthSeconds
1145cdf0e10cSrcweir                                     - (sal_Int32) aOne.HundredthSeconds;
1146cdf0e10cSrcweir                 }}
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir                 if ( nTmp < 0 )
1149cdf0e10cSrcweir                     nCompare = -1;
1150cdf0e10cSrcweir                 else if ( nTmp == 0 )
1151cdf0e10cSrcweir                     nCompare = 0;
1152cdf0e10cSrcweir                 else
1153cdf0e10cSrcweir                     nCompare = 1;
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir                 break;
1156cdf0e10cSrcweir             }
1157cdf0e10cSrcweir         case DataType::TIMESTAMP :
1158cdf0e10cSrcweir             {
1159cdf0e10cSrcweir                 DateTime aOne, aTwo;
1160cdf0e10cSrcweir                 sal_Int32   nTmp;
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir                 if ( xResultOne->absolute( nIndexOne ) )
1163cdf0e10cSrcweir                     aOne = xRowOne->getTimestamp( nColumn );
1164cdf0e10cSrcweir                 if ( xResultTwo->absolute( nIndexTwo ) )
1165cdf0e10cSrcweir                     aTwo = xRowTwo->getTimestamp( nColumn );
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir                 nTmp = (sal_Int32) aTwo.Year - (sal_Int32) aOne.Year;
1168cdf0e10cSrcweir                 if ( !nTmp ) {
1169cdf0e10cSrcweir                     nTmp = (sal_Int32) aTwo.Month - (sal_Int32) aOne.Month;
1170cdf0e10cSrcweir                 if ( !nTmp ) {
1171cdf0e10cSrcweir                     nTmp = (sal_Int32) aTwo.Day - (sal_Int32) aOne.Day;
1172cdf0e10cSrcweir                 if ( !nTmp ) {
1173cdf0e10cSrcweir                     nTmp = (sal_Int32) aTwo.Hours - (sal_Int32) aOne.Hours;
1174cdf0e10cSrcweir                 if ( !nTmp ) {
1175cdf0e10cSrcweir                     nTmp = (sal_Int32) aTwo.Minutes - (sal_Int32) aOne.Minutes;
1176cdf0e10cSrcweir                 if ( !nTmp ) {
1177cdf0e10cSrcweir                     nTmp = (sal_Int32) aTwo.Seconds - (sal_Int32) aOne.Seconds;
1178cdf0e10cSrcweir                 if ( !nTmp )
1179cdf0e10cSrcweir                     nTmp = (sal_Int32) aTwo.HundredthSeconds
1180cdf0e10cSrcweir                                     - (sal_Int32) aOne.HundredthSeconds;
1181cdf0e10cSrcweir                 }}}}}
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir                 if ( nTmp < 0 )
1184cdf0e10cSrcweir                     nCompare = -1;
1185cdf0e10cSrcweir                 else if ( nTmp == 0 )
1186cdf0e10cSrcweir                     nCompare = 0;
1187cdf0e10cSrcweir                 else
1188cdf0e10cSrcweir                     nCompare = 1;
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir                 break;
1191cdf0e10cSrcweir             }
1192cdf0e10cSrcweir         case DataType::REAL :
1193cdf0e10cSrcweir             {
1194cdf0e10cSrcweir                 float aOne = 0;
1195cdf0e10cSrcweir 				float aTwo = 0;
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir                 if ( xResultOne->absolute( nIndexOne ) )
1198cdf0e10cSrcweir                     aOne = xRowOne->getFloat( nColumn );
1199cdf0e10cSrcweir                 if ( xResultTwo->absolute( nIndexTwo ) )
1200cdf0e10cSrcweir                     aTwo = xRowTwo->getFloat( nColumn );
1201cdf0e10cSrcweir 
1202cdf0e10cSrcweir                 if ( aOne < aTwo )
1203cdf0e10cSrcweir                     nCompare = -1;
1204cdf0e10cSrcweir                 else if ( aOne == aTwo )
1205cdf0e10cSrcweir                     nCompare = 0;
1206cdf0e10cSrcweir                 else
1207cdf0e10cSrcweir                     nCompare = 1;
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir                 break;
1210cdf0e10cSrcweir             }
1211cdf0e10cSrcweir         case DataType::FLOAT :
1212cdf0e10cSrcweir         case DataType::DOUBLE :
1213cdf0e10cSrcweir             {
1214cdf0e10cSrcweir                 double aOne = 0;
1215cdf0e10cSrcweir 				double aTwo = 0;
1216cdf0e10cSrcweir 
1217cdf0e10cSrcweir                 if ( xResultOne->absolute( nIndexOne ) )
1218cdf0e10cSrcweir                     aOne = xRowOne->getDouble( nColumn );
1219cdf0e10cSrcweir                 if ( xResultTwo->absolute( nIndexTwo ) )
1220cdf0e10cSrcweir                     aTwo = xRowTwo->getDouble( nColumn );
1221cdf0e10cSrcweir 
1222cdf0e10cSrcweir                 if ( aOne < aTwo )
1223cdf0e10cSrcweir                     nCompare = -1;
1224cdf0e10cSrcweir                 else if ( aOne == aTwo )
1225cdf0e10cSrcweir                     nCompare = 0;
1226cdf0e10cSrcweir                 else
1227cdf0e10cSrcweir                     nCompare = 1;
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir                 break;
1230cdf0e10cSrcweir             }
1231cdf0e10cSrcweir         default:
1232cdf0e10cSrcweir             {
1233cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "DataType not supported for compare!" );
1234cdf0e10cSrcweir             }
1235cdf0e10cSrcweir     }
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir     return nCompare;
1238cdf0e10cSrcweir }
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir //--------------------------------------------------------------------------
CompareImpl(Reference<XResultSet> xResultOne,Reference<XResultSet> xResultTwo,long nIndexOne,long nIndexTwo)1241cdf0e10cSrcweir long SortedResultSet::CompareImpl( Reference < XResultSet > xResultOne,
1242cdf0e10cSrcweir                                    Reference < XResultSet > xResultTwo,
1243cdf0e10cSrcweir                                    long nIndexOne, long nIndexTwo )
1244cdf0e10cSrcweir     throw( SQLException, RuntimeException )
1245cdf0e10cSrcweir {
1246cdf0e10cSrcweir     long        nCompare = 0;
1247cdf0e10cSrcweir     SortInfo*   pInfo = mpSortInfo;
1248cdf0e10cSrcweir 
1249cdf0e10cSrcweir     while ( !nCompare && pInfo )
1250cdf0e10cSrcweir     {
1251cdf0e10cSrcweir         if ( pInfo->mbUseOwnCompare )
1252cdf0e10cSrcweir         {
1253cdf0e10cSrcweir             nCompare = CompareImpl( xResultOne, xResultTwo,
1254cdf0e10cSrcweir                                     nIndexOne, nIndexTwo, pInfo );
1255cdf0e10cSrcweir         }
1256cdf0e10cSrcweir         else
1257cdf0e10cSrcweir         {
1258cdf0e10cSrcweir             Any aOne, aTwo;
1259cdf0e10cSrcweir 
1260cdf0e10cSrcweir             Reference < XRow > xRowOne =
1261cdf0e10cSrcweir                             Reference< XRow >::query( xResultOne );
1262cdf0e10cSrcweir             Reference < XRow > xRowTwo =
1263cdf0e10cSrcweir                             Reference< XRow >::query( xResultTwo );
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir             if ( xResultOne->absolute( nIndexOne ) )
1266cdf0e10cSrcweir                 aOne = xRowOne->getObject( pInfo->mnColumn, NULL );
1267cdf0e10cSrcweir             if ( xResultTwo->absolute( nIndexTwo ) )
1268cdf0e10cSrcweir                 aTwo = xRowTwo->getObject( pInfo->mnColumn, NULL );
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir             nCompare = pInfo->mxCompareFunction->compare( aOne, aTwo );
1271cdf0e10cSrcweir         }
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir         if ( ! pInfo->mbAscending )
1274cdf0e10cSrcweir             nCompare = - nCompare;
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir         pInfo = pInfo->mpNext;
1277cdf0e10cSrcweir     }
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir     return nCompare;
1280cdf0e10cSrcweir }
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir //--------------------------------------------------------------------------
Compare(SortListData * pOne,SortListData * pTwo)1283cdf0e10cSrcweir long SortedResultSet::Compare( SortListData *pOne,
1284cdf0e10cSrcweir                                SortListData *pTwo )
1285cdf0e10cSrcweir     throw( SQLException, RuntimeException )
1286cdf0e10cSrcweir {
1287cdf0e10cSrcweir     long nIndexOne;
1288cdf0e10cSrcweir     long nIndexTwo;
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir     Reference < XResultSet > xResultOne;
1291cdf0e10cSrcweir     Reference < XResultSet > xResultTwo;
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir     if ( pOne->mbModified )
1294cdf0e10cSrcweir     {
1295cdf0e10cSrcweir         xResultOne = mxOther;
1296cdf0e10cSrcweir         nIndexOne = pOne->mnOldPos;
1297cdf0e10cSrcweir     }
1298cdf0e10cSrcweir     else
1299cdf0e10cSrcweir     {
1300cdf0e10cSrcweir         xResultOne = mxOriginal;
1301cdf0e10cSrcweir         nIndexOne = pOne->mnCurPos;
1302cdf0e10cSrcweir     }
1303cdf0e10cSrcweir 
1304cdf0e10cSrcweir     if ( pTwo->mbModified )
1305cdf0e10cSrcweir     {
1306cdf0e10cSrcweir         xResultTwo = mxOther;
1307cdf0e10cSrcweir         nIndexTwo = pTwo->mnOldPos;
1308cdf0e10cSrcweir     }
1309cdf0e10cSrcweir     else
1310cdf0e10cSrcweir     {
1311cdf0e10cSrcweir         xResultTwo = mxOriginal;
1312cdf0e10cSrcweir         nIndexTwo = pTwo->mnCurPos;
1313cdf0e10cSrcweir     }
1314cdf0e10cSrcweir 
1315cdf0e10cSrcweir     long nCompare;
1316cdf0e10cSrcweir     nCompare = CompareImpl( xResultOne, xResultTwo,
1317cdf0e10cSrcweir                             nIndexOne, nIndexTwo );
1318cdf0e10cSrcweir     return nCompare;
1319cdf0e10cSrcweir }
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir //--------------------------------------------------------------------------
FindPos(SortListData * pEntry,long _nStart,long _nEnd)1322cdf0e10cSrcweir long SortedResultSet::FindPos( SortListData *pEntry,
1323cdf0e10cSrcweir                                long _nStart, long _nEnd )
1324cdf0e10cSrcweir     throw( SQLException, RuntimeException )
1325cdf0e10cSrcweir {
1326cdf0e10cSrcweir     if ( _nStart > _nEnd )
1327cdf0e10cSrcweir         return _nStart + 1;
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir     long nStart = _nStart;
1330cdf0e10cSrcweir     long nEnd   = _nEnd;
1331cdf0e10cSrcweir     long nMid = 0, nCompare = 0;
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir     SortListData    *pMid;
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir     while ( nStart <= nEnd )
1336cdf0e10cSrcweir     {
1337cdf0e10cSrcweir         nMid = ( nEnd - nStart ) / 2 + nStart;
1338cdf0e10cSrcweir         pMid = maS2O.GetData( nMid );
1339cdf0e10cSrcweir         nCompare = Compare( pEntry, pMid );
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir         if ( !nCompare )
1342cdf0e10cSrcweir             nCompare = ((long) pEntry ) - ( (long) pMid );
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir         if ( nCompare < 0 ) // pEntry < pMid
1345cdf0e10cSrcweir             nEnd = nMid - 1;
1346cdf0e10cSrcweir         else
1347cdf0e10cSrcweir             nStart = nMid + 1;
1348cdf0e10cSrcweir     }
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir     if ( nCompare < 0 )     // pEntry < pMid
1351cdf0e10cSrcweir         return nMid;
1352cdf0e10cSrcweir     else
1353cdf0e10cSrcweir         return nMid+1;
1354cdf0e10cSrcweir }
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir //--------------------------------------------------------------------------
PropertyChanged(const PropertyChangeEvent & rEvt)1357cdf0e10cSrcweir void SortedResultSet::PropertyChanged( const PropertyChangeEvent& rEvt )
1358cdf0e10cSrcweir {
1359cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir     if ( !mpPropChangeListeners )
1362cdf0e10cSrcweir         return;
1363cdf0e10cSrcweir 
1364cdf0e10cSrcweir     // Notify listeners interested especially in the changed property.
1365cdf0e10cSrcweir     OInterfaceContainerHelper* pPropsContainer =
1366cdf0e10cSrcweir             mpPropChangeListeners->getContainer( rEvt.PropertyName );
1367cdf0e10cSrcweir     if ( pPropsContainer )
1368cdf0e10cSrcweir     {
1369cdf0e10cSrcweir         OInterfaceIteratorHelper aIter( *pPropsContainer );
1370cdf0e10cSrcweir         while ( aIter.hasMoreElements() )
1371cdf0e10cSrcweir         {
1372cdf0e10cSrcweir             Reference< XPropertyChangeListener > xListener(
1373cdf0e10cSrcweir                                                     aIter.next(), UNO_QUERY );
1374cdf0e10cSrcweir             if ( xListener.is() )
1375cdf0e10cSrcweir                 xListener->propertyChange( rEvt );
1376cdf0e10cSrcweir         }
1377cdf0e10cSrcweir     }
1378cdf0e10cSrcweir 
1379cdf0e10cSrcweir     // Notify listeners interested in all properties.
1380cdf0e10cSrcweir     pPropsContainer = mpPropChangeListeners->getContainer( OUString() );
1381cdf0e10cSrcweir     if ( pPropsContainer )
1382cdf0e10cSrcweir     {
1383cdf0e10cSrcweir         OInterfaceIteratorHelper aIter( *pPropsContainer );
1384cdf0e10cSrcweir         while ( aIter.hasMoreElements() )
1385cdf0e10cSrcweir         {
1386cdf0e10cSrcweir             Reference< XPropertyChangeListener > xListener(
1387cdf0e10cSrcweir                                                     aIter.next(), UNO_QUERY );
1388cdf0e10cSrcweir             if ( xListener.is() )
1389cdf0e10cSrcweir                 xListener->propertyChange( rEvt );
1390cdf0e10cSrcweir         }
1391cdf0e10cSrcweir     }
1392cdf0e10cSrcweir }
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir //-------------------------------------------------------------------------
1395cdf0e10cSrcweir 
1396cdf0e10cSrcweir //--------------------------------------------------------------------------
1397cdf0e10cSrcweir // public methods
1398cdf0e10cSrcweir //--------------------------------------------------------------------------
1399cdf0e10cSrcweir 
CopyData(SortedResultSet * pSource)1400cdf0e10cSrcweir void SortedResultSet::CopyData( SortedResultSet *pSource )
1401cdf0e10cSrcweir {
1402cdf0e10cSrcweir     const SortedEntryList *pSrcS2O = pSource->GetS2OList();
1403cdf0e10cSrcweir     const SimpleList      *pSrcO2S = pSource->GetO2SList();
1404cdf0e10cSrcweir 
1405cdf0e10cSrcweir     long i, nCount;
1406cdf0e10cSrcweir 
1407cdf0e10cSrcweir     maS2O.Clear();
1408cdf0e10cSrcweir     maO2S.Clear();
1409cdf0e10cSrcweir     maModList.Clear();
1410cdf0e10cSrcweir 
1411cdf0e10cSrcweir     maS2O.Insert( NULL, 0 );
1412cdf0e10cSrcweir     maO2S.Insert( 0, (sal_uInt32) 0 );  // value, pos
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir     nCount = pSrcS2O->Count();
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir     for ( i=1; i<nCount; i++ )
1417cdf0e10cSrcweir     {
1418cdf0e10cSrcweir         maS2O.Insert( new SortListData( (*pSrcS2O)[ i ] ), i );
1419cdf0e10cSrcweir         maO2S.Insert( pSrcO2S->GetObject( i ), (sal_uInt32) i );
1420cdf0e10cSrcweir     }
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir     mnLastSort = maS2O.Count();
1423cdf0e10cSrcweir     mxOther = pSource->GetResultSet();
1424cdf0e10cSrcweir 
1425cdf0e10cSrcweir     if ( !mpSortInfo )
1426cdf0e10cSrcweir     {
1427cdf0e10cSrcweir         mpSortInfo = pSource->GetSortInfo();
1428cdf0e10cSrcweir         mbIsCopy = sal_True;
1429cdf0e10cSrcweir     }
1430cdf0e10cSrcweir }
1431cdf0e10cSrcweir 
1432cdf0e10cSrcweir //--------------------------------------------------------------------------
Initialize(const Sequence<NumberedSortingInfo> & xSortInfo,const Reference<XAnyCompareFactory> & xCompFactory)1433cdf0e10cSrcweir void SortedResultSet::Initialize(
1434cdf0e10cSrcweir                 const Sequence < NumberedSortingInfo > &xSortInfo,
1435cdf0e10cSrcweir                 const Reference< XAnyCompareFactory > &xCompFactory )
1436cdf0e10cSrcweir {
1437cdf0e10cSrcweir     BuildSortInfo( mxOriginal, xSortInfo, xCompFactory );
1438cdf0e10cSrcweir     // Insert dummy at pos 0
1439cdf0e10cSrcweir     SortListData *pData = new SortListData( 0 );
1440cdf0e10cSrcweir     maS2O.Insert( pData, 0 );
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir     long nIndex = 1;
1443cdf0e10cSrcweir 
1444cdf0e10cSrcweir     // now fetch all the elements from the original result set,
1445cdf0e10cSrcweir     // get there new position in the sorted result set and insert
1446cdf0e10cSrcweir     // an entry in the sorted to original mapping list
1447cdf0e10cSrcweir     try {
1448cdf0e10cSrcweir         while ( mxOriginal->absolute( nIndex ) )
1449cdf0e10cSrcweir         {
1450cdf0e10cSrcweir             pData       = new SortListData( nIndex );
1451cdf0e10cSrcweir             long nPos   = FindPos( pData, 1, nIndex-1 );
1452cdf0e10cSrcweir 
1453cdf0e10cSrcweir             maS2O.Insert( pData, nPos );
1454cdf0e10cSrcweir 
1455cdf0e10cSrcweir             nIndex++;
1456cdf0e10cSrcweir         }
1457cdf0e10cSrcweir     }
1458cdf0e10cSrcweir     catch ( SQLException ) { OSL_ENSURE( sal_False, "SortedResultSet::Initialize() : Got unexpected SQLException" ); }
1459cdf0e10cSrcweir 
1460cdf0e10cSrcweir     // when we have fetched all the elements, we can create the
1461cdf0e10cSrcweir     // original to sorted mapping list from the s2o list
1462cdf0e10cSrcweir     maO2S.Clear();
1463cdf0e10cSrcweir     maO2S.Insert( NULL, (sal_uInt32) 0 );
1464cdf0e10cSrcweir 
1465cdf0e10cSrcweir     // insert some dummy entries first and replace then
1466cdf0e10cSrcweir     // the entries with the right ones
1467cdf0e10cSrcweir     sal_uInt32 i;
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir     for ( i=1; i<maS2O.Count(); i++ )
1470cdf0e10cSrcweir         maO2S.Insert( (void*) 0, i );   // Insert( data, pos )
1471cdf0e10cSrcweir     for ( i=1; i<maS2O.Count(); i++ )
1472cdf0e10cSrcweir         maO2S.Replace( (void*) i, maS2O[ i ] ); // Insert( data, pos )
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir     mnCount = maS2O.Count() - 1;
1475cdf0e10cSrcweir }
1476cdf0e10cSrcweir 
1477cdf0e10cSrcweir //--------------------------------------------------------------------------
CheckProperties(long nOldCount,sal_Bool bWasFinal)1478cdf0e10cSrcweir void SortedResultSet::CheckProperties( long nOldCount, sal_Bool bWasFinal )
1479cdf0e10cSrcweir {
1480cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( maMutex );
1481cdf0e10cSrcweir 
1482cdf0e10cSrcweir     if ( !mpPropChangeListeners )
1483cdf0e10cSrcweir         return;
1484cdf0e10cSrcweir 
1485cdf0e10cSrcweir     try {
1486cdf0e10cSrcweir         // check for propertyChangeEvents
1487cdf0e10cSrcweir         if ( nOldCount != GetCount() )
1488cdf0e10cSrcweir         {
1489cdf0e10cSrcweir             sal_Bool bIsFinal = sal_False;
1490cdf0e10cSrcweir             PropertyChangeEvent aEvt;
1491cdf0e10cSrcweir 
1492cdf0e10cSrcweir             aEvt.PropertyName = OUString::createFromAscii( "RowCount" );
1493cdf0e10cSrcweir             aEvt.Further = sal_False;
1494cdf0e10cSrcweir             aEvt.PropertyHandle = -1;
1495cdf0e10cSrcweir             aEvt.OldValue <<= nOldCount;
1496cdf0e10cSrcweir             aEvt.NewValue <<= GetCount();
1497cdf0e10cSrcweir 
1498cdf0e10cSrcweir             PropertyChanged( aEvt );
1499cdf0e10cSrcweir 
1500cdf0e10cSrcweir             OUString aName = OUString::createFromAscii( "IsRowCountFinal" );
1501cdf0e10cSrcweir             Any aRet = getPropertyValue( aName );
1502cdf0e10cSrcweir             if ( (aRet >>= bIsFinal) && bIsFinal != bWasFinal )
1503cdf0e10cSrcweir             {
1504cdf0e10cSrcweir                 aEvt.PropertyName = aName;
1505cdf0e10cSrcweir                 aEvt.Further = sal_False;
1506cdf0e10cSrcweir                 aEvt.PropertyHandle = -1;
1507cdf0e10cSrcweir                 aEvt.OldValue <<= (sal_Bool) bWasFinal;
1508cdf0e10cSrcweir                 aEvt.NewValue <<= (sal_Bool) bIsFinal;
1509cdf0e10cSrcweir                 PropertyChanged( aEvt );
1510cdf0e10cSrcweir             }
1511cdf0e10cSrcweir         }
1512cdf0e10cSrcweir     }
1513cdf0e10cSrcweir     catch ( UnknownPropertyException ) {}
1514cdf0e10cSrcweir     catch ( WrappedTargetException ) {}
1515cdf0e10cSrcweir }
1516cdf0e10cSrcweir 
1517cdf0e10cSrcweir //-------------------------------------------------------------------------
InsertNew(long nPos,long nCount)1518cdf0e10cSrcweir void SortedResultSet::InsertNew( long nPos, long nCount )
1519cdf0e10cSrcweir {
1520cdf0e10cSrcweir     // in der maS2O Liste alle Eintr�ge, die >= nPos sind, um nCount
1521cdf0e10cSrcweir     // erh�hen
1522cdf0e10cSrcweir     SortListData    *pData;
1523cdf0e10cSrcweir     long            i, nEnd;
1524cdf0e10cSrcweir 
1525cdf0e10cSrcweir     nEnd = maS2O.Count();
1526cdf0e10cSrcweir     for ( i=1; i<=nEnd; i++ )
1527cdf0e10cSrcweir     {
1528cdf0e10cSrcweir         pData = maS2O.GetData( i );
1529cdf0e10cSrcweir         if ( pData->mnCurPos >= nPos )
1530cdf0e10cSrcweir         {
1531cdf0e10cSrcweir             pData->mnCurPos += nCount;
1532cdf0e10cSrcweir         }
1533cdf0e10cSrcweir     }
1534cdf0e10cSrcweir 
1535cdf0e10cSrcweir     // und die neuen eintr�ge hinten an die maS2O Liste anh�ngen bzw
1536cdf0e10cSrcweir     // an der Position nPos in der maO2S Liste einf�gen
1537cdf0e10cSrcweir     for ( i=0; i<nCount; i++ )
1538cdf0e10cSrcweir     {
1539cdf0e10cSrcweir         nEnd += 1;
1540cdf0e10cSrcweir         pData = new SortListData( nEnd );
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir         maS2O.Insert( pData, nEnd );    // Insert( Wert, Position )
1543cdf0e10cSrcweir         maO2S.Insert( (void*)nEnd, (sal_uInt32)(nPos+i) );  // Insert( Wert, Position )
1544cdf0e10cSrcweir     }
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir     mnCount += nCount;
1547cdf0e10cSrcweir }
1548cdf0e10cSrcweir 
1549cdf0e10cSrcweir //-------------------------------------------------------------------------
Remove(long nPos,long nCount,EventList * pEvents)1550cdf0e10cSrcweir void SortedResultSet::Remove( long nPos, long nCount, EventList *pEvents )
1551cdf0e10cSrcweir {
1552cdf0e10cSrcweir     sal_uInt32  i, j;
1553cdf0e10cSrcweir     long        nOldLastSort;
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir     // correct mnLastSort first
1556cdf0e10cSrcweir     nOldLastSort = mnLastSort;
1557cdf0e10cSrcweir     if ( nPos <= mnLastSort )
1558cdf0e10cSrcweir     {
1559cdf0e10cSrcweir         if ( nPos + nCount - 1 <= mnLastSort )
1560cdf0e10cSrcweir             mnLastSort -= nCount;
1561cdf0e10cSrcweir         else
1562cdf0e10cSrcweir             mnLastSort = nPos - 1;
1563cdf0e10cSrcweir     }
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir     // remove the entries from the lists and correct the positions
1566cdf0e10cSrcweir     // in the original2sorted list
1567cdf0e10cSrcweir     for ( i=0; i < (sal_uInt32) nCount; i++ )
1568cdf0e10cSrcweir     {
1569cdf0e10cSrcweir         long nSortPos = (long) maO2S.GetObject( nPos );
1570cdf0e10cSrcweir         maO2S.Remove( (sal_uInt32) nPos );
1571cdf0e10cSrcweir 
1572cdf0e10cSrcweir         for ( j=1; j<=maO2S.Count(); j++ )
1573cdf0e10cSrcweir         {
1574cdf0e10cSrcweir             long nVal = (long) maO2S.GetObject( j );
1575cdf0e10cSrcweir             if ( nVal > nSortPos )
1576cdf0e10cSrcweir             {
1577cdf0e10cSrcweir                 --nVal;
1578cdf0e10cSrcweir                 maO2S.Replace( (void*) nVal, j );
1579cdf0e10cSrcweir             }
1580cdf0e10cSrcweir         }
1581cdf0e10cSrcweir 
1582cdf0e10cSrcweir         SortListData *pData = maS2O.Remove( nSortPos );
1583cdf0e10cSrcweir         if ( pData->mbModified )
1584cdf0e10cSrcweir             maModList.Remove( (void*) pData );
1585cdf0e10cSrcweir         delete pData;
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir         // generate remove Event, but not for new entries
1588cdf0e10cSrcweir         if ( nSortPos <= nOldLastSort )
1589cdf0e10cSrcweir             pEvents->AddEvent( ListActionType::REMOVED, nSortPos, 1 );
1590cdf0e10cSrcweir     }
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir     // correct the positions in the sorted list
1593cdf0e10cSrcweir     for ( i=1; i<= maS2O.Count(); i++ )
1594cdf0e10cSrcweir     {
1595cdf0e10cSrcweir         SortListData *pData = maS2O.GetData( i );
1596cdf0e10cSrcweir         if ( pData->mnCurPos > nPos )
1597cdf0e10cSrcweir             pData->mnCurPos -= nCount;
1598cdf0e10cSrcweir     }
1599cdf0e10cSrcweir 
1600cdf0e10cSrcweir     mnCount -= nCount;
1601cdf0e10cSrcweir }
1602cdf0e10cSrcweir 
1603cdf0e10cSrcweir //-------------------------------------------------------------------------
Move(long nPos,long nCount,long nOffset)1604cdf0e10cSrcweir void SortedResultSet::Move( long nPos, long nCount, long nOffset )
1605cdf0e10cSrcweir {
1606cdf0e10cSrcweir     if ( !nOffset )
1607cdf0e10cSrcweir         return;
1608cdf0e10cSrcweir 
1609cdf0e10cSrcweir     long i, nSortPos, nTo;
1610cdf0e10cSrcweir     SortListData *pData;
1611cdf0e10cSrcweir 
1612cdf0e10cSrcweir     for ( i=0; i<nCount; i++ )
1613cdf0e10cSrcweir     {
1614cdf0e10cSrcweir         nSortPos = (long) maO2S.GetObject( nPos+i );
1615cdf0e10cSrcweir         pData = maS2O.GetData( nSortPos );
1616cdf0e10cSrcweir         pData->mnCurPos += nOffset;
1617cdf0e10cSrcweir     }
1618cdf0e10cSrcweir 
1619cdf0e10cSrcweir     if ( nOffset < 0 )
1620cdf0e10cSrcweir     {
1621cdf0e10cSrcweir         for ( i=nPos+nOffset; i<nPos; i++ )
1622cdf0e10cSrcweir         {
1623cdf0e10cSrcweir             nSortPos = (long) maO2S.GetObject( i );
1624cdf0e10cSrcweir             pData = maS2O.GetData( nSortPos );
1625cdf0e10cSrcweir             pData->mnCurPos += nCount;
1626cdf0e10cSrcweir         }
1627cdf0e10cSrcweir     }
1628cdf0e10cSrcweir     else
1629cdf0e10cSrcweir     {
1630cdf0e10cSrcweir         long nStart = nPos + nCount;
1631cdf0e10cSrcweir         long nEnd = nStart + nOffset;
1632cdf0e10cSrcweir         for ( i=nStart; i<nEnd; i++ )
1633cdf0e10cSrcweir         {
1634cdf0e10cSrcweir             nSortPos = (long) maO2S.GetObject( i );
1635cdf0e10cSrcweir             pData = maS2O.GetData( nSortPos );
1636cdf0e10cSrcweir             pData->mnCurPos -= nCount;
1637cdf0e10cSrcweir         }
1638cdf0e10cSrcweir     }
1639cdf0e10cSrcweir 
1640cdf0e10cSrcweir     // remember the to be moved entries
1641cdf0e10cSrcweir     long *pTmpArr = new long[ nCount ];
1642cdf0e10cSrcweir     for ( i=0; i<nCount; i++ )
1643cdf0e10cSrcweir         pTmpArr[i] = (long)maO2S.GetObject( (sal_uInt32)( nPos+i ) );
1644cdf0e10cSrcweir 
1645cdf0e10cSrcweir     // now move the entries, which are in the way
1646cdf0e10cSrcweir     if ( nOffset < 0 )
1647cdf0e10cSrcweir     {
1648cdf0e10cSrcweir         // be carefully here, because nOffset is negative here, so an
1649cdf0e10cSrcweir         // addition is a subtraction
1650cdf0e10cSrcweir         long nFrom = nPos - 1;
1651cdf0e10cSrcweir         nTo = nPos + nCount - 1;
1652cdf0e10cSrcweir 
1653cdf0e10cSrcweir         // same for i here
1654cdf0e10cSrcweir         for ( i=0; i>nOffset; i-- )
1655cdf0e10cSrcweir         {
1656cdf0e10cSrcweir             long nVal = (long) maO2S.GetObject( (sal_uInt32)( nFrom+i ) );
1657cdf0e10cSrcweir             maO2S.Replace( (void*) nVal, (sal_uInt32)( nTo+i ) );
1658cdf0e10cSrcweir         }
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir     }
1661cdf0e10cSrcweir     else
1662cdf0e10cSrcweir     {
1663cdf0e10cSrcweir         long nStart = nPos + nCount;
1664cdf0e10cSrcweir         for ( i=0; i<nOffset; i++ )
1665cdf0e10cSrcweir         {
1666cdf0e10cSrcweir             long nVal = (long) maO2S.GetObject( (sal_uInt32)( nStart+i ) );
1667cdf0e10cSrcweir             maO2S.Replace( (void*) nVal, (sal_uInt32)( nPos+i ) );
1668cdf0e10cSrcweir         }
1669cdf0e10cSrcweir     }
1670cdf0e10cSrcweir 
1671cdf0e10cSrcweir     // finally put the remembered entries at there new location
1672cdf0e10cSrcweir     nTo = nPos + nOffset;
1673cdf0e10cSrcweir     for ( i=0; i<nCount; i++ )
1674cdf0e10cSrcweir     {
1675cdf0e10cSrcweir         maO2S.Replace( (void*)pTmpArr[ i ], (sal_uInt32)( nTo+i ) );
1676cdf0e10cSrcweir     }
1677cdf0e10cSrcweir 
1678cdf0e10cSrcweir     delete [] pTmpArr;
1679cdf0e10cSrcweir }
1680cdf0e10cSrcweir 
1681cdf0e10cSrcweir //--------------------------------------------------------------------------
BuildSortInfo(Reference<XResultSet> aResult,const Sequence<NumberedSortingInfo> & xSortInfo,const Reference<XAnyCompareFactory> & xCompFactory)1682cdf0e10cSrcweir void SortedResultSet::BuildSortInfo(
1683cdf0e10cSrcweir                 Reference< XResultSet > aResult,
1684cdf0e10cSrcweir                 const Sequence < NumberedSortingInfo > &xSortInfo,
1685cdf0e10cSrcweir                 const Reference< XAnyCompareFactory > &xCompFactory )
1686cdf0e10cSrcweir {
1687cdf0e10cSrcweir     Reference < XResultSetMetaDataSupplier > xMeta ( aResult, UNO_QUERY );
1688cdf0e10cSrcweir 
1689cdf0e10cSrcweir     if ( ! xMeta.is() )
1690cdf0e10cSrcweir     {
1691cdf0e10cSrcweir         OSL_ENSURE( sal_False, "No MetaData, No Sorting!" );
1692cdf0e10cSrcweir         return;
1693cdf0e10cSrcweir     }
1694cdf0e10cSrcweir 
1695cdf0e10cSrcweir     Reference < XResultSetMetaData > xData = xMeta->getMetaData();
1696cdf0e10cSrcweir     const NumberedSortingInfo *pSortInfo = xSortInfo.getConstArray();
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir     sal_Int32   nColumn;
1699cdf0e10cSrcweir     OUString    aPropName;
1700cdf0e10cSrcweir     SortInfo    *pInfo;
1701cdf0e10cSrcweir 
1702cdf0e10cSrcweir     for ( long i=xSortInfo.getLength(); i > 0; )
1703cdf0e10cSrcweir     {
1704cdf0e10cSrcweir         --i;
1705cdf0e10cSrcweir         nColumn = pSortInfo[ i ].ColumnIndex;
1706cdf0e10cSrcweir         aPropName = xData->getColumnName( nColumn );
1707cdf0e10cSrcweir         pInfo = new SortInfo;
1708cdf0e10cSrcweir 
1709cdf0e10cSrcweir         if ( xCompFactory.is() )
1710cdf0e10cSrcweir             pInfo->mxCompareFunction = xCompFactory->createAnyCompareByName(
1711cdf0e10cSrcweir                                             aPropName );
1712cdf0e10cSrcweir 
1713cdf0e10cSrcweir         if ( pInfo->mxCompareFunction.is() )
1714cdf0e10cSrcweir         {
1715cdf0e10cSrcweir             pInfo->mbUseOwnCompare = sal_False;
1716cdf0e10cSrcweir             pInfo->mnType = 0;
1717cdf0e10cSrcweir         }
1718cdf0e10cSrcweir         else
1719cdf0e10cSrcweir         {
1720cdf0e10cSrcweir             pInfo->mbUseOwnCompare = sal_True;
1721cdf0e10cSrcweir             pInfo->mnType = xData->getColumnType( nColumn );
1722cdf0e10cSrcweir         }
1723cdf0e10cSrcweir 
1724cdf0e10cSrcweir         pInfo->mnColumn = nColumn;
1725cdf0e10cSrcweir         pInfo->mbAscending = pSortInfo[ i ].Ascending;
1726cdf0e10cSrcweir         pInfo->mbCaseSensitive = xData->isCaseSensitive( nColumn );
1727cdf0e10cSrcweir         pInfo->mpNext = mpSortInfo;
1728cdf0e10cSrcweir         mpSortInfo = pInfo;
1729cdf0e10cSrcweir     }
1730cdf0e10cSrcweir }
1731cdf0e10cSrcweir 
1732cdf0e10cSrcweir //-------------------------------------------------------------------------
SetChanged(long nPos,long nCount)1733cdf0e10cSrcweir void SortedResultSet::SetChanged( long nPos, long nCount )
1734cdf0e10cSrcweir {
1735cdf0e10cSrcweir     for ( long i=0; i<nCount; i++ )
1736cdf0e10cSrcweir     {
1737cdf0e10cSrcweir         long nSortPos = (long) maO2S.GetObject( nPos );
1738cdf0e10cSrcweir         if ( nSortPos < mnLastSort )
1739cdf0e10cSrcweir         {
1740cdf0e10cSrcweir             SortListData *pData = maS2O.GetData( nSortPos );
1741cdf0e10cSrcweir             if ( ! pData->mbModified )
1742cdf0e10cSrcweir             {
1743cdf0e10cSrcweir                 pData->mbModified = sal_True;
1744cdf0e10cSrcweir                 maModList.Append( pData );
1745cdf0e10cSrcweir             }
1746cdf0e10cSrcweir         }
1747cdf0e10cSrcweir         nPos += 1;
1748cdf0e10cSrcweir     }
1749cdf0e10cSrcweir }
1750cdf0e10cSrcweir 
1751cdf0e10cSrcweir //-------------------------------------------------------------------------
ResortModified(EventList * pList)1752cdf0e10cSrcweir void SortedResultSet::ResortModified( EventList* pList )
1753cdf0e10cSrcweir {
1754cdf0e10cSrcweir     sal_uInt32 i, j;
1755cdf0e10cSrcweir     long nCompare, nCurPos, nNewPos;
1756cdf0e10cSrcweir     long nStart, nEnd, nOffset, nVal;
1757cdf0e10cSrcweir     SortListData *pData;
1758cdf0e10cSrcweir     ListAction *pAction;
1759cdf0e10cSrcweir 
1760cdf0e10cSrcweir     try {
1761cdf0e10cSrcweir         for ( i=0; i<maModList.Count(); i++ )
1762cdf0e10cSrcweir         {
1763cdf0e10cSrcweir             pData = (SortListData*) maModList.GetObject( i );
1764cdf0e10cSrcweir             nCompare = CompareImpl( mxOther, mxOriginal,
1765cdf0e10cSrcweir                                     pData->mnOldPos, pData->mnCurPos );
1766cdf0e10cSrcweir             pData->mbModified = sal_False;
1767cdf0e10cSrcweir             if ( nCompare != 0 )
1768cdf0e10cSrcweir             {
1769cdf0e10cSrcweir                 nCurPos = (long) maO2S.GetObject( (sal_uInt32) pData->mnCurPos );
1770cdf0e10cSrcweir                 if ( nCompare < 0 )
1771cdf0e10cSrcweir                 {
1772cdf0e10cSrcweir                     nNewPos = FindPos( pData, 1, nCurPos-1 );
1773cdf0e10cSrcweir                     nStart = nNewPos;
1774cdf0e10cSrcweir                     nEnd = nCurPos;
1775cdf0e10cSrcweir                     nOffset = 1;
1776cdf0e10cSrcweir                 }
1777cdf0e10cSrcweir                 else
1778cdf0e10cSrcweir                 {
1779cdf0e10cSrcweir                     nNewPos = FindPos( pData, nCurPos+1, mnLastSort );
1780cdf0e10cSrcweir                     nStart = nCurPos;
1781cdf0e10cSrcweir                     nEnd = mnLastSort;
1782cdf0e10cSrcweir                     nOffset = -1;
1783cdf0e10cSrcweir                 }
1784cdf0e10cSrcweir 
1785cdf0e10cSrcweir                 if ( nNewPos != nCurPos )
1786cdf0e10cSrcweir                 {
1787cdf0e10cSrcweir                     // correct the lists!
1788cdf0e10cSrcweir                     maS2O.Remove( (sal_uInt32) nCurPos );
1789cdf0e10cSrcweir                     maS2O.Insert( pData, nNewPos );
1790cdf0e10cSrcweir                         for ( j=1; j<maO2S.Count(); j++ )
1791cdf0e10cSrcweir                     {
1792cdf0e10cSrcweir                         nVal = (long) maO2S.GetObject( (sal_uInt32)( j ) );
1793cdf0e10cSrcweir                         if ( ( nStart <= nVal ) && ( nVal <= nEnd ) )
1794cdf0e10cSrcweir                         {
1795cdf0e10cSrcweir                             nVal += nOffset;
1796cdf0e10cSrcweir                             maO2S.Replace( (void*) (nVal), (sal_uInt32)( j ) );
1797cdf0e10cSrcweir                         }
1798cdf0e10cSrcweir                     }
1799cdf0e10cSrcweir 
1800cdf0e10cSrcweir                     maO2S.Replace( (void*) nNewPos, (sal_uInt32) pData->mnCurPos );
1801cdf0e10cSrcweir 
1802cdf0e10cSrcweir                     pAction = new ListAction;
1803cdf0e10cSrcweir                     pAction->Position = nCurPos;
1804cdf0e10cSrcweir                     pAction->Count = 1;
1805cdf0e10cSrcweir                     pAction->ListActionType = ListActionType::MOVED;
1806cdf0e10cSrcweir                     pAction->ActionInfo <<= nNewPos-nCurPos;
1807cdf0e10cSrcweir                     pList->Insert( pAction );
1808cdf0e10cSrcweir                 }
1809cdf0e10cSrcweir                 pList->AddEvent( ListActionType::PROPERTIES_CHANGED,
1810cdf0e10cSrcweir                                  nNewPos, 1 );
1811cdf0e10cSrcweir             }
1812cdf0e10cSrcweir         }
1813cdf0e10cSrcweir     }
1814cdf0e10cSrcweir     catch ( SQLException ) { OSL_ENSURE( sal_False, "SortedResultSet::ResortModified() : Got unexpected SQLException" ); }
1815cdf0e10cSrcweir 
1816cdf0e10cSrcweir     maModList.Clear();
1817cdf0e10cSrcweir }
1818cdf0e10cSrcweir 
1819cdf0e10cSrcweir //-------------------------------------------------------------------------
ResortNew(EventList * pList)1820cdf0e10cSrcweir void SortedResultSet::ResortNew( EventList* pList )
1821cdf0e10cSrcweir {
1822cdf0e10cSrcweir     long            i, j, nNewPos, nVal;
1823cdf0e10cSrcweir     SortListData    *pData;
1824cdf0e10cSrcweir 
1825cdf0e10cSrcweir     try {
1826cdf0e10cSrcweir         for ( i = mnLastSort; i<(long)maS2O.Count(); i++ )
1827cdf0e10cSrcweir         {
1828cdf0e10cSrcweir             pData = (SortListData*) maModList.GetObject( i );
1829cdf0e10cSrcweir             nNewPos = FindPos( pData, 1, mnLastSort );
1830cdf0e10cSrcweir             if ( nNewPos != i )
1831cdf0e10cSrcweir             {
1832cdf0e10cSrcweir                 maS2O.Remove( (sal_uInt32) i );
1833cdf0e10cSrcweir                 maS2O.Insert( pData, nNewPos );
1834cdf0e10cSrcweir                 // maO2S liste korigieren
1835cdf0e10cSrcweir                 for ( j=1; j<(long)maO2S.Count(); j++ )
1836cdf0e10cSrcweir                 {
1837cdf0e10cSrcweir                     nVal = (long) maO2S.GetObject( (sal_uInt32)( j ) );
1838cdf0e10cSrcweir                     if ( nVal >= nNewPos )
1839cdf0e10cSrcweir                         maO2S.Replace( (void*) (nVal+1), (sal_uInt32)( j ) );
1840cdf0e10cSrcweir                 }
1841cdf0e10cSrcweir                 maO2S.Replace( (void*) nNewPos, (sal_uInt32) pData->mnCurPos );
1842cdf0e10cSrcweir             }
1843cdf0e10cSrcweir             mnLastSort++;
1844cdf0e10cSrcweir             pList->AddEvent( ListActionType::INSERTED, nNewPos, 1 );
1845cdf0e10cSrcweir         }
1846cdf0e10cSrcweir     }
1847cdf0e10cSrcweir     catch ( SQLException ) { OSL_ENSURE( sal_False, "SortedResultSet::ResortNew() : Got unexpected SQLException" ); }
1848cdf0e10cSrcweir }
1849cdf0e10cSrcweir 
1850cdf0e10cSrcweir //-------------------------------------------------------------------------
1851cdf0e10cSrcweir //
1852cdf0e10cSrcweir // SortListData
1853cdf0e10cSrcweir //
1854cdf0e10cSrcweir //-------------------------------------------------------------------------
SortListData(long nPos,sal_Bool bModified)1855cdf0e10cSrcweir SortListData::SortListData( long nPos, sal_Bool bModified )
1856cdf0e10cSrcweir {
1857cdf0e10cSrcweir     mbModified = bModified;
1858cdf0e10cSrcweir     mnCurPos = nPos;
1859cdf0e10cSrcweir     mnOldPos = nPos;
1860cdf0e10cSrcweir };
1861cdf0e10cSrcweir 
1862cdf0e10cSrcweir 
1863cdf0e10cSrcweir //=========================================================================
Clear()1864cdf0e10cSrcweir void SortedEntryList::Clear()
1865cdf0e10cSrcweir {
1866cdf0e10cSrcweir     for ( std::deque< LISTACTION* >::size_type i = 0;
1867cdf0e10cSrcweir           i < maData.size(); ++i )
1868cdf0e10cSrcweir     {
1869cdf0e10cSrcweir         delete maData[i];
1870cdf0e10cSrcweir     }
1871cdf0e10cSrcweir 
1872cdf0e10cSrcweir     maData.clear();
1873cdf0e10cSrcweir }
1874cdf0e10cSrcweir 
1875cdf0e10cSrcweir //-------------------------------------------------------------------------
Insert(SortListData * pEntry,long nPos)1876cdf0e10cSrcweir void SortedEntryList::Insert( SortListData *pEntry, long nPos )
1877cdf0e10cSrcweir {
1878cdf0e10cSrcweir     if ( nPos < (long) maData.size() )
1879cdf0e10cSrcweir         maData.insert( maData.begin() + nPos, pEntry );
1880cdf0e10cSrcweir     else
1881cdf0e10cSrcweir         maData.push_back( pEntry );
1882cdf0e10cSrcweir }
1883cdf0e10cSrcweir 
1884cdf0e10cSrcweir //-------------------------------------------------------------------------
Remove(long nPos)1885cdf0e10cSrcweir SortListData* SortedEntryList::Remove( long nPos )
1886cdf0e10cSrcweir {
1887cdf0e10cSrcweir     SortListData *pData;
1888cdf0e10cSrcweir 
1889cdf0e10cSrcweir     if ( nPos < (long) maData.size() )
1890cdf0e10cSrcweir     {
1891cdf0e10cSrcweir         pData = maData[ nPos ];
1892cdf0e10cSrcweir         maData.erase( maData.begin() + nPos );
1893cdf0e10cSrcweir     }
1894cdf0e10cSrcweir     else
1895cdf0e10cSrcweir         pData = NULL;
1896cdf0e10cSrcweir 
1897cdf0e10cSrcweir     return pData;
1898cdf0e10cSrcweir }
1899cdf0e10cSrcweir 
1900cdf0e10cSrcweir //-------------------------------------------------------------------------
GetData(long nPos)1901cdf0e10cSrcweir SortListData* SortedEntryList::GetData( long nPos )
1902cdf0e10cSrcweir {
1903cdf0e10cSrcweir     SortListData *pData;
1904cdf0e10cSrcweir 
1905cdf0e10cSrcweir     if ( nPos < (long) maData.size() )
1906cdf0e10cSrcweir         pData = maData[ nPos ];
1907cdf0e10cSrcweir     else
1908cdf0e10cSrcweir         pData = NULL;
1909cdf0e10cSrcweir 
1910cdf0e10cSrcweir     return pData;
1911cdf0e10cSrcweir }
1912cdf0e10cSrcweir 
1913cdf0e10cSrcweir //-------------------------------------------------------------------------
operator [](long nPos) const1914cdf0e10cSrcweir long SortedEntryList::operator [] ( long nPos ) const
1915cdf0e10cSrcweir {
1916cdf0e10cSrcweir     SortListData *pData;
1917cdf0e10cSrcweir 
1918cdf0e10cSrcweir     if ( nPos < (long) maData.size() )
1919cdf0e10cSrcweir         pData = maData[ nPos ];
1920cdf0e10cSrcweir     else
1921cdf0e10cSrcweir         pData = NULL;
1922cdf0e10cSrcweir 
1923cdf0e10cSrcweir     if ( pData )
1924cdf0e10cSrcweir         if ( ! pData->mbModified )
1925cdf0e10cSrcweir             return pData->mnCurPos;
1926cdf0e10cSrcweir         else
1927cdf0e10cSrcweir         {
1928cdf0e10cSrcweir             OSL_ENSURE( sal_False, "SortedEntryList: Can't get value for modified entry!");
1929cdf0e10cSrcweir             return 0;
1930cdf0e10cSrcweir         }
1931cdf0e10cSrcweir     else
1932cdf0e10cSrcweir     {
1933cdf0e10cSrcweir         OSL_ENSURE( sal_False, "SortedEntryList: invalid pos!");
1934cdf0e10cSrcweir         return 0;
1935cdf0e10cSrcweir     }
1936cdf0e10cSrcweir }
1937cdf0e10cSrcweir 
1938cdf0e10cSrcweir //-------------------------------------------------------------------------
1939cdf0e10cSrcweir //-------------------------------------------------------------------------
1940cdf0e10cSrcweir //-------------------------------------------------------------------------
Remove(sal_uInt32 nPos)1941cdf0e10cSrcweir void SimpleList::Remove( sal_uInt32 nPos )
1942cdf0e10cSrcweir {
1943cdf0e10cSrcweir     if ( nPos < (sal_uInt32) maData.size() )
1944cdf0e10cSrcweir     {
1945cdf0e10cSrcweir         maData.erase( maData.begin() + nPos );
1946cdf0e10cSrcweir     }
1947cdf0e10cSrcweir }
1948cdf0e10cSrcweir 
1949cdf0e10cSrcweir //-------------------------------------------------------------------------
Remove(void * pData)1950cdf0e10cSrcweir void SimpleList::Remove( void* pData )
1951cdf0e10cSrcweir {
1952cdf0e10cSrcweir     sal_Bool    bFound = sal_False;
1953cdf0e10cSrcweir     sal_uInt32  i;
1954cdf0e10cSrcweir 
1955cdf0e10cSrcweir     for ( i = 0; i < (sal_uInt32) maData.size(); i++ )
1956cdf0e10cSrcweir     {
1957cdf0e10cSrcweir         if ( maData[ i ] == pData )
1958cdf0e10cSrcweir         {
1959cdf0e10cSrcweir             bFound = sal_True;
1960cdf0e10cSrcweir             break;
1961cdf0e10cSrcweir         }
1962cdf0e10cSrcweir     }
1963cdf0e10cSrcweir 
1964cdf0e10cSrcweir     if ( bFound )
1965cdf0e10cSrcweir         maData.erase( maData.begin() + i );
1966cdf0e10cSrcweir }
1967cdf0e10cSrcweir 
1968cdf0e10cSrcweir //-------------------------------------------------------------------------
Insert(void * pData,sal_uInt32 nPos)1969cdf0e10cSrcweir void SimpleList::Insert( void* pData, sal_uInt32 nPos )
1970cdf0e10cSrcweir {
1971cdf0e10cSrcweir     if ( nPos < (sal_uInt32) maData.size() )
1972cdf0e10cSrcweir         maData.insert( maData.begin() + nPos, pData );
1973cdf0e10cSrcweir     else
1974cdf0e10cSrcweir         maData.push_back( pData );
1975cdf0e10cSrcweir }
1976cdf0e10cSrcweir 
1977cdf0e10cSrcweir //-------------------------------------------------------------------------
GetObject(sal_uInt32 nPos) const1978cdf0e10cSrcweir void* SimpleList::GetObject( sal_uInt32 nPos ) const
1979cdf0e10cSrcweir {
1980cdf0e10cSrcweir     if ( nPos < (sal_uInt32) maData.size() )
1981cdf0e10cSrcweir         return maData[ nPos ];
1982cdf0e10cSrcweir     else
1983cdf0e10cSrcweir         return NULL;
1984cdf0e10cSrcweir }
1985cdf0e10cSrcweir 
1986cdf0e10cSrcweir //-------------------------------------------------------------------------
Replace(void * pData,sal_uInt32 nPos)1987cdf0e10cSrcweir void SimpleList::Replace( void* pData, sal_uInt32 nPos )
1988cdf0e10cSrcweir {
1989cdf0e10cSrcweir     if ( nPos < (sal_uInt32) maData.size() )
1990cdf0e10cSrcweir         maData[ nPos ] = pData;
1991cdf0e10cSrcweir }
1992cdf0e10cSrcweir 
1993cdf0e10cSrcweir //-------------------------------------------------------------------------
1994cdf0e10cSrcweir //
1995cdf0e10cSrcweir // class SRSPropertySetInfo.
1996cdf0e10cSrcweir //
1997cdf0e10cSrcweir //-------------------------------------------------------------------------
1998cdf0e10cSrcweir 
SRSPropertySetInfo()1999cdf0e10cSrcweir SRSPropertySetInfo::SRSPropertySetInfo()
2000cdf0e10cSrcweir {
2001cdf0e10cSrcweir     maProps[0].Name = OUString::createFromAscii( "RowCount" );
2002cdf0e10cSrcweir     maProps[0].Handle = -1;
2003cdf0e10cSrcweir     maProps[0].Type = ::getCppuType( (const OUString*) NULL );
2004cdf0e10cSrcweir     maProps[0].Attributes = -1;
2005cdf0e10cSrcweir 
2006cdf0e10cSrcweir     maProps[1].Name = OUString::createFromAscii( "IsRowCountFinal" );
2007cdf0e10cSrcweir     maProps[1].Handle = -1;
2008cdf0e10cSrcweir     maProps[1].Type = ::getBooleanCppuType();
2009cdf0e10cSrcweir     maProps[1].Attributes = -1;
2010cdf0e10cSrcweir }
2011cdf0e10cSrcweir 
2012cdf0e10cSrcweir //-------------------------------------------------------------------------
~SRSPropertySetInfo()2013cdf0e10cSrcweir SRSPropertySetInfo::~SRSPropertySetInfo()
2014cdf0e10cSrcweir {}
2015cdf0e10cSrcweir 
2016cdf0e10cSrcweir //-------------------------------------------------------------------------
2017cdf0e10cSrcweir // XInterface methods.
2018cdf0e10cSrcweir //-------------------------------------------------------------------------
2019cdf0e10cSrcweir 
2020cdf0e10cSrcweir XINTERFACE_IMPL_2( SRSPropertySetInfo,
2021cdf0e10cSrcweir                    XTypeProvider,
2022cdf0e10cSrcweir                    XPropertySetInfo );
2023cdf0e10cSrcweir 
2024cdf0e10cSrcweir //-------------------------------------------------------------------------
2025cdf0e10cSrcweir // XTypeProvider methods.
2026cdf0e10cSrcweir //-------------------------------------------------------------------------
2027cdf0e10cSrcweir 
2028cdf0e10cSrcweir XTYPEPROVIDER_IMPL_2( SRSPropertySetInfo,
2029cdf0e10cSrcweir                       XTypeProvider,
2030cdf0e10cSrcweir                       XPropertySetInfo );
2031cdf0e10cSrcweir 
2032cdf0e10cSrcweir //-------------------------------------------------------------------------
2033cdf0e10cSrcweir // XPropertySetInfo methods.
2034cdf0e10cSrcweir //-------------------------------------------------------------------------
2035cdf0e10cSrcweir Sequence< Property > SAL_CALL
getProperties()2036cdf0e10cSrcweir SRSPropertySetInfo::getProperties() throw( RuntimeException )
2037cdf0e10cSrcweir {
2038cdf0e10cSrcweir     return Sequence < Property > ( maProps, 2 );
2039cdf0e10cSrcweir }
2040cdf0e10cSrcweir 
2041cdf0e10cSrcweir //-------------------------------------------------------------------------
2042cdf0e10cSrcweir Property SAL_CALL
getPropertyByName(const OUString & Name)2043cdf0e10cSrcweir SRSPropertySetInfo::getPropertyByName( const OUString& Name )
2044cdf0e10cSrcweir     throw( UnknownPropertyException, RuntimeException )
2045cdf0e10cSrcweir {
2046cdf0e10cSrcweir     if ( Name.compareToAscii( "RowCount" ) == 0 )
2047cdf0e10cSrcweir         return maProps[0];
2048cdf0e10cSrcweir     else if ( Name.compareToAscii( "IsRowCountFinal" ) == 0 )
2049cdf0e10cSrcweir         return maProps[1];
2050cdf0e10cSrcweir     else
2051cdf0e10cSrcweir         throw UnknownPropertyException();
2052cdf0e10cSrcweir }
2053cdf0e10cSrcweir 
2054cdf0e10cSrcweir //-------------------------------------------------------------------------
2055cdf0e10cSrcweir sal_Bool SAL_CALL
hasPropertyByName(const OUString & Name)2056cdf0e10cSrcweir SRSPropertySetInfo::hasPropertyByName( const OUString& Name )
2057cdf0e10cSrcweir     throw( RuntimeException )
2058cdf0e10cSrcweir {
2059cdf0e10cSrcweir     if ( Name.compareToAscii( "RowCount" ) == 0 )
2060cdf0e10cSrcweir         return sal_True;
2061cdf0e10cSrcweir     else if ( Name.compareToAscii( "IsRowCountFinal" ) == 0 )
2062cdf0e10cSrcweir         return sal_True;
2063cdf0e10cSrcweir     else
2064cdf0e10cSrcweir         return sal_False;
2065cdf0e10cSrcweir }
2066cdf0e10cSrcweir 
2067