fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / sorter / sortresult.cxx
blob5e4c81e9612586877a5a70e65f4a756f521f55a9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <vector>
22 #include <sortresult.hxx>
23 #include <com/sun/star/sdbc/DataType.hpp>
24 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
25 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
26 #include <com/sun/star/ucb/ListActionType.hpp>
27 #include <com/sun/star/ucb/XAnyCompare.hpp>
28 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
29 #include <cppuhelper/implbase1.hxx>
30 #include <cppuhelper/interfacecontainer.hxx>
31 #include <cppuhelper/supportsservice.hxx>
32 #include <osl/diagnose.h>
33 #include <boost/scoped_array.hpp>
35 using namespace com::sun::star::beans;
36 using namespace com::sun::star::container;
37 using namespace com::sun::star::io;
38 using namespace com::sun::star::lang;
39 using namespace com::sun::star::sdbc;
40 using namespace com::sun::star::ucb;
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::util;
43 using namespace cppu;
48 // The mutex to synchronize access to containers.
49 static osl::Mutex& getContainerMutex()
51 static osl::Mutex* pMutex = NULL;
52 if( !pMutex )
54 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
55 if( !pMutex )
57 static osl::Mutex aMutex;
58 pMutex = &aMutex;
62 return *pMutex;
67 struct SortInfo
69 bool mbUseOwnCompare;
70 bool mbAscending;
71 bool mbCaseSensitive;
72 sal_Int32 mnColumn;
73 sal_Int32 mnType;
74 SortInfo* mpNext;
75 Reference < XAnyCompare > mxCompareFunction;
80 struct SortListData
82 bool mbModified;
83 sal_IntPtr mnCurPos;
84 sal_IntPtr mnOldPos;
86 SortListData( sal_IntPtr nPos, bool bModified = false );
91 // class SRSPropertySetInfo.
95 class SRSPropertySetInfo : public cppu::WeakImplHelper1 <
96 XPropertySetInfo >
98 Property maProps[2];
100 private:
102 public:
103 SRSPropertySetInfo();
104 virtual ~SRSPropertySetInfo();
106 // XPropertySetInfo
107 virtual Sequence< Property > SAL_CALL getProperties()
108 throw( RuntimeException, std::exception ) SAL_OVERRIDE;
109 virtual Property SAL_CALL getPropertyByName( const OUString& aName )
110 throw( UnknownPropertyException, RuntimeException, std::exception ) SAL_OVERRIDE;
111 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name )
112 throw( RuntimeException, std::exception ) SAL_OVERRIDE;
115 typedef OMultiTypeInterfaceContainerHelperVar<OUString>
116 PropertyChangeListenerContainer_Impl;
118 class PropertyChangeListeners_Impl : public PropertyChangeListenerContainer_Impl
120 public:
121 PropertyChangeListeners_Impl()
122 : PropertyChangeListenerContainer_Impl( getContainerMutex() ) {}
126 SortedResultSet::SortedResultSet( Reference< XResultSet > aResult )
128 mpDisposeEventListeners = NULL;
129 mpPropChangeListeners = NULL;
130 mpVetoChangeListeners = NULL;
131 mpPropSetInfo = NULL;
133 mxOriginal = aResult;
134 mpSortInfo = NULL;
135 mnLastSort = 0;
136 mnCurEntry = 0;
137 mnCount = 0;
138 mbIsCopy = false;
142 SortedResultSet::~SortedResultSet()
144 mxOriginal.clear();
145 mxOther.clear();
147 if ( !mbIsCopy )
149 SortInfo *pInfo = mpSortInfo;
150 while ( pInfo )
152 mpSortInfo = pInfo->mpNext;
153 delete pInfo;
154 pInfo = mpSortInfo;
158 mpSortInfo = NULL;
160 if ( mpPropSetInfo )
161 mpPropSetInfo->release();
163 delete mpPropChangeListeners;
164 delete mpVetoChangeListeners;
168 // XServiceInfo methods.
170 OUString SAL_CALL SortedResultSet::getImplementationName()
171 throw( css::uno::RuntimeException, std::exception )
173 return getImplementationName_Static();
176 OUString SortedResultSet::getImplementationName_Static()
178 return OUString( "com.sun.star.comp.ucb.SortedResultSet" );
181 sal_Bool SAL_CALL SortedResultSet::supportsService( const OUString& ServiceName )
182 throw( css::uno::RuntimeException, std::exception )
184 return cppu::supportsService( this, ServiceName );
187 css::uno::Sequence< OUString > SAL_CALL SortedResultSet::getSupportedServiceNames()
188 throw( css::uno::RuntimeException, std::exception )
190 return getSupportedServiceNames_Static();
193 css::uno::Sequence< OUString >SortedResultSet::getSupportedServiceNames_Static()
195 css::uno::Sequence< OUString > aSNS( 1 );
196 aSNS.getArray()[ 0 ] = RESULTSET_SERVICE_NAME;
197 return aSNS;
201 // XComponent methods.
203 void SAL_CALL SortedResultSet::dispose()
204 throw( RuntimeException, std::exception )
206 osl::Guard< osl::Mutex > aGuard( maMutex );
208 if ( mpDisposeEventListeners && mpDisposeEventListeners->getLength() )
210 EventObject aEvt;
211 aEvt.Source = static_cast< XComponent * >( this );
212 mpDisposeEventListeners->disposeAndClear( aEvt );
215 if ( mpPropChangeListeners )
217 EventObject aEvt;
218 aEvt.Source = static_cast< XPropertySet * >( this );
219 mpPropChangeListeners->disposeAndClear( aEvt );
222 if ( mpVetoChangeListeners )
224 EventObject aEvt;
225 aEvt.Source = static_cast< XPropertySet * >( this );
226 mpVetoChangeListeners->disposeAndClear( aEvt );
229 mxOriginal.clear();
230 mxOther.clear();
234 void SAL_CALL SortedResultSet::addEventListener(
235 const Reference< XEventListener >& Listener )
236 throw( RuntimeException, std::exception )
238 osl::Guard< osl::Mutex > aGuard( maMutex );
240 if ( !mpDisposeEventListeners )
241 mpDisposeEventListeners =
242 new OInterfaceContainerHelper( getContainerMutex() );
244 mpDisposeEventListeners->addInterface( Listener );
248 void SAL_CALL SortedResultSet::removeEventListener(
249 const Reference< XEventListener >& Listener )
250 throw( RuntimeException, std::exception )
252 osl::Guard< osl::Mutex > aGuard( maMutex );
254 if ( mpDisposeEventListeners )
255 mpDisposeEventListeners->removeInterface( Listener );
259 // XContentAccess methods.
262 OUString SAL_CALL
263 SortedResultSet::queryContentIdentifierString()
264 throw( RuntimeException, std::exception )
266 osl::Guard< osl::Mutex > aGuard( maMutex );
267 return Reference< XContentAccess >::query(mxOriginal)->queryContentIdentifierString();
271 Reference< XContentIdentifier > SAL_CALL
272 SortedResultSet::queryContentIdentifier()
273 throw( RuntimeException, std::exception )
275 osl::Guard< osl::Mutex > aGuard( maMutex );
276 return Reference< XContentAccess >::query(mxOriginal)->queryContentIdentifier();
280 Reference< XContent > SAL_CALL
281 SortedResultSet::queryContent()
282 throw( RuntimeException, std::exception )
284 osl::Guard< osl::Mutex > aGuard( maMutex );
285 return Reference< XContentAccess >::query(mxOriginal)->queryContent();
290 // XResultSet methods.
292 sal_Bool SAL_CALL SortedResultSet::next()
293 throw ( SQLException, RuntimeException, std::exception )
295 osl::Guard< osl::Mutex > aGuard( maMutex );
297 mnCurEntry++;
299 if ( mnCurEntry > 0 )
301 if ( mnCurEntry <= mnCount )
303 sal_Int32 nIndex = maS2O[ mnCurEntry ];
304 return mxOriginal->absolute( nIndex );
306 else
308 mnCurEntry = mnCount + 1;
311 return sal_False;
315 sal_Bool SAL_CALL SortedResultSet::isBeforeFirst()
316 throw ( SQLException, RuntimeException, std::exception )
318 if ( mnCurEntry )
319 return sal_False;
320 else
321 return sal_True;
325 sal_Bool SAL_CALL SortedResultSet::isAfterLast()
326 throw ( SQLException, RuntimeException, std::exception )
328 if ( mnCurEntry > mnCount )
329 return sal_True;
330 else
331 return sal_False;
335 sal_Bool SAL_CALL SortedResultSet::isFirst()
336 throw ( SQLException, RuntimeException, std::exception )
338 if ( mnCurEntry == 1 )
339 return sal_True;
340 else
341 return sal_False;
345 sal_Bool SAL_CALL SortedResultSet::isLast()
346 throw ( SQLException, RuntimeException, std::exception )
348 if ( mnCurEntry == mnCount )
349 return sal_True;
350 else
351 return sal_False;
355 void SAL_CALL SortedResultSet::beforeFirst()
356 throw ( SQLException, RuntimeException, std::exception )
358 osl::Guard< osl::Mutex > aGuard( maMutex );
359 mnCurEntry = 0;
360 mxOriginal->beforeFirst();
364 void SAL_CALL SortedResultSet::afterLast()
365 throw ( SQLException, RuntimeException, std::exception )
367 osl::Guard< osl::Mutex > aGuard( maMutex );
368 mnCurEntry = mnCount+1;
369 mxOriginal->afterLast();
373 sal_Bool SAL_CALL SortedResultSet::first()
374 throw ( SQLException, RuntimeException, std::exception )
376 osl::Guard< osl::Mutex > aGuard( maMutex );
378 if ( mnCount )
380 mnCurEntry = 1;
381 sal_Int32 nIndex = maS2O[ mnCurEntry ];
382 return mxOriginal->absolute( nIndex );
384 else
386 mnCurEntry = 0;
387 return sal_False;
392 sal_Bool SAL_CALL SortedResultSet::last()
393 throw ( SQLException, RuntimeException, std::exception )
395 osl::Guard< osl::Mutex > aGuard( maMutex );
397 if ( mnCount )
399 mnCurEntry = mnCount;
400 sal_Int32 nIndex = maS2O[ mnCurEntry ];
401 return mxOriginal->absolute( nIndex );
403 else
405 mnCurEntry = 0;
406 return sal_False;
411 sal_Int32 SAL_CALL SortedResultSet::getRow()
412 throw ( SQLException, RuntimeException, std::exception )
414 return mnCurEntry;
419 moves the cursor to the given row number in the result set.
420 <p>If the row number is positive, the cursor moves to the given row
421 number with respect to the beginning of the result set. The first
422 row is row 1, the second is row 2, and so on.
423 <p>If the given row number is negative, the cursor moves to an
424 absolute row position with respect to the end of the result set.
425 For example, calling <code>moveToPosition(-1)</code> positions the
426 cursor on the last row, <code>moveToPosition(-2)</code> indicates the
427 next-to-last row, and so on.
428 <p>An attempt to position the cursor beyond the first/last row in the
429 result set leaves the cursor before/after the first/last row,
430 respectively.
431 <p>Note: Calling <code>moveToPosition(1)</code> is the same
432 as calling <code>moveToFirst()</code>. Calling
433 <code>moveToPosition(-1)</code> is the same as calling
434 <code>moveToLast()</code>.
435 @param row
436 is the number of rows to move. Could be negative.
437 @returns
438 <TRUE/> if the cursor is on a row; <FALSE/> otherwise
439 @throws SQLException
440 if a database access error occurs or if row is 0, or the result set
441 type is FORWARD_ONLY.
443 sal_Bool SAL_CALL SortedResultSet::absolute( sal_Int32 row )
444 throw ( SQLException, RuntimeException, std::exception )
446 osl::Guard< osl::Mutex > aGuard( maMutex );
448 sal_Int32 nIndex;
450 if ( row > 0 )
452 if ( row <= mnCount )
454 mnCurEntry = row;
455 nIndex = maS2O[ mnCurEntry ];
456 return mxOriginal->absolute( nIndex );
458 else
460 mnCurEntry = mnCount + 1;
461 return sal_False;
464 else if ( row == 0 )
466 throw SQLException();
468 else
470 if ( mnCount + row + 1 > 0 )
472 mnCurEntry = mnCount + row + 1;
473 nIndex = maS2O[ mnCurEntry ];
474 return mxOriginal->absolute( nIndex );
476 else
478 mnCurEntry = 0;
479 return sal_False;
486 moves the cursor a relative number of rows, either positive or negative.
488 Attempting to move beyond the first/last row in the result set positions
489 the cursor before/after the first/last row. Calling
490 <code>moveRelative(0)</code> is valid, but does not change the cursor
491 position.
492 <p>Note: Calling <code>moveRelative(1)</code> is different from calling
493 <code>moveNext()</code> because is makes sense to call
494 <code>moveNext()</code> when there is no current row, for example,
495 when the cursor is positioned before the first row or after the last
496 row of the result set.
497 @param rows
498 is the number of rows to move. Could be negative.
499 @returns
500 <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off
501 the result set.
502 @throws SQLException
503 if a database access error occurs or if there is no
504 current row, or the result set type is FORWARD_ONLY.
506 sal_Bool SAL_CALL SortedResultSet::relative( sal_Int32 rows )
507 throw ( SQLException, RuntimeException, std::exception )
509 osl::Guard< osl::Mutex > aGuard( maMutex );
511 if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
513 throw SQLException();
516 if ( rows == 0 )
517 return sal_True;
519 sal_Int32 nTmp = mnCurEntry + rows;
521 if ( nTmp <= 0 )
523 mnCurEntry = 0;
524 return sal_False;
526 else if ( nTmp > mnCount )
528 mnCurEntry = mnCount + 1;
529 return sal_False;
531 else
533 mnCurEntry = nTmp;
534 nTmp = maS2O[ mnCurEntry ];
535 return mxOriginal->absolute( nTmp );
541 moves the cursor to the previous row in the result set.
542 <p>Note: <code>previous()</code> is not the same as
543 <code>relative(-1)</code> because it makes sense to call
544 <code>previous()</code> when there is no current row.
545 @returns <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off
546 the result set.
547 @throws SQLException
548 if a database access error occurs or the result set type
549 is FORWARD_ONLY.
551 sal_Bool SAL_CALL SortedResultSet::previous()
552 throw ( SQLException, RuntimeException, std::exception )
554 osl::Guard< osl::Mutex > aGuard( maMutex );
556 mnCurEntry -= 1;
558 if ( mnCurEntry > 0 )
560 if ( mnCurEntry <= mnCount )
562 sal_Int32 nIndex = maS2O[ mnCurEntry ];
563 return mxOriginal->absolute( nIndex );
566 else
567 mnCurEntry = 0;
569 return sal_False;
573 void SAL_CALL SortedResultSet::refreshRow()
574 throw ( SQLException, RuntimeException, std::exception )
576 osl::Guard< osl::Mutex > aGuard( maMutex );
578 if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
580 throw SQLException();
583 mxOriginal->refreshRow();
587 sal_Bool SAL_CALL SortedResultSet::rowUpdated()
588 throw ( SQLException, RuntimeException, std::exception )
590 osl::Guard< osl::Mutex > aGuard( maMutex );
592 if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
594 throw SQLException();
597 return mxOriginal->rowUpdated();
601 sal_Bool SAL_CALL SortedResultSet::rowInserted()
602 throw ( SQLException, RuntimeException, std::exception )
604 osl::Guard< osl::Mutex > aGuard( maMutex );
606 if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
608 throw SQLException();
611 return mxOriginal->rowInserted();
615 sal_Bool SAL_CALL SortedResultSet::rowDeleted()
616 throw ( SQLException, RuntimeException, std::exception )
618 osl::Guard< osl::Mutex > aGuard( maMutex );
620 if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
622 throw SQLException();
625 return mxOriginal->rowDeleted();
629 Reference< XInterface > SAL_CALL SortedResultSet::getStatement()
630 throw ( SQLException, RuntimeException, std::exception )
632 osl::Guard< osl::Mutex > aGuard( maMutex );
634 if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
636 throw SQLException();
639 return mxOriginal->getStatement();
643 // XRow methods.
646 sal_Bool SAL_CALL SortedResultSet::wasNull()
647 throw( SQLException, RuntimeException, std::exception )
649 osl::Guard< osl::Mutex > aGuard( maMutex );
650 return Reference< XRow >::query(mxOriginal)->wasNull();
654 OUString SAL_CALL SortedResultSet::getString( sal_Int32 columnIndex )
655 throw( SQLException, RuntimeException, std::exception )
657 osl::Guard< osl::Mutex > aGuard( maMutex );
658 return Reference< XRow >::query(mxOriginal)->getString( columnIndex );
662 sal_Bool SAL_CALL SortedResultSet::getBoolean( sal_Int32 columnIndex )
663 throw( SQLException, RuntimeException, std::exception )
665 osl::Guard< osl::Mutex > aGuard( maMutex );
666 return Reference< XRow >::query(mxOriginal)->getBoolean( columnIndex );
670 sal_Int8 SAL_CALL SortedResultSet::getByte( sal_Int32 columnIndex )
671 throw( SQLException, RuntimeException, std::exception )
673 osl::Guard< osl::Mutex > aGuard( maMutex );
674 return Reference< XRow >::query(mxOriginal)->getByte( columnIndex );
678 sal_Int16 SAL_CALL SortedResultSet::getShort( sal_Int32 columnIndex )
679 throw( SQLException, RuntimeException, std::exception )
681 osl::Guard< osl::Mutex > aGuard( maMutex );
682 return Reference< XRow >::query(mxOriginal)->getShort( columnIndex );
686 sal_Int32 SAL_CALL SortedResultSet::getInt( sal_Int32 columnIndex )
687 throw( SQLException, RuntimeException, std::exception )
689 osl::Guard< osl::Mutex > aGuard( maMutex );
690 return Reference< XRow >::query(mxOriginal)->getInt( columnIndex );
693 sal_Int64 SAL_CALL SortedResultSet::getLong( sal_Int32 columnIndex )
694 throw( SQLException, RuntimeException, std::exception )
696 osl::Guard< osl::Mutex > aGuard( maMutex );
697 return Reference< XRow >::query(mxOriginal)->getLong( columnIndex );
701 float SAL_CALL SortedResultSet::getFloat( sal_Int32 columnIndex )
702 throw( SQLException, RuntimeException, std::exception )
704 osl::Guard< osl::Mutex > aGuard( maMutex );
705 return Reference< XRow >::query(mxOriginal)->getFloat( columnIndex );
709 double SAL_CALL SortedResultSet::getDouble( sal_Int32 columnIndex )
710 throw( SQLException, RuntimeException, std::exception )
712 osl::Guard< osl::Mutex > aGuard( maMutex );
713 return Reference< XRow >::query(mxOriginal)->getDouble( columnIndex );
717 Sequence< sal_Int8 > SAL_CALL SortedResultSet::getBytes( sal_Int32 columnIndex )
718 throw( SQLException, RuntimeException, std::exception )
720 osl::Guard< osl::Mutex > aGuard( maMutex );
721 return Reference< XRow >::query(mxOriginal)->getBytes( columnIndex );
725 Date SAL_CALL SortedResultSet::getDate( sal_Int32 columnIndex )
726 throw( SQLException, RuntimeException, std::exception )
728 osl::Guard< osl::Mutex > aGuard( maMutex );
729 return Reference< XRow >::query(mxOriginal)->getDate( columnIndex );
733 Time SAL_CALL SortedResultSet::getTime( sal_Int32 columnIndex )
734 throw( SQLException, RuntimeException, std::exception )
736 osl::Guard< osl::Mutex > aGuard( maMutex );
737 return Reference< XRow >::query(mxOriginal)->getTime( columnIndex );
741 DateTime SAL_CALL SortedResultSet::getTimestamp( sal_Int32 columnIndex )
742 throw( SQLException, RuntimeException, std::exception )
744 osl::Guard< osl::Mutex > aGuard( maMutex );
745 return Reference< XRow >::query(mxOriginal)->getTimestamp( columnIndex );
749 Reference< XInputStream > SAL_CALL
750 SortedResultSet::getBinaryStream( sal_Int32 columnIndex )
751 throw( SQLException, RuntimeException, std::exception )
753 osl::Guard< osl::Mutex > aGuard( maMutex );
754 return Reference< XRow >::query(mxOriginal)->getBinaryStream( columnIndex );
758 Reference< XInputStream > SAL_CALL
759 SortedResultSet::getCharacterStream( sal_Int32 columnIndex )
760 throw( SQLException, RuntimeException, std::exception )
762 osl::Guard< osl::Mutex > aGuard( maMutex );
763 return Reference< XRow >::query(mxOriginal)->getCharacterStream( columnIndex );
767 Any SAL_CALL SortedResultSet::getObject( sal_Int32 columnIndex,
768 const Reference< XNameAccess >& typeMap )
769 throw( SQLException, RuntimeException, std::exception )
771 osl::Guard< osl::Mutex > aGuard( maMutex );
772 return Reference< XRow >::query(mxOriginal)->getObject( columnIndex,
773 typeMap);
777 Reference< XRef > SAL_CALL SortedResultSet::getRef( sal_Int32 columnIndex )
778 throw( SQLException, RuntimeException, std::exception )
780 osl::Guard< osl::Mutex > aGuard( maMutex );
781 return Reference< XRow >::query(mxOriginal)->getRef( columnIndex );
785 Reference< XBlob > SAL_CALL SortedResultSet::getBlob( sal_Int32 columnIndex )
786 throw( SQLException, RuntimeException, std::exception )
788 osl::Guard< osl::Mutex > aGuard( maMutex );
789 return Reference< XRow >::query(mxOriginal)->getBlob( columnIndex );
793 Reference< XClob > SAL_CALL SortedResultSet::getClob( sal_Int32 columnIndex )
794 throw( SQLException, RuntimeException, std::exception )
796 osl::Guard< osl::Mutex > aGuard( maMutex );
797 return Reference< XRow >::query(mxOriginal)->getClob( columnIndex );
801 Reference< XArray > SAL_CALL SortedResultSet::getArray( sal_Int32 columnIndex )
802 throw( SQLException, RuntimeException, std::exception )
804 osl::Guard< osl::Mutex > aGuard( maMutex );
805 return Reference< XRow >::query(mxOriginal)->getArray( columnIndex );
810 // XCloseable methods.
813 void SAL_CALL SortedResultSet::close()
814 throw( SQLException, RuntimeException, std::exception )
816 osl::Guard< osl::Mutex > aGuard( maMutex );
817 Reference< XCloseable >::query(mxOriginal)->close();
821 // XResultSetMetaDataSupplier methods.
824 Reference< XResultSetMetaData > SAL_CALL SortedResultSet::getMetaData()
825 throw( SQLException, RuntimeException, std::exception )
827 osl::Guard< osl::Mutex > aGuard( maMutex );
828 return Reference< XResultSetMetaDataSupplier >::query(mxOriginal)->getMetaData();
833 // XPropertySet methods.
836 Reference< XPropertySetInfo > SAL_CALL
837 SortedResultSet::getPropertySetInfo() throw( RuntimeException, std::exception )
839 osl::Guard< osl::Mutex > aGuard( maMutex );
841 if ( !mpPropSetInfo )
843 mpPropSetInfo = new SRSPropertySetInfo();
844 mpPropSetInfo->acquire();
847 return Reference< XPropertySetInfo >( mpPropSetInfo );
851 void SAL_CALL SortedResultSet::setPropertyValue(
852 const OUString& PropertyName,
853 const Any& )
854 throw( UnknownPropertyException,
855 PropertyVetoException,
856 IllegalArgumentException,
857 WrappedTargetException,
858 RuntimeException, std::exception )
860 osl::Guard< osl::Mutex > aGuard( maMutex );
862 if ( PropertyName == "RowCount" || PropertyName == "IsRowCountFinal" )
863 throw IllegalArgumentException();
864 else
865 throw UnknownPropertyException();
869 Any SAL_CALL SortedResultSet::getPropertyValue( const OUString& PropertyName )
870 throw( UnknownPropertyException,
871 WrappedTargetException,
872 RuntimeException, std::exception )
874 osl::Guard< osl::Mutex > aGuard( maMutex );
876 Any aRet;
878 if ( PropertyName == "RowCount" )
880 aRet <<= maS2O.Count();
882 else if ( PropertyName == "IsRowCountFinal" )
884 bool bOrgFinal = false;
885 Any aOrgRet;
887 aRet <<= false;
889 aOrgRet = Reference< XPropertySet >::query(mxOriginal)->
890 getPropertyValue( PropertyName );
891 aOrgRet >>= bOrgFinal;
893 if ( bOrgFinal )
895 aOrgRet = Reference< XPropertySet >::query(mxOriginal)->
896 getPropertyValue("RowCount");
897 sal_uInt32 nOrgCount = 0;
898 aOrgRet >>= nOrgCount;
899 if ( nOrgCount == maS2O.Count() )
900 aRet <<= true;
903 else
904 throw UnknownPropertyException();
906 return aRet;
910 void SAL_CALL SortedResultSet::addPropertyChangeListener(
911 const OUString& PropertyName,
912 const Reference< XPropertyChangeListener >& Listener )
913 throw( UnknownPropertyException,
914 WrappedTargetException,
915 RuntimeException, std::exception )
917 osl::Guard< osl::Mutex > aGuard( maMutex );
919 if ( !mpPropChangeListeners )
920 mpPropChangeListeners =
921 new PropertyChangeListeners_Impl();
923 mpPropChangeListeners->addInterface( PropertyName, Listener );
927 void SAL_CALL SortedResultSet::removePropertyChangeListener(
928 const OUString& PropertyName,
929 const Reference< XPropertyChangeListener >& Listener )
930 throw( UnknownPropertyException,
931 WrappedTargetException,
932 RuntimeException, std::exception )
934 osl::Guard< osl::Mutex > aGuard( maMutex );
936 if ( mpPropChangeListeners )
937 mpPropChangeListeners->removeInterface( PropertyName, Listener );
941 void SAL_CALL SortedResultSet::addVetoableChangeListener(
942 const OUString& PropertyName,
943 const Reference< XVetoableChangeListener >& Listener )
944 throw( UnknownPropertyException,
945 WrappedTargetException,
946 RuntimeException, std::exception )
948 osl::Guard< osl::Mutex > aGuard( maMutex );
950 if ( !mpVetoChangeListeners )
951 mpVetoChangeListeners =
952 new PropertyChangeListeners_Impl();
954 mpVetoChangeListeners->addInterface( PropertyName, Listener );
958 void SAL_CALL SortedResultSet::removeVetoableChangeListener(
959 const OUString& PropertyName,
960 const Reference< XVetoableChangeListener >& Listener )
961 throw( UnknownPropertyException,
962 WrappedTargetException,
963 RuntimeException, std::exception )
965 osl::Guard< osl::Mutex > aGuard( maMutex );
967 if ( mpVetoChangeListeners )
968 mpVetoChangeListeners->removeInterface( PropertyName, Listener );
972 // private methods
974 sal_IntPtr SortedResultSet::CompareImpl( Reference < XResultSet > xResultOne,
975 Reference < XResultSet > xResultTwo,
976 sal_IntPtr nIndexOne, sal_IntPtr nIndexTwo,
977 SortInfo* pSortInfo )
979 throw( SQLException, RuntimeException )
981 Reference < XRow > xRowOne = Reference< XRow >::query( xResultOne );
982 Reference < XRow > xRowTwo = Reference< XRow >::query( xResultTwo );
984 sal_IntPtr nCompare = 0;
985 sal_IntPtr nColumn = pSortInfo->mnColumn;
987 switch ( pSortInfo->mnType )
989 case DataType::BIT :
990 case DataType::TINYINT :
991 case DataType::SMALLINT :
992 case DataType::INTEGER :
994 sal_Int32 aOne = 0;
995 sal_Int32 aTwo = 0;
997 if ( xResultOne->absolute( nIndexOne ) )
998 aOne = xRowOne->getInt( nColumn );
999 if ( xResultTwo->absolute( nIndexTwo ) )
1000 aTwo = xRowTwo->getInt( nColumn );
1002 if ( aOne < aTwo )
1003 nCompare = -1;
1004 else if ( aOne == aTwo )
1005 nCompare = 0;
1006 else
1007 nCompare = 1;
1009 break;
1011 case DataType::BIGINT :
1013 sal_Int64 aOne = 0;
1014 sal_Int64 aTwo = 0;
1016 if ( xResultOne->absolute( nIndexOne ) )
1017 aOne = xRowOne->getLong( nColumn );
1018 if ( xResultTwo->absolute( nIndexTwo ) )
1019 aTwo = xRowTwo->getLong( nColumn );
1021 if ( aOne < aTwo )
1022 nCompare = -1;
1023 else if ( aOne == aTwo )
1024 nCompare = 0;
1025 else
1026 nCompare = 1;
1028 break;
1030 case DataType::CHAR :
1031 case DataType::VARCHAR :
1032 case DataType::LONGVARCHAR :
1034 OUString aOne, aTwo;
1036 if ( xResultOne->absolute( nIndexOne ) )
1037 aOne = xRowOne->getString( nColumn );
1038 if ( xResultTwo->absolute( nIndexTwo ) )
1039 aTwo = xRowTwo->getString( nColumn );
1041 if ( ! pSortInfo->mbCaseSensitive )
1043 aOne = aOne.toAsciiLowerCase();
1044 aTwo = aTwo.toAsciiLowerCase();
1047 nCompare = aOne.compareTo( aTwo );
1048 break;
1050 case DataType::DATE :
1052 Date aOne, aTwo;
1053 sal_Int32 nTmp;
1055 if ( xResultOne->absolute( nIndexOne ) )
1056 aOne = xRowOne->getDate( nColumn );
1057 if ( xResultTwo->absolute( nIndexTwo ) )
1058 aTwo = xRowTwo->getDate( nColumn );
1060 nTmp = (sal_Int32) aTwo.Year - (sal_Int32) aOne.Year;
1061 if ( !nTmp ) {
1062 nTmp = (sal_Int32) aTwo.Month - (sal_Int32) aOne.Month;
1063 if ( !nTmp )
1064 nTmp = (sal_Int32) aTwo.Day - (sal_Int32) aOne.Day;
1067 if ( nTmp < 0 )
1068 nCompare = -1;
1069 else if ( nTmp == 0 )
1070 nCompare = 0;
1071 else
1072 nCompare = 1;
1074 break;
1076 case DataType::TIME :
1078 Time aOne, aTwo;
1079 sal_Int32 nTmp;
1081 if ( xResultOne->absolute( nIndexOne ) )
1082 aOne = xRowOne->getTime( nColumn );
1083 if ( xResultTwo->absolute( nIndexTwo ) )
1084 aTwo = xRowTwo->getTime( nColumn );
1086 nTmp = (sal_Int32) aTwo.Hours - (sal_Int32) aOne.Hours;
1087 if ( !nTmp ) {
1088 nTmp = (sal_Int32) aTwo.Minutes - (sal_Int32) aOne.Minutes;
1089 if ( !nTmp ) {
1090 nTmp = (sal_Int32) aTwo.Seconds - (sal_Int32) aOne.Seconds;
1091 if ( !nTmp )
1092 nTmp = (sal_Int32) aTwo.NanoSeconds
1093 - (sal_Int32) aOne.NanoSeconds;
1096 if ( nTmp < 0 )
1097 nCompare = -1;
1098 else if ( nTmp == 0 )
1099 nCompare = 0;
1100 else
1101 nCompare = 1;
1103 break;
1105 case DataType::TIMESTAMP :
1107 DateTime aOne, aTwo;
1108 sal_Int32 nTmp;
1110 if ( xResultOne->absolute( nIndexOne ) )
1111 aOne = xRowOne->getTimestamp( nColumn );
1112 if ( xResultTwo->absolute( nIndexTwo ) )
1113 aTwo = xRowTwo->getTimestamp( nColumn );
1115 nTmp = (sal_Int32) aTwo.Year - (sal_Int32) aOne.Year;
1116 if ( !nTmp ) {
1117 nTmp = (sal_Int32) aTwo.Month - (sal_Int32) aOne.Month;
1118 if ( !nTmp ) {
1119 nTmp = (sal_Int32) aTwo.Day - (sal_Int32) aOne.Day;
1120 if ( !nTmp ) {
1121 nTmp = (sal_Int32) aTwo.Hours - (sal_Int32) aOne.Hours;
1122 if ( !nTmp ) {
1123 nTmp = (sal_Int32) aTwo.Minutes - (sal_Int32) aOne.Minutes;
1124 if ( !nTmp ) {
1125 nTmp = (sal_Int32) aTwo.Seconds - (sal_Int32) aOne.Seconds;
1126 if ( !nTmp )
1127 nTmp = (sal_Int32) aTwo.NanoSeconds
1128 - (sal_Int32) aOne.NanoSeconds;
1129 }}}}}
1131 if ( nTmp < 0 )
1132 nCompare = -1;
1133 else if ( nTmp == 0 )
1134 nCompare = 0;
1135 else
1136 nCompare = 1;
1138 break;
1140 case DataType::REAL :
1142 float aOne = 0;
1143 float aTwo = 0;
1145 if ( xResultOne->absolute( nIndexOne ) )
1146 aOne = xRowOne->getFloat( nColumn );
1147 if ( xResultTwo->absolute( nIndexTwo ) )
1148 aTwo = xRowTwo->getFloat( nColumn );
1150 if ( aOne < aTwo )
1151 nCompare = -1;
1152 else if ( aOne == aTwo )
1153 nCompare = 0;
1154 else
1155 nCompare = 1;
1157 break;
1159 case DataType::FLOAT :
1160 case DataType::DOUBLE :
1162 double aOne = 0;
1163 double aTwo = 0;
1165 if ( xResultOne->absolute( nIndexOne ) )
1166 aOne = xRowOne->getDouble( nColumn );
1167 if ( xResultTwo->absolute( nIndexTwo ) )
1168 aTwo = xRowTwo->getDouble( nColumn );
1170 if ( aOne < aTwo )
1171 nCompare = -1;
1172 else if ( aOne == aTwo )
1173 nCompare = 0;
1174 else
1175 nCompare = 1;
1177 break;
1179 default:
1181 OSL_FAIL( "DataType not supported for compare!" );
1185 return nCompare;
1189 sal_IntPtr SortedResultSet::CompareImpl( Reference < XResultSet > xResultOne,
1190 Reference < XResultSet > xResultTwo,
1191 sal_IntPtr nIndexOne, sal_IntPtr nIndexTwo )
1192 throw( SQLException, RuntimeException )
1194 sal_IntPtr nCompare = 0;
1195 SortInfo* pInfo = mpSortInfo;
1197 while ( !nCompare && pInfo )
1199 if ( pInfo->mbUseOwnCompare )
1201 nCompare = CompareImpl( xResultOne, xResultTwo,
1202 nIndexOne, nIndexTwo, pInfo );
1204 else
1206 Any aOne, aTwo;
1208 Reference < XRow > xRowOne =
1209 Reference< XRow >::query( xResultOne );
1210 Reference < XRow > xRowTwo =
1211 Reference< XRow >::query( xResultTwo );
1213 if ( xResultOne->absolute( nIndexOne ) )
1214 aOne = xRowOne->getObject( pInfo->mnColumn, NULL );
1215 if ( xResultTwo->absolute( nIndexTwo ) )
1216 aTwo = xRowTwo->getObject( pInfo->mnColumn, NULL );
1218 nCompare = pInfo->mxCompareFunction->compare( aOne, aTwo );
1221 if ( ! pInfo->mbAscending )
1222 nCompare = - nCompare;
1224 pInfo = pInfo->mpNext;
1227 return nCompare;
1231 sal_IntPtr SortedResultSet::Compare( SortListData *pOne,
1232 SortListData *pTwo )
1233 throw( SQLException, RuntimeException )
1235 sal_IntPtr nIndexOne;
1236 sal_IntPtr nIndexTwo;
1238 Reference < XResultSet > xResultOne;
1239 Reference < XResultSet > xResultTwo;
1241 if ( pOne->mbModified )
1243 xResultOne = mxOther;
1244 nIndexOne = pOne->mnOldPos;
1246 else
1248 xResultOne = mxOriginal;
1249 nIndexOne = pOne->mnCurPos;
1252 if ( pTwo->mbModified )
1254 xResultTwo = mxOther;
1255 nIndexTwo = pTwo->mnOldPos;
1257 else
1259 xResultTwo = mxOriginal;
1260 nIndexTwo = pTwo->mnCurPos;
1263 sal_IntPtr nCompare;
1264 nCompare = CompareImpl( xResultOne, xResultTwo,
1265 nIndexOne, nIndexTwo );
1266 return nCompare;
1270 sal_IntPtr SortedResultSet::FindPos( SortListData *pEntry,
1271 sal_IntPtr _nStart, sal_IntPtr _nEnd )
1272 throw( SQLException, RuntimeException )
1274 if ( _nStart > _nEnd )
1275 return _nStart + 1;
1277 sal_IntPtr nStart = _nStart;
1278 sal_IntPtr nEnd = _nEnd;
1279 sal_IntPtr nMid = 0, nCompare = 0;
1282 while ( nStart <= nEnd )
1284 nMid = ( nEnd - nStart ) / 2 + nStart;
1285 SortListData *pMid = maS2O.GetData( nMid );
1286 nCompare = Compare( pEntry, pMid );
1288 if ( !nCompare )
1289 nCompare = (pEntry != pMid) ? ((pEntry < pMid) ? -1 : 1) : 0;
1291 if ( nCompare < 0 ) // pEntry < pMid
1292 nEnd = nMid - 1;
1293 else
1294 nStart = nMid + 1;
1297 if ( nCompare < 0 ) // pEntry < pMid
1298 return nMid;
1299 else
1300 return nMid+1;
1304 void SortedResultSet::PropertyChanged( const PropertyChangeEvent& rEvt )
1306 osl::Guard< osl::Mutex > aGuard( maMutex );
1308 if ( !mpPropChangeListeners )
1309 return;
1311 // Notify listeners interested especially in the changed property.
1312 OInterfaceContainerHelper* pPropsContainer =
1313 mpPropChangeListeners->getContainer( rEvt.PropertyName );
1314 if ( pPropsContainer )
1316 OInterfaceIteratorHelper aIter( *pPropsContainer );
1317 while ( aIter.hasMoreElements() )
1319 Reference< XPropertyChangeListener > xListener(
1320 aIter.next(), UNO_QUERY );
1321 if ( xListener.is() )
1322 xListener->propertyChange( rEvt );
1326 // Notify listeners interested in all properties.
1327 pPropsContainer = mpPropChangeListeners->getContainer( OUString() );
1328 if ( pPropsContainer )
1330 OInterfaceIteratorHelper aIter( *pPropsContainer );
1331 while ( aIter.hasMoreElements() )
1333 Reference< XPropertyChangeListener > xListener(
1334 aIter.next(), UNO_QUERY );
1335 if ( xListener.is() )
1336 xListener->propertyChange( rEvt );
1344 // public methods
1347 void SortedResultSet::CopyData( SortedResultSet *pSource )
1349 const SortedEntryList& rSrcS2O = pSource->GetS2OList();
1350 const SimpleList& rSrcO2S = pSource->GetO2SList();
1352 sal_IntPtr i, nCount;
1354 maS2O.Clear();
1355 maO2S.Clear();
1356 maModList.Clear();
1358 maS2O.Insert( NULL, 0 );
1359 maO2S.Insert( 0, (sal_uInt32) 0 ); // value, pos
1361 nCount = rSrcS2O.Count();
1363 for ( i=1; i<nCount; i++ )
1365 maS2O.Insert( new SortListData( rSrcS2O[ i ] ), i );
1366 maO2S.Insert( rSrcO2S.GetObject( i ), (sal_uInt32) i );
1369 mnLastSort = maS2O.Count();
1370 mxOther = pSource->GetResultSet();
1372 if ( !mpSortInfo )
1374 mpSortInfo = pSource->GetSortInfo();
1375 mbIsCopy = true;
1380 void SortedResultSet::Initialize(
1381 const Sequence < NumberedSortingInfo > &xSortInfo,
1382 const Reference< XAnyCompareFactory > &xCompFactory )
1384 BuildSortInfo( mxOriginal, xSortInfo, xCompFactory );
1385 // Insert dummy at pos 0
1386 SortListData *pData = new SortListData( 0 );
1387 maS2O.Insert( pData, 0 );
1389 sal_IntPtr nIndex = 1;
1391 // now fetch all the elements from the original result set,
1392 // get there new position in the sorted result set and insert
1393 // an entry in the sorted to original mapping list
1394 try {
1395 while ( mxOriginal->absolute( nIndex ) )
1397 pData = new SortListData( nIndex );
1398 sal_IntPtr nPos = FindPos( pData, 1, nIndex-1 );
1400 maS2O.Insert( pData, nPos );
1402 nIndex++;
1405 catch (const SQLException&)
1407 OSL_FAIL( "SortedResultSet::Initialize() : Got unexpected SQLException" );
1410 // when we have fetched all the elements, we can create the
1411 // original to sorted mapping list from the s2o list
1412 maO2S.Clear();
1413 maO2S.Insert( NULL, (sal_uInt32) 0 );
1415 // insert some dummy entries first and replace then
1416 // the entries with the right ones
1417 size_t i;
1419 for ( i=1; i<maS2O.Count(); i++ )
1420 maO2S.Insert( (void*) 0, i ); // Insert( data, pos )
1421 for ( i=1; i<maS2O.Count(); i++ )
1422 maO2S.Replace( reinterpret_cast<void*>(i), maS2O[ i ] ); // Insert( data, pos )
1424 mnCount = maS2O.Count() - 1;
1428 void SortedResultSet::CheckProperties( sal_IntPtr nOldCount, bool bWasFinal )
1430 osl::Guard< osl::Mutex > aGuard( maMutex );
1432 if ( !mpPropChangeListeners )
1433 return;
1435 try {
1436 // check for propertyChangeEvents
1437 if ( nOldCount != GetCount() )
1439 bool bIsFinal = false;
1440 PropertyChangeEvent aEvt;
1442 aEvt.PropertyName = "RowCount";
1443 aEvt.Further = sal_False;
1444 aEvt.PropertyHandle = -1;
1445 aEvt.OldValue <<= nOldCount;
1446 aEvt.NewValue <<= GetCount();
1448 PropertyChanged( aEvt );
1450 OUString aName = "IsRowCountFinal";
1451 Any aRet = getPropertyValue( aName );
1452 if ( (aRet >>= bIsFinal) && bIsFinal != bWasFinal )
1454 aEvt.PropertyName = aName;
1455 aEvt.Further = sal_False;
1456 aEvt.PropertyHandle = -1;
1457 aEvt.OldValue <<= bWasFinal;
1458 aEvt.NewValue <<= bIsFinal;
1459 PropertyChanged( aEvt );
1463 catch (const UnknownPropertyException&) {}
1464 catch (const WrappedTargetException&) {}
1468 void SortedResultSet::InsertNew( sal_IntPtr nPos, sal_IntPtr nCount )
1470 // for all entries in the msS20-list, which are >= nPos, increase by nCount
1471 SortListData *pData;
1472 sal_IntPtr i, nEnd;
1474 nEnd = maS2O.Count();
1475 for ( i=1; i<=nEnd; i++ )
1477 pData = maS2O.GetData( i );
1478 if ( pData->mnCurPos >= nPos )
1480 pData->mnCurPos += nCount;
1484 // and append the new entries at the end of the maS20-list or insert at the
1485 // position nPos in the maS2O-list
1486 for ( i=0; i<nCount; i++ )
1488 nEnd += 1;
1489 pData = new SortListData( nEnd );
1491 maS2O.Insert( pData, nEnd ); // Insert( Value, Position )
1492 maO2S.Insert( reinterpret_cast<void*>(nEnd), (sal_uInt32)(nPos+i) ); // Insert( Value, Position )
1495 mnCount += nCount;
1499 void SortedResultSet::Remove( sal_IntPtr nPos, sal_IntPtr nCount, EventList *pEvents )
1501 sal_uInt32 i, j;
1502 sal_IntPtr nOldLastSort;
1504 // correct mnLastSort first
1505 nOldLastSort = mnLastSort;
1506 if ( nPos <= mnLastSort )
1508 if ( nPos + nCount - 1 <= mnLastSort )
1509 mnLastSort -= nCount;
1510 else
1511 mnLastSort = nPos - 1;
1514 // remove the entries from the lists and correct the positions
1515 // in the original2sorted list
1516 for ( i=0; i < (sal_uInt32) nCount; i++ )
1518 sal_IntPtr nSortPos = reinterpret_cast<sal_IntPtr>( maO2S.GetObject( nPos ) );
1519 maO2S.Remove( (sal_uInt32) nPos );
1521 for ( j=1; j<=maO2S.Count(); j++ )
1523 sal_IntPtr nVal = reinterpret_cast<sal_IntPtr>( maO2S.GetObject( j ) );
1524 if ( nVal > nSortPos )
1526 --nVal;
1527 maO2S.Replace( reinterpret_cast<void*>(nVal), j );
1531 SortListData *pData = maS2O.Remove( nSortPos );
1532 if ( pData->mbModified )
1533 maModList.Remove( (void*) pData );
1534 delete pData;
1536 // generate remove Event, but not for new entries
1537 if ( nSortPos <= nOldLastSort )
1538 pEvents->AddEvent( ListActionType::REMOVED, nSortPos, 1 );
1541 // correct the positions in the sorted list
1542 for ( i=1; i<= maS2O.Count(); i++ )
1544 SortListData *pData = maS2O.GetData( i );
1545 if ( pData->mnCurPos > nPos )
1546 pData->mnCurPos -= nCount;
1549 mnCount -= nCount;
1553 void SortedResultSet::Move( sal_IntPtr nPos, sal_IntPtr nCount, sal_IntPtr nOffset )
1555 if ( !nOffset )
1556 return;
1558 sal_IntPtr i, nSortPos, nTo;
1559 SortListData *pData;
1561 for ( i=0; i<nCount; i++ )
1563 nSortPos = reinterpret_cast<sal_IntPtr>(maO2S.GetObject( nPos+i ));
1564 pData = maS2O.GetData( nSortPos );
1565 pData->mnCurPos += nOffset;
1568 if ( nOffset < 0 )
1570 for ( i=nPos+nOffset; i<nPos; i++ )
1572 nSortPos = reinterpret_cast<sal_IntPtr>(maO2S.GetObject( i ));
1573 pData = maS2O.GetData( nSortPos );
1574 pData->mnCurPos += nCount;
1577 else
1579 sal_IntPtr nStart = nPos + nCount;
1580 sal_IntPtr nEnd = nStart + nOffset;
1581 for ( i=nStart; i<nEnd; i++ )
1583 nSortPos = reinterpret_cast<sal_IntPtr>(maO2S.GetObject( i ));
1584 pData = maS2O.GetData( nSortPos );
1585 pData->mnCurPos -= nCount;
1589 // remember the to be moved entries
1590 boost::scoped_array<sal_IntPtr> pTmpArr(new sal_IntPtr[ nCount ]);
1591 for ( i=0; i<nCount; i++ )
1592 pTmpArr[i] = reinterpret_cast<sal_IntPtr>(maO2S.GetObject( (sal_uInt32)( nPos+i ) ));
1594 // now move the entries, which are in the way
1595 if ( nOffset < 0 )
1597 // be carefully here, because nOffset is negative here, so an
1598 // addition is a subtraction
1599 sal_IntPtr nFrom = nPos - 1;
1600 nTo = nPos + nCount - 1;
1602 // same for i here
1603 for ( i=0; i>nOffset; i-- )
1605 sal_IntPtr nVal = reinterpret_cast<sal_IntPtr>( maO2S.GetObject( (sal_uInt32)( nFrom+i ) ) );
1606 maO2S.Replace( reinterpret_cast<void*>(nVal), (sal_uInt32)( nTo+i ) );
1610 else
1612 sal_IntPtr nStart = nPos + nCount;
1613 for ( i=0; i<nOffset; i++ )
1615 sal_IntPtr nVal = reinterpret_cast<sal_IntPtr>( maO2S.GetObject( (sal_uInt32)( nStart+i ) ) );
1616 maO2S.Replace( reinterpret_cast<void*>(nVal), (sal_uInt32)( nPos+i ) );
1620 // finally put the remembered entries at there new location
1621 nTo = nPos + nOffset;
1622 for ( i=0; i<nCount; i++ )
1624 maO2S.Replace( reinterpret_cast<void*>(pTmpArr[ i ]), (sal_uInt32)( nTo+i ) );
1629 void SortedResultSet::BuildSortInfo(
1630 Reference< XResultSet > aResult,
1631 const Sequence < NumberedSortingInfo > &xSortInfo,
1632 const Reference< XAnyCompareFactory > &xCompFactory )
1634 Reference < XResultSetMetaDataSupplier > xMeta ( aResult, UNO_QUERY );
1636 if ( ! xMeta.is() )
1638 OSL_FAIL( "No MetaData, No Sorting!" );
1639 return;
1642 Reference < XResultSetMetaData > xData = xMeta->getMetaData();
1643 const NumberedSortingInfo *pSortInfo = xSortInfo.getConstArray();
1645 sal_Int32 nColumn;
1646 OUString aPropName;
1647 SortInfo *pInfo;
1649 for ( sal_IntPtr i=xSortInfo.getLength(); i > 0; )
1651 --i;
1652 nColumn = pSortInfo[ i ].ColumnIndex;
1653 aPropName = xData->getColumnName( nColumn );
1654 pInfo = new SortInfo;
1656 if ( xCompFactory.is() )
1657 pInfo->mxCompareFunction = xCompFactory->createAnyCompareByName(
1658 aPropName );
1660 if ( pInfo->mxCompareFunction.is() )
1662 pInfo->mbUseOwnCompare = false;
1663 pInfo->mnType = 0;
1665 else
1667 pInfo->mbUseOwnCompare = true;
1668 pInfo->mnType = xData->getColumnType( nColumn );
1671 pInfo->mnColumn = nColumn;
1672 pInfo->mbAscending = pSortInfo[ i ].Ascending;
1673 pInfo->mbCaseSensitive = xData->isCaseSensitive( nColumn );
1674 pInfo->mpNext = mpSortInfo;
1675 mpSortInfo = pInfo;
1680 void SortedResultSet::SetChanged( sal_IntPtr nPos, sal_IntPtr nCount )
1682 for ( sal_IntPtr i=0; i<nCount; i++ )
1684 sal_IntPtr nSortPos = reinterpret_cast<sal_IntPtr>(maO2S.GetObject( nPos ));
1685 if ( nSortPos < mnLastSort )
1687 SortListData *pData = maS2O.GetData( nSortPos );
1688 if ( ! pData->mbModified )
1690 pData->mbModified = true;
1691 maModList.Append( pData );
1694 nPos += 1;
1699 void SortedResultSet::ResortModified( EventList* pList )
1701 sal_uInt32 i, j;
1702 sal_IntPtr nCompare, nCurPos, nNewPos;
1703 sal_IntPtr nStart, nEnd, nOffset, nVal;
1704 SortListData *pData;
1705 ListAction *pAction;
1707 try {
1708 for ( i=0; i<maModList.Count(); i++ )
1710 pData = static_cast<SortListData*>(maModList.GetObject( i ));
1711 nCompare = CompareImpl( mxOther, mxOriginal,
1712 pData->mnOldPos, pData->mnCurPos );
1713 pData->mbModified = false;
1714 if ( nCompare != 0 )
1716 nCurPos = reinterpret_cast<sal_IntPtr>( maO2S.GetObject( (sal_uInt32) pData->mnCurPos ) );
1717 if ( nCompare < 0 )
1719 nNewPos = FindPos( pData, 1, nCurPos-1 );
1720 nStart = nNewPos;
1721 nEnd = nCurPos;
1722 nOffset = 1;
1724 else
1726 nNewPos = FindPos( pData, nCurPos+1, mnLastSort );
1727 nStart = nCurPos;
1728 nEnd = mnLastSort;
1729 nOffset = -1;
1732 if ( nNewPos != nCurPos )
1734 // correct the lists!
1735 maS2O.Remove( (sal_uInt32) nCurPos );
1736 maS2O.Insert( pData, nNewPos );
1737 for ( j=1; j<maO2S.Count(); j++ )
1739 nVal = reinterpret_cast<sal_IntPtr>( maO2S.GetObject( (sal_uInt32)j ) );
1740 if ( ( nStart <= nVal ) && ( nVal <= nEnd ) )
1742 nVal += nOffset;
1743 maO2S.Replace( reinterpret_cast<void*>(nVal), (sal_uInt32)j );
1747 maO2S.Replace( reinterpret_cast<void*>(nNewPos), (sal_uInt32) pData->mnCurPos );
1749 pAction = new ListAction;
1750 pAction->Position = nCurPos;
1751 pAction->Count = 1;
1752 pAction->ListActionType = ListActionType::MOVED;
1753 pAction->ActionInfo <<= nNewPos-nCurPos;
1754 pList->Insert( pAction );
1756 pList->AddEvent( ListActionType::PROPERTIES_CHANGED,
1757 nNewPos, 1 );
1761 catch (const SQLException&)
1763 OSL_FAIL( "SortedResultSet::ResortModified() : Got unexpected SQLException" );
1766 maModList.Clear();
1770 void SortedResultSet::ResortNew( EventList* pList )
1772 sal_IntPtr i, j, nNewPos, nVal;
1774 try {
1775 for ( i = mnLastSort; i<(sal_IntPtr)maS2O.Count(); i++ )
1777 SortListData *pData = static_cast<SortListData*>(maModList.GetObject( i ));
1778 nNewPos = FindPos( pData, 1, mnLastSort );
1779 if ( nNewPos != i )
1781 maS2O.Remove( (sal_uInt32) i );
1782 maS2O.Insert( pData, nNewPos );
1783 // maO2S liste korigieren
1784 for ( j=1; j<(sal_IntPtr)maO2S.Count(); j++ )
1786 nVal = reinterpret_cast<sal_IntPtr>(maO2S.GetObject( (sal_uInt32)j ));
1787 if ( nVal >= nNewPos )
1788 maO2S.Replace( reinterpret_cast<void*>(nVal+1), (sal_uInt32)( j ) );
1790 maO2S.Replace( reinterpret_cast<void*>(nNewPos), (sal_uInt32) pData->mnCurPos );
1792 mnLastSort++;
1793 pList->AddEvent( ListActionType::INSERTED, nNewPos, 1 );
1796 catch (const SQLException&)
1798 OSL_FAIL( "SortedResultSet::ResortNew() : Got unexpected SQLException" );
1804 // SortListData
1807 SortListData::SortListData( sal_IntPtr nPos, bool bModified )
1809 mbModified = bModified;
1810 mnCurPos = nPos;
1811 mnOldPos = nPos;
1816 void SortedEntryList::Clear()
1818 for ( std::deque< ListAction* >::size_type i = 0;
1819 i < maData.size(); ++i )
1821 delete maData[i];
1824 maData.clear();
1828 void SortedEntryList::Insert( SortListData *pEntry, sal_IntPtr nPos )
1830 if ( nPos < (sal_IntPtr) maData.size() )
1831 maData.insert( maData.begin() + nPos, pEntry );
1832 else
1833 maData.push_back( pEntry );
1837 SortListData* SortedEntryList::Remove( sal_IntPtr nPos )
1839 SortListData *pData;
1841 if ( nPos < (sal_IntPtr) maData.size() )
1843 pData = maData[ nPos ];
1844 maData.erase( maData.begin() + nPos );
1846 else
1847 pData = NULL;
1849 return pData;
1853 SortListData* SortedEntryList::GetData( sal_IntPtr nPos )
1855 SortListData *pData;
1857 if ( nPos < (sal_IntPtr) maData.size() )
1858 pData = maData[ nPos ];
1859 else
1860 pData = NULL;
1862 return pData;
1866 sal_IntPtr SortedEntryList::operator [] ( sal_IntPtr nPos ) const
1868 SortListData *pData;
1870 if ( nPos < (sal_IntPtr) maData.size() )
1871 pData = maData[ nPos ];
1872 else
1873 pData = NULL;
1875 if ( pData )
1876 if ( ! pData->mbModified )
1877 return pData->mnCurPos;
1878 else
1880 OSL_FAIL( "SortedEntryList: Can't get value for modified entry!");
1881 return 0;
1883 else
1885 OSL_FAIL( "SortedEntryList: invalid pos!");
1886 return 0;
1893 void SimpleList::Remove( sal_uInt32 nPos )
1895 if ( nPos < (sal_uInt32) maData.size() )
1897 maData.erase( maData.begin() + nPos );
1902 void SimpleList::Remove( void* pData )
1904 bool bFound = false;
1905 sal_uInt32 i;
1907 for ( i = 0; i < (sal_uInt32) maData.size(); i++ )
1909 if ( maData[ i ] == pData )
1911 bFound = true;
1912 break;
1916 if ( bFound )
1917 maData.erase( maData.begin() + i );
1921 void SimpleList::Insert( void* pData, sal_uInt32 nPos )
1923 if ( nPos < (sal_uInt32) maData.size() )
1924 maData.insert( maData.begin() + nPos, pData );
1925 else
1926 maData.push_back( pData );
1930 void* SimpleList::GetObject( sal_uInt32 nPos ) const
1932 if ( nPos < (sal_uInt32) maData.size() )
1933 return maData[ nPos ];
1934 else
1935 return NULL;
1939 void SimpleList::Replace( void* pData, sal_uInt32 nPos )
1941 if ( nPos < (sal_uInt32) maData.size() )
1942 maData[ nPos ] = pData;
1947 // class SRSPropertySetInfo.
1951 SRSPropertySetInfo::SRSPropertySetInfo()
1953 maProps[0].Name = "RowCount";
1954 maProps[0].Handle = -1;
1955 maProps[0].Type = cppu::UnoType<OUString>::get();
1956 maProps[0].Attributes = -1;
1958 maProps[1].Name = "IsRowCountFinal";
1959 maProps[1].Handle = -1;
1960 maProps[1].Type = cppu::UnoType<bool>::get();
1961 maProps[1].Attributes = -1;
1965 SRSPropertySetInfo::~SRSPropertySetInfo()
1968 // XPropertySetInfo methods.
1970 Sequence< Property > SAL_CALL
1971 SRSPropertySetInfo::getProperties() throw( RuntimeException, std::exception )
1973 return Sequence < Property > ( maProps, 2 );
1977 Property SAL_CALL
1978 SRSPropertySetInfo::getPropertyByName( const OUString& Name )
1979 throw( UnknownPropertyException, RuntimeException, std::exception )
1981 if ( Name == "RowCount" )
1982 return maProps[0];
1983 else if ( Name == "IsRowCountFinal" )
1984 return maProps[1];
1985 else
1986 throw UnknownPropertyException();
1990 sal_Bool SAL_CALL
1991 SRSPropertySetInfo::hasPropertyByName( const OUString& Name )
1992 throw( RuntimeException, std::exception )
1994 if ( Name == "RowCount" )
1995 return sal_True;
1996 else if ( Name == "IsRowCountFinal" )
1997 return sal_True;
1998 else
1999 return sal_False;
2002 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */