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_ucb.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 throw ( RuntimeException ) 90 { 91 //list all interfaces inclusive baseclasses of interfaces 92 93 Any aRet = DynamicResultSetWrapper::queryInterface( rType ); 94 if( aRet.hasValue() ) 95 return aRet; 96 97 aRet = cppu::queryInterface( rType, 98 static_cast< XTypeProvider* >( this ) 99 , static_cast< XServiceInfo* >( this ) 100 ); 101 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); 102 } 103 104 //-------------------------------------------------------------------------- 105 // XTypeProvider methods. 106 //-------------------------------------------------------------------------- 107 //list all interfaces exclusive baseclasses 108 XTYPEPROVIDER_IMPL_5( CachedDynamicResultSetStub 109 , XTypeProvider 110 , XServiceInfo 111 , XDynamicResultSet 112 , XDynamicResultSetListener 113 , XSourceInitialization 114 ); 115 116 //-------------------------------------------------------------------------- 117 // XServiceInfo methods. 118 //-------------------------------------------------------------------------- 119 120 XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSetStub, 121 OUString::createFromAscii( 122 "com.sun.star.comp.ucb.CachedDynamicResultSetStub" ), 123 OUString::createFromAscii( 124 CACHED_DRS_STUB_SERVICE_NAME ) ); 125 126 //-------------------------------------------------------------------------- 127 //-------------------------------------------------------------------------- 128 // class CachedDynamicResultSetStubFactory 129 //-------------------------------------------------------------------------- 130 //-------------------------------------------------------------------------- 131 132 CachedDynamicResultSetStubFactory::CachedDynamicResultSetStubFactory( 133 const Reference< XMultiServiceFactory > & rSMgr ) 134 { 135 m_xSMgr = rSMgr; 136 } 137 138 CachedDynamicResultSetStubFactory::~CachedDynamicResultSetStubFactory() 139 { 140 } 141 142 //-------------------------------------------------------------------------- 143 // CachedDynamicResultSetStubFactory XInterface methods. 144 //-------------------------------------------------------------------------- 145 146 XINTERFACE_IMPL_3( CachedDynamicResultSetStubFactory, 147 XTypeProvider, 148 XServiceInfo, 149 XCachedDynamicResultSetStubFactory ); 150 151 //-------------------------------------------------------------------------- 152 // CachedDynamicResultSetStubFactory XTypeProvider methods. 153 //-------------------------------------------------------------------------- 154 155 XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetStubFactory, 156 XTypeProvider, 157 XServiceInfo, 158 XCachedDynamicResultSetStubFactory ); 159 160 //-------------------------------------------------------------------------- 161 // CachedDynamicResultSetStubFactory XServiceInfo methods. 162 //-------------------------------------------------------------------------- 163 164 XSERVICEINFO_IMPL_1( CachedDynamicResultSetStubFactory, 165 OUString::createFromAscii( 166 "com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory" ), 167 OUString::createFromAscii( 168 CACHED_DRS_STUB_FACTORY_NAME ) ); 169 170 //-------------------------------------------------------------------------- 171 // Service factory implementation. 172 //-------------------------------------------------------------------------- 173 174 ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetStubFactory ); 175 176 //-------------------------------------------------------------------------- 177 // CachedDynamicResultSetStubFactory XCachedDynamicResultSetStubFactory methods. 178 //-------------------------------------------------------------------------- 179 180 //virtual 181 Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetStubFactory 182 ::createCachedDynamicResultSetStub( 183 const Reference< XDynamicResultSet > & Source ) 184 throw( RuntimeException ) 185 { 186 Reference< XDynamicResultSet > xRet; 187 xRet = new CachedDynamicResultSetStub( Source, m_xSMgr ); 188 return xRet; 189 } 190 191 //virtual 192 void SAL_CALL CachedDynamicResultSetStubFactory 193 ::connectToCache( 194 const Reference< XDynamicResultSet > & Source 195 , const Reference< XDynamicResultSet > & TargetCache 196 , const Sequence< NumberedSortingInfo > & SortingInfo 197 , const Reference< XAnyCompareFactory > & CompareFactory 198 ) 199 throw ( ListenerAlreadySetException 200 , AlreadyInitializedException 201 , RuntimeException ) 202 { 203 OSL_ENSURE( Source.is(), "a Source is needed" ); 204 OSL_ENSURE( TargetCache.is(), "a TargetCache is needed" ); 205 206 Reference< XDynamicResultSet > xSource( Source ); 207 if( SortingInfo.getLength() && 208 !( xSource->getCapabilities() & ContentResultSetCapability::SORTED ) 209 ) 210 { 211 Reference< XSortedDynamicResultSetFactory > xSortFactory; 212 try 213 { 214 xSortFactory = Reference< XSortedDynamicResultSetFactory >( 215 m_xSMgr->createInstance( OUString::createFromAscii( 216 "com.sun.star.ucb.SortedDynamicResultSetFactory" ) ), 217 UNO_QUERY ); 218 } 219 catch ( Exception const & ) 220 { 221 } 222 223 if( xSortFactory.is() ) 224 { 225 Reference< XDynamicResultSet > xSorted( 226 xSortFactory->createSortedDynamicResultSet( 227 Source, SortingInfo, CompareFactory ) ); 228 if( xSorted.is() ) 229 xSource = xSorted; 230 } 231 } 232 233 Reference< XDynamicResultSet > xStub( 234 new CachedDynamicResultSetStub( xSource, m_xSMgr ) ); 235 236 Reference< XSourceInitialization > xTarget( TargetCache, UNO_QUERY ); 237 OSL_ENSURE( xTarget.is(), "Target must have interface XSourceInitialization" ); 238 239 xTarget->setSource( xStub ); 240 } 241 242