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>
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
> 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 SAL_CALL 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 SAL_CALL 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
;
77 //--------------------------------------------------------------------------
78 // XInterface methods.
79 //--------------------------------------------------------------------------
80 XINTERFACE_COMMON_IMPL( CachedDynamicResultSetStub
)
82 Any SAL_CALL CachedDynamicResultSetStub
83 ::queryInterface( const Type
& rType
)
84 throw ( RuntimeException
)
86 //list all interfaces inclusive baseclasses of interfaces
88 Any aRet
= DynamicResultSetWrapper::queryInterface( rType
);
92 aRet
= cppu::queryInterface( rType
,
93 static_cast< XTypeProvider
* >( this )
94 , static_cast< XServiceInfo
* >( this )
96 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
99 //--------------------------------------------------------------------------
100 // XTypeProvider methods.
101 //--------------------------------------------------------------------------
102 //list all interfaces exclusive baseclasses
103 XTYPEPROVIDER_IMPL_5( CachedDynamicResultSetStub
107 , XDynamicResultSetListener
108 , XSourceInitialization
111 //--------------------------------------------------------------------------
112 // XServiceInfo methods.
113 //--------------------------------------------------------------------------
115 XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSetStub
,
116 OUString( "com.sun.star.comp.ucb.CachedDynamicResultSetStub" ),
117 OUString( CACHED_DRS_STUB_SERVICE_NAME
) );
119 //--------------------------------------------------------------------------
120 //--------------------------------------------------------------------------
121 // class CachedDynamicResultSetStubFactory
122 //--------------------------------------------------------------------------
123 //--------------------------------------------------------------------------
125 CachedDynamicResultSetStubFactory::CachedDynamicResultSetStubFactory(
126 const Reference
< XComponentContext
> & rxContext
)
128 m_xContext
= rxContext
;
131 CachedDynamicResultSetStubFactory::~CachedDynamicResultSetStubFactory()
135 //--------------------------------------------------------------------------
136 // CachedDynamicResultSetStubFactory XInterface methods.
137 //--------------------------------------------------------------------------
139 XINTERFACE_IMPL_3( CachedDynamicResultSetStubFactory
,
142 XCachedDynamicResultSetStubFactory
);
144 //--------------------------------------------------------------------------
145 // CachedDynamicResultSetStubFactory XTypeProvider methods.
146 //--------------------------------------------------------------------------
148 XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetStubFactory
,
151 XCachedDynamicResultSetStubFactory
);
153 //--------------------------------------------------------------------------
154 // CachedDynamicResultSetStubFactory XServiceInfo methods.
155 //--------------------------------------------------------------------------
157 XSERVICEINFO_IMPL_1_CTX( CachedDynamicResultSetStubFactory
,
158 OUString( "com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory" ),
159 OUString( CACHED_DRS_STUB_FACTORY_NAME
) );
161 //--------------------------------------------------------------------------
162 // Service factory implementation.
163 //--------------------------------------------------------------------------
165 ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetStubFactory
);
167 //--------------------------------------------------------------------------
168 // CachedDynamicResultSetStubFactory XCachedDynamicResultSetStubFactory methods.
169 //--------------------------------------------------------------------------
172 Reference
< XDynamicResultSet
> SAL_CALL CachedDynamicResultSetStubFactory
173 ::createCachedDynamicResultSetStub(
174 const Reference
< XDynamicResultSet
> & Source
)
175 throw( RuntimeException
)
177 Reference
< XDynamicResultSet
> xRet
;
178 xRet
= new CachedDynamicResultSetStub( Source
, m_xContext
);
183 void SAL_CALL CachedDynamicResultSetStubFactory
185 const Reference
< XDynamicResultSet
> & Source
186 , const Reference
< XDynamicResultSet
> & TargetCache
187 , const Sequence
< NumberedSortingInfo
> & SortingInfo
188 , const Reference
< XAnyCompareFactory
> & CompareFactory
190 throw ( ListenerAlreadySetException
191 , AlreadyInitializedException
194 OSL_ENSURE( Source
.is(), "a Source is needed" );
195 OSL_ENSURE( TargetCache
.is(), "a TargetCache is needed" );
197 Reference
< XDynamicResultSet
> xSource( Source
);
198 if( SortingInfo
.getLength() &&
199 !( xSource
->getCapabilities() & ContentResultSetCapability::SORTED
)
202 Reference
< XSortedDynamicResultSetFactory
> xSortFactory
;
205 xSortFactory
= SortedDynamicResultSetFactory::create( m_xContext
);
207 catch ( Exception
const & )
211 if( xSortFactory
.is() )
213 Reference
< XDynamicResultSet
> xSorted(
214 xSortFactory
->createSortedDynamicResultSet(
215 Source
, SortingInfo
, CompareFactory
) );
221 Reference
< XDynamicResultSet
> xStub(
222 new CachedDynamicResultSetStub( xSource
, m_xContext
) );
224 Reference
< XSourceInitialization
> xTarget( TargetCache
, UNO_QUERY
);
225 OSL_ENSURE( xTarget
.is(), "Target must have interface XSourceInitialization" );
227 xTarget
->setSource( xStub
);
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */