1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _UCBHELPER_RESULTSET_HXX 29 #define _UCBHELPER_RESULTSET_HXX 30 31 #include <com/sun/star/lang/XTypeProvider.hpp> 32 #include <com/sun/star/lang/XServiceInfo.hpp> 33 #include <com/sun/star/lang/XComponent.hpp> 34 #include <com/sun/star/ucb/ResultSetException.hpp> 35 #include <com/sun/star/ucb/XCommandEnvironment.hpp> 36 #include <com/sun/star/ucb/XContentAccess.hpp> 37 #include <com/sun/star/sdbc/XResultSet.hpp> 38 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> 39 #include <com/sun/star/sdbc/XRow.hpp> 40 #include <com/sun/star/sdbc/XCloseable.hpp> 41 #include <com/sun/star/beans/XPropertySet.hpp> 42 43 #include "rtl/ref.hxx" 44 #include "salhelper/simplereferenceobject.hxx" 45 #include <cppuhelper/weak.hxx> 46 #include <ucbhelper/macros.hxx> 47 #include "ucbhelper/ucbhelperdllapi.h" 48 49 namespace ucbhelper { 50 51 //========================================================================= 52 53 #define RESULTSET_SERVICE_NAME "com.sun.star.ucb.ContentResultSet" 54 55 //========================================================================= 56 57 class ResultSetDataSupplier; 58 struct ResultSet_Impl; 59 60 /** 61 * This is an implementation of the service com.sun.star.ucb.ContentResultSet. 62 * It can be used to implement the method XDynamicResultSet::getStaticResultSet, 63 * which needs to be implemented for instance to implement the command "open" 64 * at folder objects. This class uses a user supplied ResultSetDataSupplier 65 * object to request data on demand. 66 * 67 * @see ResultSetDataSupplier 68 */ 69 class UCBHELPER_DLLPUBLIC ResultSet : 70 public cppu::OWeakObject, 71 public com::sun::star::lang::XTypeProvider, 72 public com::sun::star::lang::XServiceInfo, 73 public com::sun::star::lang::XComponent, 74 public com::sun::star::ucb::XContentAccess, 75 public com::sun::star::sdbc::XResultSet, 76 public com::sun::star::sdbc::XResultSetMetaDataSupplier, 77 public com::sun::star::sdbc::XRow, 78 public com::sun::star::sdbc::XCloseable, 79 public com::sun::star::beans::XPropertySet 80 { 81 ResultSet_Impl* m_pImpl; 82 83 public: 84 /** 85 * Construction. 86 * 87 * @param rxSMgr is a Service Manager. 88 * @param rProperties is a sequence of properties for that the resultset 89 * shall be able to obtain the values. 90 * @param rDataSupplier is a supplier for the resultset data. 91 */ 92 ResultSet( 93 const com::sun::star::uno::Reference< 94 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 95 const com::sun::star::uno::Sequence< 96 com::sun::star::beans::Property >& rProperties, 97 const rtl::Reference< ResultSetDataSupplier >& rDataSupplier ); 98 /** 99 * Construction. 100 * 101 * @param rxSMgr is a Service Manager. 102 * @param rProperties is a sequence of properties for that the resultset 103 * shall be able to obtain the values. 104 * @param rDataSupplier is a supplier for the resultset data. 105 * @param rxEnv is the environment for interactions, progress propagation, 106 * ... 107 */ 108 ResultSet( 109 const com::sun::star::uno::Reference< 110 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 111 const com::sun::star::uno::Sequence< 112 com::sun::star::beans::Property >& rProperties, 113 const rtl::Reference< ResultSetDataSupplier >& rDataSupplier, 114 const com::sun::star::uno::Reference< 115 com::sun::star::ucb::XCommandEnvironment >& rxEnv ); 116 virtual ~ResultSet(); 117 118 // XInterface 119 XINTERFACE_DECL() 120 121 // XTypeProvider 122 XTYPEPROVIDER_DECL() 123 124 // XServiceInfo 125 XSERVICEINFO_NOFACTORY_DECL() 126 127 // XComponent 128 virtual void SAL_CALL 129 dispose() 130 throw( com::sun::star::uno::RuntimeException ); 131 virtual void SAL_CALL 132 addEventListener( const com::sun::star::uno::Reference< 133 com::sun::star::lang::XEventListener >& Listener ) 134 throw( com::sun::star::uno::RuntimeException ); 135 virtual void SAL_CALL 136 removeEventListener( const com::sun::star::uno::Reference< 137 com::sun::star::lang::XEventListener >& Listener ) 138 throw( com::sun::star::uno::RuntimeException ); 139 140 // XContentAccess 141 virtual rtl::OUString SAL_CALL 142 queryContentIdentifierString() 143 throw( com::sun::star::uno::RuntimeException ); 144 virtual com::sun::star::uno::Reference< 145 com::sun::star::ucb::XContentIdentifier > SAL_CALL 146 queryContentIdentifier() 147 throw( com::sun::star::uno::RuntimeException ); 148 virtual com::sun::star::uno::Reference< 149 com::sun::star::ucb::XContent > SAL_CALL 150 queryContent() 151 throw( com::sun::star::uno::RuntimeException ); 152 153 // XResultSetMetaDataSupplier 154 virtual com::sun::star::uno::Reference< 155 com::sun::star::sdbc::XResultSetMetaData > SAL_CALL 156 getMetaData() 157 throw( com::sun::star::sdbc::SQLException, 158 com::sun::star::uno::RuntimeException ); 159 160 // XResultSet 161 virtual sal_Bool SAL_CALL 162 next() 163 throw( com::sun::star::sdbc::SQLException, 164 com::sun::star::uno::RuntimeException ); 165 virtual sal_Bool SAL_CALL 166 isBeforeFirst() 167 throw( com::sun::star::sdbc::SQLException, 168 com::sun::star::uno::RuntimeException ); 169 virtual sal_Bool SAL_CALL 170 isAfterLast() 171 throw( com::sun::star::sdbc::SQLException, 172 com::sun::star::uno::RuntimeException ); 173 virtual sal_Bool SAL_CALL 174 isFirst() 175 throw( com::sun::star::sdbc::SQLException, 176 com::sun::star::uno::RuntimeException ); 177 virtual sal_Bool SAL_CALL 178 isLast() 179 throw( com::sun::star::sdbc::SQLException, 180 com::sun::star::uno::RuntimeException ); 181 virtual void SAL_CALL 182 beforeFirst() 183 throw( com::sun::star::sdbc::SQLException, 184 com::sun::star::uno::RuntimeException ); 185 virtual void SAL_CALL 186 afterLast() 187 throw( com::sun::star::sdbc::SQLException, 188 com::sun::star::uno::RuntimeException ); 189 virtual sal_Bool SAL_CALL 190 first() 191 throw( com::sun::star::sdbc::SQLException, 192 com::sun::star::uno::RuntimeException ); 193 virtual sal_Bool SAL_CALL 194 last() 195 throw( com::sun::star::sdbc::SQLException, 196 com::sun::star::uno::RuntimeException ); 197 virtual sal_Int32 SAL_CALL 198 getRow() 199 throw( com::sun::star::sdbc::SQLException, 200 com::sun::star::uno::RuntimeException ); 201 virtual sal_Bool SAL_CALL 202 absolute( sal_Int32 row ) 203 throw( com::sun::star::sdbc::SQLException, 204 com::sun::star::uno::RuntimeException ); 205 virtual sal_Bool SAL_CALL 206 relative( sal_Int32 rows ) 207 throw( com::sun::star::sdbc::SQLException, 208 com::sun::star::uno::RuntimeException ); 209 virtual sal_Bool SAL_CALL 210 previous() 211 throw( com::sun::star::sdbc::SQLException, 212 com::sun::star::uno::RuntimeException ); 213 virtual void SAL_CALL 214 refreshRow() 215 throw( com::sun::star::sdbc::SQLException, 216 com::sun::star::uno::RuntimeException ); 217 virtual sal_Bool SAL_CALL 218 rowUpdated() 219 throw( com::sun::star::sdbc::SQLException, 220 com::sun::star::uno::RuntimeException ); 221 virtual sal_Bool SAL_CALL 222 rowInserted() 223 throw( com::sun::star::sdbc::SQLException, 224 com::sun::star::uno::RuntimeException ); 225 virtual sal_Bool SAL_CALL 226 rowDeleted() 227 throw( com::sun::star::sdbc::SQLException, 228 com::sun::star::uno::RuntimeException ); 229 virtual com::sun::star::uno::Reference< 230 com::sun::star::uno::XInterface > SAL_CALL 231 getStatement() 232 throw( com::sun::star::sdbc::SQLException, 233 com::sun::star::uno::RuntimeException ); 234 235 // XRow 236 virtual sal_Bool SAL_CALL 237 wasNull() 238 throw( com::sun::star::sdbc::SQLException, 239 com::sun::star::uno::RuntimeException ); 240 virtual rtl::OUString SAL_CALL 241 getString( sal_Int32 columnIndex ) 242 throw( com::sun::star::sdbc::SQLException, 243 com::sun::star::uno::RuntimeException ); 244 virtual sal_Bool SAL_CALL 245 getBoolean( sal_Int32 columnIndex ) 246 throw( com::sun::star::sdbc::SQLException, 247 com::sun::star::uno::RuntimeException ); 248 virtual sal_Int8 SAL_CALL 249 getByte( sal_Int32 columnIndex ) 250 throw( com::sun::star::sdbc::SQLException, 251 com::sun::star::uno::RuntimeException ); 252 virtual sal_Int16 SAL_CALL 253 getShort( sal_Int32 columnIndex ) 254 throw( com::sun::star::sdbc::SQLException, 255 com::sun::star::uno::RuntimeException ); 256 virtual sal_Int32 SAL_CALL 257 getInt( sal_Int32 columnIndex ) 258 throw( com::sun::star::sdbc::SQLException, 259 com::sun::star::uno::RuntimeException ); 260 virtual sal_Int64 SAL_CALL 261 getLong( sal_Int32 columnIndex ) 262 throw( com::sun::star::sdbc::SQLException, 263 com::sun::star::uno::RuntimeException ); 264 virtual float SAL_CALL 265 getFloat( sal_Int32 columnIndex ) 266 throw( com::sun::star::sdbc::SQLException, 267 com::sun::star::uno::RuntimeException ); 268 virtual double SAL_CALL 269 getDouble( sal_Int32 columnIndex ) 270 throw( com::sun::star::sdbc::SQLException, 271 com::sun::star::uno::RuntimeException ); 272 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL 273 getBytes( sal_Int32 columnIndex ) 274 throw( com::sun::star::sdbc::SQLException, 275 com::sun::star::uno::RuntimeException ); 276 virtual com::sun::star::util::Date SAL_CALL 277 getDate( sal_Int32 columnIndex ) 278 throw( com::sun::star::sdbc::SQLException, 279 com::sun::star::uno::RuntimeException ); 280 virtual com::sun::star::util::Time SAL_CALL 281 getTime( sal_Int32 columnIndex ) 282 throw( com::sun::star::sdbc::SQLException, 283 com::sun::star::uno::RuntimeException ); 284 virtual com::sun::star::util::DateTime SAL_CALL 285 getTimestamp( sal_Int32 columnIndex ) 286 throw( com::sun::star::sdbc::SQLException, 287 com::sun::star::uno::RuntimeException ); 288 virtual com::sun::star::uno::Reference< 289 com::sun::star::io::XInputStream > SAL_CALL 290 getBinaryStream( sal_Int32 columnIndex ) 291 throw( com::sun::star::sdbc::SQLException, 292 com::sun::star::uno::RuntimeException ); 293 virtual com::sun::star::uno::Reference< 294 com::sun::star::io::XInputStream > SAL_CALL 295 getCharacterStream( sal_Int32 columnIndex ) 296 throw( com::sun::star::sdbc::SQLException, 297 com::sun::star::uno::RuntimeException ); 298 virtual com::sun::star::uno::Any SAL_CALL 299 getObject( sal_Int32 columnIndex, 300 const com::sun::star::uno::Reference< 301 com::sun::star::container::XNameAccess >& typeMap ) 302 throw( com::sun::star::sdbc::SQLException, 303 com::sun::star::uno::RuntimeException ); 304 virtual com::sun::star::uno::Reference< 305 com::sun::star::sdbc::XRef > SAL_CALL 306 getRef( sal_Int32 columnIndex ) 307 throw( com::sun::star::sdbc::SQLException, 308 com::sun::star::uno::RuntimeException ); 309 virtual com::sun::star::uno::Reference< 310 com::sun::star::sdbc::XBlob > SAL_CALL 311 getBlob( sal_Int32 columnIndex ) 312 throw( com::sun::star::sdbc::SQLException, 313 com::sun::star::uno::RuntimeException ); 314 virtual com::sun::star::uno::Reference< 315 com::sun::star::sdbc::XClob > SAL_CALL 316 getClob( sal_Int32 columnIndex ) 317 throw( com::sun::star::sdbc::SQLException, 318 com::sun::star::uno::RuntimeException ); 319 virtual com::sun::star::uno::Reference< 320 com::sun::star::sdbc::XArray > SAL_CALL 321 getArray( sal_Int32 columnIndex ) 322 throw( com::sun::star::sdbc::SQLException, 323 com::sun::star::uno::RuntimeException ); 324 325 // XCloseable 326 virtual void SAL_CALL 327 close() 328 throw( com::sun::star::sdbc::SQLException, 329 com::sun::star::uno::RuntimeException ); 330 331 // XPropertySet 332 virtual com::sun::star::uno::Reference< 333 com::sun::star::beans::XPropertySetInfo > SAL_CALL 334 getPropertySetInfo() 335 throw( com::sun::star::uno::RuntimeException ); 336 virtual void SAL_CALL 337 setPropertyValue( const rtl::OUString& aPropertyName, 338 const com::sun::star::uno::Any& aValue ) 339 throw( com::sun::star::beans::UnknownPropertyException, 340 com::sun::star::beans::PropertyVetoException, 341 com::sun::star::lang::IllegalArgumentException, 342 com::sun::star::lang::WrappedTargetException, 343 com::sun::star::uno::RuntimeException ); 344 virtual com::sun::star::uno::Any SAL_CALL 345 getPropertyValue( const rtl::OUString& PropertyName ) 346 throw( com::sun::star::beans::UnknownPropertyException, 347 com::sun::star::lang::WrappedTargetException, 348 com::sun::star::uno::RuntimeException ); 349 virtual void SAL_CALL 350 addPropertyChangeListener( const rtl::OUString& aPropertyName, 351 const com::sun::star::uno::Reference< 352 com::sun::star::beans::XPropertyChangeListener >& xListener ) 353 throw( com::sun::star::beans::UnknownPropertyException, 354 com::sun::star::lang::WrappedTargetException, 355 com::sun::star::uno::RuntimeException ); 356 virtual void SAL_CALL 357 removePropertyChangeListener( const rtl::OUString& aPropertyName, 358 const com::sun::star::uno::Reference< 359 com::sun::star::beans::XPropertyChangeListener >& aListener ) 360 throw( com::sun::star::beans::UnknownPropertyException, 361 com::sun::star::lang::WrappedTargetException, 362 com::sun::star::uno::RuntimeException ); 363 virtual void SAL_CALL 364 addVetoableChangeListener( const rtl::OUString& PropertyName, 365 const com::sun::star::uno::Reference< 366 com::sun::star::beans::XVetoableChangeListener >& aListener ) 367 throw( com::sun::star::beans::UnknownPropertyException, 368 com::sun::star::lang::WrappedTargetException, 369 com::sun::star::uno::RuntimeException ); 370 virtual void SAL_CALL 371 removeVetoableChangeListener( const rtl::OUString& PropertyName, 372 const com::sun::star::uno::Reference< 373 com::sun::star::beans::XVetoableChangeListener >& aListener ) 374 throw( com::sun::star::beans::UnknownPropertyException, 375 com::sun::star::lang::WrappedTargetException, 376 com::sun::star::uno::RuntimeException ); 377 378 ///////////////////////////////////////////////////////////////////// 379 // Non-interface methods. 380 ///////////////////////////////////////////////////////////////////// 381 382 /** 383 * This method propagates property value changes to all registered 384 * listeners. 385 * 386 * @param rEvt is a property change event. 387 */ 388 void propertyChanged( 389 const com::sun::star::beans::PropertyChangeEvent& rEvt ); 390 391 /** 392 * This method should be called by the data supplier for the result set 393 * to indicate that there were new data obtained from the data source. 394 * 395 * @param nOld is the old count of rows; must be non-negative. 396 * @param nnew is the new count of rows; must be non-negative. 397 */ 398 void rowCountChanged( sal_uInt32 nOld, sal_uInt32 nNew ); 399 400 /** 401 * This method should be called by the data supplier for the result set 402 * to indicate that there were all rows obtained from the data source. 403 */ 404 void rowCountFinal(); 405 406 /** 407 * This method returns a sequence containing all properties ( not the 408 * values! ) of the result set. 409 * 410 * @return a sequence of properties. 411 */ 412 const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& 413 getProperties(); 414 415 /** 416 * This method returns the environment to use for interactions, progress 417 * propagation, ... It can by empty. 418 * 419 * @return an environment or an empty reference. 420 */ 421 const com::sun::star::uno::Reference< 422 com::sun::star::ucb::XCommandEnvironment >& 423 getEnvironment(); 424 }; 425 426 //========================================================================= 427 428 /** 429 * This is the base class for an object that supplies data to a result set 430 * 431 * @see ResultSet 432 */ 433 class ResultSetDataSupplier : public salhelper::SimpleReferenceObject 434 { 435 friend class ResultSet; 436 437 // No ref, otherwise we get a cyclic reference between supplier and set! 438 // Will be set from ResultSet ctor. 439 ResultSet* m_pResultSet; 440 441 public: 442 ResultSetDataSupplier() : m_pResultSet( 0 ) {} 443 444 /** 445 * This method returns the resultset this supplier belongs to. 446 * 447 * @return the resultset for that the supplier supplies data. 448 */ 449 rtl::Reference< ResultSet > getResultSet() const { return m_pResultSet; } 450 451 /** 452 * This method returns the identifier string of the content at the 453 * specified index. 454 * 455 * @param nIndex is the zero-based index within the logical data array 456 * of the supplier; must be non-negative. 457 * @return the content's identifier string. 458 */ 459 virtual rtl::OUString queryContentIdentifierString( sal_uInt32 nIndex ) = 0; 460 461 /** 462 * This method returns the identifier of the content at the specified index. 463 * 464 * @param nIndex is the zero-based index within the logical data array 465 * of the supplier; must be non-negative. 466 * @return the content's identifier. 467 */ 468 virtual com::sun::star::uno::Reference< 469 com::sun::star::ucb::XContentIdentifier > 470 queryContentIdentifier( sal_uInt32 nIndex ) = 0; 471 472 /** 473 * This method returns the the content at the specified index. 474 * 475 * @param nIndex is the zero-based index within the logical data array 476 * of the supplier; must be non-negative. 477 * @return the content. 478 */ 479 virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > 480 queryContent( sal_uInt32 nIndex ) = 0; 481 482 /** 483 * This method returns whether there is a content at the specified index. 484 * 485 * @param nIndex is the zero-based index within the logical data array 486 * of the supplier; must be non-negative. 487 * @return true, if there is a content at the given index. 488 */ 489 virtual sal_Bool getResult( sal_uInt32 nIndex ) = 0; 490 491 /** 492 * This method returns the total count of objects in the logical data array 493 * of the supplier. The implementation of this method may be very 494 * "expensive", because it can be necessary to obtain all data in order 495 * to determine the count. Therefor the ResultSet implementation calls 496 * it very seldom. 497 * 498 * @return the total count of objects; will always be non-negative. 499 */ 500 virtual sal_uInt32 totalCount() = 0; 501 502 /** 503 * This method returns the count of objects obtained so far. There is no 504 * for the implemetation to obtain all objects at once. It can obtain 505 * all data on demand. 506 * 507 * The implementation should call m_pResultSet->rowCountChanged(...) 508 * everytime it has inserted a new entry in its logical result array. 509 * 510 * @return the count of objects obtained so far; will always be 511 * non-negative. 512 */ 513 virtual sal_uInt32 currentCount() = 0; 514 515 /** 516 * This method returns whether the value returned by currentCount() is 517 * "final". This is the case, if that there was all data obtained by the 518 * supplier and the current count won't increase any more. 519 * 520 * The implementation should call m_pResultSet->rowCountFinal(...) if 521 * it has inserted all entries in its logical result array. 522 * 523 * @return true, if the the value returned by currentCount() won't change 524 anymore. 525 */ 526 virtual sal_Bool isCountFinal() = 0; 527 528 /** 529 * This method returns an object for accessing the property values at 530 * the specified index. The implementation may use the helper class 531 * ucb::PropertyValueSet to provide the return value. 532 * 533 * @param nIndex is the zero-based index within the logical data array 534 * of the supplier. 535 * @return the object for accessing the property values. 536 */ 537 virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > 538 queryPropertyValues( sal_uInt32 nIndex ) = 0; 539 540 /** 541 * This method is called to instruct the supplier to release the (possibly 542 * presnt) property values at the given index. 543 * 544 * @param nIndex is the zero-based index within the logical data array 545 * of the supplier. 546 */ 547 virtual void releasePropertyValues( sal_uInt32 nIndex ) = 0; 548 549 /** 550 * This method will be called by the resultset implementation in order 551 * to instruct the data supplier to release all resources it has 552 * allocated so far. In case the supplier is collecting data 553 * asynchronously, that process must be stopped. 554 */ 555 virtual void close() = 0; 556 557 /** 558 * This method will be called by the resultset implementation in order 559 * check, whether an error has occured while collecting data. The 560 * implementation of this method must throw an exception in that case. 561 * 562 * Note: An exception thrown to indicate an error must always be thrown 563 * by the thread that created the data supplier. If the supplier collects 564 * data asynchronously ( i.e. in a separate thread ) and an error 565 * occures, throwing of the appropriate exception must be deferred 566 * until validate() is called by the ResultSet implementation from 567 * inside the main thread. 568 * In case data are obtained synchronously, the ResultSetException can 569 * be thrown directly. 570 * 571 * @exception ResultSetException thrown, if an error has occured 572 */ 573 virtual void validate() 574 throw( com::sun::star::ucb::ResultSetException ) = 0; 575 }; 576 577 } 578 579 #endif /* !_UCBHELPER_RESULTSET_HXX */ 580