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