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 _CONTENT_RESULTSET_WRAPPER_HXX 29 #define _CONTENT_RESULTSET_WRAPPER_HXX 30 31 #include <rtl/ustring.hxx> 32 #include <ucbhelper/macros.hxx> 33 #include <osl/mutex.hxx> 34 #include <cppuhelper/weak.hxx> 35 #include <com/sun/star/lang/XComponent.hpp> 36 #include <com/sun/star/sdbc/XCloseable.hpp> 37 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> 38 #include <com/sun/star/sdbc/XResultSet.hpp> 39 #include <com/sun/star/sdbc/XRow.hpp> 40 #include <com/sun/star/ucb/XContentAccess.hpp> 41 #include <com/sun/star/beans/XPropertySet.hpp> 42 #include <com/sun/star/lang/DisposedException.hpp> 43 #include <cppuhelper/interfacecontainer.hxx> 44 45 //========================================================================= 46 47 class ContentResultSetWrapperListener; 48 class ContentResultSetWrapper 49 : public cppu::OWeakObject 50 , public com::sun::star::lang::XComponent 51 , public com::sun::star::sdbc::XCloseable 52 , public com::sun::star::sdbc::XResultSetMetaDataSupplier 53 , public com::sun::star::beans::XPropertySet 54 , public com::sun::star::ucb::XContentAccess 55 , public com::sun::star::sdbc::XResultSet 56 , public com::sun::star::sdbc::XRow 57 { 58 protected: 59 60 //-------------------------------------------------------------------------- 61 //class PropertyChangeListenerContainer_Impl. 62 63 struct equalStr_Impl 64 { 65 bool operator()( const rtl::OUString& s1, const rtl::OUString& s2 ) const 66 { 67 return !!( s1 == s2 ); 68 } 69 }; 70 71 struct hashStr_Impl 72 { 73 size_t operator()( const rtl::OUString& rName ) const 74 { 75 return rName.hashCode(); 76 } 77 }; 78 79 typedef cppu::OMultiTypeInterfaceContainerHelperVar 80 < rtl::OUString , hashStr_Impl , equalStr_Impl > 81 PropertyChangeListenerContainer_Impl; 82 //-------------------------------------------------------------------------- 83 // class ReacquireableGuard 84 85 class ReacquireableGuard 86 { 87 protected: 88 osl::Mutex* pT; 89 public: 90 91 ReacquireableGuard(osl::Mutex * t) : pT(t) 92 { 93 pT->acquire(); 94 } 95 96 ReacquireableGuard(osl::Mutex& t) : pT(&t) 97 { 98 pT->acquire(); 99 } 100 101 /** Releases mutex. */ 102 ~ReacquireableGuard() 103 { 104 if (pT) 105 pT->release(); 106 } 107 108 /** Releases mutex. */ 109 void clear() 110 { 111 if(pT) 112 { 113 pT->release(); 114 pT = NULL; 115 } 116 } 117 118 /** Reacquire mutex. */ 119 void reacquire() 120 { 121 if(pT) 122 { 123 pT->acquire(); 124 } 125 } 126 }; 127 128 //----------------------------------------------------------------- 129 //members 130 131 //my Mutex 132 osl::Mutex m_aMutex; 133 134 //different Interfaces from Origin: 135 com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > 136 m_xResultSetOrigin; 137 com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > 138 m_xRowOrigin; //XRow-interface from m_xOrigin 139 //!! call impl_init_xRowOrigin() bevor you access this member 140 com::sun::star::uno::Reference< com::sun::star::ucb::XContentAccess > 141 m_xContentAccessOrigin; //XContentAccess-interface from m_xOrigin 142 //!! call impl_init_xContentAccessOrigin() bevor you access this member 143 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > 144 m_xPropertySetOrigin; //XPropertySet-interface from m_xOrigin 145 //!! call impl_init_xPropertySetOrigin() bevor you access this member 146 147 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > 148 m_xPropertySetInfo; 149 //call impl_initPropertySetInfo() bevor you access this member 150 151 sal_Int32 m_nForwardOnly; 152 153 private: 154 com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener > 155 m_xMyListenerImpl; 156 ContentResultSetWrapperListener* 157 m_pMyListenerImpl; 158 159 com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSetMetaData > 160 m_xMetaDataFromOrigin; //XResultSetMetaData from m_xOrigin 161 162 //management of listeners 163 sal_Bool m_bDisposed; ///Dispose call ready. 164 sal_Bool m_bInDispose;///In dispose call 165 osl::Mutex m_aContainerMutex; 166 cppu::OInterfaceContainerHelper* 167 m_pDisposeEventListeners; 168 PropertyChangeListenerContainer_Impl* 169 m_pPropertyChangeListeners; 170 PropertyChangeListenerContainer_Impl* 171 m_pVetoableChangeListeners; 172 173 //----------------------------------------------------------------- 174 //methods: 175 private: 176 PropertyChangeListenerContainer_Impl* SAL_CALL 177 impl_getPropertyChangeListenerContainer(); 178 179 PropertyChangeListenerContainer_Impl* SAL_CALL 180 impl_getVetoableChangeListenerContainer(); 181 182 protected: 183 //----------------------------------------------------------------- 184 185 ContentResultSetWrapper( com::sun::star::uno::Reference< 186 com::sun::star::sdbc::XResultSet > xOrigin ); 187 188 virtual ~ContentResultSetWrapper(); 189 190 void SAL_CALL impl_init(); 191 void SAL_CALL impl_deinit(); 192 193 //-- 194 195 void SAL_CALL impl_init_xRowOrigin(); 196 void SAL_CALL impl_init_xContentAccessOrigin(); 197 void SAL_CALL impl_init_xPropertySetOrigin(); 198 199 //-- 200 201 virtual void SAL_CALL impl_initPropertySetInfo(); //helping XPropertySet 202 203 void SAL_CALL 204 impl_EnsureNotDisposed() 205 throw( com::sun::star::lang::DisposedException, 206 com::sun::star::uno::RuntimeException ); 207 208 void SAL_CALL 209 impl_notifyPropertyChangeListeners( 210 const com::sun::star::beans::PropertyChangeEvent& rEvt ); 211 212 void SAL_CALL 213 impl_notifyVetoableChangeListeners( 214 const com::sun::star::beans::PropertyChangeEvent& rEvt ) 215 throw( com::sun::star::beans::PropertyVetoException, 216 com::sun::star::uno::RuntimeException ); 217 218 sal_Bool SAL_CALL impl_isForwardOnly(); 219 220 public: 221 222 //----------------------------------------------------------------- 223 // XInterface 224 //----------------------------------------------------------------- 225 virtual com::sun::star::uno::Any SAL_CALL 226 queryInterface( const com::sun::star::uno::Type & rType ) 227 throw( com::sun::star::uno::RuntimeException ); 228 229 //----------------------------------------------------------------- 230 // XComponent 231 //----------------------------------------------------------------- 232 virtual void SAL_CALL 233 dispose() throw( com::sun::star::uno::RuntimeException ); 234 235 virtual void SAL_CALL 236 addEventListener( const com::sun::star::uno::Reference< 237 com::sun::star::lang::XEventListener >& Listener ) 238 throw( com::sun::star::uno::RuntimeException ); 239 240 virtual void SAL_CALL 241 removeEventListener( const com::sun::star::uno::Reference< 242 com::sun::star::lang::XEventListener >& Listener ) 243 throw( com::sun::star::uno::RuntimeException ); 244 245 //----------------------------------------------------------------- 246 //XCloseable 247 //----------------------------------------------------------------- 248 virtual void SAL_CALL 249 close() 250 throw( com::sun::star::sdbc::SQLException, 251 com::sun::star::uno::RuntimeException ); 252 253 //----------------------------------------------------------------- 254 //XResultSetMetaDataSupplier 255 //----------------------------------------------------------------- 256 virtual com::sun::star::uno::Reference< 257 com::sun::star::sdbc::XResultSetMetaData > SAL_CALL 258 getMetaData() 259 throw( com::sun::star::sdbc::SQLException, 260 com::sun::star::uno::RuntimeException ); 261 262 //----------------------------------------------------------------- 263 // XPropertySet 264 //----------------------------------------------------------------- 265 virtual com::sun::star::uno::Reference< 266 com::sun::star::beans::XPropertySetInfo > SAL_CALL 267 getPropertySetInfo() 268 throw( com::sun::star::uno::RuntimeException ); 269 270 virtual void SAL_CALL 271 setPropertyValue( const rtl::OUString& aPropertyName, 272 const com::sun::star::uno::Any& aValue ) 273 throw( com::sun::star::beans::UnknownPropertyException, 274 com::sun::star::beans::PropertyVetoException, 275 com::sun::star::lang::IllegalArgumentException, 276 com::sun::star::lang::WrappedTargetException, 277 com::sun::star::uno::RuntimeException ); 278 279 virtual com::sun::star::uno::Any SAL_CALL 280 getPropertyValue( const rtl::OUString& PropertyName ) 281 throw( com::sun::star::beans::UnknownPropertyException, 282 com::sun::star::lang::WrappedTargetException, 283 com::sun::star::uno::RuntimeException ); 284 285 virtual void SAL_CALL 286 addPropertyChangeListener( const rtl::OUString& aPropertyName, 287 const com::sun::star::uno::Reference< 288 com::sun::star::beans::XPropertyChangeListener >& xListener ) 289 throw( com::sun::star::beans::UnknownPropertyException, 290 com::sun::star::lang::WrappedTargetException, 291 com::sun::star::uno::RuntimeException ); 292 293 virtual void SAL_CALL 294 removePropertyChangeListener( const rtl::OUString& aPropertyName, 295 const com::sun::star::uno::Reference< 296 com::sun::star::beans::XPropertyChangeListener >& aListener ) 297 throw( com::sun::star::beans::UnknownPropertyException, 298 com::sun::star::lang::WrappedTargetException, 299 com::sun::star::uno::RuntimeException ); 300 301 virtual void SAL_CALL 302 addVetoableChangeListener( const rtl::OUString& PropertyName, 303 const com::sun::star::uno::Reference< 304 com::sun::star::beans::XVetoableChangeListener >& aListener ) 305 throw( com::sun::star::beans::UnknownPropertyException, 306 com::sun::star::lang::WrappedTargetException, 307 com::sun::star::uno::RuntimeException ); 308 309 virtual void SAL_CALL 310 removeVetoableChangeListener( const rtl::OUString& PropertyName, 311 const com::sun::star::uno::Reference< 312 com::sun::star::beans::XVetoableChangeListener >& aListener ) 313 throw( com::sun::star::beans::UnknownPropertyException, 314 com::sun::star::lang::WrappedTargetException, 315 com::sun::star::uno::RuntimeException ); 316 317 //----------------------------------------------------------------- 318 // own methods 319 //----------------------------------------------------------------- 320 virtual void SAL_CALL 321 impl_disposing( const com::sun::star::lang::EventObject& Source ) 322 throw( com::sun::star::uno::RuntimeException ); 323 324 virtual void SAL_CALL 325 impl_propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt ) 326 throw( com::sun::star::uno::RuntimeException ); 327 328 virtual void SAL_CALL 329 impl_vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent ) 330 throw( com::sun::star::beans::PropertyVetoException, 331 com::sun::star::uno::RuntimeException ); 332 333 //----------------------------------------------------------------- 334 // XContentAccess 335 //----------------------------------------------------------------- 336 virtual rtl::OUString SAL_CALL 337 queryContentIdentifierString() 338 throw( com::sun::star::uno::RuntimeException ); 339 340 virtual com::sun::star::uno::Reference< 341 com::sun::star::ucb::XContentIdentifier > SAL_CALL 342 queryContentIdentifier() 343 throw( com::sun::star::uno::RuntimeException ); 344 345 virtual com::sun::star::uno::Reference< 346 com::sun::star::ucb::XContent > SAL_CALL 347 queryContent() 348 throw( com::sun::star::uno::RuntimeException ); 349 350 //----------------------------------------------------------------- 351 // XResultSet 352 //----------------------------------------------------------------- 353 virtual sal_Bool SAL_CALL 354 next() 355 throw( com::sun::star::sdbc::SQLException, 356 com::sun::star::uno::RuntimeException ); 357 virtual sal_Bool SAL_CALL 358 isBeforeFirst() 359 throw( com::sun::star::sdbc::SQLException, 360 com::sun::star::uno::RuntimeException ); 361 virtual sal_Bool SAL_CALL 362 isAfterLast() 363 throw( com::sun::star::sdbc::SQLException, 364 com::sun::star::uno::RuntimeException ); 365 virtual sal_Bool SAL_CALL 366 isFirst() 367 throw( com::sun::star::sdbc::SQLException, 368 com::sun::star::uno::RuntimeException ); 369 virtual sal_Bool SAL_CALL 370 isLast() 371 throw( com::sun::star::sdbc::SQLException, 372 com::sun::star::uno::RuntimeException ); 373 virtual void SAL_CALL 374 beforeFirst() 375 throw( com::sun::star::sdbc::SQLException, 376 com::sun::star::uno::RuntimeException ); 377 virtual void SAL_CALL 378 afterLast() 379 throw( com::sun::star::sdbc::SQLException, 380 com::sun::star::uno::RuntimeException ); 381 virtual sal_Bool SAL_CALL 382 first() 383 throw( com::sun::star::sdbc::SQLException, 384 com::sun::star::uno::RuntimeException ); 385 virtual sal_Bool SAL_CALL 386 last() 387 throw( com::sun::star::sdbc::SQLException, 388 com::sun::star::uno::RuntimeException ); 389 virtual sal_Int32 SAL_CALL 390 getRow() 391 throw( com::sun::star::sdbc::SQLException, 392 com::sun::star::uno::RuntimeException ); 393 virtual sal_Bool SAL_CALL 394 absolute( sal_Int32 row ) 395 throw( com::sun::star::sdbc::SQLException, 396 com::sun::star::uno::RuntimeException ); 397 virtual sal_Bool SAL_CALL 398 relative( sal_Int32 rows ) 399 throw( com::sun::star::sdbc::SQLException, 400 com::sun::star::uno::RuntimeException ); 401 virtual sal_Bool SAL_CALL 402 previous() 403 throw( com::sun::star::sdbc::SQLException, 404 com::sun::star::uno::RuntimeException ); 405 virtual void SAL_CALL 406 refreshRow() 407 throw( com::sun::star::sdbc::SQLException, 408 com::sun::star::uno::RuntimeException ); 409 virtual sal_Bool SAL_CALL 410 rowUpdated() 411 throw( com::sun::star::sdbc::SQLException, 412 com::sun::star::uno::RuntimeException ); 413 virtual sal_Bool SAL_CALL 414 rowInserted() 415 throw( com::sun::star::sdbc::SQLException, 416 com::sun::star::uno::RuntimeException ); 417 virtual sal_Bool SAL_CALL 418 rowDeleted() 419 throw( com::sun::star::sdbc::SQLException, 420 com::sun::star::uno::RuntimeException ); 421 virtual com::sun::star::uno::Reference< 422 com::sun::star::uno::XInterface > SAL_CALL 423 getStatement() 424 throw( com::sun::star::sdbc::SQLException, 425 com::sun::star::uno::RuntimeException ); 426 427 //----------------------------------------------------------------- 428 // XRow 429 //----------------------------------------------------------------- 430 virtual sal_Bool SAL_CALL 431 wasNull() 432 throw( com::sun::star::sdbc::SQLException, 433 com::sun::star::uno::RuntimeException ); 434 435 virtual rtl::OUString SAL_CALL 436 getString( sal_Int32 columnIndex ) 437 throw( com::sun::star::sdbc::SQLException, 438 com::sun::star::uno::RuntimeException ); 439 440 virtual sal_Bool SAL_CALL 441 getBoolean( sal_Int32 columnIndex ) 442 throw( com::sun::star::sdbc::SQLException, 443 com::sun::star::uno::RuntimeException ); 444 445 virtual sal_Int8 SAL_CALL 446 getByte( sal_Int32 columnIndex ) 447 throw( com::sun::star::sdbc::SQLException, 448 com::sun::star::uno::RuntimeException ); 449 450 virtual sal_Int16 SAL_CALL 451 getShort( sal_Int32 columnIndex ) 452 throw( com::sun::star::sdbc::SQLException, 453 com::sun::star::uno::RuntimeException ); 454 455 virtual sal_Int32 SAL_CALL 456 getInt( sal_Int32 columnIndex ) 457 throw( com::sun::star::sdbc::SQLException, 458 com::sun::star::uno::RuntimeException ); 459 460 virtual sal_Int64 SAL_CALL 461 getLong( sal_Int32 columnIndex ) 462 throw( com::sun::star::sdbc::SQLException, 463 com::sun::star::uno::RuntimeException ); 464 465 virtual float SAL_CALL 466 getFloat( sal_Int32 columnIndex ) 467 throw( com::sun::star::sdbc::SQLException, 468 com::sun::star::uno::RuntimeException ); 469 470 virtual double SAL_CALL 471 getDouble( sal_Int32 columnIndex ) 472 throw( com::sun::star::sdbc::SQLException, 473 com::sun::star::uno::RuntimeException ); 474 475 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL 476 getBytes( sal_Int32 columnIndex ) 477 throw( com::sun::star::sdbc::SQLException, 478 com::sun::star::uno::RuntimeException ); 479 480 virtual com::sun::star::util::Date SAL_CALL 481 getDate( sal_Int32 columnIndex ) 482 throw( com::sun::star::sdbc::SQLException, 483 com::sun::star::uno::RuntimeException ); 484 485 virtual com::sun::star::util::Time SAL_CALL 486 getTime( sal_Int32 columnIndex ) 487 throw( com::sun::star::sdbc::SQLException, 488 com::sun::star::uno::RuntimeException ); 489 490 virtual com::sun::star::util::DateTime SAL_CALL 491 getTimestamp( sal_Int32 columnIndex ) 492 throw( com::sun::star::sdbc::SQLException, 493 com::sun::star::uno::RuntimeException ); 494 495 virtual com::sun::star::uno::Reference< 496 com::sun::star::io::XInputStream > SAL_CALL 497 getBinaryStream( sal_Int32 columnIndex ) 498 throw( com::sun::star::sdbc::SQLException, 499 com::sun::star::uno::RuntimeException ); 500 501 virtual com::sun::star::uno::Reference< 502 com::sun::star::io::XInputStream > SAL_CALL 503 getCharacterStream( sal_Int32 columnIndex ) 504 throw( com::sun::star::sdbc::SQLException, 505 com::sun::star::uno::RuntimeException ); 506 507 virtual com::sun::star::uno::Any SAL_CALL 508 getObject( sal_Int32 columnIndex, 509 const com::sun::star::uno::Reference< 510 com::sun::star::container::XNameAccess >& typeMap ) 511 throw( com::sun::star::sdbc::SQLException, 512 com::sun::star::uno::RuntimeException ); 513 514 virtual com::sun::star::uno::Reference< 515 com::sun::star::sdbc::XRef > SAL_CALL 516 getRef( sal_Int32 columnIndex ) 517 throw( com::sun::star::sdbc::SQLException, 518 com::sun::star::uno::RuntimeException ); 519 520 virtual com::sun::star::uno::Reference< 521 com::sun::star::sdbc::XBlob > SAL_CALL 522 getBlob( sal_Int32 columnIndex ) 523 throw( com::sun::star::sdbc::SQLException, 524 com::sun::star::uno::RuntimeException ); 525 526 virtual com::sun::star::uno::Reference< 527 com::sun::star::sdbc::XClob > SAL_CALL 528 getClob( sal_Int32 columnIndex ) 529 throw( com::sun::star::sdbc::SQLException, 530 com::sun::star::uno::RuntimeException ); 531 532 virtual com::sun::star::uno::Reference< 533 com::sun::star::sdbc::XArray > SAL_CALL 534 getArray( sal_Int32 columnIndex ) 535 throw( com::sun::star::sdbc::SQLException, 536 com::sun::star::uno::RuntimeException ); 537 }; 538 539 //========================================================================= 540 541 class ContentResultSetWrapperListener 542 : public cppu::OWeakObject 543 , public com::sun::star::beans::XPropertyChangeListener 544 , public com::sun::star::beans::XVetoableChangeListener 545 { 546 protected: 547 ContentResultSetWrapper* m_pOwner; 548 549 public: 550 ContentResultSetWrapperListener( ContentResultSetWrapper* pOwner ); 551 552 virtual ~ContentResultSetWrapperListener(); 553 554 //----------------------------------------------------------------- 555 // XInterface 556 //----------------------------------------------------------------- 557 XINTERFACE_DECL() 558 559 //----------------------------------------------------------------- 560 //XEventListener 561 //----------------------------------------------------------------- 562 virtual void SAL_CALL 563 disposing( const com::sun::star::lang::EventObject& Source ) 564 throw( com::sun::star::uno::RuntimeException ); 565 566 //----------------------------------------------------------------- 567 //XPropertyChangeListener 568 //----------------------------------------------------------------- 569 virtual void SAL_CALL 570 propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt ) 571 throw( com::sun::star::uno::RuntimeException ); 572 573 //----------------------------------------------------------------- 574 //XVetoableChangeListener 575 //----------------------------------------------------------------- 576 virtual void SAL_CALL 577 vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent ) 578 throw( com::sun::star::beans::PropertyVetoException, 579 com::sun::star::uno::RuntimeException ); 580 581 //----------------------------------------------------------------- 582 // own methods: 583 void SAL_CALL impl_OwnerDies(); 584 }; 585 586 #endif 587 588