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 throw( com::sun::star::uno::RuntimeException ); 127 virtual void SAL_CALL 128 addEventListener( const com::sun::star::uno::Reference< 129 com::sun::star::lang::XEventListener >& Listener ) 130 throw( com::sun::star::uno::RuntimeException ); 131 virtual void SAL_CALL 132 removeEventListener( const com::sun::star::uno::Reference< 133 com::sun::star::lang::XEventListener >& Listener ) 134 throw( com::sun::star::uno::RuntimeException ); 135 136 // XContentAccess 137 virtual rtl::OUString SAL_CALL 138 queryContentIdentifierString() 139 throw( com::sun::star::uno::RuntimeException ); 140 virtual com::sun::star::uno::Reference< 141 com::sun::star::ucb::XContentIdentifier > SAL_CALL 142 queryContentIdentifier() 143 throw( com::sun::star::uno::RuntimeException ); 144 virtual com::sun::star::uno::Reference< 145 com::sun::star::ucb::XContent > SAL_CALL 146 queryContent() 147 throw( com::sun::star::uno::RuntimeException ); 148 149 // XResultSetMetaDataSupplier 150 virtual com::sun::star::uno::Reference< 151 com::sun::star::sdbc::XResultSetMetaData > SAL_CALL 152 getMetaData() 153 throw( com::sun::star::sdbc::SQLException, 154 com::sun::star::uno::RuntimeException ); 155 156 // XResultSet 157 virtual sal_Bool SAL_CALL 158 next() 159 throw( com::sun::star::sdbc::SQLException, 160 com::sun::star::uno::RuntimeException ); 161 virtual sal_Bool SAL_CALL 162 isBeforeFirst() 163 throw( com::sun::star::sdbc::SQLException, 164 com::sun::star::uno::RuntimeException ); 165 virtual sal_Bool SAL_CALL 166 isAfterLast() 167 throw( com::sun::star::sdbc::SQLException, 168 com::sun::star::uno::RuntimeException ); 169 virtual sal_Bool SAL_CALL 170 isFirst() 171 throw( com::sun::star::sdbc::SQLException, 172 com::sun::star::uno::RuntimeException ); 173 virtual sal_Bool SAL_CALL 174 isLast() 175 throw( com::sun::star::sdbc::SQLException, 176 com::sun::star::uno::RuntimeException ); 177 virtual void SAL_CALL 178 beforeFirst() 179 throw( com::sun::star::sdbc::SQLException, 180 com::sun::star::uno::RuntimeException ); 181 virtual void SAL_CALL 182 afterLast() 183 throw( com::sun::star::sdbc::SQLException, 184 com::sun::star::uno::RuntimeException ); 185 virtual sal_Bool SAL_CALL 186 first() 187 throw( com::sun::star::sdbc::SQLException, 188 com::sun::star::uno::RuntimeException ); 189 virtual sal_Bool SAL_CALL 190 last() 191 throw( com::sun::star::sdbc::SQLException, 192 com::sun::star::uno::RuntimeException ); 193 virtual sal_Int32 SAL_CALL 194 getRow() 195 throw( com::sun::star::sdbc::SQLException, 196 com::sun::star::uno::RuntimeException ); 197 virtual sal_Bool SAL_CALL 198 absolute( sal_Int32 row ) 199 throw( com::sun::star::sdbc::SQLException, 200 com::sun::star::uno::RuntimeException ); 201 virtual sal_Bool SAL_CALL 202 relative( sal_Int32 rows ) 203 throw( com::sun::star::sdbc::SQLException, 204 com::sun::star::uno::RuntimeException ); 205 virtual sal_Bool SAL_CALL 206 previous() 207 throw( com::sun::star::sdbc::SQLException, 208 com::sun::star::uno::RuntimeException ); 209 virtual void SAL_CALL 210 refreshRow() 211 throw( com::sun::star::sdbc::SQLException, 212 com::sun::star::uno::RuntimeException ); 213 virtual sal_Bool SAL_CALL 214 rowUpdated() 215 throw( com::sun::star::sdbc::SQLException, 216 com::sun::star::uno::RuntimeException ); 217 virtual sal_Bool SAL_CALL 218 rowInserted() 219 throw( com::sun::star::sdbc::SQLException, 220 com::sun::star::uno::RuntimeException ); 221 virtual sal_Bool SAL_CALL 222 rowDeleted() 223 throw( com::sun::star::sdbc::SQLException, 224 com::sun::star::uno::RuntimeException ); 225 virtual com::sun::star::uno::Reference< 226 com::sun::star::uno::XInterface > SAL_CALL 227 getStatement() 228 throw( com::sun::star::sdbc::SQLException, 229 com::sun::star::uno::RuntimeException ); 230 231 // XRow 232 virtual sal_Bool SAL_CALL 233 wasNull() 234 throw( com::sun::star::sdbc::SQLException, 235 com::sun::star::uno::RuntimeException ); 236 virtual rtl::OUString SAL_CALL 237 getString( sal_Int32 columnIndex ) 238 throw( com::sun::star::sdbc::SQLException, 239 com::sun::star::uno::RuntimeException ); 240 virtual sal_Bool SAL_CALL 241 getBoolean( sal_Int32 columnIndex ) 242 throw( com::sun::star::sdbc::SQLException, 243 com::sun::star::uno::RuntimeException ); 244 virtual sal_Int8 SAL_CALL 245 getByte( sal_Int32 columnIndex ) 246 throw( com::sun::star::sdbc::SQLException, 247 com::sun::star::uno::RuntimeException ); 248 virtual sal_Int16 SAL_CALL 249 getShort( sal_Int32 columnIndex ) 250 throw( com::sun::star::sdbc::SQLException, 251 com::sun::star::uno::RuntimeException ); 252 virtual sal_Int32 SAL_CALL 253 getInt( sal_Int32 columnIndex ) 254 throw( com::sun::star::sdbc::SQLException, 255 com::sun::star::uno::RuntimeException ); 256 virtual sal_Int64 SAL_CALL 257 getLong( sal_Int32 columnIndex ) 258 throw( com::sun::star::sdbc::SQLException, 259 com::sun::star::uno::RuntimeException ); 260 virtual float SAL_CALL 261 getFloat( sal_Int32 columnIndex ) 262 throw( com::sun::star::sdbc::SQLException, 263 com::sun::star::uno::RuntimeException ); 264 virtual double SAL_CALL 265 getDouble( sal_Int32 columnIndex ) 266 throw( com::sun::star::sdbc::SQLException, 267 com::sun::star::uno::RuntimeException ); 268 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL 269 getBytes( sal_Int32 columnIndex ) 270 throw( com::sun::star::sdbc::SQLException, 271 com::sun::star::uno::RuntimeException ); 272 virtual com::sun::star::util::Date SAL_CALL 273 getDate( sal_Int32 columnIndex ) 274 throw( com::sun::star::sdbc::SQLException, 275 com::sun::star::uno::RuntimeException ); 276 virtual com::sun::star::util::Time SAL_CALL 277 getTime( sal_Int32 columnIndex ) 278 throw( com::sun::star::sdbc::SQLException, 279 com::sun::star::uno::RuntimeException ); 280 virtual com::sun::star::util::DateTime SAL_CALL 281 getTimestamp( sal_Int32 columnIndex ) 282 throw( com::sun::star::sdbc::SQLException, 283 com::sun::star::uno::RuntimeException ); 284 virtual com::sun::star::uno::Reference< 285 com::sun::star::io::XInputStream > SAL_CALL 286 getBinaryStream( sal_Int32 columnIndex ) 287 throw( com::sun::star::sdbc::SQLException, 288 com::sun::star::uno::RuntimeException ); 289 virtual com::sun::star::uno::Reference< 290 com::sun::star::io::XInputStream > SAL_CALL 291 getCharacterStream( sal_Int32 columnIndex ) 292 throw( com::sun::star::sdbc::SQLException, 293 com::sun::star::uno::RuntimeException ); 294 virtual com::sun::star::uno::Any SAL_CALL 295 getObject( sal_Int32 columnIndex, 296 const com::sun::star::uno::Reference< 297 com::sun::star::container::XNameAccess >& typeMap ) 298 throw( com::sun::star::sdbc::SQLException, 299 com::sun::star::uno::RuntimeException ); 300 virtual com::sun::star::uno::Reference< 301 com::sun::star::sdbc::XRef > SAL_CALL 302 getRef( sal_Int32 columnIndex ) 303 throw( com::sun::star::sdbc::SQLException, 304 com::sun::star::uno::RuntimeException ); 305 virtual com::sun::star::uno::Reference< 306 com::sun::star::sdbc::XBlob > SAL_CALL 307 getBlob( sal_Int32 columnIndex ) 308 throw( com::sun::star::sdbc::SQLException, 309 com::sun::star::uno::RuntimeException ); 310 virtual com::sun::star::uno::Reference< 311 com::sun::star::sdbc::XClob > SAL_CALL 312 getClob( sal_Int32 columnIndex ) 313 throw( com::sun::star::sdbc::SQLException, 314 com::sun::star::uno::RuntimeException ); 315 virtual com::sun::star::uno::Reference< 316 com::sun::star::sdbc::XArray > SAL_CALL 317 getArray( sal_Int32 columnIndex ) 318 throw( com::sun::star::sdbc::SQLException, 319 com::sun::star::uno::RuntimeException ); 320 321 // XCloseable 322 virtual void SAL_CALL 323 close() 324 throw( com::sun::star::sdbc::SQLException, 325 com::sun::star::uno::RuntimeException ); 326 327 // XPropertySet 328 virtual com::sun::star::uno::Reference< 329 com::sun::star::beans::XPropertySetInfo > SAL_CALL 330 getPropertySetInfo() 331 throw( com::sun::star::uno::RuntimeException ); 332 virtual void SAL_CALL 333 setPropertyValue( const rtl::OUString& aPropertyName, 334 const com::sun::star::uno::Any& aValue ) 335 throw( com::sun::star::beans::UnknownPropertyException, 336 com::sun::star::beans::PropertyVetoException, 337 com::sun::star::lang::IllegalArgumentException, 338 com::sun::star::lang::WrappedTargetException, 339 com::sun::star::uno::RuntimeException ); 340 virtual com::sun::star::uno::Any SAL_CALL 341 getPropertyValue( const rtl::OUString& PropertyName ) 342 throw( com::sun::star::beans::UnknownPropertyException, 343 com::sun::star::lang::WrappedTargetException, 344 com::sun::star::uno::RuntimeException ); 345 virtual void SAL_CALL 346 addPropertyChangeListener( const rtl::OUString& aPropertyName, 347 const com::sun::star::uno::Reference< 348 com::sun::star::beans::XPropertyChangeListener >& xListener ) 349 throw( com::sun::star::beans::UnknownPropertyException, 350 com::sun::star::lang::WrappedTargetException, 351 com::sun::star::uno::RuntimeException ); 352 virtual void SAL_CALL 353 removePropertyChangeListener( const rtl::OUString& aPropertyName, 354 const com::sun::star::uno::Reference< 355 com::sun::star::beans::XPropertyChangeListener >& aListener ) 356 throw( com::sun::star::beans::UnknownPropertyException, 357 com::sun::star::lang::WrappedTargetException, 358 com::sun::star::uno::RuntimeException ); 359 virtual void SAL_CALL 360 addVetoableChangeListener( const rtl::OUString& PropertyName, 361 const com::sun::star::uno::Reference< 362 com::sun::star::beans::XVetoableChangeListener >& aListener ) 363 throw( com::sun::star::beans::UnknownPropertyException, 364 com::sun::star::lang::WrappedTargetException, 365 com::sun::star::uno::RuntimeException ); 366 virtual void SAL_CALL 367 removeVetoableChangeListener( const rtl::OUString& PropertyName, 368 const com::sun::star::uno::Reference< 369 com::sun::star::beans::XVetoableChangeListener >& aListener ) 370 throw( com::sun::star::beans::UnknownPropertyException, 371 com::sun::star::lang::WrappedTargetException, 372 com::sun::star::uno::RuntimeException ); 373 374 ///////////////////////////////////////////////////////////////////// 375 // Non-interface methods. 376 ///////////////////////////////////////////////////////////////////// 377 378 /** 379 * This method propagates property value changes to all registered 380 * listeners. 381 * 382 * @param rEvt is a property change event. 383 */ 384 void propertyChanged( 385 const com::sun::star::beans::PropertyChangeEvent& rEvt ); 386 387 /** 388 * This method should be called by the data supplier for the result set 389 * to indicate that there were new data obtained from the data source. 390 * 391 * @param nOld is the old count of rows; must be non-negative. 392 * @param nnew is the new count of rows; must be non-negative. 393 */ 394 void rowCountChanged( sal_uInt32 nOld, sal_uInt32 nNew ); 395 396 /** 397 * This method should be called by the data supplier for the result set 398 * to indicate that there were all rows obtained from the data source. 399 */ 400 void rowCountFinal(); 401 402 /** 403 * This method returns a sequence containing all properties ( not the 404 * values! ) of the result set. 405 * 406 * @return a sequence of properties. 407 */ 408 const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& 409 getProperties(); 410 411 /** 412 * This method returns the environment to use for interactions, progress 413 * propagation, ... It can by empty. 414 * 415 * @return an environment or an empty reference. 416 */ 417 const com::sun::star::uno::Reference< 418 com::sun::star::ucb::XCommandEnvironment >& 419 getEnvironment(); 420 }; 421 422 //========================================================================= 423 424 /** 425 * This is the base class for an object that supplies data to a result set 426 * 427 * @see ResultSet 428 */ 429 class ResultSetDataSupplier : public salhelper::SimpleReferenceObject 430 { 431 friend class ResultSet; 432 433 // No ref, otherwise we get a cyclic reference between supplier and set! 434 // Will be set from ResultSet ctor. 435 ResultSet* m_pResultSet; 436 437 public: ResultSetDataSupplier()438 ResultSetDataSupplier() : m_pResultSet( 0 ) {} 439 440 /** 441 * This method returns the resultset this supplier belongs to. 442 * 443 * @return the resultset for that the supplier supplies data. 444 */ getResultSet() const445 rtl::Reference< ResultSet > getResultSet() const { return m_pResultSet; } 446 447 /** 448 * This method returns the identifier string of the content at the 449 * specified index. 450 * 451 * @param nIndex is the zero-based index within the logical data array 452 * of the supplier; must be non-negative. 453 * @return the content's identifier string. 454 */ 455 virtual rtl::OUString queryContentIdentifierString( sal_uInt32 nIndex ) = 0; 456 457 /** 458 * This method returns the identifier of the content at the specified index. 459 * 460 * @param nIndex is the zero-based index within the logical data array 461 * of the supplier; must be non-negative. 462 * @return the content's identifier. 463 */ 464 virtual com::sun::star::uno::Reference< 465 com::sun::star::ucb::XContentIdentifier > 466 queryContentIdentifier( sal_uInt32 nIndex ) = 0; 467 468 /** 469 * This method returns the the content at the specified index. 470 * 471 * @param nIndex is the zero-based index within the logical data array 472 * of the supplier; must be non-negative. 473 * @return the content. 474 */ 475 virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > 476 queryContent( sal_uInt32 nIndex ) = 0; 477 478 /** 479 * This method returns whether there is a content at the specified index. 480 * 481 * @param nIndex is the zero-based index within the logical data array 482 * of the supplier; must be non-negative. 483 * @return true, if there is a content at the given index. 484 */ 485 virtual sal_Bool getResult( sal_uInt32 nIndex ) = 0; 486 487 /** 488 * This method returns the total count of objects in the logical data array 489 * of the supplier. The implementation of this method may be very 490 * "expensive", because it can be necessary to obtain all data in order 491 * to determine the count. Therefor the ResultSet implementation calls 492 * it very seldom. 493 * 494 * @return the total count of objects; will always be non-negative. 495 */ 496 virtual sal_uInt32 totalCount() = 0; 497 498 /** 499 * This method returns the count of objects obtained so far. There is no 500 * for the implemetation to obtain all objects at once. It can obtain 501 * all data on demand. 502 * 503 * The implementation should call m_pResultSet->rowCountChanged(...) 504 * everytime it has inserted a new entry in its logical result array. 505 * 506 * @return the count of objects obtained so far; will always be 507 * non-negative. 508 */ 509 virtual sal_uInt32 currentCount() = 0; 510 511 /** 512 * This method returns whether the value returned by currentCount() is 513 * "final". This is the case, if that there was all data obtained by the 514 * supplier and the current count won't increase any more. 515 * 516 * The implementation should call m_pResultSet->rowCountFinal(...) if 517 * it has inserted all entries in its logical result array. 518 * 519 * @return true, if the the value returned by currentCount() won't change 520 anymore. 521 */ 522 virtual sal_Bool isCountFinal() = 0; 523 524 /** 525 * This method returns an object for accessing the property values at 526 * the specified index. The implementation may use the helper class 527 * ucb::PropertyValueSet to provide the return value. 528 * 529 * @param nIndex is the zero-based index within the logical data array 530 * of the supplier. 531 * @return the object for accessing the property values. 532 */ 533 virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > 534 queryPropertyValues( sal_uInt32 nIndex ) = 0; 535 536 /** 537 * This method is called to instruct the supplier to release the (possibly 538 * presnt) property values at the given index. 539 * 540 * @param nIndex is the zero-based index within the logical data array 541 * of the supplier. 542 */ 543 virtual void releasePropertyValues( sal_uInt32 nIndex ) = 0; 544 545 /** 546 * This method will be called by the resultset implementation in order 547 * to instruct the data supplier to release all resources it has 548 * allocated so far. In case the supplier is collecting data 549 * asynchronously, that process must be stopped. 550 */ 551 virtual void close() = 0; 552 553 /** 554 * This method will be called by the resultset implementation in order 555 * check, whether an error has occured while collecting data. The 556 * implementation of this method must throw an exception in that case. 557 * 558 * Note: An exception thrown to indicate an error must always be thrown 559 * by the thread that created the data supplier. If the supplier collects 560 * data asynchronously ( i.e. in a separate thread ) and an error 561 * occures, throwing of the appropriate exception must be deferred 562 * until validate() is called by the ResultSet implementation from 563 * inside the main thread. 564 * In case data are obtained synchronously, the ResultSetException can 565 * be thrown directly. 566 * 567 * @exception ResultSetException thrown, if an error has occured 568 */ 569 virtual void validate() 570 throw( com::sun::star::ucb::ResultSetException ) = 0; 571 }; 572 573 } 574 575 #endif /* !_UCBHELPER_RESULTSET_HXX */ 576