1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _SORTRESULT_HXX 25 #define _SORTRESULT_HXX 26 27 #include <com/sun/star/beans/XPropertySet.hpp> 28 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 29 #include <com/sun/star/lang/XTypeProvider.hpp> 30 #include <com/sun/star/lang/XServiceInfo.hpp> 31 #include <com/sun/star/lang/XComponent.hpp> 32 #include <com/sun/star/sdbc/XCloseable.hpp> 33 #include <com/sun/star/sdbc/XResultSet.hpp> 34 #include <com/sun/star/sdbc/XResultSetMetaData.hpp> 35 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> 36 #include <com/sun/star/sdbc/XRow.hpp> 37 #include <com/sun/star/ucb/XContentAccess.hpp> 38 #include <com/sun/star/ucb/NumberedSortingInfo.hpp> 39 #include <com/sun/star/ucb/XAnyCompareFactory.hpp> 40 #include <com/sun/star/ucb/ListAction.hpp> 41 #include <cppuhelper/weak.hxx> 42 #include <osl/mutex.hxx> 43 44 #include <deque> 45 #include <ucbhelper/macros.hxx> 46 47 namespace cppu { 48 class OInterfaceContainerHelper; 49 } 50 51 //----------------------------------------------------------------------------- 52 struct SortInfo; 53 struct SortListData; 54 class SRSPropertySetInfo; 55 class PropertyChangeListeners_Impl; 56 57 //----------------------------------------------------------------------------- 58 class SortedEntryList 59 { 60 std::deque < SortListData* > maData; 61 62 public: SortedEntryList()63 SortedEntryList(){} ~SortedEntryList()64 ~SortedEntryList(){ Clear(); } 65 Count() const66 sal_uInt32 Count() const { return (sal_uInt32) maData.size(); } 67 68 void Clear(); 69 void Insert( SortListData *pEntry, long nPos ); 70 SortListData* Remove( long nPos ); 71 SortListData* GetData( long nPos ); 72 73 long operator [] ( long nPos ) const; 74 }; 75 76 //----------------------------------------------------------------------------- 77 #define LISTACTION com::sun::star::ucb::ListAction 78 79 class EventList 80 { 81 std::deque < LISTACTION* > maData; 82 83 public: EventList()84 EventList(){} ~EventList()85 ~EventList(){ Clear(); } 86 Count()87 sal_uInt32 Count() { return (sal_uInt32) maData.size(); } 88 89 void AddEvent( long nType, long nPos, long nCount ); Insert(LISTACTION * pAction)90 void Insert( LISTACTION *pAction ) { maData.push_back( pAction ); } 91 void Clear(); GetAction(long nIndex)92 LISTACTION* GetAction( long nIndex ) { return maData[ nIndex ]; } 93 }; 94 95 //----------------------------------------------------------------------------- 96 97 class SimpleList 98 { 99 std::deque < void* > maData; 100 101 public: SimpleList()102 SimpleList(){} ~SimpleList()103 ~SimpleList(){ Clear(); } 104 Count()105 sal_uInt32 Count() { return (sal_uInt32) maData.size(); } Clear()106 void Clear() { maData.clear(); } 107 108 void Remove( sal_uInt32 nPos ); 109 void Remove( void* pData ); 110 Append(void * pData)111 void Append( void* pData ) 112 { maData.push_back( pData ); } 113 void Insert( void* pData, sal_uInt32 nPos ); 114 void* GetObject( sal_uInt32 nPos ) const; 115 void Replace( void* pData, sal_uInt32 nPos ); 116 }; 117 118 //----------------------------------------------------------------------------- 119 120 #define PROPERTYCHANGEEVENT com::sun::star::beans::PropertyChangeEvent 121 #define RUNTIME_EXCEPTION com::sun::star::uno::RuntimeException 122 #define REFERENCE com::sun::star::uno::Reference 123 #define SEQUENCE com::sun::star::uno::Sequence 124 #define XEVENTLISTENER com::sun::star::lang::XEventListener 125 #define XRESULTSET com::sun::star::sdbc::XResultSet 126 #define SQLEXCEPTION com::sun::star::sdbc::SQLException 127 #define XRESULTSETMETADATA com::sun::star::sdbc::XResultSetMetaData 128 #define NUMBERED_SORTINGINFO com::sun::star::ucb::NumberedSortingInfo 129 #define XANYCOMPAREFACTORY com::sun::star::ucb::XAnyCompareFactory 130 131 #define RESULTSET_SERVICE_NAME "com.sun.star.ucb.SortedResultSet" 132 133 //----------------------------------------------------------------------------- 134 135 class SortedResultSet: 136 public cppu::OWeakObject, 137 public com::sun::star::lang::XTypeProvider, 138 public com::sun::star::lang::XServiceInfo, 139 public com::sun::star::lang::XComponent, 140 public com::sun::star::ucb::XContentAccess, 141 public XRESULTSET, 142 public com::sun::star::sdbc::XRow, 143 public com::sun::star::sdbc::XCloseable, 144 public com::sun::star::sdbc::XResultSetMetaDataSupplier, 145 public com::sun::star::beans::XPropertySet 146 { 147 cppu::OInterfaceContainerHelper *mpDisposeEventListeners; 148 PropertyChangeListeners_Impl *mpPropChangeListeners; 149 PropertyChangeListeners_Impl *mpVetoChangeListeners; 150 151 REFERENCE < XRESULTSET > mxOriginal; 152 REFERENCE < XRESULTSET > mxOther; 153 154 SRSPropertySetInfo* mpPropSetInfo; 155 SortInfo* mpSortInfo; 156 osl::Mutex maMutex; 157 SortedEntryList maS2O; // maps the sorted entries to the original ones 158 SimpleList maO2S; // maps the original Entries to the sorted ones 159 SimpleList maModList; // keeps track of modified entries 160 long mnLastSort; // index of the last sorted entry; 161 long mnCurEntry; // index of the current entry 162 long mnCount; // total count of the elements 163 sal_Bool mbIsCopy; 164 165 166 private: 167 168 long FindPos( SortListData *pEntry, long nStart, long nEnd ); 169 long Compare( SortListData *pOne, 170 SortListData *pTwo ); 171 void BuildSortInfo( REFERENCE< XRESULTSET > aResult, 172 const SEQUENCE < NUMBERED_SORTINGINFO > &xSortInfo, 173 const REFERENCE< XANYCOMPAREFACTORY > &xCompFac ); 174 long CompareImpl( REFERENCE < XRESULTSET > xResultOne, 175 REFERENCE < XRESULTSET > xResultTwo, 176 long nIndexOne, long nIndexTwo, 177 SortInfo* pSortInfo ); 178 long CompareImpl( REFERENCE < XRESULTSET > xResultOne, 179 REFERENCE < XRESULTSET > xResultTwo, 180 long nIndexOne, long nIndexTwo ); 181 void PropertyChanged( const PROPERTYCHANGEEVENT& rEvt ); 182 183 public: 184 SortedResultSet( REFERENCE< XRESULTSET > aResult ); 185 ~SortedResultSet(); 186 GetS2OList() const187 const SortedEntryList* GetS2OList() const { return &maS2O; } GetO2SList() const188 const SimpleList* GetO2SList() const { return &maO2S; } GetResultSet() const189 REFERENCE < XRESULTSET > GetResultSet() const { return mxOriginal; } GetSortInfo() const190 SortInfo* GetSortInfo() const { return mpSortInfo; } GetCount() const191 long GetCount() const { return mnCount; } 192 193 void CopyData( SortedResultSet* pSource ); 194 void Initialize( const SEQUENCE < NUMBERED_SORTINGINFO > &xSortInfo, 195 const REFERENCE< XANYCOMPAREFACTORY > &xCompFac ); 196 void CheckProperties( long nOldCount, sal_Bool bWasFinal ); 197 198 void InsertNew( long nPos, long nCount ); 199 void SetChanged( long nPos, long nCount ); 200 void Remove( long nPos, long nCount, EventList *pList ); 201 void Move( long nPos, long nCount, long nOffset ); 202 203 void ResortModified( EventList* pList ); 204 void ResortNew( EventList* pList ); 205 206 // XInterface 207 XINTERFACE_DECL() 208 209 // XTypeProvider 210 XTYPEPROVIDER_DECL() 211 212 // XServiceInfo 213 XSERVICEINFO_NOFACTORY_DECL() 214 215 // XComponent 216 virtual void SAL_CALL 217 dispose(); 218 219 virtual void SAL_CALL 220 addEventListener( const REFERENCE< XEVENTLISTENER >& Listener ); 221 222 virtual void SAL_CALL 223 removeEventListener( const REFERENCE< XEVENTLISTENER >& Listener ); 224 225 // XContentAccess 226 virtual rtl::OUString SAL_CALL 227 queryContentIdentifierString(); 228 virtual REFERENCE< 229 com::sun::star::ucb::XContentIdentifier > SAL_CALL 230 queryContentIdentifier(); 231 virtual REFERENCE< 232 com::sun::star::ucb::XContent > SAL_CALL 233 queryContent(); 234 235 // XResultSet 236 virtual sal_Bool SAL_CALL 237 next(); 238 virtual sal_Bool SAL_CALL 239 isBeforeFirst(); 240 virtual sal_Bool SAL_CALL 241 isAfterLast(); 242 virtual sal_Bool SAL_CALL 243 isFirst(); 244 virtual sal_Bool SAL_CALL 245 isLast(); 246 virtual void SAL_CALL 247 beforeFirst(); 248 virtual void SAL_CALL 249 afterLast(); 250 virtual sal_Bool SAL_CALL 251 first(); 252 virtual sal_Bool SAL_CALL 253 last(); 254 virtual sal_Int32 SAL_CALL 255 getRow(); 256 virtual sal_Bool SAL_CALL 257 absolute( sal_Int32 row ); 258 virtual sal_Bool SAL_CALL 259 relative( sal_Int32 rows ); 260 virtual sal_Bool SAL_CALL 261 previous(); 262 virtual void SAL_CALL 263 refreshRow(); 264 virtual sal_Bool SAL_CALL 265 rowUpdated(); 266 virtual sal_Bool SAL_CALL 267 rowInserted(); 268 virtual sal_Bool SAL_CALL 269 rowDeleted(); 270 virtual REFERENCE< 271 com::sun::star::uno::XInterface > SAL_CALL 272 getStatement(); 273 274 // XRow 275 virtual sal_Bool SAL_CALL 276 wasNull(); 277 278 virtual rtl::OUString SAL_CALL 279 getString( sal_Int32 columnIndex ); 280 281 virtual sal_Bool SAL_CALL 282 getBoolean( sal_Int32 columnIndex ); 283 284 virtual sal_Int8 SAL_CALL 285 getByte( sal_Int32 columnIndex ); 286 287 virtual sal_Int16 SAL_CALL 288 getShort( sal_Int32 columnIndex ); 289 290 virtual sal_Int32 SAL_CALL 291 getInt( sal_Int32 columnIndex ); 292 293 virtual sal_Int64 SAL_CALL 294 getLong( sal_Int32 columnIndex ); 295 296 virtual float SAL_CALL 297 getFloat( sal_Int32 columnIndex ); 298 299 virtual double SAL_CALL 300 getDouble( sal_Int32 columnIndex ); 301 302 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL 303 getBytes( sal_Int32 columnIndex ); 304 305 virtual com::sun::star::util::Date SAL_CALL 306 getDate( sal_Int32 columnIndex ); 307 308 virtual com::sun::star::util::Time SAL_CALL 309 getTime( sal_Int32 columnIndex ); 310 311 virtual com::sun::star::util::DateTime SAL_CALL 312 getTimestamp( sal_Int32 columnIndex ); 313 314 virtual REFERENCE< 315 com::sun::star::io::XInputStream > SAL_CALL 316 getBinaryStream( sal_Int32 columnIndex ); 317 318 virtual REFERENCE< 319 com::sun::star::io::XInputStream > SAL_CALL 320 getCharacterStream( sal_Int32 columnIndex ); 321 322 virtual com::sun::star::uno::Any SAL_CALL 323 getObject( sal_Int32 columnIndex, 324 const REFERENCE< 325 com::sun::star::container::XNameAccess >& typeMap ); 326 virtual REFERENCE< 327 com::sun::star::sdbc::XRef > SAL_CALL 328 getRef( sal_Int32 columnIndex ); 329 virtual REFERENCE< 330 com::sun::star::sdbc::XBlob > SAL_CALL 331 getBlob( sal_Int32 columnIndex ); 332 virtual REFERENCE< 333 com::sun::star::sdbc::XClob > SAL_CALL 334 getClob( sal_Int32 columnIndex ); 335 virtual REFERENCE< 336 com::sun::star::sdbc::XArray > SAL_CALL 337 getArray( sal_Int32 columnIndex ); 338 339 // XCloseable 340 virtual void SAL_CALL 341 close(); 342 343 // XResultSetMetaDataSupplier 344 virtual REFERENCE< XRESULTSETMETADATA > SAL_CALL 345 getMetaData(); 346 347 348 // XPropertySet 349 virtual REFERENCE< 350 com::sun::star::beans::XPropertySetInfo > SAL_CALL 351 getPropertySetInfo(); 352 353 virtual void SAL_CALL 354 setPropertyValue( const rtl::OUString& PropertyName, 355 const com::sun::star::uno::Any& Value ); 356 357 virtual com::sun::star::uno::Any SAL_CALL 358 getPropertyValue( const rtl::OUString& PropertyName ); 359 360 virtual void SAL_CALL 361 addPropertyChangeListener( const rtl::OUString& PropertyName, 362 const REFERENCE< 363 com::sun::star::beans::XPropertyChangeListener >& Listener ); 364 365 virtual void SAL_CALL 366 removePropertyChangeListener( const rtl::OUString& PropertyName, 367 const REFERENCE< 368 com::sun::star::beans::XPropertyChangeListener >& Listener ); 369 370 virtual void SAL_CALL 371 addVetoableChangeListener( const rtl::OUString& PropertyName, 372 const REFERENCE< 373 com::sun::star::beans::XVetoableChangeListener >& Listener ); 374 375 virtual void SAL_CALL 376 removeVetoableChangeListener( const rtl::OUString& PropertyName, 377 const REFERENCE< 378 com::sun::star::beans::XVetoableChangeListener >& aListener ); 379 }; 380 381 #endif 382