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