xref: /trunk/main/ucb/source/cacher/cacheddynamicresultset.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
89     //list all interfaces inclusive baseclasses of interfaces
90 
91     Any aRet = DynamicResultSetWrapper::queryInterface( rType );
92     if( aRet.hasValue() )
93         return aRet;
94 
95     aRet = cppu::queryInterface( rType,
96                 static_cast< XTypeProvider* >( this )
97                 , static_cast< XServiceInfo* >( this )
98                 );
99     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
100 }
101 
102 //--------------------------------------------------------------------------
103 // XTypeProvider methods.
104 //--------------------------------------------------------------------------
105 //list all interfaces exclusive baseclasses
106 XTYPEPROVIDER_IMPL_4( CachedDynamicResultSet
107                     , XTypeProvider
108                     , XServiceInfo
109                     , XDynamicResultSet
110                     , XSourceInitialization
111                     );
112 
113 //--------------------------------------------------------------------------
114 // XServiceInfo methods.
115 //--------------------------------------------------------------------------
116 
117 XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSet,
118                            OUString::createFromAscii(
119                             "com.sun.star.comp.ucb.CachedDynamicResultSet" ),
120                            OUString::createFromAscii(
121                             CACHED_DRS_SERVICE_NAME ) );
122 
123 //--------------------------------------------------------------------------
124 // own methods. ( inherited )
125 //--------------------------------------------------------------------------
126 //virtual
127 void SAL_CALL CachedDynamicResultSet
impl_disposing(const EventObject & Source)128     ::impl_disposing( const EventObject& Source )
129 {
130     DynamicResultSetWrapper::impl_disposing( Source );
131     m_xContentIdentifierMapping.clear();
132 }
133 
134 //--------------------------------------------------------------------------
135 //--------------------------------------------------------------------------
136 // class CachedDynamicResultSetFactory
137 //--------------------------------------------------------------------------
138 //--------------------------------------------------------------------------
139 
CachedDynamicResultSetFactory(const Reference<XMultiServiceFactory> & rSMgr)140 CachedDynamicResultSetFactory::CachedDynamicResultSetFactory(
141         const Reference< XMultiServiceFactory > & rSMgr )
142 {
143     m_xSMgr = rSMgr;
144 }
145 
~CachedDynamicResultSetFactory()146 CachedDynamicResultSetFactory::~CachedDynamicResultSetFactory()
147 {
148 }
149 
150 //--------------------------------------------------------------------------
151 // CachedDynamicResultSetFactory XInterface methods.
152 //--------------------------------------------------------------------------
153 
154 XINTERFACE_IMPL_3( CachedDynamicResultSetFactory,
155                    XTypeProvider,
156                    XServiceInfo,
157                    XCachedDynamicResultSetFactory );
158 
159 //--------------------------------------------------------------------------
160 // CachedDynamicResultSetFactory XTypeProvider methods.
161 //--------------------------------------------------------------------------
162 
163 XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetFactory,
164                       XTypeProvider,
165                       XServiceInfo,
166                       XCachedDynamicResultSetFactory );
167 
168 //--------------------------------------------------------------------------
169 // CachedDynamicResultSetFactory XServiceInfo methods.
170 //--------------------------------------------------------------------------
171 
172 XSERVICEINFO_IMPL_1( CachedDynamicResultSetFactory,
173                      OUString::createFromAscii(
174                         "com.sun.star.comp.ucb.CachedDynamicResultSetFactory" ),
175                      OUString::createFromAscii(
176                         CACHED_DRS_FACTORY_NAME ) );
177 
178 //--------------------------------------------------------------------------
179 // Service factory implementation.
180 //--------------------------------------------------------------------------
181 
182 ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetFactory );
183 
184 //--------------------------------------------------------------------------
185 // CachedDynamicResultSetFactory XCachedDynamicResultSetFactory methods.
186 //--------------------------------------------------------------------------
187 
188 //virtual
189 Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetFactory
createCachedDynamicResultSet(const Reference<XDynamicResultSet> & SourceStub,const Reference<XContentIdentifierMapping> & ContentIdentifierMapping)190     ::createCachedDynamicResultSet(
191           const Reference< XDynamicResultSet > & SourceStub
192         , const Reference< XContentIdentifierMapping > & ContentIdentifierMapping )
193 {
194     Reference< XDynamicResultSet > xRet;
195     xRet = new CachedDynamicResultSet( SourceStub, ContentIdentifierMapping, m_xSMgr );
196     return xRet;
197 }
198