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