1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "cacheddynamicresultsetstub.hxx"
22 #include <com/sun/star/sdbc/XResultSet.hpp>
23 #include "cachedcontentresultsetstub.hxx"
24 #include <com/sun/star/ucb/ContentResultSetCapability.hpp>
25 #include <com/sun/star/ucb/SortedDynamicResultSetFactory.hpp>
26 #include <osl/diagnose.h>
27 #include <comphelper/processfactory.hxx>
28 #include <ucbhelper/getcomponentcontext.hxx>
29 #include <cppuhelper/queryinterface.hxx>
31 using namespace com::sun::star::lang
;
32 using namespace com::sun::star::sdbc
;
33 using namespace com::sun::star::ucb
;
34 using namespace com::sun::star::uno
;
37 CachedDynamicResultSetStub::CachedDynamicResultSetStub(
38 Reference
< XDynamicResultSet
> const & xOrigin
39 , const Reference
< XComponentContext
> & rxContext
)
40 : DynamicResultSetWrapper( xOrigin
, rxContext
)
42 OSL_ENSURE( m_xContext
.is(), "need Multiservicefactory to create stub" );
46 CachedDynamicResultSetStub::~CachedDynamicResultSetStub()
52 void CachedDynamicResultSetStub
53 ::impl_InitResultSetOne( const Reference
< XResultSet
>& xResultSet
)
55 DynamicResultSetWrapper::impl_InitResultSetOne( xResultSet
);
56 OSL_ENSURE( m_xSourceResultOne
.is(), "need source resultset" );
58 Reference
< XResultSet
> xStub(
59 new CachedContentResultSetStub( m_xSourceResultOne
) );
61 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
62 m_xMyResultOne
= xStub
;
66 void CachedDynamicResultSetStub
67 ::impl_InitResultSetTwo( const Reference
< XResultSet
>& xResultSet
)
69 DynamicResultSetWrapper::impl_InitResultSetTwo( xResultSet
);
70 OSL_ENSURE( m_xSourceResultTwo
.is(), "need source resultset" );
72 Reference
< XResultSet
> xStub(
73 new CachedContentResultSetStub( m_xSourceResultTwo
) );
75 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
76 m_xMyResultTwo
= xStub
;
80 // XInterface methods.
81 void SAL_CALL
CachedDynamicResultSetStub::acquire()
84 OWeakObject::acquire();
87 void SAL_CALL
CachedDynamicResultSetStub::release()
90 OWeakObject::release();
93 Any SAL_CALL CachedDynamicResultSetStub
94 ::queryInterface( const Type
& rType
)
96 //list all interfaces inclusive baseclasses of interfaces
98 Any aRet
= DynamicResultSetWrapper::queryInterface( rType
);
102 aRet
= cppu::queryInterface( rType
,
103 static_cast< XTypeProvider
* >( this )
104 , static_cast< XServiceInfo
* >( this )
106 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
110 // XTypeProvider methods.
112 //list all interfaces exclusive baseclasses
113 XTYPEPROVIDER_IMPL_5( CachedDynamicResultSetStub
117 , XDynamicResultSetListener
118 , XSourceInitialization
122 // XServiceInfo methods.
124 OUString SAL_CALL
CachedDynamicResultSetStub::getImplementationName()
126 return OUString( "com.sun.star.comp.ucb.CachedDynamicResultSetStub" );
129 sal_Bool SAL_CALL
CachedDynamicResultSetStub::supportsService( const OUString
& ServiceName
)
131 return cppu::supportsService( this, ServiceName
);
134 css::uno::Sequence
< OUString
> SAL_CALL
CachedDynamicResultSetStub::getSupportedServiceNames()
136 return { CACHED_DRS_STUB_SERVICE_NAME
};
141 // class CachedDynamicResultSetStubFactory
144 CachedDynamicResultSetStubFactory::CachedDynamicResultSetStubFactory(
145 const Reference
< XComponentContext
> & rxContext
)
147 m_xContext
= rxContext
;
150 CachedDynamicResultSetStubFactory::~CachedDynamicResultSetStubFactory()
155 // CachedDynamicResultSetStubFactory XInterface methods.
156 void SAL_CALL
CachedDynamicResultSetStubFactory::acquire()
159 OWeakObject::acquire();
162 void SAL_CALL
CachedDynamicResultSetStubFactory::release()
165 OWeakObject::release();
168 css::uno::Any SAL_CALL
CachedDynamicResultSetStubFactory::queryInterface( const css::uno::Type
& rType
)
170 css::uno::Any aRet
= cppu::queryInterface( rType
,
171 static_cast< XTypeProvider
* >(this),
172 static_cast< XServiceInfo
* >(this),
173 static_cast< XCachedDynamicResultSetStubFactory
* >(this)
175 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
178 // CachedDynamicResultSetStubFactory XTypeProvider methods.
181 XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetStubFactory
,
184 XCachedDynamicResultSetStubFactory
);
187 // CachedDynamicResultSetStubFactory XServiceInfo methods.
189 XSERVICEINFO_COMMOM_IMPL( CachedDynamicResultSetStubFactory
,
190 OUString( "com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory" ) )
191 /// @throws css::uno::Exception
192 static css::uno::Reference
< css::uno::XInterface
>
193 CachedDynamicResultSetStubFactory_CreateInstance( const css::uno::Reference
< css::lang::XMultiServiceFactory
> & rSMgr
)
195 css::lang::XServiceInfo
* pX
=
196 static_cast<css::lang::XServiceInfo
*>(new CachedDynamicResultSetStubFactory( ucbhelper::getComponentContext(rSMgr
) ));
197 return css::uno::Reference
< css::uno::XInterface
>::query( pX
);
200 css::uno::Sequence
< OUString
>
201 CachedDynamicResultSetStubFactory::getSupportedServiceNames_Static()
203 css::uno::Sequence
< OUString
> aSNS
{ CACHED_DRS_STUB_FACTORY_NAME
};
207 // Service factory implementation.
210 ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetStubFactory
);
213 // CachedDynamicResultSetStubFactory XCachedDynamicResultSetStubFactory methods.
217 Reference
< XDynamicResultSet
> SAL_CALL CachedDynamicResultSetStubFactory
218 ::createCachedDynamicResultSetStub(
219 const Reference
< XDynamicResultSet
> & Source
)
221 Reference
< XDynamicResultSet
> xRet
;
222 xRet
= new CachedDynamicResultSetStub( Source
, m_xContext
);
227 void SAL_CALL CachedDynamicResultSetStubFactory
229 const Reference
< XDynamicResultSet
> & Source
230 , const Reference
< XDynamicResultSet
> & TargetCache
231 , const Sequence
< NumberedSortingInfo
> & SortingInfo
232 , const Reference
< XAnyCompareFactory
> & CompareFactory
235 OSL_ENSURE( Source
.is(), "a Source is needed" );
236 OSL_ENSURE( TargetCache
.is(), "a TargetCache is needed" );
238 Reference
< XDynamicResultSet
> xSource( Source
);
239 if( SortingInfo
.getLength() &&
240 !( xSource
->getCapabilities() & ContentResultSetCapability::SORTED
)
243 Reference
< XSortedDynamicResultSetFactory
> xSortFactory
;
246 xSortFactory
= SortedDynamicResultSetFactory::create( m_xContext
);
248 catch ( Exception
const & )
252 if( xSortFactory
.is() )
254 Reference
< XDynamicResultSet
> xSorted(
255 xSortFactory
->createSortedDynamicResultSet(
256 Source
, SortingInfo
, CompareFactory
) );
262 Reference
< XDynamicResultSet
> xStub(
263 new CachedDynamicResultSetStub( xSource
, m_xContext
) );
265 Reference
< XSourceInitialization
> xTarget( TargetCache
, UNO_QUERY
);
266 OSL_ENSURE( xTarget
.is(), "Target must have interface XSourceInitialization" );
268 xTarget
->setSource( xStub
);
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */