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 "cachedcontentresultsetstub.hxx"
23 #include <com/sun/star/ucb/ContentResultSetCapability.hpp>
24 #include <com/sun/star/ucb/SortedDynamicResultSetFactory.hpp>
25 #include <osl/diagnose.h>
26 #include <ucbhelper/macros.hxx>
27 #include <cppuhelper/queryinterface.hxx>
29 using namespace com::sun::star::lang
;
30 using namespace com::sun::star::sdbc
;
31 using namespace com::sun::star::ucb
;
32 using namespace com::sun::star::uno
;
35 CachedDynamicResultSetStub::CachedDynamicResultSetStub(
36 Reference
< XDynamicResultSet
> const & xOrigin
37 , const Reference
< XComponentContext
> & rxContext
)
38 : DynamicResultSetWrapper( xOrigin
, rxContext
)
40 OSL_ENSURE( m_xContext
.is(), "need Multiservicefactory to create stub" );
44 CachedDynamicResultSetStub::~CachedDynamicResultSetStub()
50 void CachedDynamicResultSetStub
51 ::impl_InitResultSetOne( const Reference
< XResultSet
>& xResultSet
)
53 DynamicResultSetWrapper::impl_InitResultSetOne( xResultSet
);
54 OSL_ENSURE( m_xSourceResultOne
.is(), "need source resultset" );
56 Reference
< XResultSet
> xStub(
57 new CachedContentResultSetStub( m_xSourceResultOne
) );
59 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
60 m_xMyResultOne
= xStub
;
64 void CachedDynamicResultSetStub
65 ::impl_InitResultSetTwo( const Reference
< XResultSet
>& xResultSet
)
67 DynamicResultSetWrapper::impl_InitResultSetTwo( xResultSet
);
68 OSL_ENSURE( m_xSourceResultTwo
.is(), "need source resultset" );
70 Reference
< XResultSet
> xStub(
71 new CachedContentResultSetStub( m_xSourceResultTwo
) );
73 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
74 m_xMyResultTwo
= xStub
;
78 // XInterface methods.
79 void SAL_CALL
CachedDynamicResultSetStub::acquire()
82 OWeakObject::acquire();
85 void SAL_CALL
CachedDynamicResultSetStub::release()
88 OWeakObject::release();
91 Any SAL_CALL CachedDynamicResultSetStub
92 ::queryInterface( const Type
& rType
)
94 //list all interfaces inclusive baseclasses of interfaces
96 Any aRet
= DynamicResultSetWrapper::queryInterface( rType
);
100 aRet
= cppu::queryInterface( rType
,
101 static_cast< XTypeProvider
* >( this )
102 , static_cast< XServiceInfo
* >( this )
104 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
108 // XTypeProvider methods.
110 //list all interfaces exclusive baseclasses
111 XTYPEPROVIDER_IMPL_5( CachedDynamicResultSetStub
115 , XDynamicResultSetListener
116 , XSourceInitialization
120 // XServiceInfo methods.
122 OUString SAL_CALL
CachedDynamicResultSetStub::getImplementationName()
124 return "com.sun.star.comp.ucb.CachedDynamicResultSetStub";
127 sal_Bool SAL_CALL
CachedDynamicResultSetStub::supportsService( const OUString
& ServiceName
)
129 return cppu::supportsService( this, ServiceName
);
132 css::uno::Sequence
< OUString
> SAL_CALL
CachedDynamicResultSetStub::getSupportedServiceNames()
134 return { "com.sun.star.ucb.CachedDynamicResultSetStub" };
141 CachedDynamicResultSetStubFactory::CachedDynamicResultSetStubFactory(
142 const Reference
< XComponentContext
> & rxContext
)
144 m_xContext
= rxContext
;
147 CachedDynamicResultSetStubFactory::~CachedDynamicResultSetStubFactory()
151 // CachedDynamicResultSetStubFactory XServiceInfo methods.
153 OUString SAL_CALL
CachedDynamicResultSetStubFactory::getImplementationName()
155 return "com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory";
157 sal_Bool SAL_CALL
CachedDynamicResultSetStubFactory::supportsService( const OUString
& ServiceName
)
159 return cppu::supportsService( this, ServiceName
);
161 css::uno::Sequence
< OUString
> SAL_CALL
CachedDynamicResultSetStubFactory::getSupportedServiceNames()
163 return { "com.sun.star.ucb.CachedDynamicResultSetStubFactory" };
166 // Service factory implementation.
170 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
171 ucb_CachedDynamicResultSetStubFactory_get_implementation(
172 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
174 return cppu::acquire(new CachedDynamicResultSetStubFactory(context
));
178 // CachedDynamicResultSetStubFactory XCachedDynamicResultSetStubFactory methods.
182 Reference
< XDynamicResultSet
> SAL_CALL CachedDynamicResultSetStubFactory
183 ::createCachedDynamicResultSetStub(
184 const Reference
< XDynamicResultSet
> & Source
)
186 Reference
< XDynamicResultSet
> xRet
= new CachedDynamicResultSetStub( Source
, m_xContext
);
191 void SAL_CALL CachedDynamicResultSetStubFactory
193 const Reference
< XDynamicResultSet
> & Source
194 , const Reference
< XDynamicResultSet
> & TargetCache
195 , const Sequence
< NumberedSortingInfo
> & SortingInfo
196 , const Reference
< XAnyCompareFactory
> & CompareFactory
199 OSL_ENSURE( Source
.is(), "a Source is needed" );
200 OSL_ENSURE( TargetCache
.is(), "a TargetCache is needed" );
202 Reference
< XDynamicResultSet
> xSource( Source
);
203 if( SortingInfo
.hasElements() &&
204 !( xSource
->getCapabilities() & ContentResultSetCapability::SORTED
)
207 Reference
< XSortedDynamicResultSetFactory
> xSortFactory
;
210 xSortFactory
= SortedDynamicResultSetFactory::create( m_xContext
);
212 catch ( Exception
const & )
216 if( xSortFactory
.is() )
218 Reference
< XDynamicResultSet
> xSorted(
219 xSortFactory
->createSortedDynamicResultSet(
220 Source
, SortingInfo
, CompareFactory
) );
226 Reference
< XDynamicResultSet
> xStub(
227 new CachedDynamicResultSetStub( xSource
, m_xContext
) );
229 Reference
< XSourceInitialization
> xTarget( TargetCache
, UNO_QUERY
);
230 OSL_ENSURE( xTarget
.is(), "Target must have interface XSourceInitialization" );
232 xTarget
->setSource( xStub
);
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */