| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
#pragma once |
| 20 |
|
| 21 |
#include <mutex> |
| 22 |
#include <vector> |
| 23 |
#include <osl/file.hxx> |
| 24 |
|
| 25 |
#include <comphelper/interfacecontainer4.hxx> |
| 26 |
#include <com/sun/star/ucb/XContentAccess.hpp> |
| 27 |
#include <com/sun/star/sdbc/XCloseable.hpp> |
| 28 |
#include <com/sun/star/beans/XPropertySet.hpp> |
| 29 |
#include <com/sun/star/ucb/XDynamicResultSet.hpp> |
| 30 |
#include <com/sun/star/ucb/XDynamicResultSetListener.hpp> |
| 31 |
#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> |
| 32 |
#include <com/sun/star/ucb/NumberedSortingInfo.hpp> |
| 33 |
#include <com/sun/star/ucb/XContentIdentifier.hpp> |
| 34 |
#include <com/sun/star/beans/Property.hpp> |
| 35 |
#include "filrow.hxx" |
| 36 |
#include <cppuhelper/implbase.hxx> |
| 37 |
|
| 38 |
namespace fileaccess { |
| 39 |
|
| 40 |
class XResultSet_impl : |
| 41 |
public cppu::WeakImplHelper< css::lang::XEventListener, |
| 42 |
css::sdbc::XRow, |
| 43 |
css::sdbc::XResultSet, |
| 44 |
css::ucb::XDynamicResultSet, |
| 45 |
css::sdbc::XCloseable, |
| 46 |
css::sdbc::XResultSetMetaDataSupplier, |
| 47 |
css::beans::XPropertySet, |
| 48 |
css::ucb::XContentAccess > |
| 49 |
{ |
| 50 |
public: |
| 51 |
|
| 52 |
XResultSet_impl( TaskManager* pMyShell, |
| 53 |
const OUString& aUnqPath, |
| 54 |
sal_Int32 OpenMode, |
| 55 |
const css::uno::Sequence< css::beans::Property >& seq, |
| 56 |
const css::uno::Sequence< css::ucb::NumberedSortingInfo >& seqSort ); |
| 57 |
|
| 58 |
virtual ~XResultSet_impl() override; |
| 59 |
|
| 60 |
TaskHandlerErr CtorSuccess() const { return m_nErrorCode;} |
| 61 |
sal_Int32 getMinorError() const { return m_nMinorErrorCode;} |
| 62 |
|
| 63 |
// XEventListener |
| 64 |
virtual void SAL_CALL |
| 65 |
disposing( const css::lang::EventObject& Source ) override; |
| 66 |
|
| 67 |
// XComponent |
| 68 |
virtual void SAL_CALL |
| 69 |
dispose() override; |
| 70 |
|
| 71 |
virtual void SAL_CALL |
| 72 |
addEventListener( |
| 73 |
const css::uno::Reference< css::lang::XEventListener >& xListener ) override; |
| 74 |
|
| 75 |
virtual void SAL_CALL |
| 76 |
removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override; |
| 77 |
|
| 78 |
|
| 79 |
// XRow |
| 80 |
virtual sal_Bool SAL_CALL |
| 81 |
wasNull() override |
| 82 |
{ |
| 83 |
if( 0<= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 84 |
m_nWasNull = m_aItems[m_nRow]->wasNull(); |
| 85 |
else |
| 86 |
m_nWasNull = true; |
| 87 |
return m_nWasNull; |
| 88 |
} |
| 89 |
|
| 90 |
virtual OUString SAL_CALL |
| 91 |
getString( sal_Int32 columnIndex ) override |
| 92 |
{ |
| 93 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 94 |
return m_aItems[m_nRow]->getString( columnIndex ); |
| 95 |
else |
| 96 |
return OUString(); |
| 97 |
} |
| 98 |
|
| 99 |
virtual sal_Bool SAL_CALL |
| 100 |
getBoolean( sal_Int32 columnIndex ) override |
| 101 |
{ |
| 102 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 103 |
return m_aItems[m_nRow]->getBoolean( columnIndex ); |
| 104 |
else |
| 105 |
return false; |
| 106 |
} |
| 107 |
|
| 108 |
virtual sal_Int8 SAL_CALL |
| 109 |
getByte( sal_Int32 columnIndex ) override |
| 110 |
{ |
| 111 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 112 |
return m_aItems[m_nRow]->getByte( columnIndex ); |
| 113 |
else |
| 114 |
return sal_Int8( 0 ); |
| 115 |
} |
| 116 |
|
| 117 |
virtual sal_Int16 SAL_CALL |
| 118 |
getShort( sal_Int32 columnIndex ) override |
| 119 |
{ |
| 120 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 121 |
return m_aItems[m_nRow]->getShort( columnIndex ); |
| 122 |
else |
| 123 |
return sal_Int16( 0 ); |
| 124 |
} |
| 125 |
|
| 126 |
virtual sal_Int32 SAL_CALL |
| 127 |
getInt( sal_Int32 columnIndex ) override |
| 128 |
{ |
| 129 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 130 |
return m_aItems[m_nRow]->getInt( columnIndex ); |
| 131 |
else |
| 132 |
return 0; |
| 133 |
} |
| 134 |
|
| 135 |
virtual sal_Int64 SAL_CALL |
| 136 |
getLong( sal_Int32 columnIndex ) override |
| 137 |
{ |
| 138 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 139 |
return m_aItems[m_nRow]->getLong( columnIndex ); |
| 140 |
else |
| 141 |
return sal_Int64( 0 ); |
| 142 |
} |
| 143 |
|
| 144 |
virtual float SAL_CALL |
| 145 |
getFloat( sal_Int32 columnIndex ) override |
| 146 |
{ |
| 147 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 148 |
return m_aItems[m_nRow]->getFloat( columnIndex ); |
| 149 |
else |
| 150 |
return float( 0 ); |
| 151 |
} |
| 152 |
|
| 153 |
virtual double SAL_CALL |
| 154 |
getDouble( sal_Int32 columnIndex ) override |
| 155 |
{ |
| 156 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 157 |
return m_aItems[m_nRow]->getDouble( columnIndex ); |
| 158 |
else |
| 159 |
return double( 0 ); |
| 160 |
} |
| 161 |
|
| 162 |
virtual css::uno::Sequence< sal_Int8 > SAL_CALL |
| 163 |
getBytes( sal_Int32 columnIndex ) override |
| 164 |
{ |
| 165 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 166 |
return m_aItems[m_nRow]->getBytes( columnIndex ); |
| 167 |
else |
| 168 |
return css::uno::Sequence< sal_Int8 >(); |
| 169 |
} |
| 170 |
|
| 171 |
virtual css::util::Date SAL_CALL |
| 172 |
getDate( sal_Int32 columnIndex ) override |
| 173 |
{ |
| 174 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 175 |
return m_aItems[m_nRow]->getDate( columnIndex ); |
| 176 |
else |
| 177 |
return css::util::Date(); |
| 178 |
} |
| 179 |
|
| 180 |
virtual css::util::Time SAL_CALL |
| 181 |
getTime( sal_Int32 columnIndex ) override |
| 182 |
{ |
| 183 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 184 |
return m_aItems[m_nRow]->getTime( columnIndex ); |
| 185 |
else |
| 186 |
return css::util::Time(); |
| 187 |
} |
| 188 |
|
| 189 |
virtual css::util::DateTime SAL_CALL |
| 190 |
getTimestamp( sal_Int32 columnIndex ) override |
| 191 |
{ |
| 192 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 193 |
return m_aItems[m_nRow]->getTimestamp( columnIndex ); |
| 194 |
else |
| 195 |
return css::util::DateTime(); |
| 196 |
} |
| 197 |
|
| 198 |
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL |
| 199 |
getBinaryStream( sal_Int32 columnIndex ) override |
| 200 |
{ |
| 201 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 202 |
return m_aItems[m_nRow]->getBinaryStream( columnIndex ); |
| 203 |
else |
| 204 |
return css::uno::Reference< css::io::XInputStream >(); |
| 205 |
} |
| 206 |
|
| 207 |
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL |
| 208 |
getCharacterStream( sal_Int32 columnIndex ) override |
| 209 |
{ |
| 210 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 211 |
return m_aItems[m_nRow]->getCharacterStream( columnIndex ); |
| 212 |
else |
| 213 |
return css::uno::Reference< css::io::XInputStream >(); |
| 214 |
} |
| 215 |
|
| 216 |
virtual css::uno::Any SAL_CALL |
| 217 |
getObject( sal_Int32 columnIndex, |
| 218 |
const css::uno::Reference< css::container::XNameAccess >& typeMap ) override |
| 219 |
{ |
| 220 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 221 |
return m_aItems[m_nRow]->getObject( columnIndex,typeMap ); |
| 222 |
else |
| 223 |
return css::uno::Any(); |
| 224 |
} |
| 225 |
|
| 226 |
virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL |
| 227 |
getRef( sal_Int32 columnIndex ) override |
| 228 |
{ |
| 229 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 230 |
return m_aItems[m_nRow]->getRef( columnIndex ); |
| 231 |
else |
| 232 |
return css::uno::Reference< css::sdbc::XRef >(); |
| 233 |
} |
| 234 |
|
| 235 |
virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL |
| 236 |
getBlob( sal_Int32 columnIndex ) override |
| 237 |
{ |
| 238 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 239 |
return m_aItems[m_nRow]->getBlob( columnIndex ); |
| 240 |
else |
| 241 |
return css::uno::Reference< css::sdbc::XBlob >(); |
| 242 |
} |
| 243 |
|
| 244 |
virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL |
| 245 |
getClob( sal_Int32 columnIndex ) override |
| 246 |
{ |
| 247 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 248 |
return m_aItems[m_nRow]->getClob( columnIndex ); |
| 249 |
else |
| 250 |
return css::uno::Reference< css::sdbc::XClob >(); |
| 251 |
} |
| 252 |
|
| 253 |
virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL |
| 254 |
getArray( sal_Int32 columnIndex ) override |
| 255 |
{ |
| 256 |
if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) ) |
| 257 |
return m_aItems[m_nRow]->getArray( columnIndex ); |
| 258 |
else |
| 259 |
return css::uno::Reference< css::sdbc::XArray >(); |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
// XResultSet |
| 264 |
|
| 265 |
virtual sal_Bool SAL_CALL |
| 266 |
next() override; |
| 267 |
|
| 268 |
virtual sal_Bool SAL_CALL |
| 269 |
isBeforeFirst() override; |
| 270 |
|
| 271 |
virtual sal_Bool SAL_CALL |
| 272 |
isAfterLast() override; |
| 273 |
|
| 274 |
virtual sal_Bool SAL_CALL |
| 275 |
isFirst() override; |
| 276 |
|
| 277 |
virtual sal_Bool SAL_CALL |
| 278 |
isLast() override; |
| 279 |
|
| 280 |
virtual void SAL_CALL |
| 281 |
beforeFirst() override; |
| 282 |
|
| 283 |
virtual void SAL_CALL |
| 284 |
afterLast() override; |
| 285 |
|
| 286 |
virtual sal_Bool SAL_CALL |
| 287 |
first() override; |
| 288 |
|
| 289 |
virtual sal_Bool SAL_CALL |
| 290 |
last() override; |
| 291 |
|
| 292 |
virtual sal_Int32 SAL_CALL |
| 293 |
getRow() override; |
| 294 |
|
| 295 |
virtual sal_Bool SAL_CALL |
| 296 |
absolute( sal_Int32 row ) override; |
| 297 |
|
| 298 |
virtual sal_Bool SAL_CALL |
| 299 |
relative( sal_Int32 rows ) override; |
| 300 |
|
| 301 |
virtual sal_Bool SAL_CALL |
| 302 |
previous() override; |
| 303 |
|
| 304 |
virtual void SAL_CALL |
| 305 |
refreshRow() override; |
| 306 |
|
| 307 |
virtual sal_Bool SAL_CALL |
| 308 |
rowUpdated() override; |
| 309 |
|
| 310 |
virtual sal_Bool SAL_CALL |
| 311 |
rowInserted() override; |
| 312 |
|
| 313 |
virtual sal_Bool SAL_CALL |
| 314 |
rowDeleted() override; |
| 315 |
|
| 316 |
|
| 317 |
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL |
| 318 |
getStatement() override; |
| 319 |
|
| 320 |
|
| 321 |
// XDynamicResultSet |
| 322 |
|
| 323 |
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL |
| 324 |
getStaticResultSet() override; |
| 325 |
|
| 326 |
virtual void SAL_CALL |
| 327 |
setListener( |
| 328 |
const css::uno::Reference< |
| 329 |
css::ucb::XDynamicResultSetListener >& Listener ) override; |
| 330 |
|
| 331 |
virtual void SAL_CALL |
| 332 |
connectToCache( const css::uno::Reference< css::ucb::XDynamicResultSet > & xCache ) override; |
| 333 |
|
| 334 |
virtual sal_Int16 SAL_CALL |
| 335 |
getCapabilities() override; |
| 336 |
|
| 337 |
|
| 338 |
// XCloseable |
| 339 |
|
| 340 |
virtual void SAL_CALL |
| 341 |
close() override; |
| 342 |
|
| 343 |
// XContentAccess |
| 344 |
|
| 345 |
virtual OUString SAL_CALL |
| 346 |
queryContentIdentifierString() override; |
| 347 |
|
| 348 |
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL |
| 349 |
queryContentIdentifier() override; |
| 350 |
|
| 351 |
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL |
| 352 |
queryContent() override; |
| 353 |
|
| 354 |
// XResultSetMetaDataSupplier |
| 355 |
virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL |
| 356 |
getMetaData() override; |
| 357 |
|
| 358 |
|
| 359 |
// XPropertySet |
| 360 |
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL |
| 361 |
getPropertySetInfo() override; |
| 362 |
|
| 363 |
virtual void SAL_CALL setPropertyValue( |
| 364 |
const OUString& aPropertyName, |
| 365 |
const css::uno::Any& aValue ) override; |
| 366 |
|
| 367 |
virtual css::uno::Any SAL_CALL |
| 368 |
getPropertyValue( |
| 369 |
const OUString& PropertyName ) override; |
| 370 |
|
| 371 |
virtual void SAL_CALL |
| 372 |
addPropertyChangeListener( |
| 373 |
const OUString& aPropertyName, |
| 374 |
const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override; |
| 375 |
|
| 376 |
virtual void SAL_CALL |
| 377 |
removePropertyChangeListener( |
| 378 |
const OUString& aPropertyName, |
| 379 |
const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override; |
| 380 |
|
| 381 |
virtual void SAL_CALL |
| 382 |
addVetoableChangeListener( |
| 383 |
const OUString& PropertyName, |
| 384 |
const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; |
| 385 |
|
| 386 |
virtual void SAL_CALL removeVetoableChangeListener( |
| 387 |
const OUString& PropertyName, |
| 388 |
const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; |
| 389 |
|
| 390 |
private: |
| 391 |
|
| 392 |
TaskManager* m_pMyShell; |
| 393 |
bool m_nIsOpen; |
| 394 |
sal_Int32 m_nRow; |
| 395 |
bool m_nWasNull; |
| 396 |
sal_Int32 m_nOpenMode; |
| 397 |
bool m_bRowCountFinal; |
| 398 |
|
| 399 |
typedef std::vector< css::uno::Reference< css::ucb::XContentIdentifier > > IdentSet; |
| 400 |
typedef std::vector< css::uno::Reference< css::sdbc::XRow > > ItemSet; |
| 401 |
|
| 402 |
IdentSet m_aIdents; |
| 403 |
ItemSet m_aItems; |
| 404 |
std::vector< OUString > m_aUnqPath; |
| 405 |
const OUString m_aBaseDirectory; |
| 406 |
|
| 407 |
osl::Directory m_aFolder; |
| 408 |
css::uno::Sequence< css::beans::Property > m_sProperty; |
| 409 |
css::uno::Sequence< css::ucb::NumberedSortingInfo > m_sSortingInfo; |
| 410 |
|
| 411 |
std::mutex m_aMutex; |
| 412 |
comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aDisposeEventListeners; |
| 413 |
comphelper::OInterfaceContainerHelper4<css::beans::XPropertyChangeListener> m_aRowCountListeners; |
| 414 |
comphelper::OInterfaceContainerHelper4<css::beans::XPropertyChangeListener> m_aIsFinalListeners; |
| 415 |
|
| 416 |
css::uno::Reference< css::ucb::XDynamicResultSetListener > m_xListener; |
| 417 |
|
| 418 |
TaskHandlerErr m_nErrorCode; |
| 419 |
sal_Int32 m_nMinorErrorCode; |
| 420 |
|
| 421 |
// Methods |
| 422 |
/// @throws css::sdbc::SQLException |
| 423 |
/// @throws css::uno::RuntimeException |
| 424 |
bool OneMore(std::unique_lock<std::mutex>&); |
| 425 |
|
| 426 |
void rowCountChanged(std::unique_lock<std::mutex>&); |
| 427 |
void isFinalChanged(std::unique_lock<std::mutex>&); |
| 428 |
}; |
| 429 |
|
| 430 |
|
| 431 |
} // end namespace fileaccess |
| 432 |
|
| 433 |
|
| 434 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |