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>
39#include <rtl/ref.hxx>
40#include <deque>
41#include <memory>
42
43
44struct SortInfo;
45struct SortListData;
47
48
50{
51 std::deque < std::unique_ptr<SortListData> > maData;
52
53public:
56
57 sal_uInt32 Count() const { return static_cast<sal_uInt32>(maData.size()); }
58
59 void Clear();
60 void Insert( std::unique_ptr<SortListData> pEntry, sal_Int32 nPos );
61 std::unique_ptr<SortListData> Remove( sal_Int32 nPos );
62 SortListData* GetData( sal_Int32 nPos );
63 void Move( sal_Int32 nOldPos, sal_Int32 nNewPos );
64
65 sal_Int32 operator [] ( sal_Int32 nPos ) const;
66};
67
68
70{
71 std::deque <css::ucb::ListAction > maData;
72
73public:
75
76 sal_uInt32 Count() const { return static_cast<sal_uInt32>(maData.size()); }
77
78 void AddEvent( sal_IntPtr nType, sal_Int32 nPos );
79 void Insert( const css::ucb::ListAction& rAction ) { maData.push_back( rAction ); }
80 void Clear();
81 css::ucb::ListAction& GetAction( sal_Int32 nIndex ) { return maData[ nIndex ]; }
82};
83
84
85inline constexpr OUStringLiteral RESULTSET_SERVICE_NAME = u"com.sun.star.ucb.SortedResultSet";
86
87
88class SortedResultSet: public cppu::WeakImplHelper <
89 css::lang::XServiceInfo,
90 css::lang::XComponent,
91 css::ucb::XContentAccess,
92 css::sdbc::XResultSet,
93 css::sdbc::XRow,
94 css::sdbc::XCloseable,
95 css::sdbc::XResultSetMetaDataSupplier,
96 css::beans::XPropertySet >
97{
101
102 css::uno::Reference < css::sdbc::XResultSet > mxOriginal;
103 css::uno::Reference < css::sdbc::XResultSet > mxOther;
104
107 std::mutex maMutex;
108 SortedEntryList maS2O; // maps the sorted entries to the original ones
109 std::deque<sal_IntPtr> m_O2S;
110 std::deque<SortListData*> m_ModList;
111 sal_Int32 mnLastSort; // index of the last sorted entry;
112 sal_Int32 mnCurEntry; // index of the current entry
113 sal_Int32 mnCount; // total count of the elements
115
116
117private:
120 sal_Int32 FindPos( SortListData const *pEntry, sal_IntPtr nStart, sal_IntPtr nEnd );
123 sal_Int32 Compare( SortListData const *pOne,
124 SortListData const *pTwo );
125 void BuildSortInfo( const css::uno::Reference< css::sdbc::XResultSet >& aResult,
126 const css::uno::Sequence < css::ucb::NumberedSortingInfo > &xSortInfo,
127 const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac );
130 static sal_Int32 CompareImpl( const css::uno::Reference < css::sdbc::XResultSet >& xResultOne,
131 const css::uno::Reference < css::sdbc::XResultSet >& xResultTwo,
132 sal_Int32 nIndexOne, sal_Int32 nIndexTwo,
133 SortInfo const * pSortInfo );
136 sal_Int32 CompareImpl( const css::uno::Reference < css::sdbc::XResultSet >& xResultOne,
137 const css::uno::Reference < css::sdbc::XResultSet >& xResultTwo,
138 sal_Int32 nIndexOne, sal_Int32 nIndexTwo );
139 void PropertyChanged( const css::beans::PropertyChangeEvent& rEvt );
140
141public:
142 SortedResultSet( css::uno::Reference< css::sdbc::XResultSet > const & aResult );
143 virtual ~SortedResultSet() override;
144
145 sal_Int32 GetCount() const { return mnCount; }
146
147 void CopyData( SortedResultSet* pSource );
148 void Initialize( const css::uno::Sequence < css::ucb::NumberedSortingInfo > &xSortInfo,
149 const css::uno::Reference< css::ucb::XAnyCompareFactory > &xCompFac );
150 void CheckProperties( sal_Int32 nOldCount, bool bWasFinal );
151
152 void InsertNew( sal_Int32 nPos, sal_Int32 nCount );
153 void SetChanged( sal_Int32 nPos, sal_Int32 nCount );
154 void Remove( sal_Int32 nPos, sal_Int32 nCount, EventList *pList );
155 void Move( sal_Int32 nPos, sal_Int32 nCount, sal_Int32 nOffset );
156
157 void ResortModified( EventList* pList );
158 void ResortNew( EventList* pList );
159
160 // XServiceInfo
161 virtual OUString SAL_CALL getImplementationName() override;
162 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
163 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
164
165 // XComponent
166 virtual void SAL_CALL
167 dispose() override;
168
169 virtual void SAL_CALL
170 addEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
171
172 virtual void SAL_CALL
173 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
174
175 // XContentAccess
176 virtual OUString SAL_CALL
178 virtual css::uno::Reference<
179 css::ucb::XContentIdentifier > SAL_CALL
180 queryContentIdentifier() override;
181 virtual css::uno::Reference<
182 css::ucb::XContent > SAL_CALL
183 queryContent() override;
184
185 // XResultSet
186 virtual sal_Bool SAL_CALL
187 next() override;
188 virtual sal_Bool SAL_CALL
189 isBeforeFirst() override;
190 virtual sal_Bool SAL_CALL
191 isAfterLast() override;
192 virtual sal_Bool SAL_CALL
193 isFirst() override;
194 virtual sal_Bool SAL_CALL
195 isLast() override;
196 virtual void SAL_CALL
197 beforeFirst() override;
198 virtual void SAL_CALL
199 afterLast() override;
200 virtual sal_Bool SAL_CALL
201 first() override;
202 virtual sal_Bool SAL_CALL
203 last() override;
204 virtual sal_Int32 SAL_CALL
205 getRow() override;
206 virtual sal_Bool SAL_CALL
207 absolute( sal_Int32 row ) override;
208 virtual sal_Bool SAL_CALL
209 relative( sal_Int32 rows ) override;
210 virtual sal_Bool SAL_CALL
211 previous() override;
212 virtual void SAL_CALL
213 refreshRow() override;
214 virtual sal_Bool SAL_CALL
215 rowUpdated() override;
216 virtual sal_Bool SAL_CALL
217 rowInserted() override;
218 virtual sal_Bool SAL_CALL
219 rowDeleted() override;
220 virtual css::uno::Reference<
221 css::uno::XInterface > SAL_CALL
222 getStatement() override;
223
224 // XRow
225 virtual sal_Bool SAL_CALL
226 wasNull() override;
227
228 virtual OUString SAL_CALL
229 getString( sal_Int32 columnIndex ) override;
230
231 virtual sal_Bool SAL_CALL
232 getBoolean( sal_Int32 columnIndex ) override;
233
234 virtual sal_Int8 SAL_CALL
235 getByte( sal_Int32 columnIndex ) override;
236
237 virtual sal_Int16 SAL_CALL
238 getShort( sal_Int32 columnIndex ) override;
239
240 virtual sal_Int32 SAL_CALL
241 getInt( sal_Int32 columnIndex ) override;
242
243 virtual sal_Int64 SAL_CALL
244 getLong( sal_Int32 columnIndex ) override;
245
246 virtual float SAL_CALL
247 getFloat( sal_Int32 columnIndex ) override;
248
249 virtual double SAL_CALL
250 getDouble( sal_Int32 columnIndex ) override;
251
252 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
253 getBytes( sal_Int32 columnIndex ) override;
254
255 virtual css::util::Date SAL_CALL
256 getDate( sal_Int32 columnIndex ) override;
257
258 virtual css::util::Time SAL_CALL
259 getTime( sal_Int32 columnIndex ) override;
260
261 virtual css::util::DateTime SAL_CALL
262 getTimestamp( sal_Int32 columnIndex ) override;
263
264 virtual css::uno::Reference<
265 css::io::XInputStream > SAL_CALL
266 getBinaryStream( sal_Int32 columnIndex ) override;
267
268 virtual css::uno::Reference<
269 css::io::XInputStream > SAL_CALL
270 getCharacterStream( sal_Int32 columnIndex ) override;
271
272 virtual css::uno::Any SAL_CALL
273 getObject( sal_Int32 columnIndex,
274 const css::uno::Reference<
275 css::container::XNameAccess >& typeMap ) override;
276 virtual css::uno::Reference<
277 css::sdbc::XRef > SAL_CALL
278 getRef( sal_Int32 columnIndex ) override;
279 virtual css::uno::Reference<
280 css::sdbc::XBlob > SAL_CALL
281 getBlob( sal_Int32 columnIndex ) override;
282 virtual css::uno::Reference<
283 css::sdbc::XClob > SAL_CALL
284 getClob( sal_Int32 columnIndex ) override;
285 virtual css::uno::Reference<
286 css::sdbc::XArray > SAL_CALL
287 getArray( sal_Int32 columnIndex ) override;
288
289 // XCloseable
290 virtual void SAL_CALL
291 close() override;
292
293 // XResultSetMetaDataSupplier
294 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL
295 getMetaData() override;
296
297
298 // XPropertySet
299 virtual css::uno::Reference<
300 css::beans::XPropertySetInfo > SAL_CALL
301 getPropertySetInfo() override;
302
303 virtual void SAL_CALL
304 setPropertyValue( const OUString& PropertyName,
305 const css::uno::Any& Value ) override;
306
307 virtual css::uno::Any SAL_CALL
308 getPropertyValue( const OUString& PropertyName ) override;
309
310 virtual void SAL_CALL
311 addPropertyChangeListener( const OUString& PropertyName,
312 const css::uno::Reference<
313 css::beans::XPropertyChangeListener >& Listener ) override;
314
315 virtual void SAL_CALL
316 removePropertyChangeListener( const OUString& PropertyName,
317 const css::uno::Reference<
318 css::beans::XPropertyChangeListener >& Listener ) override;
319
320 virtual void SAL_CALL
321 addVetoableChangeListener( const OUString& PropertyName,
322 const css::uno::Reference<
323 css::beans::XVetoableChangeListener >& Listener ) override;
324
325 virtual void SAL_CALL
326 removeVetoableChangeListener( const OUString& PropertyName,
327 const css::uno::Reference<
328 css::beans::XVetoableChangeListener >& aListener ) override;
329};
330
331/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::ucb::ListAction & GetAction(sal_Int32 nIndex)
Definition: sortresult.hxx:81
void AddEvent(sal_IntPtr nType, sal_Int32 nPos)
Definition: sortdynres.cxx:449
sal_uInt32 Count() const
Definition: sortresult.hxx:76
void Insert(const css::ucb::ListAction &rAction)
Definition: sortresult.hxx:79
void Clear()
Definition: sortdynres.cxx:444
std::deque< css::ucb::ListAction > maData
Definition: sortresult.hxx:71
std::unique_ptr< SortListData > Remove(sal_Int32 nPos)
std::deque< std::unique_ptr< SortListData > > maData
Definition: sortresult.hxx:51
sal_Int32 operator[](sal_Int32 nPos) const
SortListData * GetData(sal_Int32 nPos)
sal_uInt32 Count() const
Definition: sortresult.hxx:57
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:535
std::deque< SortListData * > m_ModList
maps the original Entries to the sorted ones
Definition: sortresult.hxx:110
virtual double SAL_CALL getDouble(sal_Int32 columnIndex) override
Definition: sortresult.cxx:606
virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob(sal_Int32 columnIndex) override
Definition: sortresult.cxx:680
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream(sal_Int32 columnIndex) override
Definition: sortresult.cxx:642
sal_Int32 mnCurEntry
Definition: sortresult.hxx:112
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:168
virtual sal_Int16 SAL_CALL getShort(sal_Int32 columnIndex) override
Definition: sortresult.cxx:579
virtual void SAL_CALL dispose() override
Definition: sortresult.cxx:138
void ResortNew(EventList *pList)
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &Listener) override
Definition: sortresult.cxx:177
virtual sal_Bool SAL_CALL next() override
Definition: sortresult.cxx:215
virtual void SAL_CALL refreshRow() override
Definition: sortresult.cxx:483
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent() override
Definition: sortresult.cxx:206
virtual sal_Bool SAL_CALL rowDeleted() override
Definition: sortresult.cxx:522
virtual sal_Int8 SAL_CALL getByte(sal_Int32 columnIndex) override
Definition: sortresult.cxx:572
virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData() override
Definition: sortresult.cxx:707
virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef(sal_Int32 columnIndex) override
Definition: sortresult.cxx:666
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:565
virtual OUString SAL_CALL getImplementationName() override
Definition: sortresult.cxx:120
virtual sal_Bool SAL_CALL rowInserted() override
Definition: sortresult.cxx:509
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:418
void ResortModified(EventList *pList)
sal_Int32 mnCount
Definition: sortresult.hxx:113
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:356
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL queryContentIdentifier() override
Definition: sortresult.cxx:198
void Move(sal_Int32 nPos, sal_Int32 nCount, sal_Int32 nOffset)
css::uno::Reference< css::sdbc::XResultSet > mxOther
Definition: sortresult.hxx:103
virtual void SAL_CALL removePropertyChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &Listener) override
Definition: sortresult.cxx:790
virtual ~SortedResultSet() override
Definition: sortresult.cxx:96
virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob(sal_Int32 columnIndex) override
Definition: sortresult.cxx:673
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: sortresult.cxx:810
std::mutex maMutex
Definition: sortresult.hxx:107
virtual OUString SAL_CALL queryContentIdentifierString() override
Definition: sortresult.cxx:190
virtual sal_Bool SAL_CALL last() override
Definition: sortresult.cxx:307
virtual sal_Int32 SAL_CALL getInt(sal_Int32 columnIndex) override
Definition: sortresult.cxx:586
sal_Int32 Compare(SortListData const *pOne, SortListData const *pTwo)
virtual css::util::Date SAL_CALL getDate(sal_Int32 columnIndex) override
Definition: sortresult.cxx:620
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:592
virtual sal_Int32 SAL_CALL getRow() override
Definition: sortresult.cxx:325
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: sortresult.cxx:125
sal_Int32 mnLastSort
keeps track of modified entries
Definition: sortresult.hxx:111
virtual sal_Bool SAL_CALL first() override
Definition: sortresult.cxx:289
comphelper::OMultiTypeInterfaceContainerHelperVar4< OUString, css::beans::XPropertyChangeListener > maPropChangeListeners
Definition: sortresult.hxx:99
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream(sal_Int32 columnIndex) override
Definition: sortresult.cxx:650
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:627
virtual void SAL_CALL close() override
Definition: sortresult.cxx:697
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: sortresult.cxx:742
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:85
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes(sal_Int32 columnIndex) override
Definition: sortresult.cxx:613
sal_Int32 GetCount() const
Definition: sortresult.hxx:145
virtual sal_Bool SAL_CALL previous() override
moves the cursor to the previous row in the result set.
Definition: sortresult.cxx:462
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:246
css::uno::Reference< css::sdbc::XResultSet > mxOriginal
Definition: sortresult.hxx:102
comphelper::OMultiTypeInterfaceContainerHelperVar4< OUString, css::beans::XVetoableChangeListener > maVetoChangeListeners
Definition: sortresult.hxx:100
comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > maDisposeEventListeners
Definition: sortresult.hxx:98
rtl::Reference< SRSPropertySetInfo > mpPropSetInfo
Definition: sortresult.hxx:105
void CheckProperties(sal_Int32 nOldCount, bool bWasFinal)
virtual sal_Bool SAL_CALL rowUpdated() override
Definition: sortresult.cxx:496
virtual void SAL_CALL afterLast() override
Definition: sortresult.cxx:281
virtual sal_Bool SAL_CALL wasNull() override
Definition: sortresult.cxx:551
virtual void SAL_CALL addPropertyChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &Listener) override
Definition: sortresult.cxx:780
virtual void SAL_CALL beforeFirst() override
Definition: sortresult.cxx:273
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: sortresult.cxx:718
virtual void SAL_CALL setPropertyValue(const OUString &PropertyName, const css::uno::Any &Value) override
Definition: sortresult.cxx:731
virtual sal_Bool SAL_CALL isBeforeFirst() override
Definition: sortresult.cxx:237
std::deque< sal_IntPtr > m_O2S
Definition: sortresult.hxx:109
virtual css::uno::Any SAL_CALL getObject(sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess > &typeMap) override
Definition: sortresult.cxx:657
virtual OUString SAL_CALL getString(sal_Int32 columnIndex) override
Definition: sortresult.cxx:558
SortInfo * mpSortInfo
Definition: sortresult.hxx:106
void InsertNew(sal_Int32 nPos, sal_Int32 nCount)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: sortresult.cxx:130
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &Listener) override
Definition: sortresult.cxx:800
SortedEntryList maS2O
Definition: sortresult.hxx:108
virtual sal_Bool SAL_CALL isFirst() override
Definition: sortresult.cxx:255
virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray(sal_Int32 columnIndex) override
Definition: sortresult.cxx:687
virtual sal_Bool SAL_CALL isLast() override
Definition: sortresult.cxx:264
virtual float SAL_CALL getFloat(sal_Int32 columnIndex) override
Definition: sortresult.cxx:599
virtual css::util::DateTime SAL_CALL getTimestamp(sal_Int32 columnIndex) override
Definition: sortresult.cxx:634
float u
sal_Int32 nIndex
constexpr OUStringLiteral RESULTSET_SERVICE_NAME
Definition: sortresult.hxx:85
unsigned char sal_Bool
signed char sal_Int8