LibreOffice Module ucb (master)  1
cacheddynamicresultsetstub.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
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>
28 
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;
33 
34 
36  Reference< XDynamicResultSet > const & xOrigin
37  , const Reference< XComponentContext > & rxContext )
38  : DynamicResultSetWrapper( xOrigin, rxContext )
39 {
40  OSL_ENSURE( m_xContext.is(), "need Multiservicefactory to create stub" );
41  impl_init();
42 }
43 
45 {
46  impl_deinit();
47 }
48 
49 //virtual
50 void CachedDynamicResultSetStub
51  ::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet )
52 {
54  OSL_ENSURE( m_xSourceResultOne.is(), "need source resultset" );
55 
57  new CachedContentResultSetStub( m_xSourceResultOne ) );
58 
59  osl::Guard< osl::Mutex > aGuard( m_aMutex );
60  m_xMyResultOne = xStub;
61 }
62 
63 //virtual
64 void CachedDynamicResultSetStub
65  ::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet )
66 {
68  OSL_ENSURE( m_xSourceResultTwo.is(), "need source resultset" );
69 
71  new CachedContentResultSetStub( m_xSourceResultTwo ) );
72 
73  osl::Guard< osl::Mutex > aGuard( m_aMutex );
74  m_xMyResultTwo = xStub;
75 }
76 
77 
78 // XInterface methods.
80  throw()
81 {
82  OWeakObject::acquire();
83 }
84 
86  throw()
87 {
88  OWeakObject::release();
89 }
90 
91 Any SAL_CALL CachedDynamicResultSetStub
92  ::queryInterface( const Type& rType )
93 {
94  //list all interfaces inclusive baseclasses of interfaces
95 
97  if( aRet.hasValue() )
98  return aRet;
99 
100  aRet = cppu::queryInterface( rType,
101  static_cast< XTypeProvider* >( this )
102  , static_cast< XServiceInfo* >( this )
103  );
104  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
105 }
106 
107 
108 // XTypeProvider methods.
109 
110 //list all interfaces exclusive baseclasses
112  , XTypeProvider
113  , XServiceInfo
114  , XDynamicResultSet
115  , XDynamicResultSetListener
116  , XSourceInitialization
117  );
118 
119 
120 // XServiceInfo methods.
121 
123 {
124  return "com.sun.star.comp.ucb.CachedDynamicResultSetStub";
125 }
126 
127 sal_Bool SAL_CALL CachedDynamicResultSetStub::supportsService( const OUString& ServiceName )
128 {
129  return cppu::supportsService( this, ServiceName );
130 }
131 
132 css::uno::Sequence< OUString > SAL_CALL CachedDynamicResultSetStub::getSupportedServiceNames()
133 {
134  return { "com.sun.star.ucb.CachedDynamicResultSetStub" };
135 }
136 
137 
138 
139 
140 
142  const Reference< XComponentContext > & rxContext )
143 {
144  m_xContext = rxContext;
145 }
146 
148 {
149 }
150 
151 // CachedDynamicResultSetStubFactory XServiceInfo methods.
152 
154 {
155  return "com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory";
156 }
157 sal_Bool SAL_CALL CachedDynamicResultSetStubFactory::supportsService( const OUString& ServiceName )
158 {
159  return cppu::supportsService( this, ServiceName );
160 }
161 css::uno::Sequence< OUString > SAL_CALL CachedDynamicResultSetStubFactory::getSupportedServiceNames()
162 {
163  return { "com.sun.star.ucb.CachedDynamicResultSetStubFactory" };
164 }
165 
166 // Service factory implementation.
167 
168 
169 
170 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
172  css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
173 {
174  return cppu::acquire(new CachedDynamicResultSetStubFactory(context));
175 }
176 
177 
178 // CachedDynamicResultSetStubFactory XCachedDynamicResultSetStubFactory methods.
179 
180 
181 //virtual
182 Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetStubFactory
183  ::createCachedDynamicResultSetStub(
184  const Reference< XDynamicResultSet > & Source )
185 {
187  return xRet;
188 }
189 
190 //virtual
191 void SAL_CALL CachedDynamicResultSetStubFactory
192  ::connectToCache(
193  const Reference< XDynamicResultSet > & Source
194  , const Reference< XDynamicResultSet > & TargetCache
195  , const Sequence< NumberedSortingInfo > & SortingInfo
196  , const Reference< XAnyCompareFactory > & CompareFactory
197  )
198 {
199  OSL_ENSURE( Source.is(), "a Source is needed" );
200  OSL_ENSURE( TargetCache.is(), "a TargetCache is needed" );
201 
202  Reference< XDynamicResultSet > xSource( Source );
203  if( SortingInfo.hasElements() &&
204  !( xSource->getCapabilities() & ContentResultSetCapability::SORTED )
205  )
206  {
208  try
209  {
210  xSortFactory = SortedDynamicResultSetFactory::create( m_xContext );
211  }
212  catch ( Exception const & )
213  {
214  }
215 
216  if( xSortFactory.is() )
217  {
219  xSortFactory->createSortedDynamicResultSet(
220  Source, SortingInfo, CompareFactory ) );
221  if( xSorted.is() )
222  xSource = xSorted;
223  }
224  }
225 
227  new CachedDynamicResultSetStub( xSource, m_xContext ) );
228 
229  Reference< XSourceInitialization > xTarget( TargetCache, UNO_QUERY );
230  OSL_ENSURE( xTarget.is(), "Target must have interface XSourceInitialization" );
231 
232  xTarget->setSource( xStub );
233 }
234 
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void impl_InitResultSetTwo(const css::uno::Reference< css::sdbc::XResultSet > &xResultSet)
Type
osl::Mutex m_aMutex
virtual void SAL_CALL release() override
Reference< XInterface > xTarget
CachedDynamicResultSetStub(css::uno::Reference< css::ucb::XDynamicResultSet > const &xOrigin, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual OUString SAL_CALL getImplementationName() override
CachedDynamicResultSetStubFactory(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void impl_InitResultSetOne(const css::uno::Reference< css::sdbc::XResultSet > &xResultSet)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_CachedDynamicResultSetStubFactory_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
unsigned char sal_Bool
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL acquire() override
Reference< XComponentContext > m_xContext
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
XTYPEPROVIDER_IMPL_5(CachedDynamicResultSetStub, XTypeProvider, XServiceInfo, XDynamicResultSet, XDynamicResultSetListener, XSourceInitialization)