LibreOffice Module ucb (master) 1
sortresult.hxx
Go to the documentation of this file.
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
20#pragma once
21
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <com/sun/star/lang/XComponent.hpp>
24#include <com/sun/star/lang/XServiceInfo.hpp>
25#include <com/sun/star/sdbc/XCloseable.hpp>
26#include <com/sun/star/sdbc/XResultSet.hpp>
27#include <com/sun/star/sdbc/XResultSetMetaData.hpp>
28#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
29#include <com/sun/star/sdbc/XRow.hpp>
30#include <com/sun/star/ucb/XContentAccess.hpp>
31#include <com/sun/star/ucb/NumberedSortingInfo.hpp>
32#include <com/sun/star/ucb/XAnyCompareFactory.hpp>
33#include <com/sun/star/ucb/ListAction.hpp>
37#include <rtl/ref.hxx>
38#include <deque>
39#include <memory>
40
41
42struct SortInfo;
43struct SortListData;
45
46
48{
49 std::deque < std::unique_ptr<SortListData> > maData;
50
51public:
54
55 sal_uInt32 Count() const { return static_cast<sal_uInt32>(maData.size()); }
56
57 void Clear();
58 void Insert( std::unique_ptr<SortListData> pEntry, sal_Int32 nPos );
59 std::unique_ptr<SortListData> Remove( sal_Int32 nPos );
60 SortListData* GetData( sal_Int32 nPos );
61 void Move( sal_Int32 nOldPos, sal_Int32 nNewPos );
62
63 sal_Int32 operator [] ( sal_Int32 nPos ) const;
64};
65
66
68{
69 std::deque <css::ucb::ListAction > maData;
70
71public:
73
74 sal_uInt32 Count() const { return static_cast<sal_uInt32>(maData.size()); }
75
76 void AddEvent( sal_IntPtr nType, sal_Int32 nPos );
77 void Insert( const css::ucb::ListAction& rAction ) { maData.push_back( rAction ); }
78 void Clear();
79 css::ucb::ListAction& GetAction( sal_Int32 nIndex ) { return maData[ nIndex ]; }
80};
81
82
83inline constexpr OUStringLiteral RESULTSET_SERVICE_NAME = u"com.sun.star.ucb.SortedResultSet";
84
85
86class SortedResultSet: public cppu::WeakImplHelper <
87 css::lang::XServiceInfo,
88 css::lang::XComponent,
89 css::ucb::XContentAccess,
90 css::sdbc::XResultSet,
91 css::sdbc::XRow,
92 css::sdbc::XCloseable,
93 css::sdbc::XResultSetMetaDataSupplier,
94 css::beans::XPropertySet >
95{
97 std::unique_ptr<comphelper::OMultiTypeInterfaceContainerHelperVar3<css::beans::XPropertyChangeListener, OUString>> mpPropChangeListeners;
98 std::unique_ptr<comphelper::OMultiTypeInterfaceContainerHelperVar3<css::beans::XVetoableChangeListener, OUString>> mpVetoChangeListeners;
99
100 css::uno::Reference < css::sdbc::XResultSet > mxOriginal;
101 css::uno::Reference < css::sdbc::XResultSet > mxOther;
102
105 osl::Mutex maMutex;
106 SortedEntryList maS2O; // maps the sorted entries to the original ones
107 std::deque<sal_IntPtr> m_O2S;
108 std::deque<SortListData*> m_ModList;
109 sal_Int32 mnLastSort; // index of the last sorted entry;
110 sal_Int32 mnCurEntry; // index of the current entry
111 sal_Int32 mnCount; // total count of the elements
113
114
115private:
118 sal_Int32 FindPos( SortListData const *pEntry, sal_IntPtr nStart, sal_IntPtr nEnd );
121 sal_Int32 Compare( SortListData const *pOne,
122 SortListData const *pTwo );
123 void BuildSortInfo( const css::uno::Reference< css::sdbc::XResultSet >& aResult,
124 const css::uno::Sequence < css::ucb::NumberedSortingInfo > &xSortInfo,
125 const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac );
128 static sal_Int32 CompareImpl( const css::uno::Reference < css::sdbc::XResultSet >& xResultOne,
129 const css::uno::Reference < css::sdbc::XResultSet >& xResultTwo,
130 sal_Int32 nIndexOne, sal_Int32 nIndexTwo,
131 SortInfo const * pSortInfo );
134 sal_Int32 CompareImpl( const css::uno::Reference < css::sdbc::XResultSet >& xResultOne,
135 const css::uno::Reference < css::sdbc::XResultSet >& xResultTwo,
136 sal_Int32 nIndexOne, sal_Int32 nIndexTwo );
137 void PropertyChanged( const css::beans::PropertyChangeEvent& rEvt );
138
139public:
140 SortedResultSet( css::uno::Reference< css::sdbc::XResultSet > const & aResult );
141 virtual ~SortedResultSet() override;
142
143 sal_Int32 GetCount() const { return mnCount; }
144
145 void CopyData( SortedResultSet* pSource );
146 void Initialize( const css::uno::Sequence < css::ucb::NumberedSortingInfo > &xSortInfo,
147 const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac );
148 void CheckProperties( sal_Int32 nOldCount, bool bWasFinal );
149
150 void InsertNew( sal_Int32 nPos, sal_Int32 nCount );
151 void SetChanged( sal_Int32 nPos, sal_Int32 nCount );
152 void Remove( sal_Int32 nPos, sal_Int32 nCount, EventList *pList );
153 void Move( sal_Int32 nPos, sal_Int32 nCount, sal_Int32 nOffset );
154
155 void ResortModified( EventList* pList );
156 void ResortNew( EventList* pList );
157
158 // XServiceInfo
159 virtual OUString SAL_CALL getImplementationName() override;
160 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
161 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
162
163 // XComponent
164 virtual void SAL_CALL
165 dispose() override;
166
167 virtual void SAL_CALL
168 addEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
169
170 virtual void SAL_CALL
171 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
172
173 // XContentAccess
174 virtual OUString SAL_CALL
176 virtual css::uno::Reference<
177 css::ucb::XContentIdentifier > SAL_CALL
178 queryContentIdentifier() override;
179 virtual css::uno::Reference<
180 css::ucb::XContent > SAL_CALL
181 queryContent() override;
182
183 // XResultSet
184 virtual sal_Bool SAL_CALL
185 next() override;
186 virtual sal_Bool SAL_CALL
187 isBeforeFirst() override;
188 virtual sal_Bool SAL_CALL
189 isAfterLast() override;
190 virtual sal_Bool SAL_CALL
191 isFirst() override;
192 virtual sal_Bool SAL_CALL
193 isLast() override;
194 virtual void SAL_CALL
195 beforeFirst() override;
196 virtual void SAL_CALL
197 afterLast() override;
198 virtual sal_Bool SAL_CALL
199 first() override;
200 virtual sal_Bool SAL_CALL
201 last() override;
202 virtual sal_Int32 SAL_CALL
203 getRow() override;
204 virtual sal_Bool SAL_CALL
205 absolute( sal_Int32 row ) override;
206 virtual sal_Bool SAL_CALL
207 relative( sal_Int32 rows ) override;
208 virtual sal_Bool SAL_CALL
209 previous() override;
210 virtual void SAL_CALL
211 refreshRow() override;
212 virtual sal_Bool SAL_CALL
213 rowUpdated() override;
214 virtual sal_Bool SAL_CALL
215 rowInserted() override;
216 virtual sal_Bool SAL_CALL
217 rowDeleted() override;
218 virtual css::uno::Reference<
219 css::uno::XInterface > SAL_CALL
220 getStatement() override;
221
222 // XRow
223 virtual sal_Bool SAL_CALL
224 wasNull() override;
225
226 virtual OUString SAL_CALL
227 getString( sal_Int32 columnIndex ) override;
228
229 virtual sal_Bool SAL_CALL
230 getBoolean( sal_Int32 columnIndex ) override;
231
232 virtual sal_Int8 SAL_CALL
233 getByte( sal_Int32 columnIndex ) override;
234
235 virtual sal_Int16 SAL_CALL
236 getShort( sal_Int32 columnIndex ) override;
237
238 virtual sal_Int32 SAL_CALL
239 getInt( sal_Int32 columnIndex ) override;
240
241 virtual sal_Int64 SAL_CALL
242 getLong( sal_Int32 columnIndex ) override;
243
244 virtual float SAL_CALL
245 getFloat( sal_Int32 columnIndex ) override;
246
247 virtual double SAL_CALL
248 getDouble( sal_Int32 columnIndex ) override;
249
250 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
251 getBytes( sal_Int32 columnIndex ) override;
252
253 virtual css::util::Date SAL_CALL
254 getDate( sal_Int32 columnIndex ) override;
255
256 virtual css::util::Time SAL_CALL
257 getTime( sal_Int32 columnIndex ) override;
258
259 virtual css::util::DateTime SAL_CALL
260 getTimestamp( sal_Int32 columnIndex ) override;
261
262 virtual css::uno::Reference<
263 css::io::XInputStream > SAL_CALL
264 getBinaryStream( sal_Int32 columnIndex ) override;
265
266 virtual css::uno::Reference<
267 css::io::XInputStream > SAL_CALL
268 getCharacterStream( sal_Int32 columnIndex ) override;
269
270 virtual css::uno::Any SAL_CALL
271 getObject( sal_Int32 columnIndex,
272 const css::uno::Reference<
273 css::container::XNameAccess >& typeMap ) override;
274 virtual css::uno::Reference<
275 css::sdbc::XRef > SAL_CALL
276 getRef( sal_Int32 columnIndex ) override;
277 virtual css::uno::Reference<
278 css::sdbc::XBlob > SAL_CALL
279 getBlob( sal_Int32 columnIndex ) override;
280 virtual css::uno::Reference<
281 css::sdbc::XClob > SAL_CALL
282 getClob( sal_Int32 columnIndex ) override;
283 virtual css::uno::Reference<
284 css::sdbc::XArray > SAL_CALL
285 getArray( sal_Int32 columnIndex ) override;
286
287 // XCloseable
288 virtual void SAL_CALL
289 close() override;
290
291 // XResultSetMetaDataSupplier
292 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL
293 getMetaData() override;
294
295
296 // XPropertySet
297 virtual css::uno::Reference<
298 css::beans::XPropertySetInfo > SAL_CALL
299 getPropertySetInfo() override;
300
301 virtual void SAL_CALL
302 setPropertyValue( const OUString& PropertyName,
303 const css::uno::Any& Value ) override;
304
305 virtual css::uno::Any SAL_CALL
306 getPropertyValue( const OUString& PropertyName ) override;
307
308 virtual void SAL_CALL
309 addPropertyChangeListener( const OUString& PropertyName,
310 const css::uno::Reference<
311 css::beans::XPropertyChangeListener >& Listener ) override;
312
313 virtual void SAL_CALL
314 removePropertyChangeListener( const OUString& PropertyName,
315 const css::uno::Reference<
316 css::beans::XPropertyChangeListener >& Listener ) override;
317
318 virtual void SAL_CALL
319 addVetoableChangeListener( const OUString& PropertyName,
320 const css::uno::Reference<
321 css::beans::XVetoableChangeListener >& Listener ) override;
322
323 virtual void SAL_CALL
324 removeVetoableChangeListener( const OUString& PropertyName,
325 const css::uno::Reference<
326 css::beans::XVetoableChangeListener >& aListener ) override;
327};
328
329/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::ucb::ListAction & GetAction(sal_Int32 nIndex)
Definition: sortresult.hxx:79
void AddEvent(sal_IntPtr nType, sal_Int32 nPos)
Definition: sortdynres.cxx:461
sal_uInt32 Count() const
Definition: sortresult.hxx:74
void Insert(const css::ucb::ListAction &rAction)
Definition: sortresult.hxx:77
void Clear()
Definition: sortdynres.cxx:456
std::deque< css::ucb::ListAction > maData
Definition: sortresult.hxx:69
std::unique_ptr< SortListData > Remove(sal_Int32 nPos)
std::deque< std::unique_ptr< SortListData > > maData
Definition: sortresult.hxx:49
sal_Int32 operator[](sal_Int32 nPos) const
SortListData * GetData(sal_Int32 nPos)
sal_uInt32 Count() const
Definition: sortresult.hxx:55
void Move(sal_Int32 nOldPos, sal_Int32 nNewPos)
void Insert(std::unique_ptr< SortListData > pEntry, sal_Int32 nPos)
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement() override
Definition: sortresult.cxx:553
std::deque< SortListData * > m_ModList
maps the original Entries to the sorted ones
Definition: sortresult.hxx:108
virtual double SAL_CALL getDouble(sal_Int32 columnIndex) override
Definition: sortresult.cxx:624
virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob(sal_Int32 columnIndex) override
Definition: sortresult.cxx:698
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream(sal_Int32 columnIndex) override
Definition: sortresult.cxx:660
sal_Int32 mnCurEntry
Definition: sortresult.hxx:110
sal_Int32 FindPos(SortListData const *pEntry, sal_IntPtr nStart, sal_IntPtr nEnd)
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &Listener) override
Definition: sortresult.cxx:181
virtual sal_Int16 SAL_CALL getShort(sal_Int32 columnIndex) override
Definition: sortresult.cxx:597
virtual void SAL_CALL dispose() override
Definition: sortresult.cxx:151
void ResortNew(EventList *pList)
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &Listener) override
Definition: sortresult.cxx:194
osl::Mutex maMutex
Definition: sortresult.hxx:105
virtual sal_Bool SAL_CALL next() override
Definition: sortresult.cxx:233
virtual void SAL_CALL refreshRow() override
Definition: sortresult.cxx:501
std::unique_ptr< comphelper::OMultiTypeInterfaceContainerHelperVar3< css::beans::XVetoableChangeListener, OUString > > mpVetoChangeListeners
Definition: sortresult.hxx:98
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent() override
Definition: sortresult.cxx:224
virtual sal_Bool SAL_CALL rowDeleted() override
Definition: sortresult.cxx:540
virtual sal_Int8 SAL_CALL getByte(sal_Int32 columnIndex) override
Definition: sortresult.cxx:590
virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData() override
Definition: sortresult.cxx:725
virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef(sal_Int32 columnIndex) override
Definition: sortresult.cxx:684
sal_Int32 CompareImpl(const css::uno::Reference< css::sdbc::XResultSet > &xResultOne, const css::uno::Reference< css::sdbc::XResultSet > &xResultTwo, sal_Int32 nIndexOne, sal_Int32 nIndexTwo)
void Remove(sal_Int32 nPos, sal_Int32 nCount, EventList *pList)
virtual sal_Bool SAL_CALL getBoolean(sal_Int32 columnIndex) override
Definition: sortresult.cxx:583
virtual OUString SAL_CALL getImplementationName() override
Definition: sortresult.cxx:133
comphelper::OInterfaceContainerHelper3< css::lang::XEventListener > * mpDisposeEventListeners
Definition: sortresult.hxx:96
virtual sal_Bool SAL_CALL rowInserted() override
Definition: sortresult.cxx:527
virtual sal_Bool SAL_CALL relative(sal_Int32 rows) override
moves the cursor a relative number of rows, either positive or negative.
Definition: sortresult.cxx:436
void ResortModified(EventList *pList)
sal_Int32 mnCount
Definition: sortresult.hxx:111
void SetChanged(sal_Int32 nPos, sal_Int32 nCount)
virtual sal_Bool SAL_CALL absolute(sal_Int32 row) override
moves the cursor to the given row number in the result set.
Definition: sortresult.cxx:374
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL queryContentIdentifier() override
Definition: sortresult.cxx:216
void Move(sal_Int32 nPos, sal_Int32 nCount, sal_Int32 nOffset)
css::uno::Reference< css::sdbc::XResultSet > mxOther
Definition: sortresult.hxx:101
virtual void SAL_CALL removePropertyChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &Listener) override
Definition: sortresult.cxx:814
virtual ~SortedResultSet() override
Definition: sortresult.cxx:109
virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob(sal_Int32 columnIndex) override
Definition: sortresult.cxx:691
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: sortresult.cxx:839
virtual OUString SAL_CALL queryContentIdentifierString() override
Definition: sortresult.cxx:208
virtual sal_Bool SAL_CALL last() override
Definition: sortresult.cxx:325
virtual sal_Int32 SAL_CALL getInt(sal_Int32 columnIndex) override
Definition: sortresult.cxx:604
sal_Int32 Compare(SortListData const *pOne, SortListData const *pTwo)
virtual css::util::Date SAL_CALL getDate(sal_Int32 columnIndex) override
Definition: sortresult.cxx:638
static sal_Int32 CompareImpl(const css::uno::Reference< css::sdbc::XResultSet > &xResultOne, const css::uno::Reference< css::sdbc::XResultSet > &xResultTwo, sal_Int32 nIndexOne, sal_Int32 nIndexTwo, SortInfo const *pSortInfo)
virtual sal_Int64 SAL_CALL getLong(sal_Int32 columnIndex) override
Definition: sortresult.cxx:610
virtual sal_Int32 SAL_CALL getRow() override
Definition: sortresult.cxx:343
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: sortresult.cxx:138
sal_Int32 mnLastSort
keeps track of modified entries
Definition: sortresult.hxx:109
virtual sal_Bool SAL_CALL first() override
Definition: sortresult.cxx:307
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream(sal_Int32 columnIndex) override
Definition: sortresult.cxx:668
void CopyData(SortedResultSet *pSource)
void PropertyChanged(const css::beans::PropertyChangeEvent &rEvt)
virtual css::util::Time SAL_CALL getTime(sal_Int32 columnIndex) override
Definition: sortresult.cxx:645
virtual void SAL_CALL close() override
Definition: sortresult.cxx:715
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: sortresult.cxx:762
void Initialize(const css::uno::Sequence< css::ucb::NumberedSortingInfo > &xSortInfo, const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac)
SortedResultSet(css::uno::Reference< css::sdbc::XResultSet > const &aResult)
Definition: sortresult.cxx:94
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes(sal_Int32 columnIndex) override
Definition: sortresult.cxx:631
sal_Int32 GetCount() const
Definition: sortresult.hxx:143
virtual sal_Bool SAL_CALL previous() override
moves the cursor to the previous row in the result set.
Definition: sortresult.cxx:480
void BuildSortInfo(const css::uno::Reference< css::sdbc::XResultSet > &aResult, const css::uno::Sequence< css::ucb::NumberedSortingInfo > &xSortInfo, const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac)
virtual sal_Bool SAL_CALL isAfterLast() override
Definition: sortresult.cxx:264
css::uno::Reference< css::sdbc::XResultSet > mxOriginal
Definition: sortresult.hxx:100
rtl::Reference< SRSPropertySetInfo > mpPropSetInfo
Definition: sortresult.hxx:103
void CheckProperties(sal_Int32 nOldCount, bool bWasFinal)
virtual sal_Bool SAL_CALL rowUpdated() override
Definition: sortresult.cxx:514
virtual void SAL_CALL afterLast() override
Definition: sortresult.cxx:299
virtual sal_Bool SAL_CALL wasNull() override
Definition: sortresult.cxx:569
virtual void SAL_CALL addPropertyChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &Listener) override
Definition: sortresult.cxx:800
virtual void SAL_CALL beforeFirst() override
Definition: sortresult.cxx:291
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: sortresult.cxx:736
virtual void SAL_CALL setPropertyValue(const OUString &PropertyName, const css::uno::Any &Value) override
Definition: sortresult.cxx:749
virtual sal_Bool SAL_CALL isBeforeFirst() override
Definition: sortresult.cxx:255
std::deque< sal_IntPtr > m_O2S
Definition: sortresult.hxx:107
virtual css::uno::Any SAL_CALL getObject(sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess > &typeMap) override
Definition: sortresult.cxx:675
virtual OUString SAL_CALL getString(sal_Int32 columnIndex) override
Definition: sortresult.cxx:576
SortInfo * mpSortInfo
Definition: sortresult.hxx:104
void InsertNew(sal_Int32 nPos, sal_Int32 nCount)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: sortresult.cxx:143
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &Listener) override
Definition: sortresult.cxx:825
SortedEntryList maS2O
Definition: sortresult.hxx:106
virtual sal_Bool SAL_CALL isFirst() override
Definition: sortresult.cxx:273
virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray(sal_Int32 columnIndex) override
Definition: sortresult.cxx:705
virtual sal_Bool SAL_CALL isLast() override
Definition: sortresult.cxx:282
virtual float SAL_CALL getFloat(sal_Int32 columnIndex) override
Definition: sortresult.cxx:617
virtual css::util::DateTime SAL_CALL getTimestamp(sal_Int32 columnIndex) override
Definition: sortresult.cxx:652
std::unique_ptr< comphelper::OMultiTypeInterfaceContainerHelperVar3< css::beans::XPropertyChangeListener, OUString > > mpPropChangeListeners
Definition: sortresult.hxx:97
float u
sal_Int32 nIndex
constexpr OUStringLiteral RESULTSET_SERVICE_NAME
Definition: sortresult.hxx:83
unsigned char sal_Bool
signed char sal_Int8