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