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