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