12f86921cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 32f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 42f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file 52f86921cSAndrew Rist * distributed with this work for additional information 62f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 72f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the 82f86921cSAndrew Rist * "License"); you may not use this file except in compliance 92f86921cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 112f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 132f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing, 142f86921cSAndrew Rist * software distributed under the License is distributed on an 152f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 162f86921cSAndrew Rist * KIND, either express or implied. See the License for the 172f86921cSAndrew Rist * specific language governing permissions and limitations 182f86921cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 202f86921cSAndrew Rist *************************************************************/ 212f86921cSAndrew Rist 222f86921cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25*421ed02eSdamjan #include "precompiled_cacher.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <cacheddynamicresultsetstub.hxx> 28cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp> 29cdf0e10cSrcweir #include <cachedcontentresultsetstub.hxx> 30cdf0e10cSrcweir #include <com/sun/star/ucb/ContentResultSetCapability.hpp> 31cdf0e10cSrcweir #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp> 32cdf0e10cSrcweir #include <osl/diagnose.h> 33cdf0e10cSrcweir 34cdf0e10cSrcweir using namespace com::sun::star::lang; 35cdf0e10cSrcweir using namespace com::sun::star::sdbc; 36cdf0e10cSrcweir using namespace com::sun::star::ucb; 37cdf0e10cSrcweir using namespace com::sun::star::uno; 38cdf0e10cSrcweir using namespace rtl; 39cdf0e10cSrcweir 40cdf0e10cSrcweir CachedDynamicResultSetStub::CachedDynamicResultSetStub( 41cdf0e10cSrcweir Reference< XDynamicResultSet > xOrigin 42cdf0e10cSrcweir , const Reference< XMultiServiceFactory > & xSMgr ) 43cdf0e10cSrcweir : DynamicResultSetWrapper( xOrigin, xSMgr ) 44cdf0e10cSrcweir { 45cdf0e10cSrcweir OSL_ENSURE( m_xSMgr.is(), "need Multiservicefactory to create stub" ); 46cdf0e10cSrcweir impl_init(); 47cdf0e10cSrcweir } 48cdf0e10cSrcweir 49cdf0e10cSrcweir CachedDynamicResultSetStub::~CachedDynamicResultSetStub() 50cdf0e10cSrcweir { 51cdf0e10cSrcweir impl_deinit(); 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir //virtual 55cdf0e10cSrcweir void SAL_CALL CachedDynamicResultSetStub 56cdf0e10cSrcweir ::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir DynamicResultSetWrapper::impl_InitResultSetOne( xResultSet ); 59cdf0e10cSrcweir OSL_ENSURE( m_xSourceResultOne.is(), "need source resultset" ); 60cdf0e10cSrcweir 61cdf0e10cSrcweir Reference< XResultSet > xStub( 62cdf0e10cSrcweir new CachedContentResultSetStub( m_xSourceResultOne ) ); 63cdf0e10cSrcweir 64cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 65cdf0e10cSrcweir m_xMyResultOne = xStub; 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir //virtual 69cdf0e10cSrcweir void SAL_CALL CachedDynamicResultSetStub 70cdf0e10cSrcweir ::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet ) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir DynamicResultSetWrapper::impl_InitResultSetTwo( xResultSet ); 73cdf0e10cSrcweir OSL_ENSURE( m_xSourceResultTwo.is(), "need source resultset" ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir Reference< XResultSet > xStub( 76cdf0e10cSrcweir new CachedContentResultSetStub( m_xSourceResultTwo ) ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 79cdf0e10cSrcweir m_xMyResultTwo = xStub; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir //-------------------------------------------------------------------------- 83cdf0e10cSrcweir // XInterface methods. 84cdf0e10cSrcweir //-------------------------------------------------------------------------- 85cdf0e10cSrcweir XINTERFACE_COMMON_IMPL( CachedDynamicResultSetStub ) 86cdf0e10cSrcweir 87cdf0e10cSrcweir Any SAL_CALL CachedDynamicResultSetStub 88cdf0e10cSrcweir ::queryInterface( const Type& rType ) 89cdf0e10cSrcweir throw ( RuntimeException ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir //list all interfaces inclusive baseclasses of interfaces 92cdf0e10cSrcweir 93cdf0e10cSrcweir Any aRet = DynamicResultSetWrapper::queryInterface( rType ); 94cdf0e10cSrcweir if( aRet.hasValue() ) 95cdf0e10cSrcweir return aRet; 96cdf0e10cSrcweir 97cdf0e10cSrcweir aRet = cppu::queryInterface( rType, 98cdf0e10cSrcweir static_cast< XTypeProvider* >( this ) 99cdf0e10cSrcweir , static_cast< XServiceInfo* >( this ) 100cdf0e10cSrcweir ); 101cdf0e10cSrcweir return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir //-------------------------------------------------------------------------- 105cdf0e10cSrcweir // XTypeProvider methods. 106cdf0e10cSrcweir //-------------------------------------------------------------------------- 107cdf0e10cSrcweir //list all interfaces exclusive baseclasses 108cdf0e10cSrcweir XTYPEPROVIDER_IMPL_5( CachedDynamicResultSetStub 109cdf0e10cSrcweir , XTypeProvider 110cdf0e10cSrcweir , XServiceInfo 111cdf0e10cSrcweir , XDynamicResultSet 112cdf0e10cSrcweir , XDynamicResultSetListener 113cdf0e10cSrcweir , XSourceInitialization 114cdf0e10cSrcweir ); 115cdf0e10cSrcweir 116cdf0e10cSrcweir //-------------------------------------------------------------------------- 117cdf0e10cSrcweir // XServiceInfo methods. 118cdf0e10cSrcweir //-------------------------------------------------------------------------- 119cdf0e10cSrcweir 120cdf0e10cSrcweir XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSetStub, 121cdf0e10cSrcweir OUString::createFromAscii( 122cdf0e10cSrcweir "com.sun.star.comp.ucb.CachedDynamicResultSetStub" ), 123cdf0e10cSrcweir OUString::createFromAscii( 124cdf0e10cSrcweir CACHED_DRS_STUB_SERVICE_NAME ) ); 125cdf0e10cSrcweir 126cdf0e10cSrcweir //-------------------------------------------------------------------------- 127cdf0e10cSrcweir //-------------------------------------------------------------------------- 128cdf0e10cSrcweir // class CachedDynamicResultSetStubFactory 129cdf0e10cSrcweir //-------------------------------------------------------------------------- 130cdf0e10cSrcweir //-------------------------------------------------------------------------- 131cdf0e10cSrcweir 132cdf0e10cSrcweir CachedDynamicResultSetStubFactory::CachedDynamicResultSetStubFactory( 133cdf0e10cSrcweir const Reference< XMultiServiceFactory > & rSMgr ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir m_xSMgr = rSMgr; 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir CachedDynamicResultSetStubFactory::~CachedDynamicResultSetStubFactory() 139cdf0e10cSrcweir { 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir //-------------------------------------------------------------------------- 143cdf0e10cSrcweir // CachedDynamicResultSetStubFactory XInterface methods. 144cdf0e10cSrcweir //-------------------------------------------------------------------------- 145cdf0e10cSrcweir 146cdf0e10cSrcweir XINTERFACE_IMPL_3( CachedDynamicResultSetStubFactory, 147cdf0e10cSrcweir XTypeProvider, 148cdf0e10cSrcweir XServiceInfo, 149cdf0e10cSrcweir XCachedDynamicResultSetStubFactory ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir //-------------------------------------------------------------------------- 152cdf0e10cSrcweir // CachedDynamicResultSetStubFactory XTypeProvider methods. 153cdf0e10cSrcweir //-------------------------------------------------------------------------- 154cdf0e10cSrcweir 155cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetStubFactory, 156cdf0e10cSrcweir XTypeProvider, 157cdf0e10cSrcweir XServiceInfo, 158cdf0e10cSrcweir XCachedDynamicResultSetStubFactory ); 159cdf0e10cSrcweir 160cdf0e10cSrcweir //-------------------------------------------------------------------------- 161cdf0e10cSrcweir // CachedDynamicResultSetStubFactory XServiceInfo methods. 162cdf0e10cSrcweir //-------------------------------------------------------------------------- 163cdf0e10cSrcweir 164cdf0e10cSrcweir XSERVICEINFO_IMPL_1( CachedDynamicResultSetStubFactory, 165cdf0e10cSrcweir OUString::createFromAscii( 166cdf0e10cSrcweir "com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory" ), 167cdf0e10cSrcweir OUString::createFromAscii( 168cdf0e10cSrcweir CACHED_DRS_STUB_FACTORY_NAME ) ); 169cdf0e10cSrcweir 170cdf0e10cSrcweir //-------------------------------------------------------------------------- 171cdf0e10cSrcweir // Service factory implementation. 172cdf0e10cSrcweir //-------------------------------------------------------------------------- 173cdf0e10cSrcweir 174cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetStubFactory ); 175cdf0e10cSrcweir 176cdf0e10cSrcweir //-------------------------------------------------------------------------- 177cdf0e10cSrcweir // CachedDynamicResultSetStubFactory XCachedDynamicResultSetStubFactory methods. 178cdf0e10cSrcweir //-------------------------------------------------------------------------- 179cdf0e10cSrcweir 180cdf0e10cSrcweir //virtual 181cdf0e10cSrcweir Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetStubFactory 182cdf0e10cSrcweir ::createCachedDynamicResultSetStub( 183cdf0e10cSrcweir const Reference< XDynamicResultSet > & Source ) 184cdf0e10cSrcweir throw( RuntimeException ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir Reference< XDynamicResultSet > xRet; 187cdf0e10cSrcweir xRet = new CachedDynamicResultSetStub( Source, m_xSMgr ); 188cdf0e10cSrcweir return xRet; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir //virtual 192cdf0e10cSrcweir void SAL_CALL CachedDynamicResultSetStubFactory 193cdf0e10cSrcweir ::connectToCache( 194cdf0e10cSrcweir const Reference< XDynamicResultSet > & Source 195cdf0e10cSrcweir , const Reference< XDynamicResultSet > & TargetCache 196cdf0e10cSrcweir , const Sequence< NumberedSortingInfo > & SortingInfo 197cdf0e10cSrcweir , const Reference< XAnyCompareFactory > & CompareFactory 198cdf0e10cSrcweir ) 199cdf0e10cSrcweir throw ( ListenerAlreadySetException 200cdf0e10cSrcweir , AlreadyInitializedException 201cdf0e10cSrcweir , RuntimeException ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir OSL_ENSURE( Source.is(), "a Source is needed" ); 204cdf0e10cSrcweir OSL_ENSURE( TargetCache.is(), "a TargetCache is needed" ); 205cdf0e10cSrcweir 206cdf0e10cSrcweir Reference< XDynamicResultSet > xSource( Source ); 207cdf0e10cSrcweir if( SortingInfo.getLength() && 208cdf0e10cSrcweir !( xSource->getCapabilities() & ContentResultSetCapability::SORTED ) 209cdf0e10cSrcweir ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir Reference< XSortedDynamicResultSetFactory > xSortFactory; 212cdf0e10cSrcweir try 213cdf0e10cSrcweir { 214cdf0e10cSrcweir xSortFactory = Reference< XSortedDynamicResultSetFactory >( 215cdf0e10cSrcweir m_xSMgr->createInstance( OUString::createFromAscii( 216cdf0e10cSrcweir "com.sun.star.ucb.SortedDynamicResultSetFactory" ) ), 217cdf0e10cSrcweir UNO_QUERY ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir catch ( Exception const & ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir if( xSortFactory.is() ) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir Reference< XDynamicResultSet > xSorted( 226cdf0e10cSrcweir xSortFactory->createSortedDynamicResultSet( 227cdf0e10cSrcweir Source, SortingInfo, CompareFactory ) ); 228cdf0e10cSrcweir if( xSorted.is() ) 229cdf0e10cSrcweir xSource = xSorted; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir Reference< XDynamicResultSet > xStub( 234cdf0e10cSrcweir new CachedDynamicResultSetStub( xSource, m_xSMgr ) ); 235cdf0e10cSrcweir 236cdf0e10cSrcweir Reference< XSourceInitialization > xTarget( TargetCache, UNO_QUERY ); 237cdf0e10cSrcweir OSL_ENSURE( xTarget.is(), "Target must have interface XSourceInitialization" ); 238cdf0e10cSrcweir 239cdf0e10cSrcweir xTarget->setSource( xStub ); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242