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( std::unique_lock
<std::mutex
>& rGuard
, const Reference
< XResultSet
>& xResultSet
)
53 DynamicResultSetWrapper::impl_InitResultSetOne( rGuard
, xResultSet
);
54 OSL_ENSURE( m_xSourceResultOne
.is(), "need source resultset" );
56 Reference
< XResultSet
> xStub(
57 new CachedContentResultSetStub( m_xSourceResultOne
) );
59 m_xMyResultOne
= std::move(xStub
);
63 void CachedDynamicResultSetStub
64 ::impl_InitResultSetTwo( std::unique_lock
<std::mutex
>& rGuard
, const Reference
< XResultSet
>& xResultSet
)
66 DynamicResultSetWrapper::impl_InitResultSetTwo( rGuard
, xResultSet
);
67 OSL_ENSURE( m_xSourceResultTwo
.is(), "need source resultset" );
69 Reference
< XResultSet
> xStub(
70 new CachedContentResultSetStub( m_xSourceResultTwo
) );
72 m_xMyResultTwo
= std::move(xStub
);
75 // XInterface methods.
76 void SAL_CALL
CachedDynamicResultSetStub::acquire()
79 OWeakObject::acquire();
82 void SAL_CALL
CachedDynamicResultSetStub::release()
85 OWeakObject::release();
88 Any SAL_CALL CachedDynamicResultSetStub
89 ::queryInterface( const Type
& rType
)
91 //list all interfaces inclusive baseclasses of interfaces
93 Any aRet
= DynamicResultSetWrapper::queryInterface( rType
);
97 aRet
= cppu::queryInterface( rType
,
98 static_cast< XTypeProvider
* >( this )
99 , static_cast< XServiceInfo
* >( this )
101 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
105 // XTypeProvider methods.
107 //list all interfaces exclusive baseclasses
108 XTYPEPROVIDER_IMPL_5( CachedDynamicResultSetStub
112 , XDynamicResultSetListener
113 , XSourceInitialization
117 // XServiceInfo methods.
119 OUString SAL_CALL
CachedDynamicResultSetStub::getImplementationName()
121 return u
"com.sun.star.comp.ucb.CachedDynamicResultSetStub"_ustr
;
124 sal_Bool SAL_CALL
CachedDynamicResultSetStub::supportsService( const OUString
& ServiceName
)
126 return cppu::supportsService( this, ServiceName
);
129 css::uno::Sequence
< OUString
> SAL_CALL
CachedDynamicResultSetStub::getSupportedServiceNames()
131 return { u
"com.sun.star.ucb.CachedDynamicResultSetStub"_ustr
};
138 CachedDynamicResultSetStubFactory::CachedDynamicResultSetStubFactory(
139 const Reference
< XComponentContext
> & rxContext
)
141 m_xContext
= rxContext
;
144 CachedDynamicResultSetStubFactory::~CachedDynamicResultSetStubFactory()
148 // CachedDynamicResultSetStubFactory XServiceInfo methods.
150 OUString SAL_CALL
CachedDynamicResultSetStubFactory::getImplementationName()
152 return u
"com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory"_ustr
;
154 sal_Bool SAL_CALL
CachedDynamicResultSetStubFactory::supportsService( const OUString
& ServiceName
)
156 return cppu::supportsService( this, ServiceName
);
158 css::uno::Sequence
< OUString
> SAL_CALL
CachedDynamicResultSetStubFactory::getSupportedServiceNames()
160 return { u
"com.sun.star.ucb.CachedDynamicResultSetStubFactory"_ustr
};
163 // Service factory implementation.
167 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
168 ucb_CachedDynamicResultSetStubFactory_get_implementation(
169 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
171 return cppu::acquire(new CachedDynamicResultSetStubFactory(context
));
175 // CachedDynamicResultSetStubFactory XCachedDynamicResultSetStubFactory methods.
179 Reference
< XDynamicResultSet
> SAL_CALL CachedDynamicResultSetStubFactory
180 ::createCachedDynamicResultSetStub(
181 const Reference
< XDynamicResultSet
> & Source
)
183 Reference
< XDynamicResultSet
> xRet
= new CachedDynamicResultSetStub( Source
, m_xContext
);
188 void SAL_CALL CachedDynamicResultSetStubFactory
190 const Reference
< XDynamicResultSet
> & Source
191 , const Reference
< XDynamicResultSet
> & TargetCache
192 , const Sequence
< NumberedSortingInfo
> & SortingInfo
193 , const Reference
< XAnyCompareFactory
> & CompareFactory
196 OSL_ENSURE( Source
.is(), "a Source is needed" );
197 OSL_ENSURE( TargetCache
.is(), "a TargetCache is needed" );
199 Reference
< XDynamicResultSet
> xSource( Source
);
200 if( SortingInfo
.hasElements() &&
201 !( xSource
->getCapabilities() & ContentResultSetCapability::SORTED
)
204 Reference
< XSortedDynamicResultSetFactory
> xSortFactory
;
207 xSortFactory
= SortedDynamicResultSetFactory::create( m_xContext
);
209 catch ( Exception
const & )
213 if( xSortFactory
.is() )
215 Reference
< XDynamicResultSet
> xSorted(
216 xSortFactory
->createSortedDynamicResultSet(
217 Source
, SortingInfo
, CompareFactory
) );
219 xSource
= std::move(xSorted
);
223 Reference
< XDynamicResultSet
> xStub(
224 new CachedDynamicResultSetStub( xSource
, m_xContext
) );
226 Reference
< XSourceInitialization
> xTarget( TargetCache
, UNO_QUERY
);
227 OSL_ENSURE( xTarget
.is(), "Target must have interface XSourceInitialization" );
229 xTarget
->setSource( xStub
);
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */