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>
27 #include <ucbhelper/macros.hxx>
29 
30 using namespace com::sun::star::lang;
31 using namespace com::sun::star::sdbc;
32 using namespace com::sun::star::ucb;
33 using namespace com::sun::star::uno;
34 
35 
37  Reference< XDynamicResultSet > const & xOrigin
38  , const Reference< XComponentContext > & rxContext )
39  : DynamicResultSetWrapper( xOrigin, rxContext )
40 {
41  OSL_ENSURE( m_xContext.is(), "need Multiservicefactory to create stub" );
42  impl_init();
43 }
44 
46 {
47  impl_deinit();
48 }
49 
50 //virtual
51 void CachedDynamicResultSetStub
52  ::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet )
53 {
55  OSL_ENSURE( m_xSourceResultOne.is(), "need source resultset" );
56 
58  new CachedContentResultSetStub( m_xSourceResultOne ) );
59 
60  osl::Guard< osl::Mutex > aGuard( m_aMutex );
61  m_xMyResultOne = xStub;
62 }
63 
64 //virtual
65 void CachedDynamicResultSetStub
66  ::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet )
67 {
69  OSL_ENSURE( m_xSourceResultTwo.is(), "need source resultset" );
70 
72  new CachedContentResultSetStub( m_xSourceResultTwo ) );
73 
74  osl::Guard< osl::Mutex > aGuard( m_aMutex );
75  m_xMyResultTwo = xStub;
76 }
77 
78 
79 // XInterface methods.
81  throw()
82 {
83  OWeakObject::acquire();
84 }
85 
87  throw()
88 {
89  OWeakObject::release();
90 }
91 
92 Any SAL_CALL CachedDynamicResultSetStub
93  ::queryInterface( const Type& rType )
94 {
95  //list all interfaces inclusive baseclasses of interfaces
96 
98  if( aRet.hasValue() )
99  return aRet;
100 
101  aRet = cppu::queryInterface( rType,
102  static_cast< XTypeProvider* >( this )
103  , static_cast< XServiceInfo* >( this )
104  );
105  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
106 }
107 
108 
109 // XTypeProvider methods.
110 
111 //list all interfaces exclusive baseclasses
113  , XTypeProvider
114  , XServiceInfo
115  , XDynamicResultSet
116  , XDynamicResultSetListener
117  , XSourceInitialization
118  );
119 
120 
121 // XServiceInfo methods.
122 
124 {
125  return "com.sun.star.comp.ucb.CachedDynamicResultSetStub";
126 }
127 
128 sal_Bool SAL_CALL CachedDynamicResultSetStub::supportsService( const OUString& ServiceName )
129 {
130  return cppu::supportsService( this, ServiceName );
131 }
132 
133 css::uno::Sequence< OUString > SAL_CALL CachedDynamicResultSetStub::getSupportedServiceNames()
134 {
135  return { CACHED_DRS_STUB_SERVICE_NAME };
136 }
137 
138 
139 
140 // class CachedDynamicResultSetStubFactory
141 
142 
144  const Reference< XComponentContext > & rxContext )
145 {
146  m_xContext = rxContext;
147 }
148 
150 {
151 }
152 
153 // CachedDynamicResultSetStubFactory XServiceInfo methods.
154 
156  "com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory" )
158 static css::uno::Reference< css::uno::XInterface >
159 CachedDynamicResultSetStubFactory_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
160 {
161  css::lang::XServiceInfo* pX = new CachedDynamicResultSetStubFactory( ucbhelper::getComponentContext(rSMgr) );
162  return css::uno::Reference< css::uno::XInterface >::query( pX );
163 }
164 
165 css::uno::Sequence< OUString >
167 {
168  css::uno::Sequence< OUString > aSNS { CACHED_DRS_STUB_FACTORY_NAME };
169  return aSNS;
170 }
171 
172 // Service factory implementation.
173 
174 
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
CachedDynamicResultSetStub(css::uno::Reference< css::ucb::XDynamicResultSet > const &xOrigin, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual OUString SAL_CALL getImplementationName() override
UCBHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > getComponentContext(css::uno::Reference< css::lang::XMultiServiceFactory > const &factory)
CachedDynamicResultSetStubFactory(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
ONE_INSTANCE_SERVICE_FACTORY_IMPL(CachedDynamicResultSetStubFactory)
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
unsigned char sal_Bool
#define CACHED_DRS_STUB_SERVICE_NAME
css::uno::Reference< css::uno::XComponentContext > m_xContext
#define CACHED_DRS_STUB_FACTORY_NAME
XSERVICEINFO_COMMOM_IMPL(CachedDynamicResultSetStubFactory,"com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory") static css
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
static css::uno::Sequence< OUString > getSupportedServiceNames_Static()
virtual void SAL_CALL acquire() override
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
const uno::Reference< uno::XComponentContext > m_xContext
XTYPEPROVIDER_IMPL_5(CachedDynamicResultSetStub, XTypeProvider, XServiceInfo, XDynamicResultSet, XDynamicResultSetListener, XSourceInitialization)