LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/ucb/source/sorter - sortresult.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 188 838 22.4 %
Date: 2013-07-09 Functions: 25 109 22.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10