update dev300-m58
[ooovba.git] / ucb / source / cacher / cacheddynamicresultsetstub.cxx
blobf335210860d69f8b97bbeb5098e31094b0e967fe
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cacheddynamicresultsetstub.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
34 #include <cacheddynamicresultsetstub.hxx>
35 #include <com/sun/star/sdbc/XResultSet.hpp>
36 #include <cachedcontentresultsetstub.hxx>
37 #include <com/sun/star/ucb/ContentResultSetCapability.hpp>
38 #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
39 #include <osl/diagnose.h>
41 using namespace com::sun::star::lang;
42 using namespace com::sun::star::sdbc;
43 using namespace com::sun::star::ucb;
44 using namespace com::sun::star::uno;
45 using namespace rtl;
47 CachedDynamicResultSetStub::CachedDynamicResultSetStub(
48 Reference< XDynamicResultSet > xOrigin
49 , const Reference< XMultiServiceFactory > & xSMgr )
50 : DynamicResultSetWrapper( xOrigin, xSMgr )
52 OSL_ENSURE( m_xSMgr.is(), "need Multiservicefactory to create stub" );
53 impl_init();
56 CachedDynamicResultSetStub::~CachedDynamicResultSetStub()
58 impl_deinit();
61 //virtual
62 void SAL_CALL CachedDynamicResultSetStub
63 ::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet )
65 DynamicResultSetWrapper::impl_InitResultSetOne( xResultSet );
66 OSL_ENSURE( m_xSourceResultOne.is(), "need source resultset" );
68 Reference< XResultSet > xStub(
69 new CachedContentResultSetStub( m_xSourceResultOne ) );
71 osl::Guard< osl::Mutex > aGuard( m_aMutex );
72 m_xMyResultOne = xStub;
75 //virtual
76 void SAL_CALL CachedDynamicResultSetStub
77 ::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet )
79 DynamicResultSetWrapper::impl_InitResultSetTwo( xResultSet );
80 OSL_ENSURE( m_xSourceResultTwo.is(), "need source resultset" );
82 Reference< XResultSet > xStub(
83 new CachedContentResultSetStub( m_xSourceResultTwo ) );
85 osl::Guard< osl::Mutex > aGuard( m_aMutex );
86 m_xMyResultTwo = xStub;
89 //--------------------------------------------------------------------------
90 // XInterface methods.
91 //--------------------------------------------------------------------------
92 XINTERFACE_COMMON_IMPL( CachedDynamicResultSetStub )
94 Any SAL_CALL CachedDynamicResultSetStub
95 ::queryInterface( const Type& rType )
96 throw ( RuntimeException )
98 //list all interfaces inclusive baseclasses of interfaces
100 Any aRet = DynamicResultSetWrapper::queryInterface( rType );
101 if( aRet.hasValue() )
102 return aRet;
104 aRet = cppu::queryInterface( rType,
105 static_cast< XTypeProvider* >( this )
106 , static_cast< XServiceInfo* >( this )
108 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
111 //--------------------------------------------------------------------------
112 // XTypeProvider methods.
113 //--------------------------------------------------------------------------
114 //list all interfaces exclusive baseclasses
115 XTYPEPROVIDER_IMPL_5( CachedDynamicResultSetStub
116 , XTypeProvider
117 , XServiceInfo
118 , XDynamicResultSet
119 , XDynamicResultSetListener
120 , XSourceInitialization
123 //--------------------------------------------------------------------------
124 // XServiceInfo methods.
125 //--------------------------------------------------------------------------
127 XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSetStub,
128 OUString::createFromAscii(
129 "com.sun.star.comp.ucb.CachedDynamicResultSetStub" ),
130 OUString::createFromAscii(
131 CACHED_DRS_STUB_SERVICE_NAME ) );
133 //--------------------------------------------------------------------------
134 //--------------------------------------------------------------------------
135 // class CachedDynamicResultSetStubFactory
136 //--------------------------------------------------------------------------
137 //--------------------------------------------------------------------------
139 CachedDynamicResultSetStubFactory::CachedDynamicResultSetStubFactory(
140 const Reference< XMultiServiceFactory > & rSMgr )
142 m_xSMgr = rSMgr;
145 CachedDynamicResultSetStubFactory::~CachedDynamicResultSetStubFactory()
149 //--------------------------------------------------------------------------
150 // CachedDynamicResultSetStubFactory XInterface methods.
151 //--------------------------------------------------------------------------
153 XINTERFACE_IMPL_3( CachedDynamicResultSetStubFactory,
154 XTypeProvider,
155 XServiceInfo,
156 XCachedDynamicResultSetStubFactory );
158 //--------------------------------------------------------------------------
159 // CachedDynamicResultSetStubFactory XTypeProvider methods.
160 //--------------------------------------------------------------------------
162 XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetStubFactory,
163 XTypeProvider,
164 XServiceInfo,
165 XCachedDynamicResultSetStubFactory );
167 //--------------------------------------------------------------------------
168 // CachedDynamicResultSetStubFactory XServiceInfo methods.
169 //--------------------------------------------------------------------------
171 XSERVICEINFO_IMPL_1( CachedDynamicResultSetStubFactory,
172 OUString::createFromAscii(
173 "com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory" ),
174 OUString::createFromAscii(
175 CACHED_DRS_STUB_FACTORY_NAME ) );
177 //--------------------------------------------------------------------------
178 // Service factory implementation.
179 //--------------------------------------------------------------------------
181 ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetStubFactory );
183 //--------------------------------------------------------------------------
184 // CachedDynamicResultSetStubFactory XCachedDynamicResultSetStubFactory methods.
185 //--------------------------------------------------------------------------
187 //virtual
188 Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetStubFactory
189 ::createCachedDynamicResultSetStub(
190 const Reference< XDynamicResultSet > & Source )
191 throw( RuntimeException )
193 Reference< XDynamicResultSet > xRet;
194 xRet = new CachedDynamicResultSetStub( Source, m_xSMgr );
195 return xRet;
198 //virtual
199 void SAL_CALL CachedDynamicResultSetStubFactory
200 ::connectToCache(
201 const Reference< XDynamicResultSet > & Source
202 , const Reference< XDynamicResultSet > & TargetCache
203 , const Sequence< NumberedSortingInfo > & SortingInfo
204 , const Reference< XAnyCompareFactory > & CompareFactory
206 throw ( ListenerAlreadySetException
207 , AlreadyInitializedException
208 , RuntimeException )
210 OSL_ENSURE( Source.is(), "a Source is needed" );
211 OSL_ENSURE( TargetCache.is(), "a TargetCache is needed" );
213 Reference< XDynamicResultSet > xSource( Source );
214 if( SortingInfo.getLength() &&
215 !( xSource->getCapabilities() & ContentResultSetCapability::SORTED )
218 Reference< XSortedDynamicResultSetFactory > xSortFactory;
221 xSortFactory = Reference< XSortedDynamicResultSetFactory >(
222 m_xSMgr->createInstance( OUString::createFromAscii(
223 "com.sun.star.ucb.SortedDynamicResultSetFactory" ) ),
224 UNO_QUERY );
226 catch ( Exception const & )
230 if( xSortFactory.is() )
232 Reference< XDynamicResultSet > xSorted(
233 xSortFactory->createSortedDynamicResultSet(
234 Source, SortingInfo, CompareFactory ) );
235 if( xSorted.is() )
236 xSource = xSorted;
240 Reference< XDynamicResultSet > xStub(
241 new CachedDynamicResultSetStub( xSource, m_xSMgr ) );
243 Reference< XSourceInitialization > xTarget( TargetCache, UNO_QUERY );
244 OSL_ENSURE( xTarget.is(), "Target must have interface XSourceInitialization" );
246 xTarget->setSource( xStub );