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 _UCBHELPER_RESULTSET_HXX 25 #define _UCBHELPER_RESULTSET_HXX 26 27 #include <com/sun/star/lang/XTypeProvider.hpp> 28 #include <com/sun/star/lang/XServiceInfo.hpp> 29 #include <com/sun/star/lang/XComponent.hpp> 30 #include <com/sun/star/ucb/ResultSetException.hpp> 31 #include <com/sun/star/ucb/XCommandEnvironment.hpp> 32 #include <com/sun/star/ucb/XContentAccess.hpp> 33 #include <com/sun/star/sdbc/XResultSet.hpp> 34 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> 35 #include <com/sun/star/sdbc/XRow.hpp> 36 #include <com/sun/star/sdbc/XCloseable.hpp> 37 #include <com/sun/star/beans/XPropertySet.hpp> 38 39 #include "rtl/ref.hxx" 40 #include "salhelper/simplereferenceobject.hxx" 41 #include <cppuhelper/weak.hxx> 42 #include <ucbhelper/macros.hxx> 43 #include "ucbhelper/ucbhelperdllapi.h" 44 45 namespace ucbhelper { 46 47 //========================================================================= 48 49 #define RESULTSET_SERVICE_NAME "com.sun.star.ucb.ContentResultSet" 50 51 //========================================================================= 52 53 class ResultSetDataSupplier; 54 struct ResultSet_Impl; 55 56 /** 57 * This is an implementation of the service com.sun.star.ucb.ContentResultSet. 58 * It can be used to implement the method XDynamicResultSet::getStaticResultSet, 59 * which needs to be implemented for instance to implement the command "open" 60 * at folder objects. This class uses a user supplied ResultSetDataSupplier 61 * object to request data on demand. 62 * 63 * @see ResultSetDataSupplier 64 */ 65 class UCBHELPER_DLLPUBLIC ResultSet : 66 public cppu::OWeakObject, 67 public com::sun::star::lang::XTypeProvider, 68 public com::sun::star::lang::XServiceInfo, 69 public com::sun::star::lang::XComponent, 70 public com::sun::star::ucb::XContentAccess, 71 public com::sun::star::sdbc::XResultSet, 72 public com::sun::star::sdbc::XResultSetMetaDataSupplier, 73 public com::sun::star::sdbc::XRow, 74 public com::sun::star::sdbc::XCloseable, 75 public com::sun::star::beans::XPropertySet 76 { 77 ResultSet_Impl* m_pImpl; 78 79 public: 80 /** 81 * Construction. 82 * 83 * @param rxSMgr is a Service Manager. 84 * @param rProperties is a sequence of properties for that the resultset 85 * shall be able to obtain the values. 86 * @param rDataSupplier is a supplier for the resultset data. 87 */ 88 ResultSet( 89 const com::sun::star::uno::Reference< 90 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 91 const com::sun::star::uno::Sequence< 92 com::sun::star::beans::Property >& rProperties, 93 const rtl::Reference< ResultSetDataSupplier >& rDataSupplier ); 94 /** 95 * Construction. 96 * 97 * @param rxSMgr is a Service Manager. 98 * @param rProperties is a sequence of properties for that the resultset 99 * shall be able to obtain the values. 100 * @param rDataSupplier is a supplier for the resultset data. 101 * @param rxEnv is the environment for interactions, progress propagation, 102 * ... 103 */ 104 ResultSet( 105 const com::sun::star::uno::Reference< 106 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 107 const com::sun::star::uno::Sequence< 108 com::sun::star::beans::Property >& rProperties, 109 const rtl::Reference< ResultSetDataSupplier >& rDataSupplier, 110 const com::sun::star::uno::Reference< 111 com::sun::star::ucb::XCommandEnvironment >& rxEnv ); 112 virtual ~ResultSet(); 113 114 // XInterface 115 XINTERFACE_DECL() 116 117 // XTypeProvider 118 XTYPEPROVIDER_DECL() 119 120 // XServiceInfo 121 XSERVICEINFO_NOFACTORY_DECL() 122 123 // XComponent 124 virtual void SAL_CALL 125 dispose(); 126 virtual void SAL_CALL 127 addEventListener( const com::sun::star::uno::Reference< 128 com::sun::star::lang::XEventListener >& Listener ); 129 virtual void SAL_CALL 130 removeEventListener( const com::sun::star::uno::Reference< 131 com::sun::star::lang::XEventListener >& Listener ); 132 133 // XContentAccess 134 virtual rtl::OUString SAL_CALL 135 queryContentIdentifierString(); 136 virtual com::sun::star::uno::Reference< 137 com::sun::star::ucb::XContentIdentifier > SAL_CALL 138 queryContentIdentifier(); 139 virtual com::sun::star::uno::Reference< 140 com::sun::star::ucb::XContent > SAL_CALL 141 queryContent(); 142 143 // XResultSetMetaDataSupplier 144 virtual com::sun::star::uno::Reference< 145 com::sun::star::sdbc::XResultSetMetaData > SAL_CALL 146 getMetaData(); 147 148 // XResultSet 149 virtual sal_Bool SAL_CALL 150 next(); 151 virtual sal_Bool SAL_CALL 152 isBeforeFirst(); 153 virtual sal_Bool SAL_CALL 154 isAfterLast(); 155 virtual sal_Bool SAL_CALL 156 isFirst(); 157 virtual sal_Bool SAL_CALL 158 isLast(); 159 virtual void SAL_CALL 160 beforeFirst(); 161 virtual void SAL_CALL 162 afterLast(); 163 virtual sal_Bool SAL_CALL 164 first(); 165 virtual sal_Bool SAL_CALL 166 last(); 167 virtual sal_Int32 SAL_CALL 168 getRow(); 169 virtual sal_Bool SAL_CALL 170 absolute( sal_Int32 row ); 171 virtual sal_Bool SAL_CALL 172 relative( sal_Int32 rows ); 173 virtual sal_Bool SAL_CALL 174 previous(); 175 virtual void SAL_CALL 176 refreshRow(); 177 virtual sal_Bool SAL_CALL 178 rowUpdated(); 179 virtual sal_Bool SAL_CALL 180 rowInserted(); 181 virtual sal_Bool SAL_CALL 182 rowDeleted(); 183 virtual com::sun::star::uno::Reference< 184 com::sun::star::uno::XInterface > SAL_CALL 185 getStatement(); 186 187 // XRow 188 virtual sal_Bool SAL_CALL 189 wasNull(); 190 virtual rtl::OUString SAL_CALL 191 getString( sal_Int32 columnIndex ); 192 virtual sal_Bool SAL_CALL 193 getBoolean( sal_Int32 columnIndex ); 194 virtual sal_Int8 SAL_CALL 195 getByte( sal_Int32 columnIndex ); 196 virtual sal_Int16 SAL_CALL 197 getShort( sal_Int32 columnIndex ); 198 virtual sal_Int32 SAL_CALL 199 getInt( sal_Int32 columnIndex ); 200 virtual sal_Int64 SAL_CALL 201 getLong( sal_Int32 columnIndex ); 202 virtual float SAL_CALL 203 getFloat( sal_Int32 columnIndex ); 204 virtual double SAL_CALL 205 getDouble( sal_Int32 columnIndex ); 206 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL 207 getBytes( sal_Int32 columnIndex ); 208 virtual com::sun::star::util::Date SAL_CALL 209 getDate( sal_Int32 columnIndex ); 210 virtual com::sun::star::util::Time SAL_CALL 211 getTime( sal_Int32 columnIndex ); 212 virtual com::sun::star::util::DateTime SAL_CALL 213 getTimestamp( sal_Int32 columnIndex ); 214 virtual com::sun::star::uno::Reference< 215 com::sun::star::io::XInputStream > SAL_CALL 216 getBinaryStream( sal_Int32 columnIndex ); 217 virtual com::sun::star::uno::Reference< 218 com::sun::star::io::XInputStream > SAL_CALL 219 getCharacterStream( sal_Int32 columnIndex ); 220 virtual com::sun::star::uno::Any SAL_CALL 221 getObject( sal_Int32 columnIndex, 222 const com::sun::star::uno::Reference< 223 com::sun::star::container::XNameAccess >& typeMap ); 224 virtual com::sun::star::uno::Reference< 225 com::sun::star::sdbc::XRef > SAL_CALL 226 getRef( sal_Int32 columnIndex ); 227 virtual com::sun::star::uno::Reference< 228 com::sun::star::sdbc::XBlob > SAL_CALL 229 getBlob( sal_Int32 columnIndex ); 230 virtual com::sun::star::uno::Reference< 231 com::sun::star::sdbc::XClob > SAL_CALL 232 getClob( sal_Int32 columnIndex ); 233 virtual com::sun::star::uno::Reference< 234 com::sun::star::sdbc::XArray > SAL_CALL 235 getArray( sal_Int32 columnIndex ); 236 237 // XCloseable 238 virtual void SAL_CALL 239 close(); 240 241 // XPropertySet 242 virtual com::sun::star::uno::Reference< 243 com::sun::star::beans::XPropertySetInfo > SAL_CALL 244 getPropertySetInfo(); 245 virtual void SAL_CALL 246 setPropertyValue( const rtl::OUString& aPropertyName, 247 const com::sun::star::uno::Any& aValue ); 248 virtual com::sun::star::uno::Any SAL_CALL 249 getPropertyValue( const rtl::OUString& PropertyName ); 250 virtual void SAL_CALL 251 addPropertyChangeListener( const rtl::OUString& aPropertyName, 252 const com::sun::star::uno::Reference< 253 com::sun::star::beans::XPropertyChangeListener >& xListener ); 254 virtual void SAL_CALL 255 removePropertyChangeListener( const rtl::OUString& aPropertyName, 256 const com::sun::star::uno::Reference< 257 com::sun::star::beans::XPropertyChangeListener >& aListener ); 258 virtual void SAL_CALL 259 addVetoableChangeListener( const rtl::OUString& PropertyName, 260 const com::sun::star::uno::Reference< 261 com::sun::star::beans::XVetoableChangeListener >& aListener ); 262 virtual void SAL_CALL 263 removeVetoableChangeListener( const rtl::OUString& PropertyName, 264 const com::sun::star::uno::Reference< 265 com::sun::star::beans::XVetoableChangeListener >& aListener ); 266 267 ///////////////////////////////////////////////////////////////////// 268 // Non-interface methods. 269 ///////////////////////////////////////////////////////////////////// 270 271 /** 272 * This method propagates property value changes to all registered 273 * listeners. 274 * 275 * @param rEvt is a property change event. 276 */ 277 void propertyChanged( 278 const com::sun::star::beans::PropertyChangeEvent& rEvt ); 279 280 /** 281 * This method should be called by the data supplier for the result set 282 * to indicate that there were new data obtained from the data source. 283 * 284 * @param nOld is the old count of rows; must be non-negative. 285 * @param nnew is the new count of rows; must be non-negative. 286 */ 287 void rowCountChanged( sal_uInt32 nOld, sal_uInt32 nNew ); 288 289 /** 290 * This method should be called by the data supplier for the result set 291 * to indicate that there were all rows obtained from the data source. 292 */ 293 void rowCountFinal(); 294 295 /** 296 * This method returns a sequence containing all properties ( not the 297 * values! ) of the result set. 298 * 299 * @return a sequence of properties. 300 */ 301 const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& 302 getProperties(); 303 304 /** 305 * This method returns the environment to use for interactions, progress 306 * propagation, ... It can by empty. 307 * 308 * @return an environment or an empty reference. 309 */ 310 const com::sun::star::uno::Reference< 311 com::sun::star::ucb::XCommandEnvironment >& 312 getEnvironment(); 313 }; 314 315 //========================================================================= 316 317 /** 318 * This is the base class for an object that supplies data to a result set 319 * 320 * @see ResultSet 321 */ 322 class ResultSetDataSupplier : public salhelper::SimpleReferenceObject 323 { 324 friend class ResultSet; 325 326 // No ref, otherwise we get a cyclic reference between supplier and set! 327 // Will be set from ResultSet ctor. 328 ResultSet* m_pResultSet; 329 330 public: ResultSetDataSupplier()331 ResultSetDataSupplier() : m_pResultSet( 0 ) {} 332 333 /** 334 * This method returns the resultset this supplier belongs to. 335 * 336 * @return the resultset for that the supplier supplies data. 337 */ getResultSet() const338 rtl::Reference< ResultSet > getResultSet() const { return m_pResultSet; } 339 340 /** 341 * This method returns the identifier string of the content at the 342 * specified index. 343 * 344 * @param nIndex is the zero-based index within the logical data array 345 * of the supplier; must be non-negative. 346 * @return the content's identifier string. 347 */ 348 virtual rtl::OUString queryContentIdentifierString( sal_uInt32 nIndex ) = 0; 349 350 /** 351 * This method returns the identifier of the content at the specified index. 352 * 353 * @param nIndex is the zero-based index within the logical data array 354 * of the supplier; must be non-negative. 355 * @return the content's identifier. 356 */ 357 virtual com::sun::star::uno::Reference< 358 com::sun::star::ucb::XContentIdentifier > 359 queryContentIdentifier( sal_uInt32 nIndex ) = 0; 360 361 /** 362 * This method returns the content at the specified index. 363 * 364 * @param nIndex is the zero-based index within the logical data array 365 * of the supplier; must be non-negative. 366 * @return the content. 367 */ 368 virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > 369 queryContent( sal_uInt32 nIndex ) = 0; 370 371 /** 372 * This method returns whether there is a content at the specified index. 373 * 374 * @param nIndex is the zero-based index within the logical data array 375 * of the supplier; must be non-negative. 376 * @return true, if there is a content at the given index. 377 */ 378 virtual sal_Bool getResult( sal_uInt32 nIndex ) = 0; 379 380 /** 381 * This method returns the total count of objects in the logical data array 382 * of the supplier. The implementation of this method may be very 383 * "expensive", because it can be necessary to obtain all data in order 384 * to determine the count. Therefor the ResultSet implementation calls 385 * it very seldom. 386 * 387 * @return the total count of objects; will always be non-negative. 388 */ 389 virtual sal_uInt32 totalCount() = 0; 390 391 /** 392 * This method returns the count of objects obtained so far. There is no 393 * for the implementation to obtain all objects at once. It can obtain 394 * all data on demand. 395 * 396 * The implementation should call m_pResultSet->rowCountChanged(...) 397 * every time it has inserted a new entry in its logical result array. 398 * 399 * @return the count of objects obtained so far; will always be 400 * non-negative. 401 */ 402 virtual sal_uInt32 currentCount() = 0; 403 404 /** 405 * This method returns whether the value returned by currentCount() is 406 * "final". This is the case, if that there was all data obtained by the 407 * supplier and the current count won't increase any more. 408 * 409 * The implementation should call m_pResultSet->rowCountFinal(...) if 410 * it has inserted all entries in its logical result array. 411 * 412 * @return true, if the value returned by currentCount() won't change 413 anymore. 414 */ 415 virtual sal_Bool isCountFinal() = 0; 416 417 /** 418 * This method returns an object for accessing the property values at 419 * the specified index. The implementation may use the helper class 420 * ucb::PropertyValueSet to provide the return value. 421 * 422 * @param nIndex is the zero-based index within the logical data array 423 * of the supplier. 424 * @return the object for accessing the property values. 425 */ 426 virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > 427 queryPropertyValues( sal_uInt32 nIndex ) = 0; 428 429 /** 430 * This method is called to instruct the supplier to release the (possibly 431 * presnt) property values at the given index. 432 * 433 * @param nIndex is the zero-based index within the logical data array 434 * of the supplier. 435 */ 436 virtual void releasePropertyValues( sal_uInt32 nIndex ) = 0; 437 438 /** 439 * This method will be called by the resultset implementation in order 440 * to instruct the data supplier to release all resources it has 441 * allocated so far. In case the supplier is collecting data 442 * asynchronously, that process must be stopped. 443 */ 444 virtual void close() = 0; 445 446 /** 447 * This method will be called by the resultset implementation in order 448 * check, whether an error has occurred while collecting data. The 449 * implementation of this method must throw an exception in that case. 450 * 451 * Note: An exception thrown to indicate an error must always be thrown 452 * by the thread that created the data supplier. If the supplier collects 453 * data asynchronously ( i.e. in a separate thread ) and an error 454 * occurs, throwing of the appropriate exception must be deferred 455 * until validate() is called by the ResultSet implementation from 456 * inside the main thread. 457 * In case data are obtained synchronously, the ResultSetException can 458 * be thrown directly. 459 * 460 * @exception ResultSetException thrown, if an error has occurred 461 */ 462 virtual void validate() = 0; 463 }; 464 465 } 466 467 #endif /* !_UCBHELPER_RESULTSET_HXX */ 468