cid#1640468 Dereference after null check
[LibreOffice.git] / ucb / source / ucp / file / filrset.hxx
blob4a25c16be7237235970cb6edc2957b82d7073d6a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
21 #include <mutex>
22 #include <vector>
23 #include <osl/file.hxx>
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>
38 namespace fileaccess {
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 >
50 public:
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 );
58 virtual ~XResultSet_impl() override;
60 TaskHandlerErr CtorSuccess() const { return m_nErrorCode;}
61 sal_Int32 getMinorError() const { return m_nMinorErrorCode;}
63 // XEventListener
64 virtual void SAL_CALL
65 disposing( const css::lang::EventObject& Source ) override;
67 // XComponent
68 virtual void SAL_CALL
69 dispose() override;
71 virtual void SAL_CALL
72 addEventListener(
73 const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
75 virtual void SAL_CALL
76 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
79 // XRow
80 virtual sal_Bool SAL_CALL
81 wasNull() override
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;
90 virtual OUString SAL_CALL
91 getString( sal_Int32 columnIndex ) override
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();
99 virtual sal_Bool SAL_CALL
100 getBoolean( sal_Int32 columnIndex ) override
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;
108 virtual sal_Int8 SAL_CALL
109 getByte( sal_Int32 columnIndex ) override
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 );
117 virtual sal_Int16 SAL_CALL
118 getShort( sal_Int32 columnIndex ) override
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 );
126 virtual sal_Int32 SAL_CALL
127 getInt( sal_Int32 columnIndex ) override
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;
135 virtual sal_Int64 SAL_CALL
136 getLong( sal_Int32 columnIndex ) override
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 );
144 virtual float SAL_CALL
145 getFloat( sal_Int32 columnIndex ) override
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 );
153 virtual double SAL_CALL
154 getDouble( sal_Int32 columnIndex ) override
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 );
162 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
163 getBytes( sal_Int32 columnIndex ) override
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 >();
171 virtual css::util::Date SAL_CALL
172 getDate( sal_Int32 columnIndex ) override
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();
180 virtual css::util::Time SAL_CALL
181 getTime( sal_Int32 columnIndex ) override
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();
189 virtual css::util::DateTime SAL_CALL
190 getTimestamp( sal_Int32 columnIndex ) override
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();
198 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
199 getBinaryStream( sal_Int32 columnIndex ) override
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 >();
207 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
208 getCharacterStream( sal_Int32 columnIndex ) override
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 >();
216 virtual css::uno::Any SAL_CALL
217 getObject( sal_Int32 columnIndex,
218 const css::uno::Reference< css::container::XNameAccess >& typeMap ) override
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();
226 virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL
227 getRef( sal_Int32 columnIndex ) override
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 >();
235 virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL
236 getBlob( sal_Int32 columnIndex ) override
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 >();
244 virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL
245 getClob( sal_Int32 columnIndex ) override
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 >();
253 virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL
254 getArray( sal_Int32 columnIndex ) override
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 >();
263 // XResultSet
265 virtual sal_Bool SAL_CALL
266 next() override;
268 virtual sal_Bool SAL_CALL
269 isBeforeFirst() override;
271 virtual sal_Bool SAL_CALL
272 isAfterLast() override;
274 virtual sal_Bool SAL_CALL
275 isFirst() override;
277 virtual sal_Bool SAL_CALL
278 isLast() override;
280 virtual void SAL_CALL
281 beforeFirst() override;
283 virtual void SAL_CALL
284 afterLast() override;
286 virtual sal_Bool SAL_CALL
287 first() override;
289 virtual sal_Bool SAL_CALL
290 last() override;
292 virtual sal_Int32 SAL_CALL
293 getRow() override;
295 virtual sal_Bool SAL_CALL
296 absolute( sal_Int32 row ) override;
298 virtual sal_Bool SAL_CALL
299 relative( sal_Int32 rows ) override;
301 virtual sal_Bool SAL_CALL
302 previous() override;
304 virtual void SAL_CALL
305 refreshRow() override;
307 virtual sal_Bool SAL_CALL
308 rowUpdated() override;
310 virtual sal_Bool SAL_CALL
311 rowInserted() override;
313 virtual sal_Bool SAL_CALL
314 rowDeleted() override;
317 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
318 getStatement() override;
321 // XDynamicResultSet
323 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL
324 getStaticResultSet() override;
326 virtual void SAL_CALL
327 setListener(
328 const css::uno::Reference<
329 css::ucb::XDynamicResultSetListener >& Listener ) override;
331 virtual void SAL_CALL
332 connectToCache( const css::uno::Reference< css::ucb::XDynamicResultSet > & xCache ) override;
334 virtual sal_Int16 SAL_CALL
335 getCapabilities() override;
338 // XCloseable
340 virtual void SAL_CALL
341 close() override;
343 // XContentAccess
345 virtual OUString SAL_CALL
346 queryContentIdentifierString() override;
348 virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL
349 queryContentIdentifier() override;
351 virtual css::uno::Reference< css::ucb::XContent > SAL_CALL
352 queryContent() override;
354 // XResultSetMetaDataSupplier
355 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL
356 getMetaData() override;
359 // XPropertySet
360 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
361 getPropertySetInfo() override;
363 virtual void SAL_CALL setPropertyValue(
364 const OUString& aPropertyName,
365 const css::uno::Any& aValue ) override;
367 virtual css::uno::Any SAL_CALL
368 getPropertyValue(
369 const OUString& PropertyName ) override;
371 virtual void SAL_CALL
372 addPropertyChangeListener(
373 const OUString& aPropertyName,
374 const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
376 virtual void SAL_CALL
377 removePropertyChangeListener(
378 const OUString& aPropertyName,
379 const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
381 virtual void SAL_CALL
382 addVetoableChangeListener(
383 const OUString& PropertyName,
384 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
386 virtual void SAL_CALL removeVetoableChangeListener(
387 const OUString& PropertyName,
388 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
390 private:
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;
399 typedef std::vector< css::uno::Reference< css::ucb::XContentIdentifier > > IdentSet;
400 typedef std::vector< css::uno::Reference< css::sdbc::XRow > > ItemSet;
402 IdentSet m_aIdents;
403 ItemSet m_aItems;
404 std::vector< OUString > m_aUnqPath;
405 const OUString m_aBaseDirectory;
407 osl::Directory m_aFolder;
408 css::uno::Sequence< css::beans::Property > m_sProperty;
409 css::uno::Sequence< css::ucb::NumberedSortingInfo > m_sSortingInfo;
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;
416 css::uno::Reference< css::ucb::XDynamicResultSetListener > m_xListener;
418 TaskHandlerErr m_nErrorCode;
419 sal_Int32 m_nMinorErrorCode;
421 // Methods
422 /// @throws css::sdbc::SQLException
423 /// @throws css::uno::RuntimeException
424 bool OneMore(std::unique_lock<std::mutex>&);
426 void rowCountChanged(std::unique_lock<std::mutex>&);
427 void isFinalChanged(std::unique_lock<std::mutex>&);
431 } // end namespace fileaccess
434 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */