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 .
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>
39 namespace comphelper
{
40 class OInterfaceContainerHelper2
;
46 class SRSPropertySetInfo
;
47 class PropertyChangeListeners_Impl
;
52 std::deque
< std::unique_ptr
<SortListData
> > maData
;
58 sal_uInt32
Count() const { return static_cast<sal_uInt32
>(maData
.size()); }
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
);
66 sal_Int32
operator [] ( sal_Int32 nPos
) const;
72 std::deque
<css::ucb::ListAction
> maData
;
77 sal_uInt32
Count() { return static_cast<sal_uInt32
>(maData
.size()); }
79 void AddEvent( sal_IntPtr nType
, sal_Int32 nPos
);
80 void Insert( const css::ucb::ListAction
& rAction
) { maData
.push_back( rAction
); }
82 css::ucb::ListAction
& GetAction( sal_Int32 nIndex
) { return maData
[ nIndex
]; }
86 #define RESULTSET_SERVICE_NAME "com.sun.star.ucb.SortedResultSet"
89 class SortedResultSet
: public cppu::WeakImplHelper
<
90 css::lang::XServiceInfo
,
91 css::lang::XComponent
,
92 css::ucb::XContentAccess
,
93 css::sdbc::XResultSet
,
95 css::sdbc::XCloseable
,
96 css::sdbc::XResultSetMetaDataSupplier
,
97 css::beans::XPropertySet
>
99 comphelper::OInterfaceContainerHelper2
*mpDisposeEventListeners
;
100 std::unique_ptr
<PropertyChangeListeners_Impl
> mpPropChangeListeners
;
101 std::unique_ptr
<PropertyChangeListeners_Impl
> mpVetoChangeListeners
;
103 css::uno::Reference
< css::sdbc::XResultSet
> mxOriginal
;
104 css::uno::Reference
< css::sdbc::XResultSet
> mxOther
;
106 rtl::Reference
<SRSPropertySetInfo
> mpPropSetInfo
;
107 SortInfo
* mpSortInfo
;
109 SortedEntryList maS2O
; // maps the sorted entries to the original ones
110 std::deque
<sal_IntPtr
> m_O2S
; /// maps the original Entries to the sorted ones
111 std::deque
<SortListData
*> m_ModList
; /// keeps track of modified entries
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
119 /// @throws css::sdbc::SQLException
120 /// @throws css::uno::RuntimeException
121 sal_Int32
FindPos( SortListData
const *pEntry
, sal_IntPtr nStart
, sal_IntPtr nEnd
);
122 /// @throws css::sdbc::SQLException
123 /// @throws css::uno::RuntimeException
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
);
129 /// @throws css::sdbc::SQLException
130 /// @throws css::uno::RuntimeException
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
);
135 /// @throws css::sdbc::SQLException
136 /// @throws css::uno::RuntimeException
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
);
143 SortedResultSet( css::uno::Reference
< css::sdbc::XResultSet
> const & aResult
);
144 virtual ~SortedResultSet() override
;
146 sal_Int32
GetCount() const { return mnCount
; }
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
);
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
);
158 void ResortModified( EventList
* pList
);
159 void ResortNew( EventList
* pList
);
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
;
167 virtual void SAL_CALL
170 virtual void SAL_CALL
171 addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
) override
;
173 virtual void SAL_CALL
174 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
) override
;
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
;
187 virtual sal_Bool SAL_CALL
189 virtual sal_Bool SAL_CALL
190 isBeforeFirst() override
;
191 virtual sal_Bool SAL_CALL
192 isAfterLast() override
;
193 virtual sal_Bool SAL_CALL
195 virtual sal_Bool SAL_CALL
197 virtual void SAL_CALL
198 beforeFirst() override
;
199 virtual void SAL_CALL
200 afterLast() override
;
201 virtual sal_Bool SAL_CALL
203 virtual sal_Bool SAL_CALL
205 virtual sal_Int32 SAL_CALL
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
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
;
226 virtual sal_Bool SAL_CALL
229 virtual OUString SAL_CALL
230 getString( sal_Int32 columnIndex
) override
;
232 virtual sal_Bool SAL_CALL
233 getBoolean( sal_Int32 columnIndex
) override
;
235 virtual sal_Int8 SAL_CALL
236 getByte( sal_Int32 columnIndex
) override
;
238 virtual sal_Int16 SAL_CALL
239 getShort( sal_Int32 columnIndex
) override
;
241 virtual sal_Int32 SAL_CALL
242 getInt( sal_Int32 columnIndex
) override
;
244 virtual sal_Int64 SAL_CALL
245 getLong( sal_Int32 columnIndex
) override
;
247 virtual float SAL_CALL
248 getFloat( sal_Int32 columnIndex
) override
;
250 virtual double SAL_CALL
251 getDouble( sal_Int32 columnIndex
) override
;
253 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
254 getBytes( sal_Int32 columnIndex
) override
;
256 virtual css::util::Date SAL_CALL
257 getDate( sal_Int32 columnIndex
) override
;
259 virtual css::util::Time SAL_CALL
260 getTime( sal_Int32 columnIndex
) override
;
262 virtual css::util::DateTime SAL_CALL
263 getTimestamp( sal_Int32 columnIndex
) override
;
265 virtual css::uno::Reference
<
266 css::io::XInputStream
> SAL_CALL
267 getBinaryStream( sal_Int32 columnIndex
) override
;
269 virtual css::uno::Reference
<
270 css::io::XInputStream
> SAL_CALL
271 getCharacterStream( sal_Int32 columnIndex
) override
;
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
;
291 virtual void SAL_CALL
294 // XResultSetMetaDataSupplier
295 virtual css::uno::Reference
< css::sdbc::XResultSetMetaData
> SAL_CALL
296 getMetaData() override
;
300 virtual css::uno::Reference
<
301 css::beans::XPropertySetInfo
> SAL_CALL
302 getPropertySetInfo() override
;
304 virtual void SAL_CALL
305 setPropertyValue( const OUString
& PropertyName
,
306 const css::uno::Any
& Value
) override
;
308 virtual css::uno::Any SAL_CALL
309 getPropertyValue( const OUString
& PropertyName
) override
;
311 virtual void SAL_CALL
312 addPropertyChangeListener( const OUString
& PropertyName
,
313 const css::uno::Reference
<
314 css::beans::XPropertyChangeListener
>& Listener
) override
;
316 virtual void SAL_CALL
317 removePropertyChangeListener( const OUString
& PropertyName
,
318 const css::uno::Reference
<
319 css::beans::XPropertyChangeListener
>& Listener
) override
;
321 virtual void SAL_CALL
322 addVetoableChangeListener( const OUString
& PropertyName
,
323 const css::uno::Reference
<
324 css::beans::XVetoableChangeListener
>& Listener
) override
;
326 virtual void SAL_CALL
327 removeVetoableChangeListener( const OUString
& PropertyName
,
328 const css::uno::Reference
<
329 css::beans::XVetoableChangeListener
>& aListener
) override
;
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */