1*2f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2f86921cSAndrew Rist * distributed with this work for additional information
6*2f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2f86921cSAndrew Rist * "License"); you may not use this file except in compliance
9*2f86921cSAndrew Rist * with the License. You may obtain a copy of the License at
10*2f86921cSAndrew Rist *
11*2f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2f86921cSAndrew Rist *
13*2f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2f86921cSAndrew Rist * software distributed under the License is distributed on an
15*2f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2f86921cSAndrew Rist * KIND, either express or implied. See the License for the
17*2f86921cSAndrew Rist * specific language governing permissions and limitations
18*2f86921cSAndrew Rist * under the License.
19*2f86921cSAndrew Rist *
20*2f86921cSAndrew Rist *************************************************************/
21*2f86921cSAndrew Rist
22*2f86921cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <vector>
28cdf0e10cSrcweir #include <sortdynres.hxx>
29cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
30cdf0e10cSrcweir #include <com/sun/star/ucb/ContentResultSetCapability.hpp>
31cdf0e10cSrcweir #include <com/sun/star/ucb/ListActionType.hpp>
32cdf0e10cSrcweir #include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp>
33cdf0e10cSrcweir #include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp>
34cdf0e10cSrcweir #include <com/sun/star/ucb/XSourceInitialization.hpp>
35cdf0e10cSrcweir
36cdf0e10cSrcweir //-----------------------------------------------------------------------------
37cdf0e10cSrcweir using namespace com::sun::star::beans;
38cdf0e10cSrcweir using namespace com::sun::star::lang;
39cdf0e10cSrcweir using namespace com::sun::star::sdbc;
40cdf0e10cSrcweir using namespace com::sun::star::ucb;
41cdf0e10cSrcweir using namespace com::sun::star::uno;
42cdf0e10cSrcweir using namespace cppu;
43cdf0e10cSrcweir using namespace rtl;
44cdf0e10cSrcweir
45cdf0e10cSrcweir //=========================================================================
46cdf0e10cSrcweir
47cdf0e10cSrcweir // The mutex to synchronize access to containers.
getContainerMutex()48cdf0e10cSrcweir static osl::Mutex& getContainerMutex()
49cdf0e10cSrcweir {
50cdf0e10cSrcweir static osl::Mutex* pMutex = NULL;
51cdf0e10cSrcweir if( !pMutex )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
54cdf0e10cSrcweir if( !pMutex )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir static osl::Mutex aMutex;
57cdf0e10cSrcweir pMutex = &aMutex;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir }
60cdf0e10cSrcweir
61cdf0e10cSrcweir return *pMutex;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir
64cdf0e10cSrcweir //=========================================================================
65cdf0e10cSrcweir //
66cdf0e10cSrcweir // SortedDynamicResultSet
67cdf0e10cSrcweir //
68cdf0e10cSrcweir //=========================================================================
69cdf0e10cSrcweir
SortedDynamicResultSet(const Reference<XDynamicResultSet> & xOriginal,const Sequence<NumberedSortingInfo> & aOptions,const Reference<XAnyCompareFactory> & xCompFac,const Reference<XMultiServiceFactory> & xSMgr)70cdf0e10cSrcweir SortedDynamicResultSet::SortedDynamicResultSet(
71cdf0e10cSrcweir const Reference < XDynamicResultSet > &xOriginal,
72cdf0e10cSrcweir const Sequence < NumberedSortingInfo > &aOptions,
73cdf0e10cSrcweir const Reference < XAnyCompareFactory > &xCompFac,
74cdf0e10cSrcweir const Reference < XMultiServiceFactory > &xSMgr )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir mpDisposeEventListeners = NULL;
77cdf0e10cSrcweir mpOwnListener = new SortedDynamicResultSetListener( this );
78cdf0e10cSrcweir
79cdf0e10cSrcweir mxOwnListener = Reference< XDynamicResultSetListener >( mpOwnListener );
80cdf0e10cSrcweir
81cdf0e10cSrcweir mxOriginal = xOriginal;
82cdf0e10cSrcweir maOptions = aOptions;
83cdf0e10cSrcweir mxCompFac = xCompFac;
84cdf0e10cSrcweir mxSMgr = xSMgr;
85cdf0e10cSrcweir
86cdf0e10cSrcweir mpOne = NULL;
87cdf0e10cSrcweir mpTwo = NULL;
88cdf0e10cSrcweir
89cdf0e10cSrcweir mbGotWelcome = sal_False;
90cdf0e10cSrcweir mbUseOne = sal_True;
91cdf0e10cSrcweir mbStatic = sal_False;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir //--------------------------------------------------------------------------
~SortedDynamicResultSet()95cdf0e10cSrcweir SortedDynamicResultSet::~SortedDynamicResultSet()
96cdf0e10cSrcweir {
97cdf0e10cSrcweir mpOwnListener->impl_OwnerDies();
98cdf0e10cSrcweir mxOwnListener.clear();
99cdf0e10cSrcweir
100cdf0e10cSrcweir delete mpDisposeEventListeners;
101cdf0e10cSrcweir
102cdf0e10cSrcweir mxOne.clear();
103cdf0e10cSrcweir mxTwo.clear();
104cdf0e10cSrcweir mxOriginal.clear();
105cdf0e10cSrcweir
106cdf0e10cSrcweir mpOne = NULL;
107cdf0e10cSrcweir mpTwo = NULL;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir //--------------------------------------------------------------------------
111cdf0e10cSrcweir // XInterface methods.
112cdf0e10cSrcweir //--------------------------------------------------------------------------
113cdf0e10cSrcweir
114cdf0e10cSrcweir XINTERFACE_IMPL_4( SortedDynamicResultSet,
115cdf0e10cSrcweir XTypeProvider,
116cdf0e10cSrcweir XServiceInfo,
117cdf0e10cSrcweir XComponent, /* base class of XDynamicResultSet */
118cdf0e10cSrcweir XDynamicResultSet );
119cdf0e10cSrcweir
120cdf0e10cSrcweir //--------------------------------------------------------------------------
121cdf0e10cSrcweir // XTypeProvider methods.
122cdf0e10cSrcweir //--------------------------------------------------------------------------
123cdf0e10cSrcweir
124cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( SortedDynamicResultSet,
125cdf0e10cSrcweir XTypeProvider,
126cdf0e10cSrcweir XServiceInfo,
127cdf0e10cSrcweir XDynamicResultSet );
128cdf0e10cSrcweir
129cdf0e10cSrcweir //--------------------------------------------------------------------------
130cdf0e10cSrcweir // XServiceInfo methods.
131cdf0e10cSrcweir //--------------------------------------------------------------------------
132cdf0e10cSrcweir
133cdf0e10cSrcweir XSERVICEINFO_NOFACTORY_IMPL_1( SortedDynamicResultSet,
134cdf0e10cSrcweir OUString::createFromAscii(
135cdf0e10cSrcweir "com.sun.star.comp.ucb.SortedDynamicResultSet" ),
136cdf0e10cSrcweir OUString::createFromAscii(
137cdf0e10cSrcweir DYNAMIC_RESULTSET_SERVICE_NAME ) );
138cdf0e10cSrcweir
139cdf0e10cSrcweir //--------------------------------------------------------------------------
140cdf0e10cSrcweir // XComponent methods.
141cdf0e10cSrcweir //--------------------------------------------------------------------------
dispose()142cdf0e10cSrcweir void SAL_CALL SortedDynamicResultSet::dispose()
143cdf0e10cSrcweir throw( RuntimeException )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( maMutex );
146cdf0e10cSrcweir
147cdf0e10cSrcweir if ( mpDisposeEventListeners && mpDisposeEventListeners->getLength() )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir EventObject aEvt;
150cdf0e10cSrcweir aEvt.Source = static_cast< XComponent * >( this );
151cdf0e10cSrcweir mpDisposeEventListeners->disposeAndClear( aEvt );
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
154cdf0e10cSrcweir mxOne.clear();
155cdf0e10cSrcweir mxTwo.clear();
156cdf0e10cSrcweir mxOriginal.clear();
157cdf0e10cSrcweir
158cdf0e10cSrcweir mpOne = NULL;
159cdf0e10cSrcweir mpTwo = NULL;
160cdf0e10cSrcweir mbUseOne = sal_True;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
163cdf0e10cSrcweir //--------------------------------------------------------------------------
addEventListener(const Reference<XEventListener> & Listener)164cdf0e10cSrcweir void SAL_CALL SortedDynamicResultSet::addEventListener(
165cdf0e10cSrcweir const Reference< XEventListener >& Listener )
166cdf0e10cSrcweir throw( RuntimeException )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( maMutex );
169cdf0e10cSrcweir
170cdf0e10cSrcweir if ( !mpDisposeEventListeners )
171cdf0e10cSrcweir mpDisposeEventListeners =
172cdf0e10cSrcweir new OInterfaceContainerHelper( getContainerMutex() );
173cdf0e10cSrcweir
174cdf0e10cSrcweir mpDisposeEventListeners->addInterface( Listener );
175cdf0e10cSrcweir }
176cdf0e10cSrcweir
177cdf0e10cSrcweir //--------------------------------------------------------------------------
removeEventListener(const Reference<XEventListener> & Listener)178cdf0e10cSrcweir void SAL_CALL SortedDynamicResultSet::removeEventListener(
179cdf0e10cSrcweir const Reference< XEventListener >& Listener )
180cdf0e10cSrcweir throw( RuntimeException )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( maMutex );
183cdf0e10cSrcweir
184cdf0e10cSrcweir if ( mpDisposeEventListeners )
185cdf0e10cSrcweir mpDisposeEventListeners->removeInterface( Listener );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir //--------------------------------------------------------------------------
189cdf0e10cSrcweir // XDynamicResultSet methods.
190cdf0e10cSrcweir // ------------------------------------------------------------------------------
191cdf0e10cSrcweir Reference< XResultSet > SAL_CALL
getStaticResultSet()192cdf0e10cSrcweir SortedDynamicResultSet::getStaticResultSet()
193cdf0e10cSrcweir throw( ListenerAlreadySetException, RuntimeException )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( maMutex );
196cdf0e10cSrcweir
197cdf0e10cSrcweir if ( mxListener.is() )
198cdf0e10cSrcweir throw ListenerAlreadySetException();
199cdf0e10cSrcweir
200cdf0e10cSrcweir mbStatic = sal_True;
201cdf0e10cSrcweir
202cdf0e10cSrcweir if ( mxOriginal.is() )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir mpOne = new SortedResultSet( mxOriginal->getStaticResultSet() );
205cdf0e10cSrcweir mxOne = mpOne;
206cdf0e10cSrcweir mpOne->Initialize( maOptions, mxCompFac );
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir return mxOne;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
212cdf0e10cSrcweir // ------------------------------------------------------------------------------
213cdf0e10cSrcweir void SAL_CALL
setListener(const Reference<XDynamicResultSetListener> & Listener)214cdf0e10cSrcweir SortedDynamicResultSet::setListener( const Reference< XDynamicResultSetListener >& Listener )
215cdf0e10cSrcweir throw( ListenerAlreadySetException, RuntimeException )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( maMutex );
218cdf0e10cSrcweir
219cdf0e10cSrcweir if ( mxListener.is() )
220cdf0e10cSrcweir throw ListenerAlreadySetException();
221cdf0e10cSrcweir
222cdf0e10cSrcweir addEventListener( Reference< XEventListener >::query( Listener ) );
223cdf0e10cSrcweir
224cdf0e10cSrcweir mxListener = Listener;
225cdf0e10cSrcweir
226cdf0e10cSrcweir if ( mxOriginal.is() )
227cdf0e10cSrcweir mxOriginal->setListener( mxOwnListener );
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
230cdf0e10cSrcweir // ------------------------------------------------------------------------------
231cdf0e10cSrcweir void SAL_CALL
connectToCache(const Reference<XDynamicResultSet> & xCache)232cdf0e10cSrcweir SortedDynamicResultSet::connectToCache(
233cdf0e10cSrcweir const Reference< XDynamicResultSet > & xCache )
234cdf0e10cSrcweir throw( ListenerAlreadySetException,
235cdf0e10cSrcweir AlreadyInitializedException,
236cdf0e10cSrcweir ServiceNotFoundException,
237cdf0e10cSrcweir RuntimeException )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir if( mxListener.is() )
240cdf0e10cSrcweir throw ListenerAlreadySetException();
241cdf0e10cSrcweir
242cdf0e10cSrcweir if( mbStatic )
243cdf0e10cSrcweir throw ListenerAlreadySetException();
244cdf0e10cSrcweir
245cdf0e10cSrcweir Reference< XSourceInitialization > xTarget( xCache, UNO_QUERY );
246cdf0e10cSrcweir if( xTarget.is() && mxSMgr.is() )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir Reference< XCachedDynamicResultSetStubFactory > xStubFactory;
249cdf0e10cSrcweir try
250cdf0e10cSrcweir {
251cdf0e10cSrcweir xStubFactory = Reference< XCachedDynamicResultSetStubFactory >(
252cdf0e10cSrcweir mxSMgr->createInstance(
253cdf0e10cSrcweir OUString::createFromAscii(
254cdf0e10cSrcweir "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ) ),
255cdf0e10cSrcweir UNO_QUERY );
256cdf0e10cSrcweir }
257cdf0e10cSrcweir catch ( Exception const & )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir }
260cdf0e10cSrcweir
261cdf0e10cSrcweir if( xStubFactory.is() )
262cdf0e10cSrcweir {
263cdf0e10cSrcweir xStubFactory->connectToCache(
264cdf0e10cSrcweir this, xCache, Sequence< NumberedSortingInfo > (), NULL );
265cdf0e10cSrcweir return;
266cdf0e10cSrcweir }
267cdf0e10cSrcweir }
268cdf0e10cSrcweir throw ServiceNotFoundException();
269cdf0e10cSrcweir }
270cdf0e10cSrcweir
271cdf0e10cSrcweir // ------------------------------------------------------------------------------
272cdf0e10cSrcweir sal_Int16 SAL_CALL
getCapabilities()273cdf0e10cSrcweir SortedDynamicResultSet::getCapabilities()
274cdf0e10cSrcweir throw( RuntimeException )
275cdf0e10cSrcweir {
276cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( maMutex );
277cdf0e10cSrcweir
278cdf0e10cSrcweir sal_Int16 nCaps = 0;
279cdf0e10cSrcweir
280cdf0e10cSrcweir if ( mxOriginal.is() )
281cdf0e10cSrcweir nCaps = mxOriginal->getCapabilities();
282cdf0e10cSrcweir
283cdf0e10cSrcweir nCaps |= ContentResultSetCapability::SORTED;
284cdf0e10cSrcweir
285cdf0e10cSrcweir return nCaps;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir
288cdf0e10cSrcweir //--------------------------------------------------------------------------
289cdf0e10cSrcweir // XDynamicResultSetListener methods.
290cdf0e10cSrcweir // ------------------------------------------------------------------------------
291cdf0e10cSrcweir
292cdf0e10cSrcweir /** In the first notify-call the listener gets the two
293cdf0e10cSrcweir <type>XResultSet</type>s and has to hold them. The <type>XResultSet</type>s
294cdf0e10cSrcweir are implementations of the service <type>ContentResultSet</type>.
295cdf0e10cSrcweir
296cdf0e10cSrcweir <p>The notified new <type>XResultSet</type> will stay valid after returning
297cdf0e10cSrcweir notification. The old one will become invalid after returning notification.
298cdf0e10cSrcweir
299cdf0e10cSrcweir <p>While in notify-call the listener is allowed to read old and new version,
300cdf0e10cSrcweir except in the first call, where only the new Resultset is valid.
301cdf0e10cSrcweir
302cdf0e10cSrcweir <p>The Listener is allowed to blockade this call, until he really want to go
303cdf0e10cSrcweir to the new version. The only situation, where the listener has to return the
304cdf0e10cSrcweir update call at once is, while he disposes his broadcaster or while he is
305cdf0e10cSrcweir removing himsef as listener (otherwise you deadlock)!!!
306cdf0e10cSrcweir */
307cdf0e10cSrcweir void SAL_CALL
impl_notify(const ListEvent & Changes)308cdf0e10cSrcweir SortedDynamicResultSet::impl_notify( const ListEvent& Changes )
309cdf0e10cSrcweir throw( RuntimeException )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( maMutex );
312cdf0e10cSrcweir
313cdf0e10cSrcweir sal_Bool bHasNew = sal_False;
314cdf0e10cSrcweir sal_Bool bHasModified = sal_False;
315cdf0e10cSrcweir
316cdf0e10cSrcweir SortedResultSet *pCurSet = NULL;
317cdf0e10cSrcweir
318cdf0e10cSrcweir // mxNew und mxOld vertauschen und anschliessend die Tabellen von Old
319cdf0e10cSrcweir // nach New kopieren
320cdf0e10cSrcweir if ( mbGotWelcome )
321cdf0e10cSrcweir {
322cdf0e10cSrcweir if ( mbUseOne )
323cdf0e10cSrcweir {
324cdf0e10cSrcweir mbUseOne = sal_False;
325cdf0e10cSrcweir mpTwo->CopyData( mpOne );
326cdf0e10cSrcweir pCurSet = mpTwo;
327cdf0e10cSrcweir }
328cdf0e10cSrcweir else
329cdf0e10cSrcweir {
330cdf0e10cSrcweir mbUseOne = sal_True;
331cdf0e10cSrcweir mpOne->CopyData( mpTwo );
332cdf0e10cSrcweir pCurSet = mpOne;
333cdf0e10cSrcweir }
334cdf0e10cSrcweir }
335cdf0e10cSrcweir
336cdf0e10cSrcweir Any aRet;
337cdf0e10cSrcweir
338cdf0e10cSrcweir try {
339cdf0e10cSrcweir aRet = pCurSet->getPropertyValue( OUString::createFromAscii( "IsRowCountFinal" ) );
340cdf0e10cSrcweir }
341cdf0e10cSrcweir catch ( UnknownPropertyException ) {}
342cdf0e10cSrcweir catch ( WrappedTargetException ) {}
343cdf0e10cSrcweir
344cdf0e10cSrcweir long nOldCount = pCurSet->GetCount();
345cdf0e10cSrcweir sal_Bool bWasFinal = false;
346cdf0e10cSrcweir
347cdf0e10cSrcweir aRet >>= bWasFinal;
348cdf0e10cSrcweir
349cdf0e10cSrcweir // handle the actions in the list
350cdf0e10cSrcweir for ( long i=0; i<Changes.Changes.getLength(); i++ )
351cdf0e10cSrcweir {
352cdf0e10cSrcweir const ListAction aAction = Changes.Changes[i];
353cdf0e10cSrcweir switch ( aAction.ListActionType )
354cdf0e10cSrcweir {
355cdf0e10cSrcweir case ListActionType::WELCOME:
356cdf0e10cSrcweir {
357cdf0e10cSrcweir WelcomeDynamicResultSetStruct aWelcome;
358cdf0e10cSrcweir if ( aAction.ActionInfo >>= aWelcome )
359cdf0e10cSrcweir {
360cdf0e10cSrcweir mpTwo = new SortedResultSet( aWelcome.Old );
361cdf0e10cSrcweir mxTwo = mpTwo;
362cdf0e10cSrcweir mpOne = new SortedResultSet( aWelcome.New );
363cdf0e10cSrcweir mxOne = mpOne;
364cdf0e10cSrcweir mpOne->Initialize( maOptions, mxCompFac );
365cdf0e10cSrcweir mbGotWelcome = sal_True;
366cdf0e10cSrcweir mbUseOne = sal_True;
367cdf0e10cSrcweir pCurSet = mpOne;
368cdf0e10cSrcweir
369cdf0e10cSrcweir aWelcome.Old = mxTwo;
370cdf0e10cSrcweir aWelcome.New = mxOne;
371cdf0e10cSrcweir
372cdf0e10cSrcweir ListAction *pWelcomeAction = new ListAction;
373cdf0e10cSrcweir pWelcomeAction->ActionInfo <<= aWelcome;
374cdf0e10cSrcweir pWelcomeAction->Position = 0;
375cdf0e10cSrcweir pWelcomeAction->Count = 0;
376cdf0e10cSrcweir pWelcomeAction->ListActionType = ListActionType::WELCOME;
377cdf0e10cSrcweir
378cdf0e10cSrcweir maActions.Insert( pWelcomeAction );
379cdf0e10cSrcweir }
380cdf0e10cSrcweir else
381cdf0e10cSrcweir {
382cdf0e10cSrcweir // throw RuntimeException();
383cdf0e10cSrcweir }
384cdf0e10cSrcweir break;
385cdf0e10cSrcweir }
386cdf0e10cSrcweir case ListActionType::INSERTED:
387cdf0e10cSrcweir {
388cdf0e10cSrcweir pCurSet->InsertNew( aAction.Position, aAction.Count );
389cdf0e10cSrcweir bHasNew = sal_True;
390cdf0e10cSrcweir break;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir case ListActionType::REMOVED:
393cdf0e10cSrcweir {
394cdf0e10cSrcweir pCurSet->Remove( aAction.Position,
395cdf0e10cSrcweir aAction.Count,
396cdf0e10cSrcweir &maActions );
397cdf0e10cSrcweir break;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir case ListActionType::MOVED:
400cdf0e10cSrcweir {
401cdf0e10cSrcweir long nOffset = 0;
402cdf0e10cSrcweir if ( aAction.ActionInfo >>= nOffset )
403cdf0e10cSrcweir {
404cdf0e10cSrcweir pCurSet->Move( aAction.Position,
405cdf0e10cSrcweir aAction.Count,
406cdf0e10cSrcweir nOffset );
407cdf0e10cSrcweir }
408cdf0e10cSrcweir break;
409cdf0e10cSrcweir }
410cdf0e10cSrcweir case ListActionType::PROPERTIES_CHANGED:
411cdf0e10cSrcweir {
412cdf0e10cSrcweir pCurSet->SetChanged( aAction.Position, aAction.Count );
413cdf0e10cSrcweir bHasModified = sal_True;
414cdf0e10cSrcweir break;
415cdf0e10cSrcweir }
416cdf0e10cSrcweir default: break;
417cdf0e10cSrcweir }
418cdf0e10cSrcweir }
419cdf0e10cSrcweir
420cdf0e10cSrcweir if ( bHasModified )
421cdf0e10cSrcweir pCurSet->ResortModified( &maActions );
422cdf0e10cSrcweir
423cdf0e10cSrcweir if ( bHasNew )
424cdf0e10cSrcweir pCurSet->ResortNew( &maActions );
425cdf0e10cSrcweir
426cdf0e10cSrcweir // send the new actions with a notify to the listeners
427cdf0e10cSrcweir SendNotify();
428cdf0e10cSrcweir
429cdf0e10cSrcweir // check for propertyChangeEvents
430cdf0e10cSrcweir pCurSet->CheckProperties( nOldCount, bWasFinal );
431cdf0e10cSrcweir }
432cdf0e10cSrcweir
433cdf0e10cSrcweir //-----------------------------------------------------------------
434cdf0e10cSrcweir // XEventListener
435cdf0e10cSrcweir //-----------------------------------------------------------------
436cdf0e10cSrcweir void SAL_CALL
impl_disposing(const EventObject &)437cdf0e10cSrcweir SortedDynamicResultSet::impl_disposing( const EventObject& )
438cdf0e10cSrcweir throw( RuntimeException )
439cdf0e10cSrcweir {
440cdf0e10cSrcweir mxListener.clear();
441cdf0e10cSrcweir mxOriginal.clear();
442cdf0e10cSrcweir }
443cdf0e10cSrcweir
444cdf0e10cSrcweir // ------------------------------------------------------------------------------
445cdf0e10cSrcweir // private methods
446cdf0e10cSrcweir // ------------------------------------------------------------------------------
SendNotify()447cdf0e10cSrcweir void SortedDynamicResultSet::SendNotify()
448cdf0e10cSrcweir {
449cdf0e10cSrcweir long nCount = maActions.Count();
450cdf0e10cSrcweir
451cdf0e10cSrcweir if ( nCount && mxListener.is() )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir Sequence< ListAction > aActionList( maActions.Count() );
454cdf0e10cSrcweir ListAction *pActionList = aActionList.getArray();
455cdf0e10cSrcweir
456cdf0e10cSrcweir for ( long i=0; i<nCount; i++ )
457cdf0e10cSrcweir {
458cdf0e10cSrcweir pActionList[ i ] = *(maActions.GetAction( i ));
459cdf0e10cSrcweir }
460cdf0e10cSrcweir
461cdf0e10cSrcweir ListEvent aNewEvent;
462cdf0e10cSrcweir aNewEvent.Changes = aActionList;
463cdf0e10cSrcweir
464cdf0e10cSrcweir mxListener->notify( aNewEvent );
465cdf0e10cSrcweir }
466cdf0e10cSrcweir
467cdf0e10cSrcweir // clean up
468cdf0e10cSrcweir maActions.Clear();
469cdf0e10cSrcweir }
470cdf0e10cSrcweir
471cdf0e10cSrcweir //=========================================================================
472cdf0e10cSrcweir //
473cdf0e10cSrcweir // SortedDynamicResultSetFactory
474cdf0e10cSrcweir //
475cdf0e10cSrcweir //=========================================================================
SortedDynamicResultSetFactory(const Reference<XMultiServiceFactory> & rSMgr)476cdf0e10cSrcweir SortedDynamicResultSetFactory::SortedDynamicResultSetFactory(
477cdf0e10cSrcweir const Reference< XMultiServiceFactory > & rSMgr )
478cdf0e10cSrcweir {
479cdf0e10cSrcweir mxSMgr = rSMgr;
480cdf0e10cSrcweir }
481cdf0e10cSrcweir
482cdf0e10cSrcweir //--------------------------------------------------------------------------
~SortedDynamicResultSetFactory()483cdf0e10cSrcweir SortedDynamicResultSetFactory::~SortedDynamicResultSetFactory()
484cdf0e10cSrcweir {
485cdf0e10cSrcweir }
486cdf0e10cSrcweir
487cdf0e10cSrcweir //--------------------------------------------------------------------------
488cdf0e10cSrcweir // XInterface methods.
489cdf0e10cSrcweir //--------------------------------------------------------------------------
490cdf0e10cSrcweir
491cdf0e10cSrcweir XINTERFACE_IMPL_3( SortedDynamicResultSetFactory,
492cdf0e10cSrcweir XTypeProvider,
493cdf0e10cSrcweir XServiceInfo,
494cdf0e10cSrcweir XSortedDynamicResultSetFactory );
495cdf0e10cSrcweir
496cdf0e10cSrcweir //--------------------------------------------------------------------------
497cdf0e10cSrcweir // XTypeProvider methods.
498cdf0e10cSrcweir //--------------------------------------------------------------------------
499cdf0e10cSrcweir
500cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( SortedDynamicResultSetFactory,
501cdf0e10cSrcweir XTypeProvider,
502cdf0e10cSrcweir XServiceInfo,
503cdf0e10cSrcweir XSortedDynamicResultSetFactory );
504cdf0e10cSrcweir
505cdf0e10cSrcweir //--------------------------------------------------------------------------
506cdf0e10cSrcweir // XServiceInfo methods.
507cdf0e10cSrcweir //--------------------------------------------------------------------------
508cdf0e10cSrcweir
509cdf0e10cSrcweir XSERVICEINFO_IMPL_1( SortedDynamicResultSetFactory,
510cdf0e10cSrcweir OUString::createFromAscii(
511cdf0e10cSrcweir "com.sun.star.comp.ucb.SortedDynamicResultSetFactory" ),
512cdf0e10cSrcweir OUString::createFromAscii(
513cdf0e10cSrcweir DYNAMIC_RESULTSET_FACTORY_NAME ) );
514cdf0e10cSrcweir
515cdf0e10cSrcweir //--------------------------------------------------------------------------
516cdf0e10cSrcweir // Service factory implementation.
517cdf0e10cSrcweir //--------------------------------------------------------------------------
518cdf0e10cSrcweir
519cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( SortedDynamicResultSetFactory );
520cdf0e10cSrcweir
521cdf0e10cSrcweir //--------------------------------------------------------------------------
522cdf0e10cSrcweir // SortedDynamicResultSetFactory methods.
523cdf0e10cSrcweir //--------------------------------------------------------------------------
524cdf0e10cSrcweir Reference< XDynamicResultSet > SAL_CALL
createSortedDynamicResultSet(const Reference<XDynamicResultSet> & Source,const Sequence<NumberedSortingInfo> & Info,const Reference<XAnyCompareFactory> & CompareFactory)525cdf0e10cSrcweir SortedDynamicResultSetFactory::createSortedDynamicResultSet(
526cdf0e10cSrcweir const Reference< XDynamicResultSet > & Source,
527cdf0e10cSrcweir const Sequence< NumberedSortingInfo > & Info,
528cdf0e10cSrcweir const Reference< XAnyCompareFactory > & CompareFactory )
529cdf0e10cSrcweir throw( RuntimeException )
530cdf0e10cSrcweir {
531cdf0e10cSrcweir Reference< XDynamicResultSet > xRet;
532cdf0e10cSrcweir xRet = new SortedDynamicResultSet( Source, Info, CompareFactory, mxSMgr );
533cdf0e10cSrcweir return xRet;
534cdf0e10cSrcweir }
535cdf0e10cSrcweir
536cdf0e10cSrcweir //=========================================================================
537cdf0e10cSrcweir //
538cdf0e10cSrcweir // EventList
539cdf0e10cSrcweir //
540cdf0e10cSrcweir //=========================================================================
541cdf0e10cSrcweir
Clear()542cdf0e10cSrcweir void EventList::Clear()
543cdf0e10cSrcweir {
544cdf0e10cSrcweir for ( std::deque< LISTACTION* >::size_type i = 0;
545cdf0e10cSrcweir i < maData.size(); ++i )
546cdf0e10cSrcweir {
547cdf0e10cSrcweir delete maData[i];
548cdf0e10cSrcweir }
549cdf0e10cSrcweir
550cdf0e10cSrcweir maData.clear();
551cdf0e10cSrcweir }
552cdf0e10cSrcweir
553cdf0e10cSrcweir //--------------------------------------------------------------------------
AddEvent(long nType,long nPos,long nCount)554cdf0e10cSrcweir void EventList::AddEvent( long nType, long nPos, long nCount )
555cdf0e10cSrcweir {
556cdf0e10cSrcweir ListAction *pAction = new ListAction;
557cdf0e10cSrcweir pAction->Position = nPos;
558cdf0e10cSrcweir pAction->Count = nCount;
559cdf0e10cSrcweir pAction->ListActionType = nType;
560cdf0e10cSrcweir
561cdf0e10cSrcweir Insert( pAction );
562cdf0e10cSrcweir }
563cdf0e10cSrcweir
564cdf0e10cSrcweir //=================================================================
565cdf0e10cSrcweir //
566cdf0e10cSrcweir // SortedDynamicResultSetListener
567cdf0e10cSrcweir //
568cdf0e10cSrcweir //=================================================================
569cdf0e10cSrcweir
SortedDynamicResultSetListener(SortedDynamicResultSet * mOwner)570cdf0e10cSrcweir SortedDynamicResultSetListener::SortedDynamicResultSetListener(
571cdf0e10cSrcweir SortedDynamicResultSet *mOwner )
572cdf0e10cSrcweir {
573cdf0e10cSrcweir mpOwner = mOwner;
574cdf0e10cSrcweir }
575cdf0e10cSrcweir
576cdf0e10cSrcweir //-----------------------------------------------------------------
~SortedDynamicResultSetListener()577cdf0e10cSrcweir SortedDynamicResultSetListener::~SortedDynamicResultSetListener()
578cdf0e10cSrcweir {
579cdf0e10cSrcweir }
580cdf0e10cSrcweir
581cdf0e10cSrcweir //-----------------------------------------------------------------
582cdf0e10cSrcweir // XInterface methods.
583cdf0e10cSrcweir //-----------------------------------------------------------------
584cdf0e10cSrcweir
585cdf0e10cSrcweir XINTERFACE_IMPL_2( SortedDynamicResultSetListener,
586cdf0e10cSrcweir XEventListener, /* base class of XDynamicResultSetListener */
587cdf0e10cSrcweir XDynamicResultSetListener );
588cdf0e10cSrcweir
589cdf0e10cSrcweir //-----------------------------------------------------------------
590cdf0e10cSrcweir // XEventListener ( base of XDynamicResultSetListener )
591cdf0e10cSrcweir //-----------------------------------------------------------------
592cdf0e10cSrcweir void SAL_CALL
disposing(const EventObject & Source)593cdf0e10cSrcweir SortedDynamicResultSetListener::disposing( const EventObject& Source )
594cdf0e10cSrcweir throw( RuntimeException )
595cdf0e10cSrcweir {
596cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( maMutex );
597cdf0e10cSrcweir
598cdf0e10cSrcweir if ( mpOwner )
599cdf0e10cSrcweir mpOwner->impl_disposing( Source );
600cdf0e10cSrcweir }
601cdf0e10cSrcweir
602cdf0e10cSrcweir //-----------------------------------------------------------------
603cdf0e10cSrcweir // XDynamicResultSetListener
604cdf0e10cSrcweir //-----------------------------------------------------------------
605cdf0e10cSrcweir void SAL_CALL
notify(const ListEvent & Changes)606cdf0e10cSrcweir SortedDynamicResultSetListener::notify( const ListEvent& Changes )
607cdf0e10cSrcweir throw( RuntimeException )
608cdf0e10cSrcweir {
609cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( maMutex );
610cdf0e10cSrcweir
611cdf0e10cSrcweir if ( mpOwner )
612cdf0e10cSrcweir mpOwner->impl_notify( Changes );
613cdf0e10cSrcweir }
614cdf0e10cSrcweir
615cdf0e10cSrcweir //-----------------------------------------------------------------
616cdf0e10cSrcweir // own methods:
617cdf0e10cSrcweir //-----------------------------------------------------------------
618cdf0e10cSrcweir void SAL_CALL
impl_OwnerDies()619cdf0e10cSrcweir SortedDynamicResultSetListener::impl_OwnerDies()
620cdf0e10cSrcweir {
621cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( maMutex );
622cdf0e10cSrcweir mpOwner = NULL;
623cdf0e10cSrcweir }
624cdf0e10cSrcweir
625