1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #ifndef INCLUDED_UCB_SOURCE_SORTER_SORTRESULT_HXX
21 #define INCLUDED_UCB_SOURCE_SORTER_SORTRESULT_HXX
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/lang/XComponent.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/sdbc/XCloseable.hpp>
27 #include <com/sun/star/sdbc/XResultSet.hpp>
28 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
29 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
30 #include <com/sun/star/sdbc/XRow.hpp>
31 #include <com/sun/star/ucb/XContentAccess.hpp>
32 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
33 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
34 #include <com/sun/star/ucb/ListAction.hpp>
35 #include <cppuhelper/implbase.hxx>
36 #include <rtl/ref.hxx>
40 namespace comphelper
{
41 class OInterfaceContainerHelper2
;
47 class SRSPropertySetInfo
;
48 class PropertyChangeListeners_Impl
;
53 std::deque
< std::unique_ptr
<SortListData
> > maData
;
59 sal_uInt32
Count() const { return static_cast<sal_uInt32
>(maData
.size()); }
62 void Insert( std::unique_ptr
<SortListData
> pEntry
, sal_IntPtr nPos
);
63 std::unique_ptr
<SortListData
> Remove( sal_IntPtr nPos
);
64 SortListData
* GetData( sal_IntPtr nPos
);
65 void Move( sal_IntPtr nOldPos
, sal_IntPtr nNewPos
);
67 sal_IntPtr
operator [] ( sal_IntPtr nPos
) const;
73 std::deque
< std::unique_ptr
<css::ucb::ListAction
> > maData
;
78 sal_uInt32
Count() { return static_cast<sal_uInt32
>(maData
.size()); }
80 void AddEvent( sal_IntPtr nType
, sal_IntPtr nPos
);
81 void Insert( std::unique_ptr
<css::ucb::ListAction
> pAction
) { maData
.push_back( std::move(pAction
) ); }
83 css::ucb::ListAction
* GetAction( sal_IntPtr nIndex
) { return maData
[ nIndex
].get(); }
87 #define RESULTSET_SERVICE_NAME "com.sun.star.ucb.SortedResultSet"
90 class SortedResultSet
: public cppu::WeakImplHelper
<
91 css::lang::XServiceInfo
,
92 css::lang::XComponent
,
93 css::ucb::XContentAccess
,
94 css::sdbc::XResultSet
,
96 css::sdbc::XCloseable
,
97 css::sdbc::XResultSetMetaDataSupplier
,
98 css::beans::XPropertySet
>
100 comphelper::OInterfaceContainerHelper2
*mpDisposeEventListeners
;
101 std::unique_ptr
<PropertyChangeListeners_Impl
> mpPropChangeListeners
;
102 std::unique_ptr
<PropertyChangeListeners_Impl
> mpVetoChangeListeners
;
104 css::uno::Reference
< css::sdbc::XResultSet
> mxOriginal
;
105 css::uno::Reference
< css::sdbc::XResultSet
> mxOther
;
107 rtl::Reference
<SRSPropertySetInfo
> mpPropSetInfo
;
108 SortInfo
* mpSortInfo
;
110 SortedEntryList maS2O
; // maps the sorted entries to the original ones
111 std::deque
<sal_IntPtr
> m_O2S
; /// maps the original Entries to the sorted ones
112 std::deque
<SortListData
*> m_ModList
; /// keeps track of modified entries
113 sal_IntPtr mnLastSort
; // index of the last sorted entry;
114 sal_IntPtr mnCurEntry
; // index of the current entry
115 sal_IntPtr mnCount
; // total count of the elements
120 /// @throws css::sdbc::SQLException
121 /// @throws css::uno::RuntimeException
122 sal_IntPtr
FindPos( SortListData
const *pEntry
, sal_IntPtr nStart
, sal_IntPtr nEnd
);
123 /// @throws css::sdbc::SQLException
124 /// @throws css::uno::RuntimeException
125 sal_IntPtr
Compare( SortListData
const *pOne
,
126 SortListData
const *pTwo
);
127 void BuildSortInfo( const css::uno::Reference
< css::sdbc::XResultSet
>& aResult
,
128 const css::uno::Sequence
< css::ucb::NumberedSortingInfo
> &xSortInfo
,
129 const css::uno::Reference
< css::ucb::XAnyCompareFactory
> &xCompFac
);
130 /// @throws css::sdbc::SQLException
131 /// @throws css::uno::RuntimeException
132 static sal_IntPtr
CompareImpl( const css::uno::Reference
< css::sdbc::XResultSet
>& xResultOne
,
133 const css::uno::Reference
< css::sdbc::XResultSet
>& xResultTwo
,
134 sal_IntPtr nIndexOne
, sal_IntPtr nIndexTwo
,
135 SortInfo
const * pSortInfo
);
136 /// @throws css::sdbc::SQLException
137 /// @throws css::uno::RuntimeException
138 sal_IntPtr
CompareImpl( const css::uno::Reference
< css::sdbc::XResultSet
>& xResultOne
,
139 const css::uno::Reference
< css::sdbc::XResultSet
>& xResultTwo
,
140 sal_IntPtr nIndexOne
, sal_IntPtr nIndexTwo
);
141 void PropertyChanged( const css::beans::PropertyChangeEvent
& rEvt
);
144 SortedResultSet( css::uno::Reference
< css::sdbc::XResultSet
> const & aResult
);
145 virtual ~SortedResultSet() override
;
147 sal_IntPtr
GetCount() const { return mnCount
; }
149 void CopyData( SortedResultSet
* pSource
);
150 void Initialize( const css::uno::Sequence
< css::ucb::NumberedSortingInfo
> &xSortInfo
,
151 const css::uno::Reference
< css::ucb::XAnyCompareFactory
> &xCompFac
);
152 void CheckProperties( sal_IntPtr nOldCount
, bool bWasFinal
);
154 void InsertNew( sal_IntPtr nPos
, sal_IntPtr nCount
);
155 void SetChanged( sal_IntPtr nPos
, sal_IntPtr nCount
);
156 void Remove( sal_IntPtr nPos
, sal_IntPtr nCount
, EventList
*pList
);
157 void Move( sal_IntPtr nPos
, sal_IntPtr nCount
, sal_IntPtr nOffset
);
159 void ResortModified( EventList
* pList
);
160 void ResortNew( EventList
* pList
);
163 virtual OUString SAL_CALL
getImplementationName() override
;
164 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
165 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
168 virtual void SAL_CALL
171 virtual void SAL_CALL
172 addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
) override
;
174 virtual void SAL_CALL
175 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
) override
;
178 virtual OUString SAL_CALL
179 queryContentIdentifierString() override
;
180 virtual css::uno::Reference
<
181 css::ucb::XContentIdentifier
> SAL_CALL
182 queryContentIdentifier() override
;
183 virtual css::uno::Reference
<
184 css::ucb::XContent
> SAL_CALL
185 queryContent() override
;
188 virtual sal_Bool SAL_CALL
190 virtual sal_Bool SAL_CALL
191 isBeforeFirst() override
;
192 virtual sal_Bool SAL_CALL
193 isAfterLast() override
;
194 virtual sal_Bool SAL_CALL
196 virtual sal_Bool SAL_CALL
198 virtual void SAL_CALL
199 beforeFirst() override
;
200 virtual void SAL_CALL
201 afterLast() override
;
202 virtual sal_Bool SAL_CALL
204 virtual sal_Bool SAL_CALL
206 virtual sal_Int32 SAL_CALL
208 virtual sal_Bool SAL_CALL
209 absolute( sal_Int32 row
) override
;
210 virtual sal_Bool SAL_CALL
211 relative( sal_Int32 rows
) override
;
212 virtual sal_Bool SAL_CALL
214 virtual void SAL_CALL
215 refreshRow() override
;
216 virtual sal_Bool SAL_CALL
217 rowUpdated() override
;
218 virtual sal_Bool SAL_CALL
219 rowInserted() override
;
220 virtual sal_Bool SAL_CALL
221 rowDeleted() override
;
222 virtual css::uno::Reference
<
223 css::uno::XInterface
> SAL_CALL
224 getStatement() override
;
227 virtual sal_Bool SAL_CALL
230 virtual OUString SAL_CALL
231 getString( sal_Int32 columnIndex
) override
;
233 virtual sal_Bool SAL_CALL
234 getBoolean( sal_Int32 columnIndex
) override
;
236 virtual sal_Int8 SAL_CALL
237 getByte( sal_Int32 columnIndex
) override
;
239 virtual sal_Int16 SAL_CALL
240 getShort( sal_Int32 columnIndex
) override
;
242 virtual sal_Int32 SAL_CALL
243 getInt( sal_Int32 columnIndex
) override
;
245 virtual sal_Int64 SAL_CALL
246 getLong( sal_Int32 columnIndex
) override
;
248 virtual float SAL_CALL
249 getFloat( sal_Int32 columnIndex
) override
;
251 virtual double SAL_CALL
252 getDouble( sal_Int32 columnIndex
) override
;
254 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
255 getBytes( sal_Int32 columnIndex
) override
;
257 virtual css::util::Date SAL_CALL
258 getDate( sal_Int32 columnIndex
) override
;
260 virtual css::util::Time SAL_CALL
261 getTime( sal_Int32 columnIndex
) override
;
263 virtual css::util::DateTime SAL_CALL
264 getTimestamp( sal_Int32 columnIndex
) override
;
266 virtual css::uno::Reference
<
267 css::io::XInputStream
> SAL_CALL
268 getBinaryStream( sal_Int32 columnIndex
) override
;
270 virtual css::uno::Reference
<
271 css::io::XInputStream
> SAL_CALL
272 getCharacterStream( sal_Int32 columnIndex
) override
;
274 virtual css::uno::Any SAL_CALL
275 getObject( sal_Int32 columnIndex
,
276 const css::uno::Reference
<
277 css::container::XNameAccess
>& typeMap
) override
;
278 virtual css::uno::Reference
<
279 css::sdbc::XRef
> SAL_CALL
280 getRef( sal_Int32 columnIndex
) override
;
281 virtual css::uno::Reference
<
282 css::sdbc::XBlob
> SAL_CALL
283 getBlob( sal_Int32 columnIndex
) override
;
284 virtual css::uno::Reference
<
285 css::sdbc::XClob
> SAL_CALL
286 getClob( sal_Int32 columnIndex
) override
;
287 virtual css::uno::Reference
<
288 css::sdbc::XArray
> SAL_CALL
289 getArray( sal_Int32 columnIndex
) override
;
292 virtual void SAL_CALL
295 // XResultSetMetaDataSupplier
296 virtual css::uno::Reference
< css::sdbc::XResultSetMetaData
> SAL_CALL
297 getMetaData() override
;
301 virtual css::uno::Reference
<
302 css::beans::XPropertySetInfo
> SAL_CALL
303 getPropertySetInfo() override
;
305 virtual void SAL_CALL
306 setPropertyValue( const OUString
& PropertyName
,
307 const css::uno::Any
& Value
) override
;
309 virtual css::uno::Any SAL_CALL
310 getPropertyValue( const OUString
& PropertyName
) override
;
312 virtual void SAL_CALL
313 addPropertyChangeListener( const OUString
& PropertyName
,
314 const css::uno::Reference
<
315 css::beans::XPropertyChangeListener
>& Listener
) override
;
317 virtual void SAL_CALL
318 removePropertyChangeListener( const OUString
& PropertyName
,
319 const css::uno::Reference
<
320 css::beans::XPropertyChangeListener
>& Listener
) override
;
322 virtual void SAL_CALL
323 addVetoableChangeListener( const OUString
& PropertyName
,
324 const css::uno::Reference
<
325 css::beans::XVetoableChangeListener
>& Listener
) override
;
327 virtual void SAL_CALL
328 removeVetoableChangeListener( const OUString
& PropertyName
,
329 const css::uno::Reference
<
330 css::beans::XVetoableChangeListener
>& aListener
) override
;
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */