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 _CACHED_CONTENT_RESULTSET_HXX 29 #define _CACHED_CONTENT_RESULTSET_HXX 30 31 #include <contentresultsetwrapper.hxx> 32 #include <com/sun/star/lang/XTypeProvider.hpp> 33 #include <com/sun/star/lang/XServiceInfo.hpp> 34 #include <com/sun/star/ucb/XFetchProvider.hpp> 35 #include <com/sun/star/ucb/XFetchProviderForContentAccess.hpp> 36 #include <com/sun/star/ucb/FetchResult.hpp> 37 #include <com/sun/star/ucb/XContentIdentifierMapping.hpp> 38 #include <com/sun/star/ucb/XCachedContentResultSetFactory.hpp> 39 40 #define CACHED_CONTENT_RESULTSET_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSet" 41 #define CACHED_CONTENT_RESULTSET_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetFactory" 42 43 //========================================================================= 44 45 namespace com { namespace sun { namespace star { namespace script { 46 class XTypeConverter; 47 } } } } 48 49 class CCRS_PropertySetInfo; 50 class CachedContentResultSet 51 : public ContentResultSetWrapper 52 , public com::sun::star::lang::XTypeProvider 53 , public com::sun::star::lang::XServiceInfo 54 { 55 //-------------------------------------------------------------------------- 56 // class CCRS_Cache 57 58 class CCRS_Cache 59 { 60 private: 61 com::sun::star::ucb::FetchResult* m_pResult; 62 com::sun::star::uno::Reference< 63 com::sun::star::ucb::XContentIdentifierMapping > 64 m_xContentIdentifierMapping; 65 com::sun::star::uno::Sequence< sal_Bool >* m_pMappedReminder; 66 67 private: 68 com::sun::star::uno::Any& SAL_CALL 69 getRowAny( sal_Int32 nRow ) 70 throw( com::sun::star::sdbc::SQLException, 71 com::sun::star::uno::RuntimeException ); 72 73 void SAL_CALL clear(); 74 75 76 void SAL_CALL remindMapped( sal_Int32 nRow ); 77 sal_Bool SAL_CALL isRowMapped( sal_Int32 nRow ); 78 void SAL_CALL clearMappedReminder(); 79 com::sun::star::uno::Sequence< sal_Bool >* SAL_CALL getMappedReminder(); 80 81 public: 82 CCRS_Cache( const com::sun::star::uno::Reference< 83 com::sun::star::ucb::XContentIdentifierMapping > & xMapping ); 84 ~CCRS_Cache(); 85 86 void SAL_CALL loadData( 87 const com::sun::star::ucb::FetchResult& rResult ); 88 89 sal_Bool SAL_CALL 90 hasRow( sal_Int32 nRow ); 91 92 sal_Bool SAL_CALL 93 hasCausedException( sal_Int32 nRow ); 94 95 sal_Int32 SAL_CALL 96 getMaxRow(); 97 98 sal_Bool SAL_CALL 99 hasKnownLast(); 100 101 //--- 102 const com::sun::star::uno::Any& SAL_CALL 103 getAny( sal_Int32 nRow, sal_Int32 nColumnIndex ) 104 throw( com::sun::star::sdbc::SQLException, 105 com::sun::star::uno::RuntimeException ); 106 107 const rtl::OUString& SAL_CALL 108 getContentIdentifierString( sal_Int32 nRow ) 109 throw( com::sun::star::uno::RuntimeException ); 110 111 const com::sun::star::uno::Reference< 112 com::sun::star::ucb::XContentIdentifier >& SAL_CALL 113 getContentIdentifier( sal_Int32 nRow ) 114 throw( com::sun::star::uno::RuntimeException ); 115 116 const com::sun::star::uno::Reference< 117 com::sun::star::ucb::XContent >& SAL_CALL 118 getContent( sal_Int32 nRow ) 119 throw( com::sun::star::uno::RuntimeException ); 120 }; 121 //----------------------------------------------------------------- 122 //members 123 124 com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > 125 m_xSMgr; 126 127 //different Interfaces from Origin: 128 com::sun::star::uno::Reference< com::sun::star::ucb::XFetchProvider > 129 m_xFetchProvider; //XFetchProvider-interface from m_xOrigin 130 131 com::sun::star::uno::Reference< com::sun::star::ucb::XFetchProviderForContentAccess > 132 m_xFetchProviderForContentAccess; //XFetchProviderForContentAccess-interface from m_xOrigin 133 134 //my PropertySetInfo 135 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > 136 m_xMyPropertySetInfo;//holds m_pMyPropSetInfo alive 137 CCRS_PropertySetInfo* m_pMyPropSetInfo; 138 139 140 // 141 com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifierMapping > 142 m_xContentIdentifierMapping;// can be used for remote optimized ContentAccess 143 144 //some Properties and helping variables 145 sal_Int32 m_nRow; 146 sal_Bool m_bAfterLast; // TRUE, if m_nRow is after final count; can be TRUE without knowing the exact final count 147 148 sal_Int32 m_nLastAppliedPos; 149 sal_Bool m_bAfterLastApplied; 150 151 sal_Int32 m_nKnownCount; // count we know from the Origin 152 sal_Bool m_bFinalCount; // TRUE if the Origin has reached final count and we got that count in m_nKnownCount 153 154 sal_Int32 m_nFetchSize; 155 sal_Int32 m_nFetchDirection; 156 157 sal_Bool m_bLastReadWasFromCache; 158 sal_Bool m_bLastCachedReadWasNull; 159 160 //cache: 161 CCRS_Cache m_aCache; 162 CCRS_Cache m_aCacheContentIdentifierString; 163 CCRS_Cache m_aCacheContentIdentifier; 164 CCRS_Cache m_aCacheContent; 165 166 167 private: 168 //----------------------------------------------------------------- 169 //helping XPropertySet methods. 170 virtual void SAL_CALL impl_initPropertySetInfo(); 171 172 173 //----------------------------------------------------------------- 174 sal_Bool SAL_CALL 175 applyPositionToOrigin( sal_Int32 nRow ) 176 throw( com::sun::star::sdbc::SQLException, 177 com::sun::star::uno::RuntimeException ); 178 179 void SAL_CALL 180 impl_fetchData( sal_Int32 nRow, sal_Int32 nCount 181 , sal_Int32 nFetchDirection ) 182 throw( com::sun::star::uno::RuntimeException ); 183 184 sal_Bool SAL_CALL 185 impl_isKnownValidPosition( sal_Int32 nRow ); 186 187 sal_Bool SAL_CALL 188 impl_isKnownInvalidPosition( sal_Int32 nRow ); 189 190 void SAL_CALL 191 impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew ); 192 193 void SAL_CALL 194 impl_changeIsRowCountFinal( sal_Bool bOld, sal_Bool bNew ); 195 196 public: 197 CachedContentResultSet( 198 const com::sun::star::uno::Reference< 199 com::sun::star::lang::XMultiServiceFactory > & 200 xSMgr, 201 const com::sun::star::uno::Reference< 202 com::sun::star::sdbc::XResultSet > & xOrigin, 203 const com::sun::star::uno::Reference< 204 com::sun::star::ucb::XContentIdentifierMapping > & 205 xContentIdentifierMapping ); 206 207 virtual ~CachedContentResultSet(); 208 209 //----------------------------------------------------------------- 210 // XInterface inherited 211 //----------------------------------------------------------------- 212 XINTERFACE_DECL() 213 //----------------------------------------------------------------- 214 // XTypeProvider 215 //----------------------------------------------------------------- 216 XTYPEPROVIDER_DECL() 217 //----------------------------------------------------------------- 218 // XServiceInfo 219 //----------------------------------------------------------------- 220 XSERVICEINFO_NOFACTORY_DECL() 221 222 //----------------------------------------------------------------- 223 // XPropertySet inherited 224 //----------------------------------------------------------------- 225 226 virtual void SAL_CALL 227 setPropertyValue( const rtl::OUString& aPropertyName, 228 const com::sun::star::uno::Any& aValue ) 229 throw( com::sun::star::beans::UnknownPropertyException, 230 com::sun::star::beans::PropertyVetoException, 231 com::sun::star::lang::IllegalArgumentException, 232 com::sun::star::lang::WrappedTargetException, 233 com::sun::star::uno::RuntimeException ); 234 235 virtual com::sun::star::uno::Any SAL_CALL 236 getPropertyValue( const rtl::OUString& PropertyName ) 237 throw( com::sun::star::beans::UnknownPropertyException, 238 com::sun::star::lang::WrappedTargetException, 239 com::sun::star::uno::RuntimeException ); 240 241 //----------------------------------------------------------------- 242 // own inherited 243 //----------------------------------------------------------------- 244 virtual void SAL_CALL 245 impl_disposing( const com::sun::star::lang::EventObject& Source ) 246 throw( com::sun::star::uno::RuntimeException ); 247 248 virtual void SAL_CALL 249 impl_propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt ) 250 throw( com::sun::star::uno::RuntimeException ); 251 252 virtual void SAL_CALL 253 impl_vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent ) 254 throw( com::sun::star::beans::PropertyVetoException, 255 com::sun::star::uno::RuntimeException ); 256 257 //----------------------------------------------------------------- 258 // XContentAccess inherited 259 //----------------------------------------------------------------- 260 virtual rtl::OUString SAL_CALL 261 queryContentIdentifierString() 262 throw( com::sun::star::uno::RuntimeException ); 263 264 virtual com::sun::star::uno::Reference< 265 com::sun::star::ucb::XContentIdentifier > SAL_CALL 266 queryContentIdentifier() 267 throw( com::sun::star::uno::RuntimeException ); 268 269 virtual com::sun::star::uno::Reference< 270 com::sun::star::ucb::XContent > SAL_CALL 271 queryContent() 272 throw( com::sun::star::uno::RuntimeException ); 273 274 //----------------------------------------------------------------- 275 // XResultSet inherited 276 //----------------------------------------------------------------- 277 virtual sal_Bool SAL_CALL 278 next() 279 throw( com::sun::star::sdbc::SQLException, 280 com::sun::star::uno::RuntimeException ); 281 virtual sal_Bool SAL_CALL 282 isBeforeFirst() 283 throw( com::sun::star::sdbc::SQLException, 284 com::sun::star::uno::RuntimeException ); 285 virtual sal_Bool SAL_CALL 286 isAfterLast() 287 throw( com::sun::star::sdbc::SQLException, 288 com::sun::star::uno::RuntimeException ); 289 virtual sal_Bool SAL_CALL 290 isFirst() 291 throw( com::sun::star::sdbc::SQLException, 292 com::sun::star::uno::RuntimeException ); 293 virtual sal_Bool SAL_CALL 294 isLast() 295 throw( com::sun::star::sdbc::SQLException, 296 com::sun::star::uno::RuntimeException ); 297 virtual void SAL_CALL 298 beforeFirst() 299 throw( com::sun::star::sdbc::SQLException, 300 com::sun::star::uno::RuntimeException ); 301 virtual void SAL_CALL 302 afterLast() 303 throw( com::sun::star::sdbc::SQLException, 304 com::sun::star::uno::RuntimeException ); 305 virtual sal_Bool SAL_CALL 306 first() 307 throw( com::sun::star::sdbc::SQLException, 308 com::sun::star::uno::RuntimeException ); 309 virtual sal_Bool SAL_CALL 310 last() 311 throw( com::sun::star::sdbc::SQLException, 312 com::sun::star::uno::RuntimeException ); 313 virtual sal_Int32 SAL_CALL 314 getRow() 315 throw( com::sun::star::sdbc::SQLException, 316 com::sun::star::uno::RuntimeException ); 317 virtual sal_Bool SAL_CALL 318 absolute( sal_Int32 row ) 319 throw( com::sun::star::sdbc::SQLException, 320 com::sun::star::uno::RuntimeException ); 321 virtual sal_Bool SAL_CALL 322 relative( sal_Int32 rows ) 323 throw( com::sun::star::sdbc::SQLException, 324 com::sun::star::uno::RuntimeException ); 325 virtual sal_Bool SAL_CALL 326 previous() 327 throw( com::sun::star::sdbc::SQLException, 328 com::sun::star::uno::RuntimeException ); 329 virtual void SAL_CALL 330 refreshRow() 331 throw( com::sun::star::sdbc::SQLException, 332 com::sun::star::uno::RuntimeException ); 333 virtual sal_Bool SAL_CALL 334 rowUpdated() 335 throw( com::sun::star::sdbc::SQLException, 336 com::sun::star::uno::RuntimeException ); 337 virtual sal_Bool SAL_CALL 338 rowInserted() 339 throw( com::sun::star::sdbc::SQLException, 340 com::sun::star::uno::RuntimeException ); 341 virtual sal_Bool SAL_CALL 342 rowDeleted() 343 throw( com::sun::star::sdbc::SQLException, 344 com::sun::star::uno::RuntimeException ); 345 virtual com::sun::star::uno::Reference< 346 com::sun::star::uno::XInterface > SAL_CALL 347 getStatement() 348 throw( com::sun::star::sdbc::SQLException, 349 com::sun::star::uno::RuntimeException ); 350 351 //----------------------------------------------------------------- 352 // XRow inherited 353 //----------------------------------------------------------------- 354 virtual sal_Bool SAL_CALL 355 wasNull() 356 throw( com::sun::star::sdbc::SQLException, 357 com::sun::star::uno::RuntimeException ); 358 359 virtual rtl::OUString SAL_CALL 360 getString( sal_Int32 columnIndex ) 361 throw( com::sun::star::sdbc::SQLException, 362 com::sun::star::uno::RuntimeException ); 363 364 virtual sal_Bool SAL_CALL 365 getBoolean( sal_Int32 columnIndex ) 366 throw( com::sun::star::sdbc::SQLException, 367 com::sun::star::uno::RuntimeException ); 368 369 virtual sal_Int8 SAL_CALL 370 getByte( sal_Int32 columnIndex ) 371 throw( com::sun::star::sdbc::SQLException, 372 com::sun::star::uno::RuntimeException ); 373 374 virtual sal_Int16 SAL_CALL 375 getShort( sal_Int32 columnIndex ) 376 throw( com::sun::star::sdbc::SQLException, 377 com::sun::star::uno::RuntimeException ); 378 379 virtual sal_Int32 SAL_CALL 380 getInt( sal_Int32 columnIndex ) 381 throw( com::sun::star::sdbc::SQLException, 382 com::sun::star::uno::RuntimeException ); 383 384 virtual sal_Int64 SAL_CALL 385 getLong( sal_Int32 columnIndex ) 386 throw( com::sun::star::sdbc::SQLException, 387 com::sun::star::uno::RuntimeException ); 388 389 virtual float SAL_CALL 390 getFloat( sal_Int32 columnIndex ) 391 throw( com::sun::star::sdbc::SQLException, 392 com::sun::star::uno::RuntimeException ); 393 394 virtual double SAL_CALL 395 getDouble( sal_Int32 columnIndex ) 396 throw( com::sun::star::sdbc::SQLException, 397 com::sun::star::uno::RuntimeException ); 398 399 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL 400 getBytes( sal_Int32 columnIndex ) 401 throw( com::sun::star::sdbc::SQLException, 402 com::sun::star::uno::RuntimeException ); 403 404 virtual com::sun::star::util::Date SAL_CALL 405 getDate( sal_Int32 columnIndex ) 406 throw( com::sun::star::sdbc::SQLException, 407 com::sun::star::uno::RuntimeException ); 408 409 virtual com::sun::star::util::Time SAL_CALL 410 getTime( sal_Int32 columnIndex ) 411 throw( com::sun::star::sdbc::SQLException, 412 com::sun::star::uno::RuntimeException ); 413 414 virtual com::sun::star::util::DateTime SAL_CALL 415 getTimestamp( sal_Int32 columnIndex ) 416 throw( com::sun::star::sdbc::SQLException, 417 com::sun::star::uno::RuntimeException ); 418 419 virtual com::sun::star::uno::Reference< 420 com::sun::star::io::XInputStream > SAL_CALL 421 getBinaryStream( sal_Int32 columnIndex ) 422 throw( com::sun::star::sdbc::SQLException, 423 com::sun::star::uno::RuntimeException ); 424 425 virtual com::sun::star::uno::Reference< 426 com::sun::star::io::XInputStream > SAL_CALL 427 getCharacterStream( sal_Int32 columnIndex ) 428 throw( com::sun::star::sdbc::SQLException, 429 com::sun::star::uno::RuntimeException ); 430 431 virtual com::sun::star::uno::Any SAL_CALL 432 getObject( sal_Int32 columnIndex, 433 const com::sun::star::uno::Reference< 434 com::sun::star::container::XNameAccess >& typeMap ) 435 throw( com::sun::star::sdbc::SQLException, 436 com::sun::star::uno::RuntimeException ); 437 438 virtual com::sun::star::uno::Reference< 439 com::sun::star::sdbc::XRef > SAL_CALL 440 getRef( sal_Int32 columnIndex ) 441 throw( com::sun::star::sdbc::SQLException, 442 com::sun::star::uno::RuntimeException ); 443 444 virtual com::sun::star::uno::Reference< 445 com::sun::star::sdbc::XBlob > SAL_CALL 446 getBlob( sal_Int32 columnIndex ) 447 throw( com::sun::star::sdbc::SQLException, 448 com::sun::star::uno::RuntimeException ); 449 450 virtual com::sun::star::uno::Reference< 451 com::sun::star::sdbc::XClob > SAL_CALL 452 getClob( sal_Int32 columnIndex ) 453 throw( com::sun::star::sdbc::SQLException, 454 com::sun::star::uno::RuntimeException ); 455 456 virtual com::sun::star::uno::Reference< 457 com::sun::star::sdbc::XArray > SAL_CALL 458 getArray( sal_Int32 columnIndex ) 459 throw( com::sun::star::sdbc::SQLException, 460 com::sun::star::uno::RuntimeException ); 461 462 //----------------------------------------------------------------- 463 // Type Converter support 464 //----------------------------------------------------------------- 465 466 private: 467 sal_Bool m_bTriedToGetTypeConverter; 468 com::sun::star::uno::Reference< 469 com::sun::star::script::XTypeConverter > m_xTypeConverter; 470 471 const com::sun::star::uno::Reference< 472 com::sun::star::script::XTypeConverter >& getTypeConverter(); 473 }; 474 475 //========================================================================= 476 477 class CachedContentResultSetFactory 478 : public cppu::OWeakObject 479 , public com::sun::star::lang::XTypeProvider 480 , public com::sun::star::lang::XServiceInfo 481 , public com::sun::star::ucb::XCachedContentResultSetFactory 482 { 483 protected: 484 com::sun::star::uno::Reference< 485 com::sun::star::lang::XMultiServiceFactory > m_xSMgr; 486 487 public: 488 489 CachedContentResultSetFactory( 490 const com::sun::star::uno::Reference< 491 com::sun::star::lang::XMultiServiceFactory > & rSMgr); 492 493 virtual ~CachedContentResultSetFactory(); 494 495 //----------------------------------------------------------------- 496 // XInterface 497 XINTERFACE_DECL() 498 499 //----------------------------------------------------------------- 500 // XTypeProvider 501 XTYPEPROVIDER_DECL() 502 503 //----------------------------------------------------------------- 504 // XServiceInfo 505 XSERVICEINFO_DECL() 506 507 //----------------------------------------------------------------- 508 // XCachedContentResultSetFactory 509 510 virtual com::sun::star::uno::Reference< 511 com::sun::star::sdbc::XResultSet > SAL_CALL 512 createCachedContentResultSet( 513 const com::sun::star::uno::Reference< 514 com::sun::star::sdbc::XResultSet > & xSource, 515 const com::sun::star::uno::Reference< 516 com::sun::star::ucb::XContentIdentifierMapping > & xMapping ) 517 throw( com::sun::star::uno::RuntimeException ); 518 }; 519 520 #endif 521 522