1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
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
;
48 // The mutex to synchronize access to containers.
49 static osl::Mutex
& getContainerMutex()
51 static osl::Mutex
* pMutex
= NULL
;
54 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
57 static osl::Mutex aMutex
;
75 Reference
< XAnyCompare
> mxCompareFunction
;
86 SortListData( sal_IntPtr nPos
, bool bModified
= false );
91 // class SRSPropertySetInfo.
95 class SRSPropertySetInfo
: public cppu::WeakImplHelper1
<
103 SRSPropertySetInfo();
104 virtual ~SRSPropertySetInfo();
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
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
;
142 SortedResultSet::~SortedResultSet()
149 SortInfo
*pInfo
= mpSortInfo
;
152 mpSortInfo
= pInfo
->mpNext
;
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
;
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() )
211 aEvt
.Source
= static_cast< XComponent
* >( this );
212 mpDisposeEventListeners
->disposeAndClear( aEvt
);
215 if ( mpPropChangeListeners
)
218 aEvt
.Source
= static_cast< XPropertySet
* >( this );
219 mpPropChangeListeners
->disposeAndClear( aEvt
);
222 if ( mpVetoChangeListeners
)
225 aEvt
.Source
= static_cast< XPropertySet
* >( this );
226 mpVetoChangeListeners
->disposeAndClear( aEvt
);
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.
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
);
299 if ( mnCurEntry
> 0 )
301 if ( mnCurEntry
<= mnCount
)
303 sal_Int32 nIndex
= maS2O
[ mnCurEntry
];
304 return mxOriginal
->absolute( nIndex
);
308 mnCurEntry
= mnCount
+ 1;
315 sal_Bool SAL_CALL
SortedResultSet::isBeforeFirst()
316 throw ( SQLException
, RuntimeException
, std::exception
)
325 sal_Bool SAL_CALL
SortedResultSet::isAfterLast()
326 throw ( SQLException
, RuntimeException
, std::exception
)
328 if ( mnCurEntry
> mnCount
)
335 sal_Bool SAL_CALL
SortedResultSet::isFirst()
336 throw ( SQLException
, RuntimeException
, std::exception
)
338 if ( mnCurEntry
== 1 )
345 sal_Bool SAL_CALL
SortedResultSet::isLast()
346 throw ( SQLException
, RuntimeException
, std::exception
)
348 if ( mnCurEntry
== mnCount
)
355 void SAL_CALL
SortedResultSet::beforeFirst()
356 throw ( SQLException
, RuntimeException
, std::exception
)
358 osl::Guard
< osl::Mutex
> aGuard( maMutex
);
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
);
381 sal_Int32 nIndex
= maS2O
[ mnCurEntry
];
382 return mxOriginal
->absolute( nIndex
);
392 sal_Bool SAL_CALL
SortedResultSet::last()
393 throw ( SQLException
, RuntimeException
, std::exception
)
395 osl::Guard
< osl::Mutex
> aGuard( maMutex
);
399 mnCurEntry
= mnCount
;
400 sal_Int32 nIndex
= maS2O
[ mnCurEntry
];
401 return mxOriginal
->absolute( nIndex
);
411 sal_Int32 SAL_CALL
SortedResultSet::getRow()
412 throw ( SQLException
, RuntimeException
, std::exception
)
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,
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>.
436 is the number of rows to move. Could be negative.
438 <TRUE/> if the cursor is on a row; <FALSE/> otherwise
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
);
452 if ( row
<= mnCount
)
455 nIndex
= maS2O
[ mnCurEntry
];
456 return mxOriginal
->absolute( nIndex
);
460 mnCurEntry
= mnCount
+ 1;
466 throw SQLException();
470 if ( mnCount
+ row
+ 1 > 0 )
472 mnCurEntry
= mnCount
+ row
+ 1;
473 nIndex
= maS2O
[ mnCurEntry
];
474 return mxOriginal
->absolute( nIndex
);
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
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.
498 is the number of rows to move. Could be negative.
500 <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off
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();
519 sal_Int32 nTmp
= mnCurEntry
+ rows
;
526 else if ( nTmp
> mnCount
)
528 mnCurEntry
= mnCount
+ 1;
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
548 if a database access error occurs or the result set type
551 sal_Bool SAL_CALL
SortedResultSet::previous()
552 throw ( SQLException
, RuntimeException
, std::exception
)
554 osl::Guard
< osl::Mutex
> aGuard( maMutex
);
558 if ( mnCurEntry
> 0 )
560 if ( mnCurEntry
<= mnCount
)
562 sal_Int32 nIndex
= maS2O
[ mnCurEntry
];
563 return mxOriginal
->absolute( nIndex
);
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();
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
,
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
,
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();
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
);
878 if ( PropertyName
== "RowCount" )
880 aRet
<<= maS2O
.Count();
882 else if ( PropertyName
== "IsRowCountFinal" )
884 bool bOrgFinal
= false;
889 aOrgRet
= Reference
< XPropertySet
>::query(mxOriginal
)->
890 getPropertyValue( PropertyName
);
891 aOrgRet
>>= bOrgFinal
;
895 aOrgRet
= Reference
< XPropertySet
>::query(mxOriginal
)->
896 getPropertyValue("RowCount");
897 sal_uInt32 nOrgCount
= 0;
898 aOrgRet
>>= nOrgCount
;
899 if ( nOrgCount
== maS2O
.Count() )
904 throw UnknownPropertyException();
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
);
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
)
990 case DataType::TINYINT
:
991 case DataType::SMALLINT
:
992 case DataType::INTEGER
:
997 if ( xResultOne
->absolute( nIndexOne
) )
998 aOne
= xRowOne
->getInt( nColumn
);
999 if ( xResultTwo
->absolute( nIndexTwo
) )
1000 aTwo
= xRowTwo
->getInt( nColumn
);
1004 else if ( aOne
== aTwo
)
1011 case DataType::BIGINT
:
1016 if ( xResultOne
->absolute( nIndexOne
) )
1017 aOne
= xRowOne
->getLong( nColumn
);
1018 if ( xResultTwo
->absolute( nIndexTwo
) )
1019 aTwo
= xRowTwo
->getLong( nColumn
);
1023 else if ( aOne
== aTwo
)
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
);
1050 case DataType::DATE
:
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
;
1062 nTmp
= (sal_Int32
) aTwo
.Month
- (sal_Int32
) aOne
.Month
;
1064 nTmp
= (sal_Int32
) aTwo
.Day
- (sal_Int32
) aOne
.Day
;
1069 else if ( nTmp
== 0 )
1076 case DataType::TIME
:
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
;
1088 nTmp
= (sal_Int32
) aTwo
.Minutes
- (sal_Int32
) aOne
.Minutes
;
1090 nTmp
= (sal_Int32
) aTwo
.Seconds
- (sal_Int32
) aOne
.Seconds
;
1092 nTmp
= (sal_Int32
) aTwo
.NanoSeconds
1093 - (sal_Int32
) aOne
.NanoSeconds
;
1098 else if ( nTmp
== 0 )
1105 case DataType::TIMESTAMP
:
1107 DateTime aOne
, aTwo
;
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
;
1117 nTmp
= (sal_Int32
) aTwo
.Month
- (sal_Int32
) aOne
.Month
;
1119 nTmp
= (sal_Int32
) aTwo
.Day
- (sal_Int32
) aOne
.Day
;
1121 nTmp
= (sal_Int32
) aTwo
.Hours
- (sal_Int32
) aOne
.Hours
;
1123 nTmp
= (sal_Int32
) aTwo
.Minutes
- (sal_Int32
) aOne
.Minutes
;
1125 nTmp
= (sal_Int32
) aTwo
.Seconds
- (sal_Int32
) aOne
.Seconds
;
1127 nTmp
= (sal_Int32
) aTwo
.NanoSeconds
1128 - (sal_Int32
) aOne
.NanoSeconds
;
1133 else if ( nTmp
== 0 )
1140 case DataType::REAL
:
1145 if ( xResultOne
->absolute( nIndexOne
) )
1146 aOne
= xRowOne
->getFloat( nColumn
);
1147 if ( xResultTwo
->absolute( nIndexTwo
) )
1148 aTwo
= xRowTwo
->getFloat( nColumn
);
1152 else if ( aOne
== aTwo
)
1159 case DataType::FLOAT
:
1160 case DataType::DOUBLE
:
1165 if ( xResultOne
->absolute( nIndexOne
) )
1166 aOne
= xRowOne
->getDouble( nColumn
);
1167 if ( xResultTwo
->absolute( nIndexTwo
) )
1168 aTwo
= xRowTwo
->getDouble( nColumn
);
1172 else if ( aOne
== aTwo
)
1181 OSL_FAIL( "DataType not supported for compare!" );
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
);
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
;
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
;
1248 xResultOne
= mxOriginal
;
1249 nIndexOne
= pOne
->mnCurPos
;
1252 if ( pTwo
->mbModified
)
1254 xResultTwo
= mxOther
;
1255 nIndexTwo
= pTwo
->mnOldPos
;
1259 xResultTwo
= mxOriginal
;
1260 nIndexTwo
= pTwo
->mnCurPos
;
1263 sal_IntPtr nCompare
;
1264 nCompare
= CompareImpl( xResultOne
, xResultTwo
,
1265 nIndexOne
, nIndexTwo
);
1270 sal_IntPtr
SortedResultSet::FindPos( SortListData
*pEntry
,
1271 sal_IntPtr _nStart
, sal_IntPtr _nEnd
)
1272 throw( SQLException
, RuntimeException
)
1274 if ( _nStart
> _nEnd
)
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
);
1289 nCompare
= (pEntry
!= pMid
) ? ((pEntry
< pMid
) ? -1 : 1) : 0;
1291 if ( nCompare
< 0 ) // pEntry < pMid
1297 if ( nCompare
< 0 ) // pEntry < pMid
1304 void SortedResultSet::PropertyChanged( const PropertyChangeEvent
& rEvt
)
1306 osl::Guard
< osl::Mutex
> aGuard( maMutex
);
1308 if ( !mpPropChangeListeners
)
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
);
1347 void SortedResultSet::CopyData( SortedResultSet
*pSource
)
1349 const SortedEntryList
& rSrcS2O
= pSource
->GetS2OList();
1350 const SimpleList
& rSrcO2S
= pSource
->GetO2SList();
1352 sal_IntPtr i
, nCount
;
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();
1374 mpSortInfo
= pSource
->GetSortInfo();
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
1395 while ( mxOriginal
->absolute( nIndex
) )
1397 pData
= new SortListData( nIndex
);
1398 sal_IntPtr nPos
= FindPos( pData
, 1, nIndex
-1 );
1400 maS2O
.Insert( pData
, nPos
);
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
1413 maO2S
.Insert( NULL
, (sal_uInt32
) 0 );
1415 // insert some dummy entries first and replace then
1416 // the entries with the right ones
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
)
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
;
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
++ )
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 )
1499 void SortedResultSet::Remove( sal_IntPtr nPos
, sal_IntPtr nCount
, EventList
*pEvents
)
1502 sal_IntPtr nOldLastSort
;
1504 // correct mnLastSort first
1505 nOldLastSort
= mnLastSort
;
1506 if ( nPos
<= mnLastSort
)
1508 if ( nPos
+ nCount
- 1 <= mnLastSort
)
1509 mnLastSort
-= nCount
;
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
)
1527 maO2S
.Replace( reinterpret_cast<void*>(nVal
), j
);
1531 SortListData
*pData
= maS2O
.Remove( nSortPos
);
1532 if ( pData
->mbModified
)
1533 maModList
.Remove( (void*) 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
;
1553 void SortedResultSet::Move( sal_IntPtr nPos
, sal_IntPtr nCount
, sal_IntPtr nOffset
)
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
;
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
;
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
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;
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
) );
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
);
1638 OSL_FAIL( "No MetaData, No Sorting!" );
1642 Reference
< XResultSetMetaData
> xData
= xMeta
->getMetaData();
1643 const NumberedSortingInfo
*pSortInfo
= xSortInfo
.getConstArray();
1649 for ( sal_IntPtr i
=xSortInfo
.getLength(); i
> 0; )
1652 nColumn
= pSortInfo
[ i
].ColumnIndex
;
1653 aPropName
= xData
->getColumnName( nColumn
);
1654 pInfo
= new SortInfo
;
1656 if ( xCompFactory
.is() )
1657 pInfo
->mxCompareFunction
= xCompFactory
->createAnyCompareByName(
1660 if ( pInfo
->mxCompareFunction
.is() )
1662 pInfo
->mbUseOwnCompare
= false;
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
;
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
);
1699 void SortedResultSet::ResortModified( EventList
* pList
)
1702 sal_IntPtr nCompare
, nCurPos
, nNewPos
;
1703 sal_IntPtr nStart
, nEnd
, nOffset
, nVal
;
1704 SortListData
*pData
;
1705 ListAction
*pAction
;
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
) );
1719 nNewPos
= FindPos( pData
, 1, nCurPos
-1 );
1726 nNewPos
= FindPos( pData
, nCurPos
+1, mnLastSort
);
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
) )
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
;
1752 pAction
->ListActionType
= ListActionType::MOVED
;
1753 pAction
->ActionInfo
<<= nNewPos
-nCurPos
;
1754 pList
->Insert( pAction
);
1756 pList
->AddEvent( ListActionType::PROPERTIES_CHANGED
,
1761 catch (const SQLException
&)
1763 OSL_FAIL( "SortedResultSet::ResortModified() : Got unexpected SQLException" );
1770 void SortedResultSet::ResortNew( EventList
* pList
)
1772 sal_IntPtr i
, j
, nNewPos
, nVal
;
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
);
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
);
1793 pList
->AddEvent( ListActionType::INSERTED
, nNewPos
, 1 );
1796 catch (const SQLException
&)
1798 OSL_FAIL( "SortedResultSet::ResortNew() : Got unexpected SQLException" );
1807 SortListData::SortListData( sal_IntPtr nPos
, bool bModified
)
1809 mbModified
= bModified
;
1816 void SortedEntryList::Clear()
1818 for ( std::deque
< ListAction
* >::size_type i
= 0;
1819 i
< maData
.size(); ++i
)
1828 void SortedEntryList::Insert( SortListData
*pEntry
, sal_IntPtr nPos
)
1830 if ( nPos
< (sal_IntPtr
) maData
.size() )
1831 maData
.insert( maData
.begin() + nPos
, pEntry
);
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
);
1853 SortListData
* SortedEntryList::GetData( sal_IntPtr nPos
)
1855 SortListData
*pData
;
1857 if ( nPos
< (sal_IntPtr
) maData
.size() )
1858 pData
= maData
[ nPos
];
1866 sal_IntPtr
SortedEntryList::operator [] ( sal_IntPtr nPos
) const
1868 SortListData
*pData
;
1870 if ( nPos
< (sal_IntPtr
) maData
.size() )
1871 pData
= maData
[ nPos
];
1876 if ( ! pData
->mbModified
)
1877 return pData
->mnCurPos
;
1880 OSL_FAIL( "SortedEntryList: Can't get value for modified entry!");
1885 OSL_FAIL( "SortedEntryList: invalid pos!");
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;
1907 for ( i
= 0; i
< (sal_uInt32
) maData
.size(); i
++ )
1909 if ( maData
[ i
] == pData
)
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
);
1926 maData
.push_back( pData
);
1930 void* SimpleList::GetObject( sal_uInt32 nPos
) const
1932 if ( nPos
< (sal_uInt32
) maData
.size() )
1933 return maData
[ nPos
];
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 );
1978 SRSPropertySetInfo::getPropertyByName( const OUString
& Name
)
1979 throw( UnknownPropertyException
, RuntimeException
, std::exception
)
1981 if ( Name
== "RowCount" )
1983 else if ( Name
== "IsRowCountFinal" )
1986 throw UnknownPropertyException();
1991 SRSPropertySetInfo::hasPropertyByName( const OUString
& Name
)
1992 throw( RuntimeException
, std::exception
)
1994 if ( Name
== "RowCount" )
1996 else if ( Name
== "IsRowCountFinal" )
2002 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */