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 <cacheddynamicresultsetstub.hxx> 28 #include <com/sun/star/sdbc/XResultSet.hpp> 29 #include <cachedcontentresultsetstub.hxx> 30 #include <com/sun/star/ucb/ContentResultSetCapability.hpp> 31 #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp> 32 #include <osl/diagnose.h> 33 34 using namespace com::sun::star::lang; 35 using namespace com::sun::star::sdbc; 36 using namespace com::sun::star::ucb; 37 using namespace com::sun::star::uno; 38 using namespace rtl; 39 40 CachedDynamicResultSetStub::CachedDynamicResultSetStub( 41 Reference< XDynamicResultSet > xOrigin 42 , const Reference< XMultiServiceFactory > & xSMgr ) 43 : DynamicResultSetWrapper( xOrigin, xSMgr ) 44 { 45 OSL_ENSURE( m_xSMgr.is(), "need Multiservicefactory to create stub" ); 46 impl_init(); 47 } 48 49 CachedDynamicResultSetStub::~CachedDynamicResultSetStub() 50 { 51 impl_deinit(); 52 } 53 54 //virtual 55 void SAL_CALL CachedDynamicResultSetStub 56 ::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet ) 57 { 58 DynamicResultSetWrapper::impl_InitResultSetOne( xResultSet ); 59 OSL_ENSURE( m_xSourceResultOne.is(), "need source resultset" ); 60 61 Reference< XResultSet > xStub( 62 new CachedContentResultSetStub( m_xSourceResultOne ) ); 63 64 osl::Guard< osl::Mutex > aGuard( m_aMutex ); 65 m_xMyResultOne = xStub; 66 } 67 68 //virtual 69 void SAL_CALL CachedDynamicResultSetStub 70 ::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet ) 71 { 72 DynamicResultSetWrapper::impl_InitResultSetTwo( xResultSet ); 73 OSL_ENSURE( m_xSourceResultTwo.is(), "need source resultset" ); 74 75 Reference< XResultSet > xStub( 76 new CachedContentResultSetStub( m_xSourceResultTwo ) ); 77 78 osl::Guard< osl::Mutex > aGuard( m_aMutex ); 79 m_xMyResultTwo = xStub; 80 } 81 82 //-------------------------------------------------------------------------- 83 // XInterface methods. 84 //-------------------------------------------------------------------------- 85 XINTERFACE_COMMON_IMPL( CachedDynamicResultSetStub ) 86 87 Any SAL_CALL CachedDynamicResultSetStub 88 ::queryInterface( const Type& rType ) 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_5( CachedDynamicResultSetStub 108 , XTypeProvider 109 , XServiceInfo 110 , XDynamicResultSet 111 , XDynamicResultSetListener 112 , XSourceInitialization 113 ); 114 115 //-------------------------------------------------------------------------- 116 // XServiceInfo methods. 117 //-------------------------------------------------------------------------- 118 119 XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSetStub, 120 OUString::createFromAscii( 121 "com.sun.star.comp.ucb.CachedDynamicResultSetStub" ), 122 OUString::createFromAscii( 123 CACHED_DRS_STUB_SERVICE_NAME ) ); 124 125 //-------------------------------------------------------------------------- 126 //-------------------------------------------------------------------------- 127 // class CachedDynamicResultSetStubFactory 128 //-------------------------------------------------------------------------- 129 //-------------------------------------------------------------------------- 130 131 CachedDynamicResultSetStubFactory::CachedDynamicResultSetStubFactory( 132 const Reference< XMultiServiceFactory > & rSMgr ) 133 { 134 m_xSMgr = rSMgr; 135 } 136 137 CachedDynamicResultSetStubFactory::~CachedDynamicResultSetStubFactory() 138 { 139 } 140 141 //-------------------------------------------------------------------------- 142 // CachedDynamicResultSetStubFactory XInterface methods. 143 //-------------------------------------------------------------------------- 144 145 XINTERFACE_IMPL_3( CachedDynamicResultSetStubFactory, 146 XTypeProvider, 147 XServiceInfo, 148 XCachedDynamicResultSetStubFactory ); 149 150 //-------------------------------------------------------------------------- 151 // CachedDynamicResultSetStubFactory XTypeProvider methods. 152 //-------------------------------------------------------------------------- 153 154 XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetStubFactory, 155 XTypeProvider, 156 XServiceInfo, 157 XCachedDynamicResultSetStubFactory ); 158 159 //-------------------------------------------------------------------------- 160 // CachedDynamicResultSetStubFactory XServiceInfo methods. 161 //-------------------------------------------------------------------------- 162 163 XSERVICEINFO_IMPL_1( CachedDynamicResultSetStubFactory, 164 OUString::createFromAscii( 165 "com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory" ), 166 OUString::createFromAscii( 167 CACHED_DRS_STUB_FACTORY_NAME ) ); 168 169 //-------------------------------------------------------------------------- 170 // Service factory implementation. 171 //-------------------------------------------------------------------------- 172 173 ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetStubFactory ); 174 175 //-------------------------------------------------------------------------- 176 // CachedDynamicResultSetStubFactory XCachedDynamicResultSetStubFactory methods. 177 //-------------------------------------------------------------------------- 178 179 //virtual 180 Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetStubFactory 181 ::createCachedDynamicResultSetStub( 182 const Reference< XDynamicResultSet > & Source ) 183 { 184 Reference< XDynamicResultSet > xRet; 185 xRet = new CachedDynamicResultSetStub( Source, m_xSMgr ); 186 return xRet; 187 } 188 189 //virtual 190 void SAL_CALL CachedDynamicResultSetStubFactory 191 ::connectToCache( 192 const Reference< XDynamicResultSet > & Source 193 , const Reference< XDynamicResultSet > & TargetCache 194 , const Sequence< NumberedSortingInfo > & SortingInfo 195 , const Reference< XAnyCompareFactory > & CompareFactory 196 ) 197 { 198 OSL_ENSURE( Source.is(), "a Source is needed" ); 199 OSL_ENSURE( TargetCache.is(), "a TargetCache is needed" ); 200 201 Reference< XDynamicResultSet > xSource( Source ); 202 if( SortingInfo.getLength() && 203 !( xSource->getCapabilities() & ContentResultSetCapability::SORTED ) 204 ) 205 { 206 Reference< XSortedDynamicResultSetFactory > xSortFactory; 207 try 208 { 209 xSortFactory = Reference< XSortedDynamicResultSetFactory >( 210 m_xSMgr->createInstance( OUString::createFromAscii( 211 "com.sun.star.ucb.SortedDynamicResultSetFactory" ) ), 212 UNO_QUERY ); 213 } 214 catch ( Exception const & ) 215 { 216 } 217 218 if( xSortFactory.is() ) 219 { 220 Reference< XDynamicResultSet > xSorted( 221 xSortFactory->createSortedDynamicResultSet( 222 Source, SortingInfo, CompareFactory ) ); 223 if( xSorted.is() ) 224 xSource = xSorted; 225 } 226 } 227 228 Reference< XDynamicResultSet > xStub( 229 new CachedDynamicResultSetStub( xSource, m_xSMgr ) ); 230 231 Reference< XSourceInitialization > xTarget( TargetCache, UNO_QUERY ); 232 OSL_ENSURE( xTarget.is(), "Target must have interface XSourceInitialization" ); 233 234 xTarget->setSource( xStub ); 235 } 236