Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <vector>
31 : : #include <sortresult.hxx>
32 : : #include <cppuhelper/interfacecontainer.hxx>
33 : : #include <com/sun/star/sdbc/DataType.hpp>
34 : : #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
35 : : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
36 : : #include <com/sun/star/ucb/ListActionType.hpp>
37 : : #include <com/sun/star/ucb/XAnyCompare.hpp>
38 : : #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
39 : : #include <osl/diagnose.h>
40 : :
41 : : //-----------------------------------------------------------------------------
42 : : using namespace com::sun::star::beans;
43 : : using namespace com::sun::star::container;
44 : : using namespace com::sun::star::io;
45 : : using namespace com::sun::star::lang;
46 : : using namespace com::sun::star::sdbc;
47 : : using namespace com::sun::star::ucb;
48 : : using namespace com::sun::star::uno;
49 : : using namespace com::sun::star::util;
50 : : using namespace cppu;
51 : :
52 : : using ::rtl::OUString;
53 : :
54 : : //=========================================================================
55 : :
56 : : // The mutex to synchronize access to containers.
57 : 0 : static osl::Mutex& getContainerMutex()
58 : : {
59 : : static osl::Mutex* pMutex = NULL;
60 [ # # ]: 0 : if( !pMutex )
61 : : {
62 [ # # ][ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
63 [ # # ]: 0 : if( !pMutex )
64 : : {
65 [ # # ][ # # ]: 0 : static osl::Mutex aMutex;
[ # # ][ # # ]
66 : 0 : pMutex = &aMutex;
67 [ # # ]: 0 : }
68 : : }
69 : :
70 : 0 : return *pMutex;
71 : : }
72 : :
73 : : //==========================================================================
74 : :
75 : 292 : struct SortInfo
76 : : {
77 : : sal_Bool mbUseOwnCompare;
78 : : sal_Bool mbAscending;
79 : : sal_Bool mbCaseSensitive;
80 : : sal_Int32 mnColumn;
81 : : sal_Int32 mnType;
82 : : SortInfo* mpNext;
83 : : Reference < XAnyCompare > mxCompareFunction;
84 : : };
85 : :
86 : : //-----------------------------------------------------------------------------
87 : :
88 : : struct SortListData
89 : : {
90 : : sal_Bool mbModified;
91 : : long mnCurPos;
92 : : long mnOldPos;
93 : :
94 : : SortListData( long nPos, sal_Bool bModified = sal_False );
95 : : };
96 : :
97 : : //============================================================================
98 : : //
99 : : // class SRSPropertySetInfo.
100 : : //
101 : : //============================================================================
102 : :
103 : : class SRSPropertySetInfo :
104 : : public OWeakObject,
105 : : public XTypeProvider,
106 : : public XPropertySetInfo
107 : : {
108 : : Property maProps[2];
109 : :
110 : : private:
111 : :
112 : : public:
113 : : SRSPropertySetInfo();
114 : : virtual ~SRSPropertySetInfo();
115 : :
116 : : // XInterface
117 : : XINTERFACE_DECL()
118 : :
119 : : // XTypeProvider
120 : : XTYPEPROVIDER_DECL()
121 : :
122 : : // XPropertySetInfo
123 : : virtual Sequence< Property > SAL_CALL getProperties()
124 : : throw( RuntimeException );
125 : : virtual Property SAL_CALL getPropertyByName( const OUString& aName )
126 : : throw( UnknownPropertyException, RuntimeException );
127 : : virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name )
128 : : throw( RuntimeException );
129 : : };
130 : :
131 : : //=========================================================================
132 : : //
133 : : // PropertyChangeListenerContainer_Impl.
134 : : //
135 : : //=========================================================================
136 : :
137 : : struct equalStr_Impl
138 : : {
139 : 0 : bool operator()( const OUString& s1, const OUString& s2 ) const
140 : : {
141 : 0 : return !!( s1 == s2 );
142 : : }
143 : : };
144 : :
145 : : struct hashStr_Impl
146 : : {
147 : : size_t operator()( const OUString& rName ) const
148 : : {
149 : : return rName.hashCode();
150 : : }
151 : : };
152 : :
153 : : typedef OMultiTypeInterfaceContainerHelperVar
154 : : <
155 : : OUString,
156 : : hashStr_Impl,
157 : : equalStr_Impl
158 : : > PropertyChangeListenerContainer_Impl;
159 : :
160 : : //=========================================================================
161 : : //
162 : : // class PropertyChangeListeners_Impl
163 : : //
164 : : //=========================================================================
165 : :
166 : 0 : class PropertyChangeListeners_Impl : public PropertyChangeListenerContainer_Impl
167 : : {
168 : : public:
169 : 0 : PropertyChangeListeners_Impl()
170 : 0 : : PropertyChangeListenerContainer_Impl( getContainerMutex() ) {}
171 : : };
172 : :
173 : : //==========================================================================
174 [ + - ][ + - ]: 146 : SortedResultSet::SortedResultSet( Reference< XResultSet > aResult )
[ + - ][ + - ]
175 : : {
176 : 146 : mpDisposeEventListeners = NULL;
177 : 146 : mpPropChangeListeners = NULL;
178 : 146 : mpVetoChangeListeners = NULL;
179 : 146 : mpPropSetInfo = NULL;
180 : :
181 [ + - ]: 146 : mxOriginal = aResult;
182 : 146 : mpSortInfo = NULL;
183 : 146 : mnLastSort = 0;
184 : 146 : mnCurEntry = 0;
185 : 146 : mnCount = 0;
186 : 146 : mbIsCopy = sal_False;
187 : 146 : }
188 : :
189 : : //--------------------------------------------------------------------------
190 [ + - ][ + - ]: 146 : SortedResultSet::~SortedResultSet()
[ + - ][ + - ]
191 : : {
192 : 146 : mxOriginal.clear();
193 : 146 : mxOther.clear();
194 : :
195 [ + - ]: 146 : if ( !mbIsCopy )
196 : : {
197 : 146 : SortInfo *pInfo = mpSortInfo;
198 [ + + ]: 292 : while ( pInfo )
199 : : {
200 : 146 : mpSortInfo = pInfo->mpNext;
201 [ + - ][ + - ]: 146 : delete pInfo;
202 : 146 : pInfo = mpSortInfo;
203 : : }
204 : : }
205 : :
206 : 146 : mpSortInfo = NULL;
207 : :
208 [ - + ]: 146 : if ( mpPropSetInfo )
209 : 0 : mpPropSetInfo->release();
210 : :
211 [ - + ][ # # ]: 146 : delete mpPropChangeListeners;
212 [ - + ][ # # ]: 146 : delete mpVetoChangeListeners;
213 [ - + ]: 292 : }
214 : :
215 : : //--------------------------------------------------------------------------
216 : : // XInterface methods.
217 : : //--------------------------------------------------------------------------
218 : :
219 [ + - ][ + - ]: 1386 : XINTERFACE_IMPL_9( SortedResultSet,
[ # # ]
220 : : XTypeProvider,
221 : : XServiceInfo,
222 : : XComponent,
223 : : XContentAccess,
224 : : XResultSet,
225 : : XRow,
226 : : XCloseable,
227 : : XResultSetMetaDataSupplier,
228 : : XPropertySet );
229 : :
230 : : //--------------------------------------------------------------------------
231 : : // XTypeProvider methods.
232 : : //--------------------------------------------------------------------------
233 : :
234 [ # # ][ # # ]: 0 : XTYPEPROVIDER_IMPL_9( SortedResultSet,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
235 : : XTypeProvider,
236 : : XServiceInfo,
237 : : XComponent,
238 : : XContentAccess,
239 : : XResultSet,
240 : : XRow,
241 : : XCloseable,
242 : : XResultSetMetaDataSupplier,
243 : : XPropertySet );
244 : :
245 : : //--------------------------------------------------------------------------
246 : : // XServiceInfo methods.
247 : : //--------------------------------------------------------------------------
248 : :
249 [ # # ][ # # ]: 0 : XSERVICEINFO_NOFACTORY_IMPL_1( SortedResultSet,
[ # # ][ # # ]
[ # # ][ # # ]
250 : : OUString( "com.sun.star.comp.ucb.SortedResultSet" ),
251 : : OUString( RESULTSET_SERVICE_NAME ) );
252 : :
253 : : //--------------------------------------------------------------------------
254 : : // XComponent methods.
255 : : //--------------------------------------------------------------------------
256 : 0 : void SAL_CALL SortedResultSet::dispose()
257 : : throw( RuntimeException )
258 : : {
259 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
260 : :
261 [ # # ][ # # ]: 0 : if ( mpDisposeEventListeners && mpDisposeEventListeners->getLength() )
[ # # ][ # # ]
262 : : {
263 [ # # ]: 0 : EventObject aEvt;
264 [ # # ]: 0 : aEvt.Source = static_cast< XComponent * >( this );
265 [ # # ][ # # ]: 0 : mpDisposeEventListeners->disposeAndClear( aEvt );
266 : : }
267 : :
268 [ # # ]: 0 : if ( mpPropChangeListeners )
269 : : {
270 [ # # ]: 0 : EventObject aEvt;
271 [ # # ]: 0 : aEvt.Source = static_cast< XPropertySet * >( this );
272 [ # # ][ # # ]: 0 : mpPropChangeListeners->disposeAndClear( aEvt );
273 : : }
274 : :
275 [ # # ]: 0 : if ( mpVetoChangeListeners )
276 : : {
277 [ # # ]: 0 : EventObject aEvt;
278 [ # # ]: 0 : aEvt.Source = static_cast< XPropertySet * >( this );
279 [ # # ][ # # ]: 0 : mpVetoChangeListeners->disposeAndClear( aEvt );
280 : : }
281 : :
282 : 0 : mxOriginal.clear();
283 [ # # ]: 0 : mxOther.clear();
284 : 0 : }
285 : :
286 : : //--------------------------------------------------------------------------
287 : 0 : void SAL_CALL SortedResultSet::addEventListener(
288 : : const Reference< XEventListener >& Listener )
289 : : throw( RuntimeException )
290 : : {
291 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
292 : :
293 [ # # ]: 0 : if ( !mpDisposeEventListeners )
294 : : mpDisposeEventListeners =
295 [ # # ][ # # ]: 0 : new OInterfaceContainerHelper( getContainerMutex() );
296 : :
297 [ # # ][ # # ]: 0 : mpDisposeEventListeners->addInterface( Listener );
298 : 0 : }
299 : :
300 : : //--------------------------------------------------------------------------
301 : 0 : void SAL_CALL SortedResultSet::removeEventListener(
302 : : const Reference< XEventListener >& Listener )
303 : : throw( RuntimeException )
304 : : {
305 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
306 : :
307 [ # # ]: 0 : if ( mpDisposeEventListeners )
308 [ # # ][ # # ]: 0 : mpDisposeEventListeners->removeInterface( Listener );
309 : 0 : }
310 : :
311 : : //--------------------------------------------------------------------------
312 : : // XContentAccess methods.
313 : : //--------------------------------------------------------------------------
314 : :
315 : : OUString SAL_CALL
316 : 6 : SortedResultSet::queryContentIdentifierString()
317 : : throw( RuntimeException )
318 : : {
319 [ + - ]: 6 : osl::Guard< osl::Mutex > aGuard( maMutex );
320 [ + - ][ + - ]: 6 : return Reference< XContentAccess >::query(mxOriginal)->queryContentIdentifierString();
[ + - ][ + - ]
321 : : }
322 : :
323 : : //--------------------------------------------------------------------------
324 : : Reference< XContentIdentifier > SAL_CALL
325 : 0 : SortedResultSet::queryContentIdentifier()
326 : : throw( RuntimeException )
327 : : {
328 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
329 [ # # ][ # # ]: 0 : return Reference< XContentAccess >::query(mxOriginal)->queryContentIdentifier();
[ # # ][ # # ]
330 : : }
331 : :
332 : : //--------------------------------------------------------------------------
333 : : Reference< XContent > SAL_CALL
334 : 0 : SortedResultSet::queryContent()
335 : : throw( RuntimeException )
336 : : {
337 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
338 [ # # ][ # # ]: 0 : return Reference< XContentAccess >::query(mxOriginal)->queryContent();
[ # # ][ # # ]
339 : : }
340 : :
341 : :
342 : : //--------------------------------------------------------------------------
343 : : // XResultSet methods.
344 : : //--------------------------------------------------------------------------
345 : 592 : sal_Bool SAL_CALL SortedResultSet::next()
346 : : throw ( SQLException, RuntimeException )
347 : : {
348 [ + - ]: 592 : osl::Guard< osl::Mutex > aGuard( maMutex );
349 : :
350 : 592 : mnCurEntry++;
351 : :
352 [ + - ]: 592 : if ( mnCurEntry > 0 )
353 : : {
354 [ + + ]: 592 : if ( mnCurEntry <= mnCount )
355 : : {
356 [ + - ]: 446 : sal_Int32 nIndex = maS2O[ mnCurEntry ];
357 [ + - ][ + - ]: 446 : return mxOriginal->absolute( nIndex );
358 : : }
359 : : else
360 : : {
361 : 146 : mnCurEntry = mnCount + 1;
362 : : }
363 : : }
364 [ + - ]: 592 : return sal_False;
365 : : }
366 : :
367 : : //-------------------------------------------------------------------------
368 : 0 : sal_Bool SAL_CALL SortedResultSet::isBeforeFirst()
369 : : throw ( SQLException, RuntimeException )
370 : : {
371 [ # # ]: 0 : if ( mnCurEntry )
372 : 0 : return sal_False;
373 : : else
374 : 0 : return sal_True;
375 : : }
376 : :
377 : : //-------------------------------------------------------------------------
378 : 0 : sal_Bool SAL_CALL SortedResultSet::isAfterLast()
379 : : throw ( SQLException, RuntimeException )
380 : : {
381 [ # # ]: 0 : if ( mnCurEntry > mnCount )
382 : 0 : return sal_True;
383 : : else
384 : 0 : return sal_False;
385 : : }
386 : :
387 : : //-------------------------------------------------------------------------
388 : 0 : sal_Bool SAL_CALL SortedResultSet::isFirst()
389 : : throw ( SQLException, RuntimeException )
390 : : {
391 [ # # ]: 0 : if ( mnCurEntry == 1 )
392 : 0 : return sal_True;
393 : : else
394 : 0 : return sal_False;
395 : : }
396 : :
397 : : //-------------------------------------------------------------------------
398 : 0 : sal_Bool SAL_CALL SortedResultSet::isLast()
399 : : throw ( SQLException, RuntimeException )
400 : : {
401 [ # # ]: 0 : if ( mnCurEntry == mnCount )
402 : 0 : return sal_True;
403 : : else
404 : 0 : return sal_False;
405 : : }
406 : :
407 : : //-------------------------------------------------------------------------
408 : 138 : void SAL_CALL SortedResultSet::beforeFirst()
409 : : throw ( SQLException, RuntimeException )
410 : : {
411 [ + - ]: 138 : osl::Guard< osl::Mutex > aGuard( maMutex );
412 : 138 : mnCurEntry = 0;
413 [ + - ][ + - ]: 138 : mxOriginal->beforeFirst();
[ + - ]
414 : 138 : }
415 : :
416 : : //-------------------------------------------------------------------------
417 : 0 : void SAL_CALL SortedResultSet::afterLast()
418 : : throw ( SQLException, RuntimeException )
419 : : {
420 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
421 : 0 : mnCurEntry = mnCount+1;
422 [ # # ][ # # ]: 0 : mxOriginal->afterLast();
[ # # ]
423 : 0 : }
424 : :
425 : : //-------------------------------------------------------------------------
426 : 0 : sal_Bool SAL_CALL SortedResultSet::first()
427 : : throw ( SQLException, RuntimeException )
428 : : {
429 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
430 : :
431 [ # # ]: 0 : if ( mnCount )
432 : : {
433 : 0 : mnCurEntry = 1;
434 [ # # ]: 0 : sal_Int32 nIndex = maS2O[ mnCurEntry ];
435 [ # # ][ # # ]: 0 : return mxOriginal->absolute( nIndex );
436 : : }
437 : : else
438 : : {
439 : 0 : mnCurEntry = 0;
440 : 0 : return sal_False;
441 [ # # ]: 0 : }
442 : : }
443 : :
444 : : //-------------------------------------------------------------------------
445 : 0 : sal_Bool SAL_CALL SortedResultSet::last()
446 : : throw ( SQLException, RuntimeException )
447 : : {
448 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
449 : :
450 [ # # ]: 0 : if ( mnCount )
451 : : {
452 : 0 : mnCurEntry = mnCount;
453 [ # # ]: 0 : sal_Int32 nIndex = maS2O[ mnCurEntry ];
454 [ # # ][ # # ]: 0 : return mxOriginal->absolute( nIndex );
455 : : }
456 : : else
457 : : {
458 : 0 : mnCurEntry = 0;
459 : 0 : return sal_False;
460 [ # # ]: 0 : }
461 : : }
462 : :
463 : : //-------------------------------------------------------------------------
464 : 0 : sal_Int32 SAL_CALL SortedResultSet::getRow()
465 : : throw ( SQLException, RuntimeException )
466 : : {
467 : 0 : return mnCurEntry;
468 : : }
469 : :
470 : : //-------------------------------------------------------------------------
471 : : /**
472 : : moves the cursor to the given row number in the result set.
473 : : <p>If the row number is positive, the cursor moves to the given row
474 : : number with respect to the beginning of the result set. The first
475 : : row is row 1, the second is row 2, and so on.
476 : : <p>If the given row number is negative, the cursor moves to an
477 : : absolute row position with respect to the end of the result set.
478 : : For example, calling <code>moveToPosition(-1)</code> positions the
479 : : cursor on the last row, <code>moveToPosition(-2)</code> indicates the
480 : : next-to-last row, and so on.
481 : : <p>An attempt to position the cursor beyond the first/last row in the
482 : : result set leaves the cursor before/after the first/last row,
483 : : respectively.
484 : : <p>Note: Calling <code>moveToPosition(1)</code> is the same
485 : : as calling <code>moveToFirst()</code>. Calling
486 : : <code>moveToPosition(-1)</code> is the same as calling
487 : : <code>moveToLast()</code>.
488 : : @param row
489 : : is the number of rows to move. Could be negative.
490 : : @returns
491 : : <TRUE/> if the cursor is on a row; <FALSE/> otherwise
492 : : @throws SQLException
493 : : if a database access error occurs or if row is 0, or the result set
494 : : type is FORWARD_ONLY.
495 : : */
496 : 0 : sal_Bool SAL_CALL SortedResultSet::absolute( sal_Int32 row )
497 : : throw ( SQLException, RuntimeException )
498 : : {
499 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
500 : :
501 : : sal_Int32 nIndex;
502 : :
503 [ # # ]: 0 : if ( row > 0 )
504 : : {
505 [ # # ]: 0 : if ( row <= mnCount )
506 : : {
507 : 0 : mnCurEntry = row;
508 [ # # ]: 0 : nIndex = maS2O[ mnCurEntry ];
509 [ # # ][ # # ]: 0 : return mxOriginal->absolute( nIndex );
510 : : }
511 : : else
512 : : {
513 : 0 : mnCurEntry = mnCount + 1;
514 : 0 : return sal_False;
515 : : }
516 : : }
517 [ # # ]: 0 : else if ( row == 0 )
518 : : {
519 [ # # ]: 0 : throw SQLException();
520 : : }
521 : : else
522 : : {
523 [ # # ]: 0 : if ( mnCount + row + 1 > 0 )
524 : : {
525 : 0 : mnCurEntry = mnCount + row + 1;
526 [ # # ]: 0 : nIndex = maS2O[ mnCurEntry ];
527 [ # # ][ # # ]: 0 : return mxOriginal->absolute( nIndex );
528 : : }
529 : : else
530 : : {
531 : 0 : mnCurEntry = 0;
532 : 0 : return sal_False;
533 : : }
534 [ # # ]: 0 : }
535 : : }
536 : :
537 : : //-------------------------------------------------------------------------
538 : : /**
539 : : moves the cursor a relative number of rows, either positive or negative.
540 : : <p>
541 : : Attempting to move beyond the first/last row in the result set positions
542 : : the cursor before/after the first/last row. Calling
543 : : <code>moveRelative(0)</code> is valid, but does not change the cursor
544 : : position.
545 : : <p>Note: Calling <code>moveRelative(1)</code> is different from calling
546 : : <code>moveNext()</code> because is makes sense to call
547 : : <code>moveNext()</code> when there is no current row, for example,
548 : : when the cursor is positioned before the first row or after the last
549 : : row of the result set.
550 : : @param rows
551 : : is the number of rows to move. Could be negative.
552 : : @returns
553 : : <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off
554 : : the result set.
555 : : @throws SQLException
556 : : if a database access error occurs or if there is no
557 : : current row, or the result set type is FORWARD_ONLY.
558 : : */
559 : 0 : sal_Bool SAL_CALL SortedResultSet::relative( sal_Int32 rows )
560 : : throw ( SQLException, RuntimeException )
561 : : {
562 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
563 : :
564 [ # # ][ # # ]: 0 : if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
565 : : {
566 [ # # ]: 0 : throw SQLException();
567 : : }
568 : :
569 [ # # ]: 0 : if ( rows == 0 )
570 : 0 : return sal_True;
571 : :
572 : 0 : sal_Int32 nTmp = mnCurEntry + rows;
573 : :
574 [ # # ]: 0 : if ( nTmp <= 0 )
575 : : {
576 : 0 : mnCurEntry = 0;
577 : 0 : return sal_False;
578 : : }
579 [ # # ]: 0 : else if ( nTmp > mnCount )
580 : : {
581 : 0 : mnCurEntry = mnCount + 1;
582 : 0 : return sal_False;
583 : : }
584 : : else
585 : : {
586 : 0 : mnCurEntry = nTmp;
587 [ # # ]: 0 : nTmp = maS2O[ mnCurEntry ];
588 [ # # ][ # # ]: 0 : return mxOriginal->absolute( nTmp );
589 [ # # ]: 0 : }
590 : : }
591 : :
592 : : //-------------------------------------------------------------------------
593 : : /**
594 : : moves the cursor to the previous row in the result set.
595 : : <p>Note: <code>previous()</code> is not the same as
596 : : <code>relative(-1)</code> because it makes sense to call
597 : : <code>previous()</code> when there is no current row.
598 : : @returns <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off
599 : : the result set.
600 : : @throws SQLException
601 : : if a database access error occurs or the result set type
602 : : is FORWARD_ONLY.
603 : : */
604 : 0 : sal_Bool SAL_CALL SortedResultSet::previous()
605 : : throw ( SQLException, RuntimeException )
606 : : {
607 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
608 : :
609 : 0 : mnCurEntry -= 1;
610 : :
611 [ # # ]: 0 : if ( mnCurEntry > 0 )
612 : : {
613 [ # # ]: 0 : if ( mnCurEntry <= mnCount )
614 : : {
615 [ # # ]: 0 : sal_Int32 nIndex = maS2O[ mnCurEntry ];
616 [ # # ][ # # ]: 0 : return mxOriginal->absolute( nIndex );
617 : : }
618 : : }
619 : : else
620 : 0 : mnCurEntry = 0;
621 : :
622 [ # # ]: 0 : return sal_False;
623 : : }
624 : :
625 : : //-------------------------------------------------------------------------
626 : 0 : void SAL_CALL SortedResultSet::refreshRow()
627 : : throw ( SQLException, RuntimeException )
628 : : {
629 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
630 : :
631 [ # # ][ # # ]: 0 : if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
632 : : {
633 [ # # ]: 0 : throw SQLException();
634 : : }
635 : :
636 [ # # ][ # # ]: 0 : mxOriginal->refreshRow();
[ # # ]
637 : 0 : }
638 : :
639 : : //-------------------------------------------------------------------------
640 : 0 : sal_Bool SAL_CALL SortedResultSet::rowUpdated()
641 : : throw ( SQLException, RuntimeException )
642 : : {
643 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
644 : :
645 [ # # ][ # # ]: 0 : if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
646 : : {
647 [ # # ]: 0 : throw SQLException();
648 : : }
649 : :
650 [ # # ][ # # ]: 0 : return mxOriginal->rowUpdated();
[ # # ]
651 : : }
652 : :
653 : : //-------------------------------------------------------------------------
654 : 0 : sal_Bool SAL_CALL SortedResultSet::rowInserted()
655 : : throw ( SQLException, RuntimeException )
656 : : {
657 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
658 : :
659 [ # # ][ # # ]: 0 : if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
660 : : {
661 [ # # ]: 0 : throw SQLException();
662 : : }
663 : :
664 [ # # ][ # # ]: 0 : return mxOriginal->rowInserted();
[ # # ]
665 : : }
666 : :
667 : : //-------------------------------------------------------------------------
668 : 0 : sal_Bool SAL_CALL SortedResultSet::rowDeleted()
669 : : throw ( SQLException, RuntimeException )
670 : : {
671 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
672 : :
673 [ # # ][ # # ]: 0 : if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
674 : : {
675 [ # # ]: 0 : throw SQLException();
676 : : }
677 : :
678 [ # # ][ # # ]: 0 : return mxOriginal->rowDeleted();
[ # # ]
679 : : }
680 : :
681 : : //-------------------------------------------------------------------------
682 : 0 : Reference< XInterface > SAL_CALL SortedResultSet::getStatement()
683 : : throw ( SQLException, RuntimeException )
684 : : {
685 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
686 : :
687 [ # # ][ # # ]: 0 : if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) )
688 : : {
689 [ # # ]: 0 : throw SQLException();
690 : : }
691 : :
692 [ # # ][ # # ]: 0 : return mxOriginal->getStatement();
[ # # ]
693 : : }
694 : :
695 : : //--------------------------------------------------------------------------
696 : : // XRow methods.
697 : : //--------------------------------------------------------------------------
698 : :
699 : 0 : sal_Bool SAL_CALL SortedResultSet::wasNull()
700 : : throw( SQLException, RuntimeException )
701 : : {
702 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
703 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->wasNull();
[ # # ][ # # ]
704 : : }
705 : :
706 : : //-------------------------------------------------------------------------
707 : 466 : OUString SAL_CALL SortedResultSet::getString( sal_Int32 columnIndex )
708 : : throw( SQLException, RuntimeException )
709 : : {
710 [ + - ]: 466 : osl::Guard< osl::Mutex > aGuard( maMutex );
711 [ + - ][ + - ]: 466 : return Reference< XRow >::query(mxOriginal)->getString( columnIndex );
[ + - ][ + - ]
712 : : }
713 : :
714 : : //-------------------------------------------------------------------------
715 : 0 : sal_Bool SAL_CALL SortedResultSet::getBoolean( sal_Int32 columnIndex )
716 : : throw( SQLException, RuntimeException )
717 : : {
718 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
719 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getBoolean( columnIndex );
[ # # ][ # # ]
720 : : }
721 : :
722 : : //-------------------------------------------------------------------------
723 : 0 : sal_Int8 SAL_CALL SortedResultSet::getByte( sal_Int32 columnIndex )
724 : : throw( SQLException, RuntimeException )
725 : : {
726 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
727 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getByte( columnIndex );
[ # # ][ # # ]
728 : : }
729 : :
730 : : //-------------------------------------------------------------------------
731 : 0 : sal_Int16 SAL_CALL SortedResultSet::getShort( sal_Int32 columnIndex )
732 : : throw( SQLException, RuntimeException )
733 : : {
734 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
735 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getShort( columnIndex );
[ # # ][ # # ]
736 : : }
737 : :
738 : : //-------------------------------------------------------------------------
739 : 0 : sal_Int32 SAL_CALL SortedResultSet::getInt( sal_Int32 columnIndex )
740 : : throw( SQLException, RuntimeException )
741 : : {
742 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
743 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getInt( columnIndex );
[ # # ][ # # ]
744 : : }
745 : : //-------------------------------------------------------------------------
746 : 0 : sal_Int64 SAL_CALL SortedResultSet::getLong( sal_Int32 columnIndex )
747 : : throw( SQLException, RuntimeException )
748 : : {
749 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
750 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getLong( columnIndex );
[ # # ][ # # ]
751 : : }
752 : :
753 : : //-------------------------------------------------------------------------
754 : 0 : float SAL_CALL SortedResultSet::getFloat( sal_Int32 columnIndex )
755 : : throw( SQLException, RuntimeException )
756 : : {
757 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
758 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getFloat( columnIndex );
[ # # ][ # # ]
759 : : }
760 : :
761 : : //-------------------------------------------------------------------------
762 : 0 : double SAL_CALL SortedResultSet::getDouble( sal_Int32 columnIndex )
763 : : throw( SQLException, RuntimeException )
764 : : {
765 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
766 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getDouble( columnIndex );
[ # # ][ # # ]
767 : : }
768 : :
769 : : //-------------------------------------------------------------------------
770 : 0 : Sequence< sal_Int8 > SAL_CALL SortedResultSet::getBytes( sal_Int32 columnIndex )
771 : : throw( SQLException, RuntimeException )
772 : : {
773 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
774 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getBytes( columnIndex );
[ # # ][ # # ]
775 : : }
776 : :
777 : : //-------------------------------------------------------------------------
778 : 0 : Date SAL_CALL SortedResultSet::getDate( sal_Int32 columnIndex )
779 : : throw( SQLException, RuntimeException )
780 : : {
781 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
782 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getDate( columnIndex );
[ # # ][ # # ]
783 : : }
784 : :
785 : : //-------------------------------------------------------------------------
786 : 0 : Time SAL_CALL SortedResultSet::getTime( sal_Int32 columnIndex )
787 : : throw( SQLException, RuntimeException )
788 : : {
789 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
790 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getTime( columnIndex );
[ # # ][ # # ]
791 : : }
792 : :
793 : : //-------------------------------------------------------------------------
794 : 0 : DateTime SAL_CALL SortedResultSet::getTimestamp( sal_Int32 columnIndex )
795 : : throw( SQLException, RuntimeException )
796 : : {
797 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
798 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getTimestamp( columnIndex );
[ # # ][ # # ]
799 : : }
800 : :
801 : : //-------------------------------------------------------------------------
802 : : Reference< XInputStream > SAL_CALL
803 : 0 : SortedResultSet::getBinaryStream( sal_Int32 columnIndex )
804 : : throw( SQLException, RuntimeException )
805 : : {
806 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
807 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getBinaryStream( columnIndex );
[ # # ][ # # ]
808 : : }
809 : :
810 : : //-------------------------------------------------------------------------
811 : : Reference< XInputStream > SAL_CALL
812 : 0 : SortedResultSet::getCharacterStream( sal_Int32 columnIndex )
813 : : throw( SQLException, RuntimeException )
814 : : {
815 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
816 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getCharacterStream( columnIndex );
[ # # ][ # # ]
817 : : }
818 : :
819 : : //-------------------------------------------------------------------------
820 : 0 : Any SAL_CALL SortedResultSet::getObject( sal_Int32 columnIndex,
821 : : const Reference< XNameAccess >& typeMap )
822 : : throw( SQLException, RuntimeException )
823 : : {
824 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
825 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getObject( columnIndex,
826 [ # # # # ]: 0 : typeMap);
827 : : }
828 : :
829 : : //-------------------------------------------------------------------------
830 : 0 : Reference< XRef > SAL_CALL SortedResultSet::getRef( sal_Int32 columnIndex )
831 : : throw( SQLException, RuntimeException )
832 : : {
833 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
834 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getRef( columnIndex );
[ # # ][ # # ]
835 : : }
836 : :
837 : : //-------------------------------------------------------------------------
838 : 0 : Reference< XBlob > SAL_CALL SortedResultSet::getBlob( sal_Int32 columnIndex )
839 : : throw( SQLException, RuntimeException )
840 : : {
841 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
842 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getBlob( columnIndex );
[ # # ][ # # ]
843 : : }
844 : :
845 : : //-------------------------------------------------------------------------
846 : 0 : Reference< XClob > SAL_CALL SortedResultSet::getClob( sal_Int32 columnIndex )
847 : : throw( SQLException, RuntimeException )
848 : : {
849 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
850 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getClob( columnIndex );
[ # # ][ # # ]
851 : : }
852 : :
853 : : //-------------------------------------------------------------------------
854 : 0 : Reference< XArray > SAL_CALL SortedResultSet::getArray( sal_Int32 columnIndex )
855 : : throw( SQLException, RuntimeException )
856 : : {
857 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
858 [ # # ][ # # ]: 0 : return Reference< XRow >::query(mxOriginal)->getArray( columnIndex );
[ # # ][ # # ]
859 : : }
860 : :
861 : :
862 : : //--------------------------------------------------------------------------
863 : : // XCloseable methods.
864 : : //--------------------------------------------------------------------------
865 : :
866 : 0 : void SAL_CALL SortedResultSet::close()
867 : : throw( SQLException, RuntimeException )
868 : : {
869 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
870 [ # # ][ # # ]: 0 : Reference< XCloseable >::query(mxOriginal)->close();
[ # # ][ # # ]
871 : 0 : }
872 : :
873 : : //--------------------------------------------------------------------------
874 : : // XResultSetMetaDataSupplier methods.
875 : : //--------------------------------------------------------------------------
876 : :
877 : 0 : Reference< XResultSetMetaData > SAL_CALL SortedResultSet::getMetaData()
878 : : throw( SQLException, RuntimeException )
879 : : {
880 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
881 [ # # ][ # # ]: 0 : return Reference< XResultSetMetaDataSupplier >::query(mxOriginal)->getMetaData();
[ # # ][ # # ]
882 : : }
883 : :
884 : :
885 : : //--------------------------------------------------------------------------
886 : : // XPropertySet methods.
887 : : //--------------------------------------------------------------------------
888 : :
889 : : Reference< XPropertySetInfo > SAL_CALL
890 : 0 : SortedResultSet::getPropertySetInfo() throw( RuntimeException )
891 : : {
892 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
893 : :
894 [ # # ]: 0 : if ( !mpPropSetInfo )
895 : : {
896 [ # # ]: 0 : mpPropSetInfo = new SRSPropertySetInfo();
897 : 0 : mpPropSetInfo->acquire();
898 : : }
899 : :
900 [ # # ][ # # ]: 0 : return Reference< XPropertySetInfo >( mpPropSetInfo );
[ # # ]
901 : : }
902 : :
903 : : //--------------------------------------------------------------------------
904 : 0 : void SAL_CALL SortedResultSet::setPropertyValue(
905 : : const OUString& PropertyName,
906 : : const Any& )
907 : : throw( UnknownPropertyException,
908 : : PropertyVetoException,
909 : : IllegalArgumentException,
910 : : WrappedTargetException,
911 : : RuntimeException )
912 : : {
913 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
914 : :
915 [ # # # # ]: 0 : if ( ( PropertyName.compareToAscii( "RowCount" ) == 0 ) ||
[ # # ]
916 : 0 : ( PropertyName.compareToAscii( "IsRowCountFinal" ) == 0 ) )
917 [ # # ]: 0 : throw IllegalArgumentException();
918 : : else
919 [ # # ]: 0 : throw UnknownPropertyException();
920 : : }
921 : :
922 : : //--------------------------------------------------------------------------
923 : 0 : Any SAL_CALL SortedResultSet::getPropertyValue( const OUString& PropertyName )
924 : : throw( UnknownPropertyException,
925 : : WrappedTargetException,
926 : : RuntimeException )
927 : : {
928 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
929 : :
930 : 0 : Any aRet;
931 : :
932 [ # # ]: 0 : if ( PropertyName.compareToAscii( "RowCount" ) == 0 )
933 : : {
934 [ # # ]: 0 : aRet <<= maS2O.Count();
935 : : }
936 [ # # ]: 0 : else if ( PropertyName.compareToAscii( "IsRowCountFinal" ) == 0 )
937 : : {
938 : 0 : sal_Bool bOrgFinal = false;
939 : 0 : Any aOrgRet;
940 : :
941 [ # # ]: 0 : aRet <<= (sal_Bool) sal_False;
942 : :
943 [ # # ][ # # ]: 0 : aOrgRet = Reference< XPropertySet >::query(mxOriginal)->
944 [ # # ]: 0 : getPropertyValue( PropertyName );
945 : 0 : aOrgRet >>= bOrgFinal;
946 : :
947 [ # # ]: 0 : if ( bOrgFinal )
948 : : {
949 [ # # ][ # # ]: 0 : aOrgRet = Reference< XPropertySet >::query(mxOriginal)->
950 [ # # ]: 0 : getPropertyValue( OUString("RowCount") );
951 : 0 : sal_uInt32 nOrgCount = 0;
952 : 0 : aOrgRet >>= nOrgCount;
953 [ # # ]: 0 : if ( nOrgCount == maS2O.Count() )
954 [ # # ]: 0 : aRet <<= (sal_Bool) sal_True;
955 : 0 : }
956 : : }
957 : : else
958 [ # # ]: 0 : throw UnknownPropertyException();
959 : :
960 [ # # ]: 0 : return aRet;
961 : : }
962 : :
963 : : //--------------------------------------------------------------------------
964 : 0 : void SAL_CALL SortedResultSet::addPropertyChangeListener(
965 : : const OUString& PropertyName,
966 : : const Reference< XPropertyChangeListener >& Listener )
967 : : throw( UnknownPropertyException,
968 : : WrappedTargetException,
969 : : RuntimeException )
970 : : {
971 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
972 : :
973 [ # # ]: 0 : if ( !mpPropChangeListeners )
974 : : mpPropChangeListeners =
975 [ # # ]: 0 : new PropertyChangeListeners_Impl();
976 : :
977 [ # # ][ # # ]: 0 : mpPropChangeListeners->addInterface( PropertyName, Listener );
978 : 0 : }
979 : :
980 : : //--------------------------------------------------------------------------
981 : 0 : void SAL_CALL SortedResultSet::removePropertyChangeListener(
982 : : const OUString& PropertyName,
983 : : const Reference< XPropertyChangeListener >& Listener )
984 : : throw( UnknownPropertyException,
985 : : WrappedTargetException,
986 : : RuntimeException )
987 : : {
988 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
989 : :
990 [ # # ]: 0 : if ( mpPropChangeListeners )
991 [ # # ][ # # ]: 0 : mpPropChangeListeners->removeInterface( PropertyName, Listener );
992 : 0 : }
993 : :
994 : : //--------------------------------------------------------------------------
995 : 0 : void SAL_CALL SortedResultSet::addVetoableChangeListener(
996 : : const OUString& PropertyName,
997 : : const Reference< XVetoableChangeListener >& Listener )
998 : : throw( UnknownPropertyException,
999 : : WrappedTargetException,
1000 : : RuntimeException )
1001 : : {
1002 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
1003 : :
1004 [ # # ]: 0 : if ( !mpVetoChangeListeners )
1005 : : mpVetoChangeListeners =
1006 [ # # ]: 0 : new PropertyChangeListeners_Impl();
1007 : :
1008 [ # # ][ # # ]: 0 : mpVetoChangeListeners->addInterface( PropertyName, Listener );
1009 : 0 : }
1010 : :
1011 : : //--------------------------------------------------------------------------
1012 : 0 : void SAL_CALL SortedResultSet::removeVetoableChangeListener(
1013 : : const OUString& PropertyName,
1014 : : const Reference< XVetoableChangeListener >& Listener )
1015 : : throw( UnknownPropertyException,
1016 : : WrappedTargetException,
1017 : : RuntimeException )
1018 : : {
1019 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
1020 : :
1021 [ # # ]: 0 : if ( mpVetoChangeListeners )
1022 [ # # ][ # # ]: 0 : mpVetoChangeListeners->removeInterface( PropertyName, Listener );
1023 : 0 : }
1024 : :
1025 : : //--------------------------------------------------------------------------
1026 : : // private methods
1027 : : //--------------------------------------------------------------------------
1028 : 547 : long SortedResultSet::CompareImpl( Reference < XResultSet > xResultOne,
1029 : : Reference < XResultSet > xResultTwo,
1030 : : long nIndexOne, long nIndexTwo,
1031 : : SortInfo* pSortInfo )
1032 : :
1033 : : throw( SQLException, RuntimeException )
1034 : : {
1035 [ + - ]: 547 : Reference < XRow > xRowOne = Reference< XRow >::query( xResultOne );
1036 [ + - ]: 547 : Reference < XRow > xRowTwo = Reference< XRow >::query( xResultTwo );
1037 : :
1038 : 547 : long nCompare = 0;
1039 : 547 : long nColumn = pSortInfo->mnColumn;
1040 : :
1041 [ - - + - : 547 : switch ( pSortInfo->mnType )
- - - -
- ]
1042 : : {
1043 : : case DataType::BIT :
1044 : : case DataType::TINYINT :
1045 : : case DataType::SMALLINT :
1046 : : case DataType::INTEGER :
1047 : : {
1048 : 0 : sal_Int32 aOne = 0;
1049 : 0 : sal_Int32 aTwo = 0;
1050 : :
1051 [ # # ][ # # ]: 0 : if ( xResultOne->absolute( nIndexOne ) )
[ # # ]
1052 [ # # ][ # # ]: 0 : aOne = xRowOne->getInt( nColumn );
1053 [ # # ][ # # ]: 0 : if ( xResultTwo->absolute( nIndexTwo ) )
[ # # ]
1054 [ # # ][ # # ]: 0 : aTwo = xRowTwo->getInt( nColumn );
1055 : :
1056 [ # # ]: 0 : if ( aOne < aTwo )
1057 : 0 : nCompare = -1;
1058 [ # # ]: 0 : else if ( aOne == aTwo )
1059 : 0 : nCompare = 0;
1060 : : else
1061 : 0 : nCompare = 1;
1062 : :
1063 : 0 : break;
1064 : : }
1065 : : case DataType::BIGINT :
1066 : : {
1067 : 0 : sal_Int64 aOne = 0;
1068 : 0 : sal_Int64 aTwo = 0;
1069 : :
1070 [ # # ][ # # ]: 0 : if ( xResultOne->absolute( nIndexOne ) )
[ # # ]
1071 [ # # ][ # # ]: 0 : aOne = xRowOne->getLong( nColumn );
1072 [ # # ][ # # ]: 0 : if ( xResultTwo->absolute( nIndexTwo ) )
[ # # ]
1073 [ # # ][ # # ]: 0 : aTwo = xRowTwo->getLong( nColumn );
1074 : :
1075 [ # # ]: 0 : if ( aOne < aTwo )
1076 : 0 : nCompare = -1;
1077 [ # # ]: 0 : else if ( aOne == aTwo )
1078 : 0 : nCompare = 0;
1079 : : else
1080 : 0 : nCompare = 1;
1081 : :
1082 : 0 : break;
1083 : : }
1084 : : case DataType::CHAR :
1085 : : case DataType::VARCHAR :
1086 : : case DataType::LONGVARCHAR :
1087 : : {
1088 : 547 : OUString aOne, aTwo;
1089 : :
1090 [ + - ][ + - ]: 547 : if ( xResultOne->absolute( nIndexOne ) )
[ + - ]
1091 [ + - ][ + - ]: 547 : aOne = xRowOne->getString( nColumn );
1092 [ + - ][ + - ]: 547 : if ( xResultTwo->absolute( nIndexTwo ) )
[ + - ]
1093 [ + - ][ + - ]: 547 : aTwo = xRowTwo->getString( nColumn );
1094 : :
1095 [ + - ]: 547 : if ( ! pSortInfo->mbCaseSensitive )
1096 : : {
1097 : 547 : aOne = aOne.toAsciiLowerCase();
1098 : 547 : aTwo = aTwo.toAsciiLowerCase();
1099 : : }
1100 : :
1101 : 547 : nCompare = aOne.compareTo( aTwo );
1102 : 547 : break;
1103 : : }
1104 : : case DataType::DATE :
1105 : : {
1106 : 0 : Date aOne, aTwo;
1107 : : sal_Int32 nTmp;
1108 : :
1109 [ # # ][ # # ]: 0 : if ( xResultOne->absolute( nIndexOne ) )
[ # # ]
1110 [ # # ][ # # ]: 0 : aOne = xRowOne->getDate( nColumn );
1111 [ # # ][ # # ]: 0 : if ( xResultTwo->absolute( nIndexTwo ) )
[ # # ]
1112 [ # # ][ # # ]: 0 : aTwo = xRowTwo->getDate( nColumn );
1113 : :
1114 : 0 : nTmp = (sal_Int32) aTwo.Year - (sal_Int32) aOne.Year;
1115 [ # # ]: 0 : if ( !nTmp ) {
1116 : 0 : nTmp = (sal_Int32) aTwo.Month - (sal_Int32) aOne.Month;
1117 [ # # ]: 0 : if ( !nTmp )
1118 : 0 : nTmp = (sal_Int32) aTwo.Day - (sal_Int32) aOne.Day;
1119 : : }
1120 : :
1121 [ # # ]: 0 : if ( nTmp < 0 )
1122 : 0 : nCompare = -1;
1123 [ # # ]: 0 : else if ( nTmp == 0 )
1124 : 0 : nCompare = 0;
1125 : : else
1126 : 0 : nCompare = 1;
1127 : :
1128 : : break;
1129 : : }
1130 : : case DataType::TIME :
1131 : : {
1132 : 0 : Time aOne, aTwo;
1133 : : sal_Int32 nTmp;
1134 : :
1135 [ # # ][ # # ]: 0 : if ( xResultOne->absolute( nIndexOne ) )
[ # # ]
1136 [ # # ][ # # ]: 0 : aOne = xRowOne->getTime( nColumn );
1137 [ # # ][ # # ]: 0 : if ( xResultTwo->absolute( nIndexTwo ) )
[ # # ]
1138 [ # # ][ # # ]: 0 : aTwo = xRowTwo->getTime( nColumn );
1139 : :
1140 : 0 : nTmp = (sal_Int32) aTwo.Hours - (sal_Int32) aOne.Hours;
1141 [ # # ]: 0 : if ( !nTmp ) {
1142 : 0 : nTmp = (sal_Int32) aTwo.Minutes - (sal_Int32) aOne.Minutes;
1143 [ # # ]: 0 : if ( !nTmp ) {
1144 : 0 : nTmp = (sal_Int32) aTwo.Seconds - (sal_Int32) aOne.Seconds;
1145 [ # # ]: 0 : if ( !nTmp )
1146 : : nTmp = (sal_Int32) aTwo.HundredthSeconds
1147 : 0 : - (sal_Int32) aOne.HundredthSeconds;
1148 : : }}
1149 : :
1150 [ # # ]: 0 : if ( nTmp < 0 )
1151 : 0 : nCompare = -1;
1152 [ # # ]: 0 : else if ( nTmp == 0 )
1153 : 0 : nCompare = 0;
1154 : : else
1155 : 0 : nCompare = 1;
1156 : :
1157 : : break;
1158 : : }
1159 : : case DataType::TIMESTAMP :
1160 : : {
1161 : 0 : DateTime aOne, aTwo;
1162 : : sal_Int32 nTmp;
1163 : :
1164 [ # # ][ # # ]: 0 : if ( xResultOne->absolute( nIndexOne ) )
[ # # ]
1165 [ # # ][ # # ]: 0 : aOne = xRowOne->getTimestamp( nColumn );
1166 [ # # ][ # # ]: 0 : if ( xResultTwo->absolute( nIndexTwo ) )
[ # # ]
1167 [ # # ][ # # ]: 0 : aTwo = xRowTwo->getTimestamp( nColumn );
1168 : :
1169 : 0 : nTmp = (sal_Int32) aTwo.Year - (sal_Int32) aOne.Year;
1170 [ # # ]: 0 : if ( !nTmp ) {
1171 : 0 : nTmp = (sal_Int32) aTwo.Month - (sal_Int32) aOne.Month;
1172 [ # # ]: 0 : if ( !nTmp ) {
1173 : 0 : nTmp = (sal_Int32) aTwo.Day - (sal_Int32) aOne.Day;
1174 [ # # ]: 0 : if ( !nTmp ) {
1175 : 0 : nTmp = (sal_Int32) aTwo.Hours - (sal_Int32) aOne.Hours;
1176 [ # # ]: 0 : if ( !nTmp ) {
1177 : 0 : nTmp = (sal_Int32) aTwo.Minutes - (sal_Int32) aOne.Minutes;
1178 [ # # ]: 0 : if ( !nTmp ) {
1179 : 0 : nTmp = (sal_Int32) aTwo.Seconds - (sal_Int32) aOne.Seconds;
1180 [ # # ]: 0 : if ( !nTmp )
1181 : : nTmp = (sal_Int32) aTwo.HundredthSeconds
1182 : 0 : - (sal_Int32) aOne.HundredthSeconds;
1183 : : }}}}}
1184 : :
1185 [ # # ]: 0 : if ( nTmp < 0 )
1186 : 0 : nCompare = -1;
1187 [ # # ]: 0 : else if ( nTmp == 0 )
1188 : 0 : nCompare = 0;
1189 : : else
1190 : 0 : nCompare = 1;
1191 : :
1192 : : break;
1193 : : }
1194 : : case DataType::REAL :
1195 : : {
1196 : 0 : float aOne = 0;
1197 : 0 : float aTwo = 0;
1198 : :
1199 [ # # ][ # # ]: 0 : if ( xResultOne->absolute( nIndexOne ) )
[ # # ]
1200 [ # # ][ # # ]: 0 : aOne = xRowOne->getFloat( nColumn );
1201 [ # # ][ # # ]: 0 : if ( xResultTwo->absolute( nIndexTwo ) )
[ # # ]
1202 [ # # ][ # # ]: 0 : aTwo = xRowTwo->getFloat( nColumn );
1203 : :
1204 [ # # ]: 0 : if ( aOne < aTwo )
1205 : 0 : nCompare = -1;
1206 [ # # ]: 0 : else if ( aOne == aTwo )
1207 : 0 : nCompare = 0;
1208 : : else
1209 : 0 : nCompare = 1;
1210 : :
1211 : 0 : break;
1212 : : }
1213 : : case DataType::FLOAT :
1214 : : case DataType::DOUBLE :
1215 : : {
1216 : 0 : double aOne = 0;
1217 : 0 : double aTwo = 0;
1218 : :
1219 [ # # ][ # # ]: 0 : if ( xResultOne->absolute( nIndexOne ) )
[ # # ]
1220 [ # # ][ # # ]: 0 : aOne = xRowOne->getDouble( nColumn );
1221 [ # # ][ # # ]: 0 : if ( xResultTwo->absolute( nIndexTwo ) )
[ # # ]
1222 [ # # ][ # # ]: 0 : aTwo = xRowTwo->getDouble( nColumn );
1223 : :
1224 [ # # ]: 0 : if ( aOne < aTwo )
1225 : 0 : nCompare = -1;
1226 [ # # ]: 0 : else if ( aOne == aTwo )
1227 : 0 : nCompare = 0;
1228 : : else
1229 : 0 : nCompare = 1;
1230 : :
1231 : 0 : break;
1232 : : }
1233 : : default:
1234 : : {
1235 : : OSL_FAIL( "DataType not supported for compare!" );
1236 : : }
1237 : : }
1238 : :
1239 : 547 : return nCompare;
1240 : : }
1241 : :
1242 : : //--------------------------------------------------------------------------
1243 : 601 : long SortedResultSet::CompareImpl( Reference < XResultSet > xResultOne,
1244 : : Reference < XResultSet > xResultTwo,
1245 : : long nIndexOne, long nIndexTwo )
1246 : : throw( SQLException, RuntimeException )
1247 : : {
1248 : 601 : long nCompare = 0;
1249 : 601 : SortInfo* pInfo = mpSortInfo;
1250 : :
1251 [ + + ][ + - ]: 1202 : while ( !nCompare && pInfo )
[ + + ]
1252 : : {
1253 [ + + ]: 601 : if ( pInfo->mbUseOwnCompare )
1254 : : {
1255 : : nCompare = CompareImpl( xResultOne, xResultTwo,
1256 [ + - ]: 547 : nIndexOne, nIndexTwo, pInfo );
1257 : : }
1258 : : else
1259 : : {
1260 : 54 : Any aOne, aTwo;
1261 : :
1262 : : Reference < XRow > xRowOne =
1263 [ + - ]: 54 : Reference< XRow >::query( xResultOne );
1264 : : Reference < XRow > xRowTwo =
1265 [ + - ]: 54 : Reference< XRow >::query( xResultTwo );
1266 : :
1267 [ + - ][ + - ]: 54 : if ( xResultOne->absolute( nIndexOne ) )
[ + - ]
1268 [ + - ][ + - ]: 54 : aOne = xRowOne->getObject( pInfo->mnColumn, NULL );
[ + - ]
1269 [ + - ][ + - ]: 54 : if ( xResultTwo->absolute( nIndexTwo ) )
[ + - ]
1270 [ + - ][ + - ]: 54 : aTwo = xRowTwo->getObject( pInfo->mnColumn, NULL );
[ + - ]
1271 : :
1272 [ + - ][ + - ]: 54 : nCompare = pInfo->mxCompareFunction->compare( aOne, aTwo );
1273 : : }
1274 : :
1275 [ - + ]: 601 : if ( ! pInfo->mbAscending )
1276 : 0 : nCompare = - nCompare;
1277 : :
1278 : 601 : pInfo = pInfo->mpNext;
1279 : : }
1280 : :
1281 : 601 : return nCompare;
1282 : : }
1283 : :
1284 : : //--------------------------------------------------------------------------
1285 : 601 : long SortedResultSet::Compare( SortListData *pOne,
1286 : : SortListData *pTwo )
1287 : : throw( SQLException, RuntimeException )
1288 : : {
1289 : : long nIndexOne;
1290 : : long nIndexTwo;
1291 : :
1292 : 601 : Reference < XResultSet > xResultOne;
1293 : 601 : Reference < XResultSet > xResultTwo;
1294 : :
1295 [ - + ]: 601 : if ( pOne->mbModified )
1296 : : {
1297 [ # # ]: 0 : xResultOne = mxOther;
1298 : 0 : nIndexOne = pOne->mnOldPos;
1299 : : }
1300 : : else
1301 : : {
1302 [ + - ]: 601 : xResultOne = mxOriginal;
1303 : 601 : nIndexOne = pOne->mnCurPos;
1304 : : }
1305 : :
1306 [ - + ]: 601 : if ( pTwo->mbModified )
1307 : : {
1308 [ # # ]: 0 : xResultTwo = mxOther;
1309 : 0 : nIndexTwo = pTwo->mnOldPos;
1310 : : }
1311 : : else
1312 : : {
1313 [ + - ]: 601 : xResultTwo = mxOriginal;
1314 : 601 : nIndexTwo = pTwo->mnCurPos;
1315 : : }
1316 : :
1317 : : long nCompare;
1318 : : nCompare = CompareImpl( xResultOne, xResultTwo,
1319 [ + - ]: 601 : nIndexOne, nIndexTwo );
1320 : 601 : return nCompare;
1321 : : }
1322 : :
1323 : : //--------------------------------------------------------------------------
1324 : 446 : long SortedResultSet::FindPos( SortListData *pEntry,
1325 : : long _nStart, long _nEnd )
1326 : : throw( SQLException, RuntimeException )
1327 : : {
1328 [ + + ]: 446 : if ( _nStart > _nEnd )
1329 : 142 : return _nStart + 1;
1330 : :
1331 : 304 : long nStart = _nStart;
1332 : 304 : long nEnd = _nEnd;
1333 : 304 : long nMid = 0, nCompare = 0;
1334 : :
1335 : : SortListData *pMid;
1336 : :
1337 [ + + ]: 905 : while ( nStart <= nEnd )
1338 : : {
1339 : 601 : nMid = ( nEnd - nStart ) / 2 + nStart;
1340 : 601 : pMid = maS2O.GetData( nMid );
1341 : 601 : nCompare = Compare( pEntry, pMid );
1342 : :
1343 [ - + ]: 601 : if ( !nCompare )
1344 : 0 : nCompare = ((long) pEntry ) - ( (long) pMid );
1345 : :
1346 [ + + ]: 601 : if ( nCompare < 0 ) // pEntry < pMid
1347 : 247 : nEnd = nMid - 1;
1348 : : else
1349 : 354 : nStart = nMid + 1;
1350 : : }
1351 : :
1352 [ + + ]: 304 : if ( nCompare < 0 ) // pEntry < pMid
1353 : 112 : return nMid;
1354 : : else
1355 : 446 : return nMid+1;
1356 : : }
1357 : :
1358 : : //--------------------------------------------------------------------------
1359 : 0 : void SortedResultSet::PropertyChanged( const PropertyChangeEvent& rEvt )
1360 : : {
1361 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
1362 : :
1363 [ # # ]: 0 : if ( !mpPropChangeListeners )
1364 : 0 : return;
1365 : :
1366 : : // Notify listeners interested especially in the changed property.
1367 : : OInterfaceContainerHelper* pPropsContainer =
1368 [ # # ]: 0 : mpPropChangeListeners->getContainer( rEvt.PropertyName );
1369 [ # # ]: 0 : if ( pPropsContainer )
1370 : : {
1371 [ # # ]: 0 : OInterfaceIteratorHelper aIter( *pPropsContainer );
1372 [ # # ]: 0 : while ( aIter.hasMoreElements() )
1373 : : {
1374 : : Reference< XPropertyChangeListener > xListener(
1375 [ # # ][ # # ]: 0 : aIter.next(), UNO_QUERY );
1376 [ # # ]: 0 : if ( xListener.is() )
1377 [ # # ][ # # ]: 0 : xListener->propertyChange( rEvt );
1378 [ # # ]: 0 : }
1379 : : }
1380 : :
1381 : : // Notify listeners interested in all properties.
1382 [ # # ]: 0 : pPropsContainer = mpPropChangeListeners->getContainer( OUString() );
1383 [ # # ]: 0 : if ( pPropsContainer )
1384 : : {
1385 [ # # ]: 0 : OInterfaceIteratorHelper aIter( *pPropsContainer );
1386 [ # # ]: 0 : while ( aIter.hasMoreElements() )
1387 : : {
1388 : : Reference< XPropertyChangeListener > xListener(
1389 [ # # ][ # # ]: 0 : aIter.next(), UNO_QUERY );
1390 [ # # ]: 0 : if ( xListener.is() )
1391 [ # # ][ # # ]: 0 : xListener->propertyChange( rEvt );
1392 [ # # ]: 0 : }
1393 [ # # ][ # # ]: 0 : }
1394 : : }
1395 : :
1396 : : //-------------------------------------------------------------------------
1397 : :
1398 : : //--------------------------------------------------------------------------
1399 : : // public methods
1400 : : //--------------------------------------------------------------------------
1401 : :
1402 : 0 : void SortedResultSet::CopyData( SortedResultSet *pSource )
1403 : : {
1404 : 0 : const SortedEntryList *pSrcS2O = pSource->GetS2OList();
1405 : 0 : const SimpleList *pSrcO2S = pSource->GetO2SList();
1406 : :
1407 : : long i, nCount;
1408 : :
1409 : 0 : maS2O.Clear();
1410 : 0 : maO2S.Clear();
1411 : 0 : maModList.Clear();
1412 : :
1413 : 0 : maS2O.Insert( NULL, 0 );
1414 : 0 : maO2S.Insert( 0, (sal_uInt32) 0 ); // value, pos
1415 : :
1416 : 0 : nCount = pSrcS2O->Count();
1417 : :
1418 [ # # ]: 0 : for ( i=1; i<nCount; i++ )
1419 : : {
1420 : 0 : maS2O.Insert( new SortListData( (*pSrcS2O)[ i ] ), i );
1421 : 0 : maO2S.Insert( pSrcO2S->GetObject( i ), (sal_uInt32) i );
1422 : : }
1423 : :
1424 : 0 : mnLastSort = maS2O.Count();
1425 [ # # ]: 0 : mxOther = pSource->GetResultSet();
1426 : :
1427 [ # # ]: 0 : if ( !mpSortInfo )
1428 : : {
1429 : 0 : mpSortInfo = pSource->GetSortInfo();
1430 : 0 : mbIsCopy = sal_True;
1431 : : }
1432 : 0 : }
1433 : :
1434 : : //--------------------------------------------------------------------------
1435 : 146 : void SortedResultSet::Initialize(
1436 : : const Sequence < NumberedSortingInfo > &xSortInfo,
1437 : : const Reference< XAnyCompareFactory > &xCompFactory )
1438 : : {
1439 [ + - ][ # # ]: 146 : BuildSortInfo( mxOriginal, xSortInfo, xCompFactory );
1440 : : // Insert dummy at pos 0
1441 : 146 : SortListData *pData = new SortListData( 0 );
1442 : 146 : maS2O.Insert( pData, 0 );
1443 : :
1444 : 146 : long nIndex = 1;
1445 : :
1446 : : // now fetch all the elements from the original result set,
1447 : : // get there new position in the sorted result set and insert
1448 : : // an entry in the sorted to original mapping list
1449 : : try {
1450 [ + - ][ + - ]: 592 : while ( mxOriginal->absolute( nIndex ) )
[ + + ]
1451 : : {
1452 [ + - ]: 446 : pData = new SortListData( nIndex );
1453 [ + - ]: 446 : long nPos = FindPos( pData, 1, nIndex-1 );
1454 : :
1455 [ + - ]: 446 : maS2O.Insert( pData, nPos );
1456 : :
1457 : 446 : nIndex++;
1458 : : }
1459 : : }
1460 : 0 : catch (const SQLException&)
1461 : : {
1462 : : OSL_FAIL( "SortedResultSet::Initialize() : Got unexpected SQLException" );
1463 : : }
1464 : :
1465 : : // when we have fetched all the elements, we can create the
1466 : : // original to sorted mapping list from the s2o list
1467 : 146 : maO2S.Clear();
1468 : 146 : maO2S.Insert( NULL, (sal_uInt32) 0 );
1469 : :
1470 : : // insert some dummy entries first and replace then
1471 : : // the entries with the right ones
1472 : : size_t i;
1473 : :
1474 [ + + ]: 592 : for ( i=1; i<maS2O.Count(); i++ )
1475 : 446 : maO2S.Insert( (void*) 0, i ); // Insert( data, pos )
1476 [ + + ]: 592 : for ( i=1; i<maS2O.Count(); i++ )
1477 : 446 : maO2S.Replace( (void*) i, maS2O[ i ] ); // Insert( data, pos )
1478 : :
1479 : 146 : mnCount = maS2O.Count() - 1;
1480 : 146 : }
1481 : :
1482 : : //--------------------------------------------------------------------------
1483 : 0 : void SortedResultSet::CheckProperties( long nOldCount, sal_Bool bWasFinal )
1484 : : {
1485 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( maMutex );
1486 : :
1487 [ # # ]: 0 : if ( !mpPropChangeListeners )
1488 : 0 : return;
1489 : :
1490 : : try {
1491 : : // check for propertyChangeEvents
1492 [ # # ]: 0 : if ( nOldCount != GetCount() )
1493 : : {
1494 : 0 : sal_Bool bIsFinal = sal_False;
1495 [ # # ]: 0 : PropertyChangeEvent aEvt;
1496 : :
1497 : 0 : aEvt.PropertyName = OUString("RowCount");
1498 : 0 : aEvt.Further = sal_False;
1499 : 0 : aEvt.PropertyHandle = -1;
1500 [ # # ]: 0 : aEvt.OldValue <<= nOldCount;
1501 [ # # ]: 0 : aEvt.NewValue <<= GetCount();
1502 : :
1503 [ # # ]: 0 : PropertyChanged( aEvt );
1504 : :
1505 : 0 : OUString aName = OUString("IsRowCountFinal");
1506 [ # # ]: 0 : Any aRet = getPropertyValue( aName );
1507 [ # # ][ # # ]: 0 : if ( (aRet >>= bIsFinal) && bIsFinal != bWasFinal )
[ # # ]
1508 : : {
1509 : 0 : aEvt.PropertyName = aName;
1510 : 0 : aEvt.Further = sal_False;
1511 : 0 : aEvt.PropertyHandle = -1;
1512 [ # # ]: 0 : aEvt.OldValue <<= (sal_Bool) bWasFinal;
1513 [ # # ]: 0 : aEvt.NewValue <<= (sal_Bool) bIsFinal;
1514 [ # # ]: 0 : PropertyChanged( aEvt );
1515 [ # # ]: 0 : }
[ # # # ]
1516 : : }
1517 : : }
1518 [ # # ]: 0 : catch (const UnknownPropertyException&) {}
1519 [ # # ][ # # ]: 0 : catch (const WrappedTargetException&) {}
[ # # ]
1520 : : }
1521 : :
1522 : : //-------------------------------------------------------------------------
1523 : 0 : void SortedResultSet::InsertNew( long nPos, long nCount )
1524 : : {
1525 : : // for all entries in the msS20-list, which are >= nPos, increase by nCount
1526 : : SortListData *pData;
1527 : : long i, nEnd;
1528 : :
1529 : 0 : nEnd = maS2O.Count();
1530 [ # # ]: 0 : for ( i=1; i<=nEnd; i++ )
1531 : : {
1532 : 0 : pData = maS2O.GetData( i );
1533 [ # # ]: 0 : if ( pData->mnCurPos >= nPos )
1534 : : {
1535 : 0 : pData->mnCurPos += nCount;
1536 : : }
1537 : : }
1538 : :
1539 : : // and append the new entries at the end of the maS20-list or insert at the
1540 : : // position nPos in the maS2O-list
1541 [ # # ]: 0 : for ( i=0; i<nCount; i++ )
1542 : : {
1543 : 0 : nEnd += 1;
1544 : 0 : pData = new SortListData( nEnd );
1545 : :
1546 : 0 : maS2O.Insert( pData, nEnd ); // Insert( Value, Position )
1547 : 0 : maO2S.Insert( (void*)nEnd, (sal_uInt32)(nPos+i) ); // Insert( Value, Position )
1548 : : }
1549 : :
1550 : 0 : mnCount += nCount;
1551 : 0 : }
1552 : :
1553 : : //-------------------------------------------------------------------------
1554 : 0 : void SortedResultSet::Remove( long nPos, long nCount, EventList *pEvents )
1555 : : {
1556 : : sal_uInt32 i, j;
1557 : : long nOldLastSort;
1558 : :
1559 : : // correct mnLastSort first
1560 : 0 : nOldLastSort = mnLastSort;
1561 [ # # ]: 0 : if ( nPos <= mnLastSort )
1562 : : {
1563 [ # # ]: 0 : if ( nPos + nCount - 1 <= mnLastSort )
1564 : 0 : mnLastSort -= nCount;
1565 : : else
1566 : 0 : mnLastSort = nPos - 1;
1567 : : }
1568 : :
1569 : : // remove the entries from the lists and correct the positions
1570 : : // in the original2sorted list
1571 [ # # ]: 0 : for ( i=0; i < (sal_uInt32) nCount; i++ )
1572 : : {
1573 : 0 : long nSortPos = (long) maO2S.GetObject( nPos );
1574 : 0 : maO2S.Remove( (sal_uInt32) nPos );
1575 : :
1576 [ # # ]: 0 : for ( j=1; j<=maO2S.Count(); j++ )
1577 : : {
1578 : 0 : long nVal = (long) maO2S.GetObject( j );
1579 [ # # ]: 0 : if ( nVal > nSortPos )
1580 : : {
1581 : 0 : --nVal;
1582 : 0 : maO2S.Replace( (void*) nVal, j );
1583 : : }
1584 : : }
1585 : :
1586 : 0 : SortListData *pData = maS2O.Remove( nSortPos );
1587 [ # # ]: 0 : if ( pData->mbModified )
1588 : 0 : maModList.Remove( (void*) pData );
1589 : 0 : delete pData;
1590 : :
1591 : : // generate remove Event, but not for new entries
1592 [ # # ]: 0 : if ( nSortPos <= nOldLastSort )
1593 : 0 : pEvents->AddEvent( ListActionType::REMOVED, nSortPos, 1 );
1594 : : }
1595 : :
1596 : : // correct the positions in the sorted list
1597 [ # # ]: 0 : for ( i=1; i<= maS2O.Count(); i++ )
1598 : : {
1599 : 0 : SortListData *pData = maS2O.GetData( i );
1600 [ # # ]: 0 : if ( pData->mnCurPos > nPos )
1601 : 0 : pData->mnCurPos -= nCount;
1602 : : }
1603 : :
1604 : 0 : mnCount -= nCount;
1605 : 0 : }
1606 : :
1607 : : //-------------------------------------------------------------------------
1608 : 0 : void SortedResultSet::Move( long nPos, long nCount, long nOffset )
1609 : : {
1610 [ # # ]: 0 : if ( !nOffset )
1611 : 0 : return;
1612 : :
1613 : : long i, nSortPos, nTo;
1614 : : SortListData *pData;
1615 : :
1616 [ # # ]: 0 : for ( i=0; i<nCount; i++ )
1617 : : {
1618 : 0 : nSortPos = (long) maO2S.GetObject( nPos+i );
1619 : 0 : pData = maS2O.GetData( nSortPos );
1620 : 0 : pData->mnCurPos += nOffset;
1621 : : }
1622 : :
1623 [ # # ]: 0 : if ( nOffset < 0 )
1624 : : {
1625 [ # # ]: 0 : for ( i=nPos+nOffset; i<nPos; i++ )
1626 : : {
1627 : 0 : nSortPos = (long) maO2S.GetObject( i );
1628 : 0 : pData = maS2O.GetData( nSortPos );
1629 : 0 : pData->mnCurPos += nCount;
1630 : : }
1631 : : }
1632 : : else
1633 : : {
1634 : 0 : long nStart = nPos + nCount;
1635 : 0 : long nEnd = nStart + nOffset;
1636 [ # # ]: 0 : for ( i=nStart; i<nEnd; i++ )
1637 : : {
1638 : 0 : nSortPos = (long) maO2S.GetObject( i );
1639 : 0 : pData = maS2O.GetData( nSortPos );
1640 : 0 : pData->mnCurPos -= nCount;
1641 : : }
1642 : : }
1643 : :
1644 : : // remember the to be moved entries
1645 : 0 : long *pTmpArr = new long[ nCount ];
1646 [ # # ]: 0 : for ( i=0; i<nCount; i++ )
1647 : 0 : pTmpArr[i] = (long)maO2S.GetObject( (sal_uInt32)( nPos+i ) );
1648 : :
1649 : : // now move the entries, which are in the way
1650 [ # # ]: 0 : if ( nOffset < 0 )
1651 : : {
1652 : : // be carefully here, because nOffset is negative here, so an
1653 : : // addition is a subtraction
1654 : 0 : long nFrom = nPos - 1;
1655 : 0 : nTo = nPos + nCount - 1;
1656 : :
1657 : : // same for i here
1658 [ # # ]: 0 : for ( i=0; i>nOffset; i-- )
1659 : : {
1660 : 0 : long nVal = (long) maO2S.GetObject( (sal_uInt32)( nFrom+i ) );
1661 : 0 : maO2S.Replace( (void*) nVal, (sal_uInt32)( nTo+i ) );
1662 : : }
1663 : :
1664 : : }
1665 : : else
1666 : : {
1667 : 0 : long nStart = nPos + nCount;
1668 [ # # ]: 0 : for ( i=0; i<nOffset; i++ )
1669 : : {
1670 : 0 : long nVal = (long) maO2S.GetObject( (sal_uInt32)( nStart+i ) );
1671 : 0 : maO2S.Replace( (void*) nVal, (sal_uInt32)( nPos+i ) );
1672 : : }
1673 : : }
1674 : :
1675 : : // finally put the remembered entries at there new location
1676 : 0 : nTo = nPos + nOffset;
1677 [ # # ]: 0 : for ( i=0; i<nCount; i++ )
1678 : : {
1679 : 0 : maO2S.Replace( (void*)pTmpArr[ i ], (sal_uInt32)( nTo+i ) );
1680 : : }
1681 : :
1682 [ # # ]: 0 : delete [] pTmpArr;
1683 : : }
1684 : :
1685 : : //--------------------------------------------------------------------------
1686 : 146 : void SortedResultSet::BuildSortInfo(
1687 : : Reference< XResultSet > aResult,
1688 : : const Sequence < NumberedSortingInfo > &xSortInfo,
1689 : : const Reference< XAnyCompareFactory > &xCompFactory )
1690 : : {
1691 [ + - ]: 146 : Reference < XResultSetMetaDataSupplier > xMeta ( aResult, UNO_QUERY );
1692 : :
1693 [ - + ]: 146 : if ( ! xMeta.is() )
1694 : : {
1695 : : OSL_FAIL( "No MetaData, No Sorting!" );
1696 : 146 : return;
1697 : : }
1698 : :
1699 [ + - ][ + - ]: 146 : Reference < XResultSetMetaData > xData = xMeta->getMetaData();
1700 : 146 : const NumberedSortingInfo *pSortInfo = xSortInfo.getConstArray();
1701 : :
1702 : : sal_Int32 nColumn;
1703 : 146 : OUString aPropName;
1704 : : SortInfo *pInfo;
1705 : :
1706 [ + + ]: 292 : for ( long i=xSortInfo.getLength(); i > 0; )
1707 : : {
1708 : 146 : --i;
1709 : 146 : nColumn = pSortInfo[ i ].ColumnIndex;
1710 [ + - ][ + - ]: 146 : aPropName = xData->getColumnName( nColumn );
1711 [ + - ][ + - ]: 146 : pInfo = new SortInfo;
1712 : :
1713 [ + + ]: 146 : if ( xCompFactory.is() )
1714 [ + - ]: 8 : pInfo->mxCompareFunction = xCompFactory->createAnyCompareByName(
1715 [ + - ][ + - ]: 8 : aPropName );
1716 : :
1717 [ + + ]: 146 : if ( pInfo->mxCompareFunction.is() )
1718 : : {
1719 : 8 : pInfo->mbUseOwnCompare = sal_False;
1720 : 8 : pInfo->mnType = 0;
1721 : : }
1722 : : else
1723 : : {
1724 : 138 : pInfo->mbUseOwnCompare = sal_True;
1725 [ + - ][ + - ]: 138 : pInfo->mnType = xData->getColumnType( nColumn );
1726 : : }
1727 : :
1728 : 146 : pInfo->mnColumn = nColumn;
1729 : 146 : pInfo->mbAscending = pSortInfo[ i ].Ascending;
1730 [ + - ][ + - ]: 146 : pInfo->mbCaseSensitive = xData->isCaseSensitive( nColumn );
1731 : 146 : pInfo->mpNext = mpSortInfo;
1732 : 146 : mpSortInfo = pInfo;
1733 [ + - ]: 146 : }
1734 : : }
1735 : :
1736 : : //-------------------------------------------------------------------------
1737 : 0 : void SortedResultSet::SetChanged( long nPos, long nCount )
1738 : : {
1739 [ # # ]: 0 : for ( long i=0; i<nCount; i++ )
1740 : : {
1741 : 0 : long nSortPos = (long) maO2S.GetObject( nPos );
1742 [ # # ]: 0 : if ( nSortPos < mnLastSort )
1743 : : {
1744 : 0 : SortListData *pData = maS2O.GetData( nSortPos );
1745 [ # # ]: 0 : if ( ! pData->mbModified )
1746 : : {
1747 : 0 : pData->mbModified = sal_True;
1748 : 0 : maModList.Append( pData );
1749 : : }
1750 : : }
1751 : 0 : nPos += 1;
1752 : : }
1753 : 0 : }
1754 : :
1755 : : //-------------------------------------------------------------------------
1756 : 0 : void SortedResultSet::ResortModified( EventList* pList )
1757 : : {
1758 : : sal_uInt32 i, j;
1759 : : long nCompare, nCurPos, nNewPos;
1760 : : long nStart, nEnd, nOffset, nVal;
1761 : : SortListData *pData;
1762 : : ListAction *pAction;
1763 : :
1764 : : try {
1765 [ # # ]: 0 : for ( i=0; i<maModList.Count(); i++ )
1766 : : {
1767 [ # # ]: 0 : pData = (SortListData*) maModList.GetObject( i );
1768 : : nCompare = CompareImpl( mxOther, mxOriginal,
1769 [ # # ]: 0 : pData->mnOldPos, pData->mnCurPos );
1770 : 0 : pData->mbModified = sal_False;
1771 [ # # ]: 0 : if ( nCompare != 0 )
1772 : : {
1773 [ # # ]: 0 : nCurPos = (long) maO2S.GetObject( (sal_uInt32) pData->mnCurPos );
1774 [ # # ]: 0 : if ( nCompare < 0 )
1775 : : {
1776 [ # # ]: 0 : nNewPos = FindPos( pData, 1, nCurPos-1 );
1777 : 0 : nStart = nNewPos;
1778 : 0 : nEnd = nCurPos;
1779 : 0 : nOffset = 1;
1780 : : }
1781 : : else
1782 : : {
1783 [ # # ]: 0 : nNewPos = FindPos( pData, nCurPos+1, mnLastSort );
1784 : 0 : nStart = nCurPos;
1785 : 0 : nEnd = mnLastSort;
1786 : 0 : nOffset = -1;
1787 : : }
1788 : :
1789 [ # # ]: 0 : if ( nNewPos != nCurPos )
1790 : : {
1791 : : // correct the lists!
1792 [ # # ]: 0 : maS2O.Remove( (sal_uInt32) nCurPos );
1793 [ # # ]: 0 : maS2O.Insert( pData, nNewPos );
1794 [ # # ]: 0 : for ( j=1; j<maO2S.Count(); j++ )
1795 : : {
1796 [ # # ]: 0 : nVal = (long) maO2S.GetObject( (sal_uInt32)( j ) );
1797 [ # # ][ # # ]: 0 : if ( ( nStart <= nVal ) && ( nVal <= nEnd ) )
1798 : : {
1799 : 0 : nVal += nOffset;
1800 [ # # ]: 0 : maO2S.Replace( (void*) (nVal), (sal_uInt32)( j ) );
1801 : : }
1802 : : }
1803 : :
1804 [ # # ]: 0 : maO2S.Replace( (void*) nNewPos, (sal_uInt32) pData->mnCurPos );
1805 : :
1806 [ # # ]: 0 : pAction = new ListAction;
1807 : 0 : pAction->Position = nCurPos;
1808 : 0 : pAction->Count = 1;
1809 : 0 : pAction->ListActionType = ListActionType::MOVED;
1810 [ # # # # ]: 0 : pAction->ActionInfo <<= nNewPos-nCurPos;
1811 [ # # ]: 0 : pList->Insert( pAction );
1812 : : }
1813 : : pList->AddEvent( ListActionType::PROPERTIES_CHANGED,
1814 [ # # ]: 0 : nNewPos, 1 );
1815 : : }
1816 : : }
1817 : : }
1818 : 0 : catch (const SQLException&)
1819 : : {
1820 : : OSL_FAIL( "SortedResultSet::ResortModified() : Got unexpected SQLException" );
1821 : : }
1822 : :
1823 : 0 : maModList.Clear();
1824 : 0 : }
1825 : :
1826 : : //-------------------------------------------------------------------------
1827 : 0 : void SortedResultSet::ResortNew( EventList* pList )
1828 : : {
1829 : : long i, j, nNewPos, nVal;
1830 : : SortListData *pData;
1831 : :
1832 : : try {
1833 [ # # ]: 0 : for ( i = mnLastSort; i<(long)maS2O.Count(); i++ )
1834 : : {
1835 [ # # ]: 0 : pData = (SortListData*) maModList.GetObject( i );
1836 [ # # ]: 0 : nNewPos = FindPos( pData, 1, mnLastSort );
1837 [ # # ]: 0 : if ( nNewPos != i )
1838 : : {
1839 [ # # ]: 0 : maS2O.Remove( (sal_uInt32) i );
1840 [ # # ]: 0 : maS2O.Insert( pData, nNewPos );
1841 : : // maO2S liste korigieren
1842 [ # # ]: 0 : for ( j=1; j<(long)maO2S.Count(); j++ )
1843 : : {
1844 [ # # ]: 0 : nVal = (long) maO2S.GetObject( (sal_uInt32)( j ) );
1845 [ # # ]: 0 : if ( nVal >= nNewPos )
1846 [ # # ]: 0 : maO2S.Replace( (void*) (nVal+1), (sal_uInt32)( j ) );
1847 : : }
1848 [ # # ]: 0 : maO2S.Replace( (void*) nNewPos, (sal_uInt32) pData->mnCurPos );
1849 : : }
1850 : 0 : mnLastSort++;
1851 [ # # ]: 0 : pList->AddEvent( ListActionType::INSERTED, nNewPos, 1 );
1852 : : }
1853 : : }
1854 : 0 : catch (const SQLException&)
1855 : : {
1856 : : OSL_FAIL( "SortedResultSet::ResortNew() : Got unexpected SQLException" );
1857 : : }
1858 [ # # ]: 0 : }
1859 : :
1860 : : //-------------------------------------------------------------------------
1861 : : //
1862 : : // SortListData
1863 : : //
1864 : : //-------------------------------------------------------------------------
1865 : 592 : SortListData::SortListData( long nPos, sal_Bool bModified )
1866 : : {
1867 : 592 : mbModified = bModified;
1868 : 592 : mnCurPos = nPos;
1869 : 592 : mnOldPos = nPos;
1870 : 592 : };
1871 : :
1872 : :
1873 : : //=========================================================================
1874 : 146 : void SortedEntryList::Clear()
1875 : : {
1876 [ + + ]: 1476 : for ( std::deque< LISTACTION* >::size_type i = 0;
1877 : 738 : i < maData.size(); ++i )
1878 : : {
1879 : 592 : delete maData[i];
1880 : : }
1881 : :
1882 : 146 : maData.clear();
1883 : 146 : }
1884 : :
1885 : : //-------------------------------------------------------------------------
1886 : 592 : void SortedEntryList::Insert( SortListData *pEntry, long nPos )
1887 : : {
1888 [ + + ]: 592 : if ( nPos < (long) maData.size() )
1889 [ + - ][ + - ]: 159 : maData.insert( maData.begin() + nPos, pEntry );
1890 : : else
1891 : 433 : maData.push_back( pEntry );
1892 : 592 : }
1893 : :
1894 : : //-------------------------------------------------------------------------
1895 : 0 : SortListData* SortedEntryList::Remove( long nPos )
1896 : : {
1897 : : SortListData *pData;
1898 : :
1899 [ # # ]: 0 : if ( nPos < (long) maData.size() )
1900 : : {
1901 : 0 : pData = maData[ nPos ];
1902 [ # # ][ # # ]: 0 : maData.erase( maData.begin() + nPos );
1903 : : }
1904 : : else
1905 : 0 : pData = NULL;
1906 : :
1907 : 0 : return pData;
1908 : : }
1909 : :
1910 : : //-------------------------------------------------------------------------
1911 : 601 : SortListData* SortedEntryList::GetData( long nPos )
1912 : : {
1913 : : SortListData *pData;
1914 : :
1915 [ + - ]: 601 : if ( nPos < (long) maData.size() )
1916 : 601 : pData = maData[ nPos ];
1917 : : else
1918 : 0 : pData = NULL;
1919 : :
1920 : 601 : return pData;
1921 : : }
1922 : :
1923 : : //-------------------------------------------------------------------------
1924 : 892 : long SortedEntryList::operator [] ( long nPos ) const
1925 : : {
1926 : : SortListData *pData;
1927 : :
1928 [ + - ]: 892 : if ( nPos < (long) maData.size() )
1929 : 892 : pData = maData[ nPos ];
1930 : : else
1931 : 0 : pData = NULL;
1932 : :
1933 [ + - ]: 892 : if ( pData )
1934 [ + - ]: 892 : if ( ! pData->mbModified )
1935 : 892 : return pData->mnCurPos;
1936 : : else
1937 : : {
1938 : : OSL_FAIL( "SortedEntryList: Can't get value for modified entry!");
1939 : 0 : return 0;
1940 : : }
1941 : : else
1942 : : {
1943 : : OSL_FAIL( "SortedEntryList: invalid pos!");
1944 : 892 : return 0;
1945 : : }
1946 : : }
1947 : :
1948 : : //-------------------------------------------------------------------------
1949 : : //-------------------------------------------------------------------------
1950 : : //-------------------------------------------------------------------------
1951 : 0 : void SimpleList::Remove( sal_uInt32 nPos )
1952 : : {
1953 [ # # ]: 0 : if ( nPos < (sal_uInt32) maData.size() )
1954 : : {
1955 [ # # ][ # # ]: 0 : maData.erase( maData.begin() + nPos );
1956 : : }
1957 : 0 : }
1958 : :
1959 : : //-------------------------------------------------------------------------
1960 : 0 : void SimpleList::Remove( void* pData )
1961 : : {
1962 : 0 : sal_Bool bFound = sal_False;
1963 : : sal_uInt32 i;
1964 : :
1965 [ # # ]: 0 : for ( i = 0; i < (sal_uInt32) maData.size(); i++ )
1966 : : {
1967 [ # # ]: 0 : if ( maData[ i ] == pData )
1968 : : {
1969 : 0 : bFound = sal_True;
1970 : 0 : break;
1971 : : }
1972 : : }
1973 : :
1974 [ # # ]: 0 : if ( bFound )
1975 [ # # ][ # # ]: 0 : maData.erase( maData.begin() + i );
1976 : 0 : }
1977 : :
1978 : : //-------------------------------------------------------------------------
1979 : 592 : void SimpleList::Insert( void* pData, sal_uInt32 nPos )
1980 : : {
1981 [ - + ]: 592 : if ( nPos < (sal_uInt32) maData.size() )
1982 [ # # ][ # # ]: 0 : maData.insert( maData.begin() + nPos, pData );
1983 : : else
1984 : 592 : maData.push_back( pData );
1985 : 592 : }
1986 : :
1987 : : //-------------------------------------------------------------------------
1988 : 0 : void* SimpleList::GetObject( sal_uInt32 nPos ) const
1989 : : {
1990 [ # # ]: 0 : if ( nPos < (sal_uInt32) maData.size() )
1991 : 0 : return maData[ nPos ];
1992 : : else
1993 : 0 : return NULL;
1994 : : }
1995 : :
1996 : : //-------------------------------------------------------------------------
1997 : 446 : void SimpleList::Replace( void* pData, sal_uInt32 nPos )
1998 : : {
1999 [ + - ]: 446 : if ( nPos < (sal_uInt32) maData.size() )
2000 : 446 : maData[ nPos ] = pData;
2001 : 446 : }
2002 : :
2003 : : //-------------------------------------------------------------------------
2004 : : //
2005 : : // class SRSPropertySetInfo.
2006 : : //
2007 : : //-------------------------------------------------------------------------
2008 : :
2009 [ # # ]: 0 : SRSPropertySetInfo::SRSPropertySetInfo()
2010 : : {
2011 : 0 : maProps[0].Name = OUString("RowCount");
2012 : 0 : maProps[0].Handle = -1;
2013 [ # # ]: 0 : maProps[0].Type = ::getCppuType( (const OUString*) NULL );
2014 : 0 : maProps[0].Attributes = -1;
2015 : :
2016 : 0 : maProps[1].Name = OUString("IsRowCountFinal");
2017 : 0 : maProps[1].Handle = -1;
2018 [ # # ]: 0 : maProps[1].Type = ::getBooleanCppuType();
2019 : 0 : maProps[1].Attributes = -1;
2020 [ # # # # ]: 0 : }
2021 : :
2022 : : //-------------------------------------------------------------------------
2023 : 0 : SRSPropertySetInfo::~SRSPropertySetInfo()
2024 [ # # ]: 0 : {}
[ # # # # ]
2025 : :
2026 : : //-------------------------------------------------------------------------
2027 : : // XInterface methods.
2028 : : //-------------------------------------------------------------------------
2029 : :
2030 [ # # ][ # # ]: 0 : XINTERFACE_IMPL_2( SRSPropertySetInfo,
[ # # ]
2031 : : XTypeProvider,
2032 : : XPropertySetInfo );
2033 : :
2034 : : //-------------------------------------------------------------------------
2035 : : // XTypeProvider methods.
2036 : : //-------------------------------------------------------------------------
2037 : :
2038 [ # # ][ # # ]: 0 : XTYPEPROVIDER_IMPL_2( SRSPropertySetInfo,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2039 : : XTypeProvider,
2040 : : XPropertySetInfo );
2041 : :
2042 : : //-------------------------------------------------------------------------
2043 : : // XPropertySetInfo methods.
2044 : : //-------------------------------------------------------------------------
2045 : : Sequence< Property > SAL_CALL
2046 : 0 : SRSPropertySetInfo::getProperties() throw( RuntimeException )
2047 : : {
2048 : 0 : return Sequence < Property > ( maProps, 2 );
2049 : : }
2050 : :
2051 : : //-------------------------------------------------------------------------
2052 : : Property SAL_CALL
2053 : 0 : SRSPropertySetInfo::getPropertyByName( const OUString& Name )
2054 : : throw( UnknownPropertyException, RuntimeException )
2055 : : {
2056 [ # # ]: 0 : if ( Name.compareToAscii( "RowCount" ) == 0 )
2057 : 0 : return maProps[0];
2058 [ # # ]: 0 : else if ( Name.compareToAscii( "IsRowCountFinal" ) == 0 )
2059 : 0 : return maProps[1];
2060 : : else
2061 [ # # ]: 0 : throw UnknownPropertyException();
2062 : : }
2063 : :
2064 : : //-------------------------------------------------------------------------
2065 : : sal_Bool SAL_CALL
2066 : 0 : SRSPropertySetInfo::hasPropertyByName( const OUString& Name )
2067 : : throw( RuntimeException )
2068 : : {
2069 [ # # ]: 0 : if ( Name.compareToAscii( "RowCount" ) == 0 )
2070 : 0 : return sal_True;
2071 [ # # ]: 0 : else if ( Name.compareToAscii( "IsRowCountFinal" ) == 0 )
2072 : 0 : return sal_True;
2073 : : else
2074 : 0 : return sal_False;
2075 : : }
2076 : :
2077 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|