1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cacher.hxx"
26
27 #include <cacheddynamicresultset.hxx>
28 #include <com/sun/star/sdbc/XResultSet.hpp>
29 #include <cachedcontentresultset.hxx>
30 #include <osl/diagnose.h>
31
32 using namespace com::sun::star::lang;
33 using namespace com::sun::star::sdbc;
34 using namespace com::sun::star::ucb;
35 using namespace com::sun::star::uno;
36 using namespace rtl;
37
CachedDynamicResultSet(Reference<XDynamicResultSet> xOrigin,const Reference<XContentIdentifierMapping> & xContentMapping,const Reference<XMultiServiceFactory> & xSMgr)38 CachedDynamicResultSet::CachedDynamicResultSet(
39 Reference< XDynamicResultSet > xOrigin
40 , const Reference< XContentIdentifierMapping > & xContentMapping
41 , const Reference< XMultiServiceFactory > & xSMgr )
42 : DynamicResultSetWrapper( xOrigin, xSMgr )
43 , m_xContentIdentifierMapping( xContentMapping )
44 {
45 impl_init();
46 }
47
~CachedDynamicResultSet()48 CachedDynamicResultSet::~CachedDynamicResultSet()
49 {
50 impl_deinit();
51 }
52
53 //virtual
54 void SAL_CALL CachedDynamicResultSet
impl_InitResultSetOne(const Reference<XResultSet> & xResultSet)55 ::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet )
56 {
57 DynamicResultSetWrapper::impl_InitResultSetOne( xResultSet );
58 OSL_ENSURE( m_xSourceResultOne.is(), "need source resultset" );
59
60 Reference< XResultSet > xCache(
61 new CachedContentResultSet( m_xSMgr, m_xSourceResultOne, m_xContentIdentifierMapping ) );
62
63 osl::Guard< osl::Mutex > aGuard( m_aMutex );
64 m_xMyResultOne = xCache;
65 }
66
67 //virtual
68 void SAL_CALL CachedDynamicResultSet
impl_InitResultSetTwo(const Reference<XResultSet> & xResultSet)69 ::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet )
70 {
71 DynamicResultSetWrapper::impl_InitResultSetTwo( xResultSet );
72 OSL_ENSURE( m_xSourceResultTwo.is(), "need source resultset" );
73
74 Reference< XResultSet > xCache(
75 new CachedContentResultSet( m_xSMgr, m_xSourceResultTwo, m_xContentIdentifierMapping ) );
76
77 osl::Guard< osl::Mutex > aGuard( m_aMutex );
78 m_xMyResultTwo = xCache;
79 }
80
81 //--------------------------------------------------------------------------
82 // XInterface methods.
83 //--------------------------------------------------------------------------
XINTERFACE_COMMON_IMPL(CachedDynamicResultSet)84 XINTERFACE_COMMON_IMPL( CachedDynamicResultSet )
85
86 Any SAL_CALL CachedDynamicResultSet
87 ::queryInterface( const Type& rType )
88 throw ( RuntimeException )
89 {
90 //list all interfaces inclusive baseclasses of interfaces
91
92 Any aRet = DynamicResultSetWrapper::queryInterface( rType );
93 if( aRet.hasValue() )
94 return aRet;
95
96 aRet = cppu::queryInterface( rType,
97 static_cast< XTypeProvider* >( this )
98 , static_cast< XServiceInfo* >( this )
99 );
100 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
101 }
102
103 //--------------------------------------------------------------------------
104 // XTypeProvider methods.
105 //--------------------------------------------------------------------------
106 //list all interfaces exclusive baseclasses
107 XTYPEPROVIDER_IMPL_4( CachedDynamicResultSet
108 , XTypeProvider
109 , XServiceInfo
110 , XDynamicResultSet
111 , XSourceInitialization
112 );
113
114 //--------------------------------------------------------------------------
115 // XServiceInfo methods.
116 //--------------------------------------------------------------------------
117
118 XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSet,
119 OUString::createFromAscii(
120 "com.sun.star.comp.ucb.CachedDynamicResultSet" ),
121 OUString::createFromAscii(
122 CACHED_DRS_SERVICE_NAME ) );
123
124 //--------------------------------------------------------------------------
125 // own methds. ( inherited )
126 //--------------------------------------------------------------------------
127 //virtual
128 void SAL_CALL CachedDynamicResultSet
impl_disposing(const EventObject & Source)129 ::impl_disposing( const EventObject& Source )
130 throw( RuntimeException )
131 {
132 DynamicResultSetWrapper::impl_disposing( Source );
133 m_xContentIdentifierMapping.clear();
134 }
135
136 //--------------------------------------------------------------------------
137 //--------------------------------------------------------------------------
138 // class CachedDynamicResultSetFactory
139 //--------------------------------------------------------------------------
140 //--------------------------------------------------------------------------
141
CachedDynamicResultSetFactory(const Reference<XMultiServiceFactory> & rSMgr)142 CachedDynamicResultSetFactory::CachedDynamicResultSetFactory(
143 const Reference< XMultiServiceFactory > & rSMgr )
144 {
145 m_xSMgr = rSMgr;
146 }
147
~CachedDynamicResultSetFactory()148 CachedDynamicResultSetFactory::~CachedDynamicResultSetFactory()
149 {
150 }
151
152 //--------------------------------------------------------------------------
153 // CachedDynamicResultSetFactory XInterface methods.
154 //--------------------------------------------------------------------------
155
156 XINTERFACE_IMPL_3( CachedDynamicResultSetFactory,
157 XTypeProvider,
158 XServiceInfo,
159 XCachedDynamicResultSetFactory );
160
161 //--------------------------------------------------------------------------
162 // CachedDynamicResultSetFactory XTypeProvider methods.
163 //--------------------------------------------------------------------------
164
165 XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetFactory,
166 XTypeProvider,
167 XServiceInfo,
168 XCachedDynamicResultSetFactory );
169
170 //--------------------------------------------------------------------------
171 // CachedDynamicResultSetFactory XServiceInfo methods.
172 //--------------------------------------------------------------------------
173
174 XSERVICEINFO_IMPL_1( CachedDynamicResultSetFactory,
175 OUString::createFromAscii(
176 "com.sun.star.comp.ucb.CachedDynamicResultSetFactory" ),
177 OUString::createFromAscii(
178 CACHED_DRS_FACTORY_NAME ) );
179
180 //--------------------------------------------------------------------------
181 // Service factory implementation.
182 //--------------------------------------------------------------------------
183
184 ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetFactory );
185
186 //--------------------------------------------------------------------------
187 // CachedDynamicResultSetFactory XCachedDynamicResultSetFactory methods.
188 //--------------------------------------------------------------------------
189
190 //virtual
191 Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetFactory
createCachedDynamicResultSet(const Reference<XDynamicResultSet> & SourceStub,const Reference<XContentIdentifierMapping> & ContentIdentifierMapping)192 ::createCachedDynamicResultSet(
193 const Reference< XDynamicResultSet > & SourceStub
194 , const Reference< XContentIdentifierMapping > & ContentIdentifierMapping )
195 throw( RuntimeException )
196 {
197 Reference< XDynamicResultSet > xRet;
198 xRet = new CachedDynamicResultSet( SourceStub, ContentIdentifierMapping, m_xSMgr );
199 return xRet;
200 }
201
202
203