diff options
Diffstat (limited to 'ucb/source/cacher')
-rw-r--r-- | ucb/source/cacher/cached.xml | 146 | ||||
-rw-r--r-- | ucb/source/cacher/cachedcontentresultset.cxx | 2229 | ||||
-rw-r--r-- | ucb/source/cacher/cachedcontentresultset.hxx | 521 | ||||
-rw-r--r-- | ucb/source/cacher/cachedcontentresultsetstub.cxx | 631 | ||||
-rw-r--r-- | ucb/source/cacher/cachedcontentresultsetstub.hxx | 202 | ||||
-rw-r--r-- | ucb/source/cacher/cacheddynamicresultset.cxx | 206 | ||||
-rw-r--r-- | ucb/source/cacher/cacheddynamicresultset.hxx | 137 | ||||
-rw-r--r-- | ucb/source/cacher/cacheddynamicresultsetstub.cxx | 245 | ||||
-rw-r--r-- | ucb/source/cacher/cacheddynamicresultsetstub.hxx | 136 | ||||
-rw-r--r-- | ucb/source/cacher/cacheserv.cxx | 187 | ||||
-rw-r--r-- | ucb/source/cacher/contentresultsetwrapper.cxx | 1477 | ||||
-rw-r--r-- | ucb/source/cacher/contentresultsetwrapper.hxx | 587 | ||||
-rw-r--r-- | ucb/source/cacher/dynamicresultsetwrapper.cxx | 528 | ||||
-rw-r--r-- | ucb/source/cacher/dynamicresultsetwrapper.hxx | 229 | ||||
-rw-r--r-- | ucb/source/cacher/makefile.mk | 68 |
15 files changed, 7529 insertions, 0 deletions
diff --git a/ucb/source/cacher/cached.xml b/ucb/source/cacher/cached.xml new file mode 100644 index 000000000000..208520272f7c --- /dev/null +++ b/ucb/source/cacher/cached.xml @@ -0,0 +1,146 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd"> +<module-description xmlns:xlink="http://www.w3.org/1999/xlink"> + + <module-name> + cached + </module-name> + + <component-description> + <author> + Ingrid Halama + </author> + <name> + com.sun.star.comp.ucb.CachedContentResultSetFactory + </name> + <description> + This component implements a factory for locally cached resultsets. + </description> + <loader-name> + com.sun.star.loader.SharedLibrary + </loader-name> + <language> + c++ + </language> + <status value="final"/> + <supported-service> + com.sun.star.ucb.CachedContentResultSetFactory + </supported-service> + + <service-dependency> + com.sun.star.script.Converter + </service-dependency> + </component-description> + <component-description> + <author> + Ingrid Halama + </author> + <name> + com.sun.star.comp.ucb.CachedContentResultSetStubFactory + </name> + <description> + This component implements a factory for stubs for locally cached + resultsets. + </description> + <loader-name> + com.sun.star.loader.SharedLibrary + </loader-name> + <language> + c++ + </language> + <status value="final"/> + <supported-service> + com.sun.star.ucb.CachedContentResultSetStubFactory + </supported-service> + </component-description> + <component-description> + <author> + Ingrid Halama + </author> + <name> + com.sun.star.comp.ucb.CachedDynamicResultSetFactory + </name> + <description> + This component implements a factory for locally cached dynamic + resultsets. + </description> + <loader-name> + com.sun.star.loader.SharedLibrary + </loader-name> + <language> + c++ + </language> + <status value="final"/> + <supported-service> + com.sun.star.ucb.CachedDynamicResultSetFactory + </supported-service> + </component-description> + <component-description> + <author> + Ingrid Halama + </author> + <name> + com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory + </name> + <description> + This component implements a factory for stubs for locally cached + dynamic resultsets. + </description> + <loader-name> + com.sun.star.loader.SharedLibrary + </loader-name> + <language> + c++ + </language> + <status value="final"/> + <supported-service> + com.sun.star.ucb.CachedDynamicResultSetStubFactory + </supported-service> + + <service-dependency> + com.sun.star.ucb.SortedDynamicResultSetFactory + </service-dependency> + </component-description> + + <project-build-dependency> sal </project-build-dependency> + <project-build-dependency> cppu </project-build-dependency> + <project-build-dependency> cppuhelper </project-build-dependency> + + <runtime-module-dependency> sal3 </runtime-module-dependency> + <runtime-module-dependency> cppu3 </runtime-module-dependency> + <runtime-module-dependency> cppuhelper3$(COM) </runtime-module-dependency> + + <type> com.sun.star.beans.PropertyAttribute </type> + <type> com.sun.star.beans.XPropertySet </type> + <type> com.sun.star.lang.DisposedException </type> + <type> com.sun.star.lang.XComponent </type> + <type> com.sun.star.lang.XMultiServiceFactory </type> + <type> com.sun.star.lang.XServiceInfo </type> + <type> com.sun.star.lang.XSingleServiceFactory </type> + <type> com.sun.star.lang.XTypeProvider </type> + <type> com.sun.star.registry.XRegistryKey </type> + <type> com.sun.star.script.XTypeConverter </type> + <type> com.sun.star.sdbc.FetchDirection </type> + <type> com.sun.star.sdbc.ResultSetType </type> + <type> com.sun.star.sdbc.XCloseable </type> + <type> com.sun.star.sdbc.XResultSet </type> + <type> com.sun.star.sdbc.XResultSetMetaDataSupplier </type> + <type> com.sun.star.sdbc.XRow </type> + <type> com.sun.star.ucb.ContentResultSetCapability </type> + <type> com.sun.star.ucb.FetchError </type> + <type> com.sun.star.ucb.ListActionType </type> + <type> com.sun.star.ucb.ResultSetException </type> + <type> com.sun.star.ucb.WelcomeDynamicResultSetStruct </type> + <type> com.sun.star.ucb.XContentAccess </type> + <type> com.sun.star.ucb.XCachedContentResultSetFactory </type> + <type> com.sun.star.ucb.XCachedContentResultSetStubFactory </type> + <type> com.sun.star.ucb.XCachedDynamicResultSetFactory </type> + <type> com.sun.star.ucb.XCachedDynamicResultSetStubFactory </type> + <type> com.sun.star.ucb.XContentIdentifierMapping </type> + <type> com.sun.star.ucb.XDynamicResultSet </type> + <type> com.sun.star.ucb.XFetchProvider </type> + <type> com.sun.star.ucb.XFetchProviderForContentAccess </type> + <type> com.sun.star.ucb.XSortedDynamicResultSetFactory </type> + <type> com.sun.star.ucb.XSourceInitialization </type> + <type> com.sun.star.uno.XWeak </type> +</module-description> diff --git a/ucb/source/cacher/cachedcontentresultset.cxx b/ucb/source/cacher/cachedcontentresultset.cxx new file mode 100644 index 000000000000..e5c879448338 --- /dev/null +++ b/ucb/source/cacher/cachedcontentresultset.cxx @@ -0,0 +1,2229 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_ucb.hxx" + +#include <cachedcontentresultset.hxx> +#include <com/sun/star/sdbc/FetchDirection.hpp> +#include <com/sun/star/ucb/FetchError.hpp> +#include <com/sun/star/ucb/ResultSetException.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/script/XTypeConverter.hpp> +#include <com/sun/star/sdbc/ResultSetType.hpp> +#include <rtl/ustring.hxx> +#include <osl/diagnose.h> + +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::script; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace cppu; +using namespace rtl; + +#define COMSUNSTARUCBCCRS_DEFAULT_FETCH_SIZE 256 +#define COMSUNSTARUCBCCRS_DEFAULT_FETCH_DIRECTION FetchDirection::FORWARD + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +//define for getXXX methods of interface XRow +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +//if you change this macro please pay attention to +//function ::getObject, where this is similar implemented + +#define XROW_GETXXX( getXXX, Type ) \ +impl_EnsureNotDisposed(); \ +ReacquireableGuard aGuard( m_aMutex ); \ +sal_Int32 nRow = m_nRow; \ +sal_Int32 nFetchSize = m_nFetchSize; \ +sal_Int32 nFetchDirection = m_nFetchDirection; \ +if( !m_aCache.hasRow( nRow ) ) \ +{ \ + if( !m_aCache.hasCausedException( nRow ) ) \ +{ \ + if( !m_xFetchProvider.is() ) \ + { \ + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); \ + throw SQLException(); \ + } \ + aGuard.clear(); \ + if( impl_isForwardOnly() ) \ + applyPositionToOrigin( nRow ); \ + \ + impl_fetchData( nRow, nFetchSize, nFetchDirection ); \ + } \ + aGuard.reacquire(); \ + if( !m_aCache.hasRow( nRow ) ) \ + { \ + m_bLastReadWasFromCache = sal_False; \ + aGuard.clear(); \ + applyPositionToOrigin( nRow ); \ + impl_init_xRowOrigin(); \ + return m_xRowOrigin->getXXX( columnIndex ); \ + } \ +} \ +const Any& rValue = m_aCache.getAny( nRow, columnIndex );\ +Type aRet = Type(); \ +m_bLastReadWasFromCache = sal_True; \ +m_bLastCachedReadWasNull = !( rValue >>= aRet ); \ +/* Last chance. Try type converter service... */ \ +if ( m_bLastCachedReadWasNull && rValue.hasValue() ) \ +{ \ + Reference< XTypeConverter > xConverter \ + = getTypeConverter(); \ + if ( xConverter.is() ) \ + { \ + try \ + { \ + Any aConvAny = xConverter->convertTo( \ + rValue, \ + getCppuType( static_cast< \ + const Type * >( 0 ) ) ); \ + m_bLastCachedReadWasNull = !( aConvAny >>= aRet ); \ + } \ + catch ( IllegalArgumentException ) \ + { \ + } \ + catch ( CannotConvertException ) \ + { \ + } \ + } \ +} \ +return aRet; + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// CCRS_Cache methoeds. +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedContentResultSet::CCRS_Cache::CCRS_Cache( + const Reference< XContentIdentifierMapping > & xMapping ) + : m_pResult( NULL ) + , m_xContentIdentifierMapping( xMapping ) + , m_pMappedReminder( NULL ) +{ +} + +CachedContentResultSet::CCRS_Cache::~CCRS_Cache() +{ + delete m_pResult; +} + +void SAL_CALL CachedContentResultSet::CCRS_Cache + ::clear() +{ + if( m_pResult ) + { + delete m_pResult; + m_pResult = NULL; + } + clearMappedReminder(); +} + +void SAL_CALL CachedContentResultSet::CCRS_Cache + ::loadData( const FetchResult& rResult ) +{ + clear(); + m_pResult = new FetchResult( rResult ); +} + +sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache + ::hasRow( sal_Int32 row ) +{ + if( !m_pResult ) + return sal_False; + long nStart = m_pResult->StartIndex; + long nEnd = nStart; + if( m_pResult->Orientation ) + nEnd += m_pResult->Rows.getLength() - 1; + else + nStart -= m_pResult->Rows.getLength() + 1; + + return nStart <= row && row <= nEnd; +} + +sal_Int32 SAL_CALL CachedContentResultSet::CCRS_Cache + ::getMaxRow() +{ + if( !m_pResult ) + return 0; + long nEnd = m_pResult->StartIndex; + if( m_pResult->Orientation ) + return nEnd += m_pResult->Rows.getLength() - 1; + else + return nEnd; +} + +sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache + ::hasKnownLast() +{ + if( !m_pResult ) + return sal_False; + + if( ( m_pResult->FetchError & FetchError::ENDOFDATA ) + && m_pResult->Orientation + && m_pResult->Rows.getLength() ) + return sal_True; + + return sal_False; +} + +sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache + ::hasCausedException( sal_Int32 nRow ) +{ + if( !m_pResult ) + return sal_False; + if( !( m_pResult->FetchError & FetchError::EXCEPTION ) ) + return sal_False; + + long nEnd = m_pResult->StartIndex; + if( m_pResult->Orientation ) + nEnd += m_pResult->Rows.getLength(); + + return nRow == nEnd+1; +} + +Any& SAL_CALL CachedContentResultSet::CCRS_Cache + ::getRowAny( sal_Int32 nRow ) + throw( SQLException, + RuntimeException ) +{ + if( !nRow ) + throw SQLException(); + if( !m_pResult ) + throw SQLException(); + if( !hasRow( nRow ) ) + throw SQLException(); + + long nDiff = nRow - m_pResult->StartIndex; + if( nDiff < 0 ) + nDiff *= -1; + + return (m_pResult->Rows)[nDiff]; +} + +void SAL_CALL CachedContentResultSet::CCRS_Cache + ::remindMapped( sal_Int32 nRow ) +{ + //remind that this row was mapped + if( !m_pResult ) + return; + long nDiff = nRow - m_pResult->StartIndex; + if( nDiff < 0 ) + nDiff *= -1; + Sequence< sal_Bool >* pMappedReminder = getMappedReminder(); + if( nDiff < pMappedReminder->getLength() ) + (*pMappedReminder)[nDiff] = sal_True; +} + +sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache + ::isRowMapped( sal_Int32 nRow ) +{ + if( !m_pMappedReminder || !m_pResult ) + return sal_False; + long nDiff = nRow - m_pResult->StartIndex; + if( nDiff < 0 ) + nDiff *= -1; + if( nDiff < m_pMappedReminder->getLength() ) + return (*m_pMappedReminder)[nDiff]; + return sal_False; +} + +void SAL_CALL CachedContentResultSet::CCRS_Cache + ::clearMappedReminder() +{ + delete m_pMappedReminder; + m_pMappedReminder = NULL; +} + +Sequence< sal_Bool >* SAL_CALL CachedContentResultSet::CCRS_Cache + ::getMappedReminder() +{ + if( !m_pMappedReminder ) + { + sal_Int32 nCount = m_pResult->Rows.getLength(); + m_pMappedReminder = new Sequence< sal_Bool >( nCount ); + for( ;nCount; nCount-- ) + (*m_pMappedReminder)[nCount] = sal_False; + } + return m_pMappedReminder; +} + +const Any& SAL_CALL CachedContentResultSet::CCRS_Cache + ::getAny( sal_Int32 nRow, sal_Int32 nColumnIndex ) + throw( SQLException, + RuntimeException ) +{ + if( !nColumnIndex ) + throw SQLException(); + if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) ) + { + Any& rRow = getRowAny( nRow ); + Sequence< Any > aValue; + rRow >>= aValue; + if( m_xContentIdentifierMapping->mapRow( aValue ) ) + { + rRow <<= aValue; + remindMapped( nRow ); + } + else + m_xContentIdentifierMapping.clear(); + } + const Sequence< Any >& rRow = + (* reinterpret_cast< const Sequence< Any > * > + (getRowAny( nRow ).getValue() )); + + if( nColumnIndex > rRow.getLength() ) + throw SQLException(); + return rRow[nColumnIndex-1]; +} + +const rtl::OUString& SAL_CALL CachedContentResultSet::CCRS_Cache + ::getContentIdentifierString( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ) +{ + try + { + if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) ) + { + Any& rRow = getRowAny( nRow ); + rtl::OUString aValue; + rRow >>= aValue; + rRow <<= m_xContentIdentifierMapping->mapContentIdentifierString( aValue ); + remindMapped( nRow ); + } + return (* reinterpret_cast< const rtl::OUString * > + (getRowAny( nRow ).getValue() )); + } + catch( SQLException ) + { + throw RuntimeException(); + } +} + +const Reference< XContentIdentifier >& SAL_CALL CachedContentResultSet::CCRS_Cache + ::getContentIdentifier( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ) +{ + try + { + if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) ) + { + Any& rRow = getRowAny( nRow ); + Reference< XContentIdentifier > aValue; + rRow >>= aValue; + rRow <<= m_xContentIdentifierMapping->mapContentIdentifier( aValue ); + remindMapped( nRow ); + } + return (* reinterpret_cast< const Reference< XContentIdentifier > * > + (getRowAny( nRow ).getValue() )); + } + catch( SQLException ) + { + throw RuntimeException(); + } +} + +const Reference< XContent >& SAL_CALL CachedContentResultSet::CCRS_Cache + ::getContent( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ) +{ + try + { + if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) ) + { + Any& rRow = getRowAny( nRow ); + Reference< XContent > aValue; + rRow >>= aValue; + rRow <<= m_xContentIdentifierMapping->mapContent( aValue ); + remindMapped( nRow ); + } + return (* reinterpret_cast< const Reference< XContent > * > + (getRowAny( nRow ).getValue() )); + } + catch( SQLException ) + { + throw RuntimeException(); + } +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CCRS_PropertySetInfo +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +class CCRS_PropertySetInfo : + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::beans::XPropertySetInfo +{ + friend class CachedContentResultSet; + + //my Properties + Sequence< com::sun::star::beans::Property >* + m_pProperties; + + //some helping variables ( names for my special properties ) + static rtl::OUString m_aPropertyNameForCount; + static rtl::OUString m_aPropertyNameForFinalCount; + static rtl::OUString m_aPropertyNameForFetchSize; + static rtl::OUString m_aPropertyNameForFetchDirection; + + long m_nFetchSizePropertyHandle; + long m_nFetchDirectionPropertyHandle; + +private: + sal_Int32 SAL_CALL + impl_getRemainedHandle() const; + + sal_Bool SAL_CALL + impl_queryProperty( + const rtl::OUString& rName + , com::sun::star::beans::Property& rProp ) const; + sal_Int32 SAL_CALL + impl_getPos( const rtl::OUString& rName ) const; + + static sal_Bool SAL_CALL + impl_isMyPropertyName( const rtl::OUString& rName ); + +public: + CCRS_PropertySetInfo( Reference< + XPropertySetInfo > xPropertySetInfoOrigin ); + + virtual ~CCRS_PropertySetInfo(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XPropertySetInfo + virtual Sequence< com::sun::star::beans::Property > SAL_CALL + getProperties() + throw( RuntimeException ); + + virtual com::sun::star::beans::Property SAL_CALL + getPropertyByName( const rtl::OUString& aName ) + throw( com::sun::star::beans::UnknownPropertyException, RuntimeException ); + + virtual sal_Bool SAL_CALL + hasPropertyByName( const rtl::OUString& Name ) + throw( RuntimeException ); +}; + +OUString CCRS_PropertySetInfo::m_aPropertyNameForCount( OUString::createFromAscii( "RowCount" ) ); +OUString CCRS_PropertySetInfo::m_aPropertyNameForFinalCount( OUString::createFromAscii( "IsRowCountFinal" ) ); +OUString CCRS_PropertySetInfo::m_aPropertyNameForFetchSize( OUString::createFromAscii( "FetchSize" ) ); +OUString CCRS_PropertySetInfo::m_aPropertyNameForFetchDirection( OUString::createFromAscii( "FetchDirection" ) ); + +CCRS_PropertySetInfo::CCRS_PropertySetInfo( + Reference< XPropertySetInfo > xInfo ) + : m_pProperties( NULL ) + , m_nFetchSizePropertyHandle( -1 ) + , m_nFetchDirectionPropertyHandle( -1 ) +{ + //initialize list of properties: + + // it is required, that the received xInfo contains the two + // properties with names 'm_aPropertyNameForCount' and + // 'm_aPropertyNameForFinalCount' + + if( xInfo.is() ) + { + Sequence<Property> aProps = xInfo->getProperties(); + m_pProperties = new Sequence<Property> ( aProps ); + } + else + { + OSL_ENSURE( sal_False, "The received XPropertySetInfo doesn't contain required properties" ); + m_pProperties = new Sequence<Property>; + } + + //ensure, that we haven't got the Properties 'FetchSize' and 'Direction' twice: + sal_Int32 nFetchSize = impl_getPos( m_aPropertyNameForFetchSize ); + sal_Int32 nFetchDirection = impl_getPos( m_aPropertyNameForFetchDirection ); + sal_Int32 nDeleted = 0; + if( nFetchSize != -1 ) + nDeleted++; + if( nFetchDirection != -1 ) + nDeleted++; + + Sequence< Property >* pOrigProps = new Sequence<Property> ( *m_pProperties ); + sal_Int32 nOrigProps = pOrigProps->getLength(); + + m_pProperties->realloc( nOrigProps + 2 - nDeleted );//note that nDeleted is <= 2 + for( sal_Int32 n = 0, m = 0; n < nOrigProps; n++, m++ ) + { + if( n == nFetchSize || n == nFetchDirection ) + m--; + else + (*m_pProperties)[ m ] = (*pOrigProps)[ n ]; + } + { + Property& rMyProp = (*m_pProperties)[ nOrigProps - nDeleted ]; + rMyProp.Name = m_aPropertyNameForFetchSize; + rMyProp.Type = getCppuType( static_cast< const sal_Int32 * >( 0 ) ); + rMyProp.Attributes = PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT; + + if( nFetchSize != -1 ) + m_nFetchSizePropertyHandle = (*pOrigProps)[nFetchSize].Handle; + else + m_nFetchSizePropertyHandle = impl_getRemainedHandle(); + + rMyProp.Handle = m_nFetchSizePropertyHandle; + + } + { + Property& rMyProp = (*m_pProperties)[ nOrigProps - nDeleted + 1 ]; + rMyProp.Name = m_aPropertyNameForFetchDirection; + rMyProp.Type = getCppuType( static_cast< const sal_Bool * >( 0 ) ); + rMyProp.Attributes = PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT; + + if( nFetchSize != -1 ) + m_nFetchDirectionPropertyHandle = (*pOrigProps)[nFetchDirection].Handle; + else + m_nFetchDirectionPropertyHandle = impl_getRemainedHandle(); + + m_nFetchDirectionPropertyHandle = rMyProp.Handle; + } + delete pOrigProps; +} + +CCRS_PropertySetInfo::~CCRS_PropertySetInfo() +{ + delete m_pProperties; +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +//list all interfaces inclusive baseclasses of interfaces +XINTERFACE_IMPL_2( CCRS_PropertySetInfo + , XTypeProvider + , XPropertySetInfo + ); + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- +//list all interfaces exclusive baseclasses +XTYPEPROVIDER_IMPL_2( CCRS_PropertySetInfo + , XTypeProvider + , XPropertySetInfo + ); +//-------------------------------------------------------------------------- +// XPropertySetInfo methods. +//-------------------------------------------------------------------------- +//virtual +Sequence< Property > SAL_CALL CCRS_PropertySetInfo + ::getProperties() throw( RuntimeException ) +{ + return *m_pProperties; +} + +//virtual +Property SAL_CALL CCRS_PropertySetInfo + ::getPropertyByName( const rtl::OUString& aName ) + throw( UnknownPropertyException, RuntimeException ) +{ + if ( !aName.getLength() ) + throw UnknownPropertyException(); + + Property aProp; + if ( impl_queryProperty( aName, aProp ) ) + return aProp; + + throw UnknownPropertyException(); +} + +//virtual +sal_Bool SAL_CALL CCRS_PropertySetInfo + ::hasPropertyByName( const rtl::OUString& Name ) + throw( RuntimeException ) +{ + return ( impl_getPos( Name ) != -1 ); +} + +//-------------------------------------------------------------------------- +// impl_ methods. +//-------------------------------------------------------------------------- + +sal_Int32 SAL_CALL CCRS_PropertySetInfo + ::impl_getPos( const OUString& rName ) const +{ + for( sal_Int32 nN = m_pProperties->getLength(); nN--; ) + { + const Property& rMyProp = (*m_pProperties)[nN]; + if( rMyProp.Name == rName ) + return nN; + } + return -1; +} + +sal_Bool SAL_CALL CCRS_PropertySetInfo + ::impl_queryProperty( const OUString& rName, Property& rProp ) const +{ + for( sal_Int32 nN = m_pProperties->getLength(); nN--; ) + { + const Property& rMyProp = (*m_pProperties)[nN]; + if( rMyProp.Name == rName ) + { + rProp.Name = rMyProp.Name; + rProp.Handle = rMyProp.Handle; + rProp.Type = rMyProp.Type; + rProp.Attributes = rMyProp.Attributes; + + return sal_True; + } + } + return sal_False; +} + +//static +sal_Bool SAL_CALL CCRS_PropertySetInfo + ::impl_isMyPropertyName( const OUString& rPropertyName ) +{ + return ( rPropertyName == m_aPropertyNameForCount + || rPropertyName == m_aPropertyNameForFinalCount + || rPropertyName == m_aPropertyNameForFetchSize + || rPropertyName == m_aPropertyNameForFetchDirection ); +} + +sal_Int32 SAL_CALL CCRS_PropertySetInfo + ::impl_getRemainedHandle( ) const +{ + sal_Int32 nHandle = 1; + + if( !m_pProperties ) + { + OSL_ENSURE( sal_False, "Properties not initialized yet" ); + return nHandle; + } + sal_Bool bFound = sal_True; + while( bFound ) + { + bFound = sal_False; + for( sal_Int32 nN = m_pProperties->getLength(); nN--; ) + { + if( nHandle == (*m_pProperties)[nN].Handle ) + { + bFound = sal_True; + nHandle++; + break; + } + } + } + return nHandle; +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CachedContentResultSet +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedContentResultSet::CachedContentResultSet( + const Reference< XMultiServiceFactory > & xSMgr + , const Reference< XResultSet > & xOrigin + , const Reference< XContentIdentifierMapping > & + xContentIdentifierMapping ) + : ContentResultSetWrapper( xOrigin ) + + , m_xSMgr( xSMgr ) + , m_xFetchProvider( NULL ) + , m_xFetchProviderForContentAccess( NULL ) + + , m_xMyPropertySetInfo( NULL ) + , m_pMyPropSetInfo( NULL ) + + , m_xContentIdentifierMapping( xContentIdentifierMapping ) + , m_nRow( 0 ) // Position is one-based. Zero means: before first element. + , m_bAfterLast( sal_False ) + , m_nLastAppliedPos( 0 ) + , m_bAfterLastApplied( sal_False ) + , m_nKnownCount( 0 ) + , m_bFinalCount( sal_False ) + , m_nFetchSize( + COMSUNSTARUCBCCRS_DEFAULT_FETCH_SIZE ) + , m_nFetchDirection( + COMSUNSTARUCBCCRS_DEFAULT_FETCH_DIRECTION ) + + , m_bLastReadWasFromCache( sal_False ) + , m_bLastCachedReadWasNull( sal_True ) + , m_aCache( m_xContentIdentifierMapping ) + , m_aCacheContentIdentifierString( m_xContentIdentifierMapping ) + , m_aCacheContentIdentifier( m_xContentIdentifierMapping ) + , m_aCacheContent( m_xContentIdentifierMapping ) + , m_bTriedToGetTypeConverter( sal_False ) + , m_xTypeConverter( NULL ) +{ + m_xFetchProvider = Reference< XFetchProvider >( m_xResultSetOrigin, UNO_QUERY ); + OSL_ENSURE( m_xFetchProvider.is(), "interface XFetchProvider is required" ); + + m_xFetchProviderForContentAccess = Reference< XFetchProviderForContentAccess >( m_xResultSetOrigin, UNO_QUERY ); + OSL_ENSURE( m_xFetchProviderForContentAccess.is(), "interface XFetchProviderForContentAccess is required" ); + + impl_init(); +}; + +CachedContentResultSet::~CachedContentResultSet() +{ + impl_deinit(); + //do not delete m_pMyPropSetInfo, cause it is hold via reference +}; + +//-------------------------------------------------------------------------- +// impl_ methods. +//-------------------------------------------------------------------------- + +sal_Bool SAL_CALL CachedContentResultSet + ::applyPositionToOrigin( sal_Int32 nRow ) + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + //------------------------------------------------------------------------- + /** + @returns + <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off + the result set. + */ + + ReacquireableGuard aGuard( m_aMutex ); + OSL_ENSURE( nRow >= 0, "only positive values supported" ); + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return sal_False; + } +// OSL_ENSURE( nRow <= m_nKnownCount, "don't step into regions you don't know with this method" ); + + sal_Int32 nLastAppliedPos = m_nLastAppliedPos; + sal_Bool bAfterLastApplied = m_bAfterLastApplied; + sal_Bool bAfterLast = m_bAfterLast; + sal_Int32 nForwardOnly = m_nForwardOnly; + + aGuard.clear(); + + if( bAfterLastApplied || nLastAppliedPos != nRow ) + { + if( nForwardOnly == 1 ) + { + if( bAfterLastApplied || bAfterLast || !nRow || nRow < nLastAppliedPos ) + throw SQLException(); + + sal_Int32 nN = nRow - nLastAppliedPos; + sal_Int32 nM; + for( nM = 0; nN--; nM++ ) + { + if( !m_xResultSetOrigin->next() ) + break; + } + + aGuard.reacquire(); + m_nLastAppliedPos += nM; + m_bAfterLastApplied = nRow != m_nLastAppliedPos; + return nRow == m_nLastAppliedPos; + } + + if( !nRow ) //absolute( 0 ) will throw exception + { + m_xResultSetOrigin->beforeFirst(); + + aGuard.reacquire(); + m_nLastAppliedPos = 0; + m_bAfterLastApplied = sal_False; + return sal_False; + } + try + { + //move absolute, if !nLastAppliedPos + //because move relative would throw exception + if( !nLastAppliedPos || bAfterLast || bAfterLastApplied ) + { + sal_Bool bValid = m_xResultSetOrigin->absolute( nRow ); + + aGuard.reacquire(); + m_nLastAppliedPos = nRow; + m_bAfterLastApplied = !bValid; + return bValid; + } + else + { + sal_Bool bValid = m_xResultSetOrigin->relative( nRow - nLastAppliedPos ); + + aGuard.reacquire(); + m_nLastAppliedPos += ( nRow - nLastAppliedPos ); + m_bAfterLastApplied = !bValid; + return bValid; + } + } + catch( SQLException& rEx ) + { + if( !bAfterLastApplied && !bAfterLast && nRow > nLastAppliedPos && impl_isForwardOnly() ) + { + sal_Int32 nN = nRow - nLastAppliedPos; + sal_Int32 nM; + for( nM = 0; nN--; nM++ ) + { + if( !m_xResultSetOrigin->next() ) + break; + } + + aGuard.reacquire(); + m_nLastAppliedPos += nM; + m_bAfterLastApplied = nRow != m_nLastAppliedPos; + } + else + throw rEx; + } + + return nRow == m_nLastAppliedPos; + } + return sal_True; +}; + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +//define for fetching data +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +#define FETCH_XXX( aCache, fetchInterface, fetchMethod ) \ +sal_Bool bDirection = !!( \ + nFetchDirection != FetchDirection::REVERSE ); \ +FetchResult aResult = \ + fetchInterface->fetchMethod( nRow, nFetchSize, bDirection ); \ +osl::ClearableGuard< osl::Mutex > aGuard2( m_aMutex ); \ +aCache.loadData( aResult ); \ +sal_Int32 nMax = aCache.getMaxRow(); \ +sal_Int32 nCurCount = m_nKnownCount; \ +sal_Bool bIsFinalCount = aCache.hasKnownLast(); \ +sal_Bool bCurIsFinalCount = m_bFinalCount; \ +aGuard2.clear(); \ +if( nMax > nCurCount ) \ + impl_changeRowCount( nCurCount, nMax ); \ +if( bIsFinalCount && !bCurIsFinalCount ) \ + impl_changeIsRowCountFinal( bCurIsFinalCount, bIsFinalCount ); + +void SAL_CALL CachedContentResultSet + ::impl_fetchData( sal_Int32 nRow + , sal_Int32 nFetchSize, sal_Int32 nFetchDirection ) + throw( com::sun::star::uno::RuntimeException ) +{ + FETCH_XXX( m_aCache, m_xFetchProvider, fetch ); +} + +void SAL_CALL CachedContentResultSet + ::impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew ) +{ + OSL_ENSURE( nNew > nOld, "RowCount only can grow" ); + if( nNew <= nOld ) + return; + + //create PropertyChangeEvent and set value + PropertyChangeEvent aEvt; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = sal_False; + aEvt.OldValue <<= nOld; + aEvt.NewValue <<= nNew; + + m_nKnownCount = nNew; + } + + //send PropertyChangeEvent to listeners + impl_notifyPropertyChangeListeners( aEvt ); +} + +void SAL_CALL CachedContentResultSet + ::impl_changeIsRowCountFinal( sal_Bool bOld, sal_Bool bNew ) +{ + OSL_ENSURE( !bOld && bNew, "This change is not allowed for IsRowCountFinal" ); + if( ! (!bOld && bNew ) ) + return; + + //create PropertyChangeEvent and set value + PropertyChangeEvent aEvt; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = sal_False; + aEvt.OldValue <<= bOld; + aEvt.NewValue <<= bNew; + + m_bFinalCount = bNew; + } + + //send PropertyChangeEvent to listeners + impl_notifyPropertyChangeListeners( aEvt ); +} + +sal_Bool SAL_CALL CachedContentResultSet + ::impl_isKnownValidPosition( sal_Int32 nRow ) +{ + return m_nKnownCount && nRow + && nRow <= m_nKnownCount; +} + +sal_Bool SAL_CALL CachedContentResultSet + ::impl_isKnownInvalidPosition( sal_Int32 nRow ) +{ + if( !nRow ) + return sal_True; + if( !m_bFinalCount ) + return sal_False; + return nRow > m_nKnownCount; +} + + +//virtual +void SAL_CALL CachedContentResultSet + ::impl_initPropertySetInfo() +{ + ContentResultSetWrapper::impl_initPropertySetInfo(); + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_pMyPropSetInfo ) + return; + m_pMyPropSetInfo = new CCRS_PropertySetInfo( m_xPropertySetInfo ); + m_xMyPropertySetInfo = m_pMyPropSetInfo; + m_xPropertySetInfo = m_xMyPropertySetInfo; +} + +//-------------------------------------------------------------------------- +// XInterface methods. ( inherited ) +//-------------------------------------------------------------------------- +XINTERFACE_COMMON_IMPL( CachedContentResultSet ) + +Any SAL_CALL CachedContentResultSet + ::queryInterface( const Type& rType ) + throw ( RuntimeException ) +{ + //list all interfaces inclusive baseclasses of interfaces + + Any aRet = ContentResultSetWrapper::queryInterface( rType ); + if( aRet.hasValue() ) + return aRet; + + aRet = cppu::queryInterface( rType, + static_cast< XTypeProvider* >( this ), + static_cast< XServiceInfo* >( this ) ); + + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- +//list all interfaces exclusive baseclasses +XTYPEPROVIDER_IMPL_11( CachedContentResultSet + , XTypeProvider + , XServiceInfo + , XComponent + , XCloseable + , XResultSetMetaDataSupplier + , XPropertySet + + , XPropertyChangeListener + , XVetoableChangeListener + + , XContentAccess + + , XResultSet + , XRow ); + +//-------------------------------------------------------------------------- +// XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_NOFACTORY_IMPL_1( CachedContentResultSet, + OUString::createFromAscii( + "com.sun.star.comp.ucb.CachedContentResultSet" ), + OUString::createFromAscii( + CACHED_CONTENT_RESULTSET_SERVICE_NAME ) ); + +//-------------------------------------------------------------------------- +// XPropertySet methods. ( inherited ) +//-------------------------------------------------------------------------- + +// virtual +void SAL_CALL CachedContentResultSet + ::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) + throw( UnknownPropertyException, + PropertyVetoException, + IllegalArgumentException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !getPropertySetInfo().is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + + Property aProp = m_pMyPropSetInfo->getPropertyByName( aPropertyName ); + //throws UnknownPropertyException, if so + + if( aProp.Attributes & PropertyAttribute::READONLY ) + { + //It is assumed, that the properties + //'RowCount' and 'IsRowCountFinal' are readonly! + throw IllegalArgumentException(); + } + if( aProp.Name == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchDirection ) + { + //check value + sal_Int32 nNew; + if( !( aValue >>= nNew ) ) + { + throw IllegalArgumentException(); + } + + if( nNew == FetchDirection::UNKNOWN ) + { + nNew = COMSUNSTARUCBCCRS_DEFAULT_FETCH_DIRECTION; + } + else if( !( nNew == FetchDirection::FORWARD + || nNew == FetchDirection::REVERSE ) ) + { + throw IllegalArgumentException(); + } + + //create PropertyChangeEvent and set value + PropertyChangeEvent aEvt; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.PropertyName = aPropertyName; + aEvt.Further = sal_False; + aEvt.PropertyHandle = m_pMyPropSetInfo-> + m_nFetchDirectionPropertyHandle; + aEvt.OldValue <<= m_nFetchDirection; + aEvt.NewValue <<= nNew; + + m_nFetchDirection = nNew; + } + + //send PropertyChangeEvent to listeners + impl_notifyPropertyChangeListeners( aEvt ); + } + else if( aProp.Name == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchSize ) + { + //check value + sal_Int32 nNew; + if( !( aValue >>= nNew ) ) + { + throw IllegalArgumentException(); + } + + if( nNew < 0 ) + { + nNew = COMSUNSTARUCBCCRS_DEFAULT_FETCH_SIZE; + } + + //create PropertyChangeEvent and set value + PropertyChangeEvent aEvt; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.PropertyName = aPropertyName; + aEvt.Further = sal_False; + aEvt.PropertyHandle = m_pMyPropSetInfo-> + m_nFetchSizePropertyHandle; + aEvt.OldValue <<= m_nFetchSize; + aEvt.NewValue <<= nNew; + + m_nFetchSize = nNew; + } + + //send PropertyChangeEvent to listeners + impl_notifyPropertyChangeListeners( aEvt ); + } + else + { + impl_init_xPropertySetOrigin(); + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return; + } + } + m_xPropertySetOrigin->setPropertyValue( aPropertyName, aValue ); + } +} + +//-------------------------------------------------------------------------- +// virtual +Any SAL_CALL CachedContentResultSet + ::getPropertyValue( const OUString& rPropertyName ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !getPropertySetInfo().is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + + Property aProp = m_pMyPropSetInfo->getPropertyByName( rPropertyName ); + //throws UnknownPropertyException, if so + + Any aValue; + if( rPropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForCount ) + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + aValue <<= m_nKnownCount; + } + else if( rPropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFinalCount ) + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + aValue <<= m_bFinalCount; + } + else if( rPropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchSize ) + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + aValue <<= m_nFetchSize; + } + else if( rPropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchDirection ) + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + aValue <<= m_nFetchDirection; + } + else + { + impl_init_xPropertySetOrigin(); + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + } + aValue = m_xPropertySetOrigin->getPropertyValue( rPropertyName ); + } + return aValue; +} + +//-------------------------------------------------------------------------- +// own methods. ( inherited ) +//-------------------------------------------------------------------------- + +//virtual +void SAL_CALL CachedContentResultSet + ::impl_disposing( const EventObject& rEventObject ) + throw( RuntimeException ) +{ + { + impl_EnsureNotDisposed(); + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + //release all references to the broadcaster: + m_xFetchProvider.clear(); + m_xFetchProviderForContentAccess.clear(); + } + ContentResultSetWrapper::impl_disposing( rEventObject ); +} + +//virtual +void SAL_CALL CachedContentResultSet + ::impl_propertyChange( const PropertyChangeEvent& rEvt ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + PropertyChangeEvent aEvt( rEvt ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = sal_False; + //--------- + + if( CCRS_PropertySetInfo + ::impl_isMyPropertyName( rEvt.PropertyName ) ) + { + //don't notify foreign events on fetchsize and fetchdirection + if( aEvt.PropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchSize + || aEvt.PropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchDirection ) + return; + + //adjust my props 'RowCount' and 'IsRowCountFinal' + if( aEvt.PropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForCount ) + {//RowCount changed + + //check value + sal_Int32 nNew = 0; + if( !( aEvt.NewValue >>= nNew ) ) + { + OSL_ENSURE( sal_False, "PropertyChangeEvent contains wrong data" ); + return; + } + + impl_changeRowCount( m_nKnownCount, nNew ); + } + else if( aEvt.PropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFinalCount ) + {//IsRowCountFinal changed + + //check value + sal_Bool bNew = sal_False; + if( !( aEvt.NewValue >>= bNew ) ) + { + OSL_ENSURE( sal_False, "PropertyChangeEvent contains wrong data" ); + return; + } + impl_changeIsRowCountFinal( m_bFinalCount, bNew ); + } + return; + } + + //----------- + impl_notifyPropertyChangeListeners( aEvt ); +} + + +//virtual +void SAL_CALL CachedContentResultSet + ::impl_vetoableChange( const PropertyChangeEvent& rEvt ) + throw( PropertyVetoException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //don't notify events on my properties, cause they are not vetoable + if( CCRS_PropertySetInfo + ::impl_isMyPropertyName( rEvt.PropertyName ) ) + { + return; + } + + + PropertyChangeEvent aEvt( rEvt ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = sal_False; + + impl_notifyVetoableChangeListeners( aEvt ); +} + +//-------------------------------------------------------------------------- +// XContentAccess methods. ( inherited ) ( -- position dependent ) +//-------------------------------------------------------------------------- + +#define XCONTENTACCESS_queryXXX( queryXXX, XXX, TYPE ) \ +impl_EnsureNotDisposed(); \ +ReacquireableGuard aGuard( m_aMutex ); \ +sal_Int32 nRow = m_nRow; \ +sal_Int32 nFetchSize = m_nFetchSize; \ +sal_Int32 nFetchDirection = m_nFetchDirection; \ +if( !m_aCache##XXX.hasRow( nRow ) ) \ +{ \ + if( !m_aCache##XXX.hasCausedException( nRow ) ) \ +{ \ + if( !m_xFetchProviderForContentAccess.is() ) \ + { \ + OSL_ENSURE( sal_False, "broadcaster was disposed already" );\ + throw RuntimeException(); \ + } \ + aGuard.clear(); \ + if( impl_isForwardOnly() ) \ + applyPositionToOrigin( nRow ); \ + \ + FETCH_XXX( m_aCache##XXX, m_xFetchProviderForContentAccess, fetch##XXX##s ); \ + } \ + aGuard.reacquire(); \ + if( !m_aCache##XXX.hasRow( nRow ) ) \ + { \ + aGuard.clear(); \ + applyPositionToOrigin( nRow ); \ + TYPE aRet = ContentResultSetWrapper::queryXXX(); \ + if( m_xContentIdentifierMapping.is() ) \ + return m_xContentIdentifierMapping->map##XXX( aRet );\ + return aRet; \ + } \ +} \ +return m_aCache##XXX.get##XXX( nRow ); + +//-------------------------------------------------------------------------- +// virtual +OUString SAL_CALL CachedContentResultSet + ::queryContentIdentifierString() + throw( RuntimeException ) +{ + XCONTENTACCESS_queryXXX( queryContentIdentifierString, ContentIdentifierString, OUString ) +} + +//-------------------------------------------------------------------------- +// virtual +Reference< XContentIdentifier > SAL_CALL CachedContentResultSet + ::queryContentIdentifier() + throw( RuntimeException ) +{ + XCONTENTACCESS_queryXXX( queryContentIdentifier, ContentIdentifier, Reference< XContentIdentifier > ) +} + +//-------------------------------------------------------------------------- +// virtual +Reference< XContent > SAL_CALL CachedContentResultSet + ::queryContent() + throw( RuntimeException ) +{ + XCONTENTACCESS_queryXXX( queryContent, Content, Reference< XContent > ) +} + +//----------------------------------------------------------------- +// XResultSet methods. ( inherited ) +//----------------------------------------------------------------- +//virtual + +sal_Bool SAL_CALL CachedContentResultSet + ::next() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + ReacquireableGuard aGuard( m_aMutex ); + //after last + if( m_bAfterLast ) + return sal_False; + //last + aGuard.clear(); + if( isLast() ) + { + aGuard.reacquire(); + m_nRow++; + m_bAfterLast = sal_True; + return sal_False; + } + aGuard.reacquire(); + //known valid position + if( impl_isKnownValidPosition( m_nRow + 1 ) ) + { + m_nRow++; + return sal_True; + } + + //unknown position + sal_Int32 nRow = m_nRow; + aGuard.clear(); + + sal_Bool bValid = applyPositionToOrigin( nRow + 1 ); + + aGuard.reacquire(); + m_nRow = nRow + 1; + m_bAfterLast = !bValid; + return bValid; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::previous() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + ReacquireableGuard aGuard( m_aMutex ); + //before first ?: + if( !m_bAfterLast && !m_nRow ) + return sal_False; + //first ?: + if( !m_bAfterLast && m_nKnownCount && m_nRow == 1 ) + { + m_nRow--; + m_bAfterLast = sal_False; + return sal_False; + } + //known valid position ?: + if( impl_isKnownValidPosition( m_nRow - 1 ) ) + { + m_nRow--; + m_bAfterLast = sal_False; + return sal_True; + } + //unknown position: + sal_Int32 nRow = m_nRow; + aGuard.clear(); + + sal_Bool bValid = applyPositionToOrigin( nRow - 1 ); + + aGuard.reacquire(); + m_nRow = nRow - 1; + m_bAfterLast = sal_False; + return bValid; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::absolute( sal_Int32 row ) + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !row ) + throw SQLException(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + ReacquireableGuard aGuard( m_aMutex ); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return sal_False; + } + if( row < 0 ) + { + if( m_bFinalCount ) + { + sal_Int32 nNewRow = m_nKnownCount + 1 + row; + sal_Bool bValid = sal_True; + if( nNewRow <= 0 ) + { + nNewRow = 0; + bValid = sal_False; + } + m_nRow = nNewRow; + m_bAfterLast = sal_False; + return bValid; + } + //unknown final count: + aGuard.clear(); + + // Solaris has problems catching or propagating derived exceptions + // when only the base class is known, so make ResultSetException + // (derived from SQLException) known here: + sal_Bool bValid; + try + { + bValid = m_xResultSetOrigin->absolute( row ); + } + catch (ResultSetException &) + { + throw; + } + + aGuard.reacquire(); + if( m_bFinalCount ) + { + sal_Int32 nNewRow = m_nKnownCount + 1 + row; + if( nNewRow < 0 ) + nNewRow = 0; + m_nLastAppliedPos = nNewRow; + m_nRow = nNewRow; + m_bAfterLastApplied = m_bAfterLast = sal_False; + return bValid; + } + aGuard.clear(); + + sal_Int32 nCurRow = m_xResultSetOrigin->getRow(); + + aGuard.reacquire(); + m_nLastAppliedPos = nCurRow; + m_nRow = nCurRow; + m_bAfterLast = sal_False; + return nCurRow != 0; + } + //row > 0: + if( m_bFinalCount ) + { + if( row > m_nKnownCount ) + { + m_nRow = m_nKnownCount + 1; + m_bAfterLast = sal_True; + return sal_False; + } + m_nRow = row; + m_bAfterLast = sal_False; + return sal_True; + } + //unknown new position: + aGuard.clear(); + + sal_Bool bValid = m_xResultSetOrigin->absolute( row ); + + aGuard.reacquire(); + if( m_bFinalCount ) + { + sal_Int32 nNewRow = row; + if( nNewRow > m_nKnownCount ) + { + nNewRow = m_nKnownCount + 1; + m_bAfterLastApplied = m_bAfterLast = sal_True; + } + else + m_bAfterLastApplied = m_bAfterLast = sal_False; + + m_nLastAppliedPos = nNewRow; + m_nRow = nNewRow; + return bValid; + } + aGuard.clear(); + + sal_Int32 nCurRow = m_xResultSetOrigin->getRow(); + sal_Bool bIsAfterLast = m_xResultSetOrigin->isAfterLast(); + + aGuard.reacquire(); + m_nLastAppliedPos = nCurRow; + m_nRow = nCurRow; + m_bAfterLastApplied = m_bAfterLast = bIsAfterLast; + return nCurRow && !bIsAfterLast; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::relative( sal_Int32 rows ) + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + ReacquireableGuard aGuard( m_aMutex ); + if( m_bAfterLast || impl_isKnownInvalidPosition( m_nRow ) ) + throw SQLException(); + + if( !rows ) + return sal_True; + + sal_Int32 nNewRow = m_nRow + rows; + if( nNewRow < 0 ) + nNewRow = 0; + + if( impl_isKnownValidPosition( nNewRow ) ) + { + m_nRow = nNewRow; + m_bAfterLast = sal_False; + return sal_True; + } + else + { + //known invalid new position: + if( nNewRow == 0 ) + { + m_bAfterLast = sal_False; + m_nRow = 0; + return sal_False; + } + if( m_bFinalCount && nNewRow > m_nKnownCount ) + { + m_bAfterLast = sal_True; + m_nRow = m_nKnownCount + 1; + return sal_False; + } + //unknown new position: + aGuard.clear(); + sal_Bool bValid = applyPositionToOrigin( nNewRow ); + + aGuard.reacquire(); + m_nRow = nNewRow; + m_bAfterLast = !bValid && nNewRow > 0; + return bValid; + } +} + + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::first() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + ReacquireableGuard aGuard( m_aMutex ); + if( impl_isKnownValidPosition( 1 ) ) + { + m_nRow = 1; + m_bAfterLast = sal_False; + return sal_True; + } + if( impl_isKnownInvalidPosition( 1 ) ) + { + m_nRow = 1; + m_bAfterLast = sal_False; + return sal_False; + } + //unknown position + aGuard.clear(); + + sal_Bool bValid = applyPositionToOrigin( 1 ); + + aGuard.reacquire(); + m_nRow = 1; + m_bAfterLast = sal_False; + return bValid; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::last() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + ReacquireableGuard aGuard( m_aMutex ); + if( m_bFinalCount ) + { + m_nRow = m_nKnownCount; + m_bAfterLast = sal_False; + return m_nKnownCount != 0; + } + //unknown position + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return sal_False; + } + aGuard.clear(); + + sal_Bool bValid = m_xResultSetOrigin->last(); + + aGuard.reacquire(); + m_bAfterLastApplied = m_bAfterLast = sal_False; + if( m_bFinalCount ) + { + m_nLastAppliedPos = m_nKnownCount; + m_nRow = m_nKnownCount; + return bValid; + } + aGuard.clear(); + + sal_Int32 nCurRow = m_xResultSetOrigin->getRow(); + + aGuard.reacquire(); + m_nLastAppliedPos = nCurRow; + m_nRow = nCurRow; + OSL_ENSURE( nCurRow >= m_nKnownCount, "position of last row < known Count, that could not be" ); + m_nKnownCount = nCurRow; + m_bFinalCount = sal_True; + return nCurRow != 0; +} + +//virtual +void SAL_CALL CachedContentResultSet + ::beforeFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_nRow = 0; + m_bAfterLast = sal_False; +} + +//virtual +void SAL_CALL CachedContentResultSet + ::afterLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_nRow = 1; + m_bAfterLast = sal_True; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::isAfterLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + ReacquireableGuard aGuard( m_aMutex ); + if( !m_bAfterLast ) + return sal_False; + if( m_nKnownCount ) + return m_bAfterLast; + if( m_bFinalCount ) + return sal_False; + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return sal_False; + } + aGuard.clear(); + + //find out whethter the original resultset contains rows or not + m_xResultSetOrigin->afterLast(); + + aGuard.reacquire(); + m_bAfterLastApplied = sal_True; + aGuard.clear(); + + return m_xResultSetOrigin->isAfterLast(); +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::isBeforeFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + ReacquireableGuard aGuard( m_aMutex ); + if( m_bAfterLast ) + return sal_False; + if( m_nRow ) + return sal_False; + if( m_nKnownCount ) + return !m_nRow; + if( m_bFinalCount ) + return sal_False; + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return sal_False; + } + aGuard.clear(); + + //find out whethter the original resultset contains rows or not + m_xResultSetOrigin->beforeFirst(); + + aGuard.reacquire(); + m_bAfterLastApplied = sal_False; + m_nLastAppliedPos = 0; + aGuard.clear(); + + return m_xResultSetOrigin->isBeforeFirst(); +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::isFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + sal_Int32 nRow = 0; + Reference< XResultSet > xResultSetOrigin; + + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_bAfterLast ) + return sal_False; + if( m_nRow != 1 ) + return sal_False; + if( m_nKnownCount ) + return m_nRow == 1; + if( m_bFinalCount ) + return sal_False; + + nRow = m_nRow; + xResultSetOrigin = m_xResultSetOrigin; + } + + //need to ask origin + { + if( applyPositionToOrigin( nRow ) ) + return xResultSetOrigin->isFirst(); + else + return sal_False; + } +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::isLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + sal_Int32 nRow = 0; + Reference< XResultSet > xResultSetOrigin; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_bAfterLast ) + return sal_False; + if( m_nRow < m_nKnownCount ) + return sal_False; + if( m_bFinalCount ) + return m_nKnownCount && m_nRow == m_nKnownCount; + + nRow = m_nRow; + xResultSetOrigin = m_xResultSetOrigin; + } + + //need to ask origin + { + if( applyPositionToOrigin( nRow ) ) + return xResultSetOrigin->isLast(); + else + return sal_False; + } +} + + +//virtual +sal_Int32 SAL_CALL CachedContentResultSet + ::getRow() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_bAfterLast ) + return 0; + return m_nRow; +} + +//virtual +void SAL_CALL CachedContentResultSet + ::refreshRow() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //the ContentResultSet is static and will not change + //therefore we don't need to reload anything +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::rowUpdated() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //the ContentResultSet is static and will not change + return sal_False; +} +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::rowInserted() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //the ContentResultSet is static and will not change + return sal_False; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::rowDeleted() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //the ContentResultSet is static and will not change + return sal_False; +} + +//virtual +Reference< XInterface > SAL_CALL CachedContentResultSet + ::getStatement() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + //@todo ?return anything + return Reference< XInterface >(); +} + +//----------------------------------------------------------------- +// XRow methods. ( inherited ) +//----------------------------------------------------------------- + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::wasNull() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + impl_init_xRowOrigin(); + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_bLastReadWasFromCache ) + return m_bLastCachedReadWasNull; + if( !m_xRowOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return sal_False; + } + } + return m_xRowOrigin->wasNull(); +} + +//virtual +rtl::OUString SAL_CALL CachedContentResultSet + ::getString( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getString, OUString ); +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::getBoolean( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBoolean, sal_Bool ); +} + +//virtual +sal_Int8 SAL_CALL CachedContentResultSet + ::getByte( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getByte, sal_Int8 ); +} + +//virtual +sal_Int16 SAL_CALL CachedContentResultSet + ::getShort( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getShort, sal_Int16 ); +} + +//virtual +sal_Int32 SAL_CALL CachedContentResultSet + ::getInt( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getInt, sal_Int32 ); +} + +//virtual +sal_Int64 SAL_CALL CachedContentResultSet + ::getLong( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getLong, sal_Int64 ); +} + +//virtual +float SAL_CALL CachedContentResultSet + ::getFloat( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getFloat, float ); +} + +//virtual +double SAL_CALL CachedContentResultSet + ::getDouble( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getDouble, double ); +} + +//virtual +Sequence< sal_Int8 > SAL_CALL CachedContentResultSet + ::getBytes( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBytes, Sequence< sal_Int8 > ); +} + +//virtual +Date SAL_CALL CachedContentResultSet + ::getDate( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getDate, Date ); +} + +//virtual +Time SAL_CALL CachedContentResultSet + ::getTime( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getTime, Time ); +} + +//virtual +DateTime SAL_CALL CachedContentResultSet + ::getTimestamp( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getTimestamp, DateTime ); +} + +//virtual +Reference< com::sun::star::io::XInputStream > + SAL_CALL CachedContentResultSet + ::getBinaryStream( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBinaryStream, Reference< com::sun::star::io::XInputStream > ); +} + +//virtual +Reference< com::sun::star::io::XInputStream > + SAL_CALL CachedContentResultSet + ::getCharacterStream( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getCharacterStream, Reference< com::sun::star::io::XInputStream > ); +} + +//virtual +Any SAL_CALL CachedContentResultSet + ::getObject( sal_Int32 columnIndex, + const Reference< + com::sun::star::container::XNameAccess >& typeMap ) + throw( SQLException, + RuntimeException ) +{ + //if you change this macro please pay attention to + //define XROW_GETXXX, where this is similar implemented + + ReacquireableGuard aGuard( m_aMutex ); + sal_Int32 nRow = m_nRow; + sal_Int32 nFetchSize = m_nFetchSize; + sal_Int32 nFetchDirection = m_nFetchDirection; + if( !m_aCache.hasRow( nRow ) ) + { + if( !m_aCache.hasCausedException( nRow ) ) + { + if( !m_xFetchProvider.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return Any(); + } + aGuard.clear(); + + impl_fetchData( nRow, nFetchSize, nFetchDirection ); + } + aGuard.reacquire(); + if( !m_aCache.hasRow( nRow ) ) + { + m_bLastReadWasFromCache = sal_False; + aGuard.clear(); + applyPositionToOrigin( nRow ); + impl_init_xRowOrigin(); + return m_xRowOrigin->getObject( columnIndex, typeMap ); + } + } + //@todo: pay attention to typeMap + const Any& rValue = m_aCache.getAny( nRow, columnIndex ); + Any aRet; + m_bLastReadWasFromCache = sal_True; + m_bLastCachedReadWasNull = !( rValue >>= aRet ); + return aRet; +} + +//virtual +Reference< XRef > SAL_CALL CachedContentResultSet + ::getRef( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getRef, Reference< XRef > ); +} + +//virtual +Reference< XBlob > SAL_CALL CachedContentResultSet + ::getBlob( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBlob, Reference< XBlob > ); +} + +//virtual +Reference< XClob > SAL_CALL CachedContentResultSet + ::getClob( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getClob, Reference< XClob > ); +} + +//virtual +Reference< XArray > SAL_CALL CachedContentResultSet + ::getArray( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getArray, Reference< XArray > ); +} + +//----------------------------------------------------------------- +// Type Converter Support +//----------------------------------------------------------------- + +const Reference< XTypeConverter >& CachedContentResultSet::getTypeConverter() +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_bTriedToGetTypeConverter && !m_xTypeConverter.is() ) + { + m_bTriedToGetTypeConverter = sal_True; + m_xTypeConverter = Reference< XTypeConverter >( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.script.Converter" ) ), + UNO_QUERY ); + + OSL_ENSURE( m_xTypeConverter.is(), + "PropertyValueSet::getTypeConverter() - " + "Service 'com.sun.star.script.Converter' n/a!" ); + } + return m_xTypeConverter; +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CachedContentResultSetFactory +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedContentResultSetFactory::CachedContentResultSetFactory( + const Reference< XMultiServiceFactory > & rSMgr ) +{ + m_xSMgr = rSMgr; +} + +CachedContentResultSetFactory::~CachedContentResultSetFactory() +{ +} + +//-------------------------------------------------------------------------- +// CachedContentResultSetFactory XInterface methods. +//-------------------------------------------------------------------------- + +XINTERFACE_IMPL_3( CachedContentResultSetFactory, + XTypeProvider, + XServiceInfo, + XCachedContentResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetFactory XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_3( CachedContentResultSetFactory, + XTypeProvider, + XServiceInfo, + XCachedContentResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetFactory XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_IMPL_1( CachedContentResultSetFactory, + OUString::createFromAscii( + "com.sun.star.comp.ucb.CachedContentResultSetFactory" ), + OUString::createFromAscii( + CACHED_CONTENT_RESULTSET_FACTORY_NAME ) ); + +//-------------------------------------------------------------------------- +// Service factory implementation. +//-------------------------------------------------------------------------- + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedContentResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetFactory XCachedContentResultSetFactory methods. +//-------------------------------------------------------------------------- + + //virtual +Reference< XResultSet > SAL_CALL CachedContentResultSetFactory + ::createCachedContentResultSet( + const Reference< XResultSet > & xSource, + const Reference< XContentIdentifierMapping > & xMapping ) + throw( com::sun::star::uno::RuntimeException ) +{ + Reference< XResultSet > xRet; + xRet = new CachedContentResultSet( m_xSMgr, xSource, xMapping ); + return xRet; +} + diff --git a/ucb/source/cacher/cachedcontentresultset.hxx b/ucb/source/cacher/cachedcontentresultset.hxx new file mode 100644 index 000000000000..f2ab5dce2505 --- /dev/null +++ b/ucb/source/cacher/cachedcontentresultset.hxx @@ -0,0 +1,521 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CACHED_CONTENT_RESULTSET_HXX +#define _CACHED_CONTENT_RESULTSET_HXX + +#include <contentresultsetwrapper.hxx> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/ucb/XFetchProvider.hpp> +#include <com/sun/star/ucb/XFetchProviderForContentAccess.hpp> +#include <com/sun/star/ucb/FetchResult.hpp> +#include <com/sun/star/ucb/XContentIdentifierMapping.hpp> +#include <com/sun/star/ucb/XCachedContentResultSetFactory.hpp> + +#define CACHED_CONTENT_RESULTSET_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSet" +#define CACHED_CONTENT_RESULTSET_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetFactory" + +//========================================================================= + +namespace com { namespace sun { namespace star { namespace script { + class XTypeConverter; +} } } } + +class CCRS_PropertySetInfo; +class CachedContentResultSet + : public ContentResultSetWrapper + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo +{ + //-------------------------------------------------------------------------- + // class CCRS_Cache + + class CCRS_Cache + { + private: + com::sun::star::ucb::FetchResult* m_pResult; + com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > + m_xContentIdentifierMapping; + com::sun::star::uno::Sequence< sal_Bool >* m_pMappedReminder; + + private: + com::sun::star::uno::Any& SAL_CALL + getRowAny( sal_Int32 nRow ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + void SAL_CALL clear(); + + + void SAL_CALL remindMapped( sal_Int32 nRow ); + sal_Bool SAL_CALL isRowMapped( sal_Int32 nRow ); + void SAL_CALL clearMappedReminder(); + com::sun::star::uno::Sequence< sal_Bool >* SAL_CALL getMappedReminder(); + + public: + CCRS_Cache( const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > & xMapping ); + ~CCRS_Cache(); + + void SAL_CALL loadData( + const com::sun::star::ucb::FetchResult& rResult ); + + sal_Bool SAL_CALL + hasRow( sal_Int32 nRow ); + + sal_Bool SAL_CALL + hasCausedException( sal_Int32 nRow ); + + sal_Int32 SAL_CALL + getMaxRow(); + + sal_Bool SAL_CALL + hasKnownLast(); + + //--- + const com::sun::star::uno::Any& SAL_CALL + getAny( sal_Int32 nRow, sal_Int32 nColumnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + const rtl::OUString& SAL_CALL + getContentIdentifierString( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ); + + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& SAL_CALL + getContentIdentifier( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ); + + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContent >& SAL_CALL + getContent( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ); + }; + //----------------------------------------------------------------- + //members + + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + m_xSMgr; + + //different Interfaces from Origin: + com::sun::star::uno::Reference< com::sun::star::ucb::XFetchProvider > + m_xFetchProvider; //XFetchProvider-interface from m_xOrigin + + com::sun::star::uno::Reference< com::sun::star::ucb::XFetchProviderForContentAccess > + m_xFetchProviderForContentAccess; //XFetchProviderForContentAccess-interface from m_xOrigin + + //my PropertySetInfo + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > + m_xMyPropertySetInfo;//holds m_pMyPropSetInfo alive + CCRS_PropertySetInfo* m_pMyPropSetInfo; + + + // + com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifierMapping > + m_xContentIdentifierMapping;// can be used for remote optimized ContentAccess + + //some Properties and helping variables + sal_Int32 m_nRow; + sal_Bool m_bAfterLast; // TRUE, if m_nRow is after final count; can be TRUE without knowing the exact final count + + sal_Int32 m_nLastAppliedPos; + sal_Bool m_bAfterLastApplied; + + sal_Int32 m_nKnownCount; // count we know from the Origin + sal_Bool m_bFinalCount; // TRUE if the Origin has reached final count and we got that count in m_nKnownCount + + sal_Int32 m_nFetchSize; + sal_Int32 m_nFetchDirection; + + sal_Bool m_bLastReadWasFromCache; + sal_Bool m_bLastCachedReadWasNull; + + //cache: + CCRS_Cache m_aCache; + CCRS_Cache m_aCacheContentIdentifierString; + CCRS_Cache m_aCacheContentIdentifier; + CCRS_Cache m_aCacheContent; + + +private: + //----------------------------------------------------------------- + //helping XPropertySet methods. + virtual void SAL_CALL impl_initPropertySetInfo(); + + + //----------------------------------------------------------------- + sal_Bool SAL_CALL + applyPositionToOrigin( sal_Int32 nRow ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + void SAL_CALL + impl_fetchData( sal_Int32 nRow, sal_Int32 nCount + , sal_Int32 nFetchDirection ) + throw( com::sun::star::uno::RuntimeException ); + + sal_Bool SAL_CALL + impl_isKnownValidPosition( sal_Int32 nRow ); + + sal_Bool SAL_CALL + impl_isKnownInvalidPosition( sal_Int32 nRow ); + + void SAL_CALL + impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew ); + + void SAL_CALL + impl_changeIsRowCountFinal( sal_Bool bOld, sal_Bool bNew ); + +public: + CachedContentResultSet( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & + xSMgr, + const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > & xOrigin, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > & + xContentIdentifierMapping ); + + virtual ~CachedContentResultSet(); + + //----------------------------------------------------------------- + // XInterface inherited + //----------------------------------------------------------------- + XINTERFACE_DECL() + //----------------------------------------------------------------- + // XTypeProvider + //----------------------------------------------------------------- + XTYPEPROVIDER_DECL() + //----------------------------------------------------------------- + // XServiceInfo + //----------------------------------------------------------------- + XSERVICEINFO_NOFACTORY_DECL() + + //----------------------------------------------------------------- + // XPropertySet inherited + //----------------------------------------------------------------- + + virtual void SAL_CALL + setPropertyValue( const rtl::OUString& aPropertyName, + const com::sun::star::uno::Any& aValue ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::PropertyVetoException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Any SAL_CALL + getPropertyValue( const rtl::OUString& PropertyName ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // own inherited + //----------------------------------------------------------------- + virtual void SAL_CALL + impl_disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent ) + throw( com::sun::star::beans::PropertyVetoException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XContentAccess inherited + //----------------------------------------------------------------- + virtual rtl::OUString SAL_CALL + queryContentIdentifierString() + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier > SAL_CALL + queryContentIdentifier() + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContent > SAL_CALL + queryContent() + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XResultSet inherited + //----------------------------------------------------------------- + virtual sal_Bool SAL_CALL + next() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isBeforeFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isAfterLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + beforeFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + afterLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + first() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + last() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Int32 SAL_CALL + getRow() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + absolute( sal_Int32 row ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + relative( sal_Int32 rows ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + previous() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + refreshRow() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowUpdated() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowInserted() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowDeleted() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Reference< + com::sun::star::uno::XInterface > SAL_CALL + getStatement() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XRow inherited + //----------------------------------------------------------------- + virtual sal_Bool SAL_CALL + wasNull() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual rtl::OUString SAL_CALL + getString( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL + getBoolean( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int8 SAL_CALL + getByte( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int16 SAL_CALL + getShort( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int32 SAL_CALL + getInt( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int64 SAL_CALL + getLong( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual float SAL_CALL + getFloat( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual double SAL_CALL + getDouble( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL + getBytes( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::Date SAL_CALL + getDate( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::Time SAL_CALL + getTime( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::DateTime SAL_CALL + getTimestamp( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::io::XInputStream > SAL_CALL + getBinaryStream( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::io::XInputStream > SAL_CALL + getCharacterStream( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Any SAL_CALL + getObject( sal_Int32 columnIndex, + const com::sun::star::uno::Reference< + com::sun::star::container::XNameAccess >& typeMap ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XRef > SAL_CALL + getRef( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XBlob > SAL_CALL + getBlob( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XClob > SAL_CALL + getClob( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XArray > SAL_CALL + getArray( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // Type Converter support + //----------------------------------------------------------------- + +private: + sal_Bool m_bTriedToGetTypeConverter; + com::sun::star::uno::Reference< + com::sun::star::script::XTypeConverter > m_xTypeConverter; + + const com::sun::star::uno::Reference< + com::sun::star::script::XTypeConverter >& getTypeConverter(); +}; + +//========================================================================= + +class CachedContentResultSetFactory + : public cppu::OWeakObject + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo + , public com::sun::star::ucb::XCachedContentResultSetFactory +{ +protected: + com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + +public: + + CachedContentResultSetFactory( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & rSMgr); + + virtual ~CachedContentResultSetFactory(); + + //----------------------------------------------------------------- + // XInterface + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XTypeProvider + XTYPEPROVIDER_DECL() + + //----------------------------------------------------------------- + // XServiceInfo + XSERVICEINFO_DECL() + + //----------------------------------------------------------------- + // XCachedContentResultSetFactory + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > SAL_CALL + createCachedContentResultSet( + const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > & xSource, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > & xMapping ) + throw( com::sun::star::uno::RuntimeException ); +}; + +#endif + diff --git a/ucb/source/cacher/cachedcontentresultsetstub.cxx b/ucb/source/cacher/cachedcontentresultsetstub.cxx new file mode 100644 index 000000000000..cb0685a020f5 --- /dev/null +++ b/ucb/source/cacher/cachedcontentresultsetstub.cxx @@ -0,0 +1,631 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_ucb.hxx" + +#include <cachedcontentresultsetstub.hxx> +#include <com/sun/star/sdbc/FetchDirection.hpp> +#include <com/sun/star/ucb/FetchError.hpp> +#include <osl/diagnose.h> + +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace cppu; +using namespace rtl; + +CachedContentResultSetStub::CachedContentResultSetStub( Reference< XResultSet > xOrigin ) + : ContentResultSetWrapper( xOrigin ) + , m_nColumnCount( 0 ) + , m_bColumnCountCached( sal_False ) + , m_bNeedToPropagateFetchSize( sal_True ) + , m_bFirstFetchSizePropagationDone( sal_False ) + , m_nLastFetchSize( 1 )//this value is not important at all + , m_bLastFetchDirection( sal_True )//this value is not important at all + , m_aPropertyNameForFetchSize( OUString::createFromAscii( "FetchSize" ) ) + , m_aPropertyNameForFetchDirection( OUString::createFromAscii( "FetchDirection" ) ) +{ + impl_init(); +} + +CachedContentResultSetStub::~CachedContentResultSetStub() +{ + impl_deinit(); +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +XINTERFACE_COMMON_IMPL( CachedContentResultSetStub ) + +Any SAL_CALL CachedContentResultSetStub + ::queryInterface( const Type& rType ) + throw ( RuntimeException ) +{ + //list all interfaces inclusive baseclasses of interfaces + + Any aRet = ContentResultSetWrapper::queryInterface( rType ); + if( aRet.hasValue() ) + return aRet; + + aRet = cppu::queryInterface( rType + , static_cast< XTypeProvider* >( this ) + , static_cast< XServiceInfo* >( this ) + , static_cast< XFetchProvider* >( this ) + , static_cast< XFetchProviderForContentAccess* >( this ) + ); + + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//-------------------------------------------------------------------------- +// own methods. ( inherited ) +//-------------------------------------------------------------------------- + +//virtual +void SAL_CALL CachedContentResultSetStub + ::impl_propertyChange( const PropertyChangeEvent& rEvt ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //don't notify events on fetchsize and fetchdirection to the above CachedContentResultSet + //because it will ignore them anyway and we can save this remote calls + if( rEvt.PropertyName == m_aPropertyNameForFetchSize + || rEvt.PropertyName == m_aPropertyNameForFetchDirection ) + return; + + PropertyChangeEvent aEvt( rEvt ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = sal_False; + + impl_notifyPropertyChangeListeners( aEvt ); +} + + +//virtual +void SAL_CALL CachedContentResultSetStub + ::impl_vetoableChange( const PropertyChangeEvent& rEvt ) + throw( PropertyVetoException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //don't notify events on fetchsize and fetchdirection to the above CachedContentResultSet + //because it will ignore them anyway and we can save this remote calls + if( rEvt.PropertyName == m_aPropertyNameForFetchSize + || rEvt.PropertyName == m_aPropertyNameForFetchDirection ) + return; + + PropertyChangeEvent aEvt( rEvt ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = sal_False; + + impl_notifyVetoableChangeListeners( aEvt ); +} + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_COMMON_IMPL( CachedContentResultSetStub ) +//list all interfaces exclusive baseclasses +Sequence< Type > SAL_CALL CachedContentResultSetStub + ::getTypes() + throw( RuntimeException ) +{ + static Sequence< Type >* pTypes = NULL; + if( !pTypes ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pTypes ) + { + pTypes = new Sequence< Type >(13); + (*pTypes)[0] = CPPU_TYPE_REF( XTypeProvider ); + (*pTypes)[1] = CPPU_TYPE_REF( XServiceInfo ); + (*pTypes)[2] = CPPU_TYPE_REF( XComponent ); + (*pTypes)[3] = CPPU_TYPE_REF( XCloseable ); + (*pTypes)[4] = CPPU_TYPE_REF( XResultSetMetaDataSupplier ); + (*pTypes)[5] = CPPU_TYPE_REF( XPropertySet ); + (*pTypes)[6] = CPPU_TYPE_REF( XPropertyChangeListener ); + (*pTypes)[7] = CPPU_TYPE_REF( XVetoableChangeListener ); + (*pTypes)[8] = CPPU_TYPE_REF( XResultSet ); + (*pTypes)[9] = CPPU_TYPE_REF( XContentAccess ); + (*pTypes)[10] = CPPU_TYPE_REF( XRow ); + (*pTypes)[11] = CPPU_TYPE_REF( XFetchProvider ); + (*pTypes)[12] = CPPU_TYPE_REF( XFetchProviderForContentAccess ); + } + } + return *pTypes; + /* + static cppu::OTypeCollection * pCollection = 0; + if (!pCollection) + { + osl::MutexGuard aGuard(osl::Mutex::getGlobalMutex()); + if (!pCollection) + { + static cppu::OTypeCollection + aTheCollection( + getCppuType( + static_cast< Reference< XTypeProvider > + const * >( + 0)), + getCppuType( + static_cast< Reference< XServiceInfo > + const * >( + 0)), + getCppuType( + static_cast< Reference< XComponent > + const * >( + 0)), + getCppuType( + static_cast< Reference< XCloseable > + const * >( + 0)), + getCppuType( + static_cast< Reference< XResultSetMetaDataSupplier > + const * >( + 0)), + getCppuType( + static_cast< Reference< XPropertySet > + const * >( + 0)), + getCppuType( + static_cast< Reference< XPropertyChangeListener > + const * >( + 0)), + getCppuType( + static_cast< Reference< XVetoableChangeListener > + const * >( + 0)), + getCppuType( + static_cast< Reference< XResultSet > + const * >( + 0)), + getCppuType( + static_cast< Reference< XContentAccess > + const * >( + 0)), + getCppuType( + static_cast< Reference< XRow > + const * >( + 0)), + getCppuType( + static_cast< Reference< XFetchProvider > + const * >( + 0)), + getCppuType( + static_cast< Reference< XFetchProviderForContentAccess > + const * >( + 0)) + ); + pCollection = &aTheCollection; + } + } + return pCollection->getTypes(); + */ +} + +//-------------------------------------------------------------------------- +// XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_NOFACTORY_IMPL_1( CachedContentResultSetStub, + OUString::createFromAscii( + "com.sun.star.comp.ucb.CachedContentResultSetStub" ), + OUString::createFromAscii( + CACHED_CRS_STUB_SERVICE_NAME ) ); + +//----------------------------------------------------------------- +// XFetchProvider methods. +//----------------------------------------------------------------- + +#define FETCH_XXX( impl_loadRow, loadInterface ) \ +impl_EnsureNotDisposed(); \ +if( !m_xResultSetOrigin.is() ) \ +{ \ + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); \ + throw RuntimeException(); \ +} \ +impl_propagateFetchSizeAndDirection( nRowCount, bDirection ); \ +FetchResult aRet; \ +aRet.StartIndex = nRowStartPosition; \ +aRet.Orientation = bDirection; \ +aRet.FetchError = FetchError::SUCCESS; /*ENDOFDATA, EXCEPTION*/ \ +sal_Int32 nOldOriginal_Pos = m_xResultSetOrigin->getRow(); \ +if( impl_isForwardOnly() ) \ +{ \ + if( nOldOriginal_Pos != nRowStartPosition ) \ + { \ + /*@todo*/ \ + aRet.FetchError = FetchError::EXCEPTION; \ + return aRet; \ + } \ + if( nRowCount != 1 ) \ + aRet.FetchError = FetchError::EXCEPTION; \ + \ + aRet.Rows.realloc( 1 ); \ + \ + try \ + { \ + impl_loadRow( aRet.Rows[0], loadInterface ); \ + } \ + catch( SQLException& ) \ + { \ + aRet.Rows.realloc( 0 ); \ + aRet.FetchError = FetchError::EXCEPTION; \ + return aRet; \ + } \ + return aRet; \ +} \ +aRet.Rows.realloc( nRowCount ); \ +sal_Bool bOldOriginal_AfterLast = sal_False; \ +if( !nOldOriginal_Pos ) \ + bOldOriginal_AfterLast = m_xResultSetOrigin->isAfterLast(); \ +sal_Int32 nN = 1; \ +sal_Bool bValidNewPos = sal_False; \ +try \ +{ \ + try \ + { \ + /*if( nOldOriginal_Pos != nRowStartPosition )*/ \ + bValidNewPos = m_xResultSetOrigin->absolute( nRowStartPosition ); \ + } \ + catch( SQLException& ) \ + { \ + aRet.Rows.realloc( 0 ); \ + aRet.FetchError = FetchError::EXCEPTION; \ + return aRet; \ + } \ + if( !bValidNewPos ) \ + { \ + aRet.Rows.realloc( 0 ); \ + aRet.FetchError = FetchError::EXCEPTION; \ + \ + /*restore old position*/ \ + if( nOldOriginal_Pos ) \ + m_xResultSetOrigin->absolute( nOldOriginal_Pos ); \ + else if( bOldOriginal_AfterLast ) \ + m_xResultSetOrigin->afterLast(); \ + else \ + m_xResultSetOrigin->beforeFirst(); \ + \ + return aRet; \ + } \ + for( ; nN <= nRowCount; ) \ + { \ + impl_loadRow( aRet.Rows[nN-1], loadInterface ); \ + nN++; \ + if( nN <= nRowCount ) \ + { \ + if( bDirection ) \ + { \ + if( !m_xResultSetOrigin->next() ) \ + { \ + aRet.Rows.realloc( nN-1 ); \ + aRet.FetchError = FetchError::ENDOFDATA; \ + break; \ + } \ + } \ + else \ + { \ + if( !m_xResultSetOrigin->previous() ) \ + { \ + aRet.Rows.realloc( nN-1 ); \ + aRet.FetchError = FetchError::ENDOFDATA; \ + break; \ + } \ + } \ + } \ + } \ +} \ +catch( SQLException& ) \ +{ \ + aRet.Rows.realloc( nN-1 ); \ + aRet.FetchError = FetchError::EXCEPTION; \ +} \ +/*restore old position*/ \ +if( nOldOriginal_Pos ) \ + m_xResultSetOrigin->absolute( nOldOriginal_Pos ); \ +else if( bOldOriginal_AfterLast ) \ + m_xResultSetOrigin->afterLast(); \ +else \ + m_xResultSetOrigin->beforeFirst(); \ +return aRet; + +FetchResult SAL_CALL CachedContentResultSetStub + ::fetch( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( RuntimeException ) +{ + impl_init_xRowOrigin(); + FETCH_XXX( impl_getCurrentRowContent, m_xRowOrigin ); +} + +sal_Int32 SAL_CALL CachedContentResultSetStub + ::impl_getColumnCount() +{ + sal_Int32 nCount; + sal_Bool bCached; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + nCount = m_nColumnCount; + bCached = m_bColumnCountCached; + } + if( !bCached ) + { + try + { + Reference< XResultSetMetaData > xMetaData = getMetaData(); + if( xMetaData.is() ) + nCount = xMetaData->getColumnCount(); + } + catch( SQLException& ) + { + OSL_ENSURE( sal_False, "couldn't determine the column count" ); + nCount = 0; + } + } + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_nColumnCount = nCount; + m_bColumnCountCached = sal_True; + return m_nColumnCount; +} + +void SAL_CALL CachedContentResultSetStub + ::impl_getCurrentRowContent( Any& rRowContent + , Reference< XRow > xRow ) + throw ( SQLException, RuntimeException ) +{ + sal_Int32 nCount = impl_getColumnCount(); + + Sequence< Any > aContent( nCount ); + for( sal_Int32 nN = 1; nN <= nCount; nN++ ) + { + aContent[nN-1] = xRow->getObject( nN, NULL ); + } + + rRowContent <<= aContent; +} + +void SAL_CALL CachedContentResultSetStub + ::impl_propagateFetchSizeAndDirection( sal_Int32 nFetchSize, sal_Bool bFetchDirection ) + throw ( RuntimeException ) +{ + //this is done only for the case, that there is another CachedContentResultSet in the chain of underlying ResulSets + + //we do not propagate the property 'FetchSize' or 'FetchDirection' via 'setPropertyValue' from the above CachedContentResultSet to save remote calls + + //if the underlying ResultSet has a property FetchSize and FetchDirection, + //we will set these properties, if the new given parameters are different from the last ones + + if( !m_bNeedToPropagateFetchSize ) + return; + + sal_Bool bNeedAction; + sal_Int32 nLastSize; + sal_Bool bLastDirection; + sal_Bool bFirstPropagationDone; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + bNeedAction = m_bNeedToPropagateFetchSize; + nLastSize = m_nLastFetchSize; + bLastDirection = m_bLastFetchDirection; + bFirstPropagationDone = m_bFirstFetchSizePropagationDone; + } + if( bNeedAction ) + { + if( nLastSize == nFetchSize + && bLastDirection == bFetchDirection + && bFirstPropagationDone == sal_True ) + return; + + if(!bFirstPropagationDone) + { + //check wether the properties 'FetchSize' and 'FetchDirection' do exist + + Reference< XPropertySetInfo > xPropertySetInfo = getPropertySetInfo(); + sal_Bool bHasSize = xPropertySetInfo->hasPropertyByName( m_aPropertyNameForFetchSize ); + sal_Bool bHasDirection = xPropertySetInfo->hasPropertyByName( m_aPropertyNameForFetchDirection ); + + if(!bHasSize || !bHasDirection) + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_bNeedToPropagateFetchSize = sal_False; + return; + } + } + + sal_Bool bSetSize = ( nLastSize !=nFetchSize ) || !bFirstPropagationDone; + sal_Bool bSetDirection = ( bLastDirection !=bFetchDirection ) || !bFirstPropagationDone; + + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_bFirstFetchSizePropagationDone = sal_True; + m_nLastFetchSize = nFetchSize; + m_bLastFetchDirection = bFetchDirection; + } + + if( bSetSize ) + { + Any aValue; + aValue <<= nFetchSize; + try + { + setPropertyValue( m_aPropertyNameForFetchSize, aValue ); + } + catch( com::sun::star::uno::Exception& ) {} + } + if( bSetDirection ) + { + sal_Int32 nFetchDirection = FetchDirection::FORWARD; + if( !bFetchDirection ) + nFetchDirection = FetchDirection::REVERSE; + Any aValue; + aValue <<= nFetchDirection; + try + { + setPropertyValue( m_aPropertyNameForFetchDirection, aValue ); + } + catch( com::sun::star::uno::Exception& ) {} + } + + } +} + +//----------------------------------------------------------------- +// XFetchProviderForContentAccess methods. +//----------------------------------------------------------------- + +void SAL_CALL CachedContentResultSetStub + ::impl_getCurrentContentIdentifierString( Any& rAny + , Reference< XContentAccess > xContentAccess ) + throw ( RuntimeException ) +{ + rAny <<= xContentAccess->queryContentIdentifierString(); +} + +void SAL_CALL CachedContentResultSetStub + ::impl_getCurrentContentIdentifier( Any& rAny + , Reference< XContentAccess > xContentAccess ) + throw ( RuntimeException ) +{ + rAny <<= xContentAccess->queryContentIdentifier(); +} + +void SAL_CALL CachedContentResultSetStub + ::impl_getCurrentContent( Any& rAny + , Reference< XContentAccess > xContentAccess ) + throw ( RuntimeException ) +{ + rAny <<= xContentAccess->queryContent(); +} + +//virtual +FetchResult SAL_CALL CachedContentResultSetStub + ::fetchContentIdentifierStrings( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ) +{ + impl_init_xContentAccessOrigin(); + FETCH_XXX( impl_getCurrentContentIdentifierString, m_xContentAccessOrigin ); +} + +//virtual +FetchResult SAL_CALL CachedContentResultSetStub + ::fetchContentIdentifiers( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ) +{ + impl_init_xContentAccessOrigin(); + FETCH_XXX( impl_getCurrentContentIdentifier, m_xContentAccessOrigin ); +} + +//virtual +FetchResult SAL_CALL CachedContentResultSetStub + ::fetchContents( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ) +{ + impl_init_xContentAccessOrigin(); + FETCH_XXX( impl_getCurrentContent, m_xContentAccessOrigin ); +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CachedContentResultSetStubFactory +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedContentResultSetStubFactory::CachedContentResultSetStubFactory( + const Reference< XMultiServiceFactory > & rSMgr ) +{ + m_xSMgr = rSMgr; +} + +CachedContentResultSetStubFactory::~CachedContentResultSetStubFactory() +{ +} + +//-------------------------------------------------------------------------- +// CachedContentResultSetStubFactory XInterface methods. +//-------------------------------------------------------------------------- + +XINTERFACE_IMPL_3( CachedContentResultSetStubFactory, + XTypeProvider, + XServiceInfo, + XCachedContentResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetStubFactory XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_3( CachedContentResultSetStubFactory, + XTypeProvider, + XServiceInfo, + XCachedContentResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetStubFactory XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_IMPL_1( CachedContentResultSetStubFactory, + OUString::createFromAscii( + "com.sun.star.comp.ucb.CachedContentResultSetStubFactory" ), + OUString::createFromAscii( + CACHED_CRS_STUB_FACTORY_NAME ) ); + +//-------------------------------------------------------------------------- +// Service factory implementation. +//-------------------------------------------------------------------------- + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedContentResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetStubFactory XCachedContentResultSetStubFactory methods. +//-------------------------------------------------------------------------- + + //virtual +Reference< XResultSet > SAL_CALL CachedContentResultSetStubFactory + ::createCachedContentResultSetStub( + const Reference< XResultSet > & xSource ) + throw( RuntimeException ) +{ + if( xSource.is() ) + { + Reference< XResultSet > xRet; + xRet = new CachedContentResultSetStub( xSource ); + return xRet; + } + return NULL; +} + + diff --git a/ucb/source/cacher/cachedcontentresultsetstub.hxx b/ucb/source/cacher/cachedcontentresultsetstub.hxx new file mode 100644 index 000000000000..59394e232dde --- /dev/null +++ b/ucb/source/cacher/cachedcontentresultsetstub.hxx @@ -0,0 +1,202 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CACHED_CONTENT_RESULTSET_STUB_HXX +#define _CACHED_CONTENT_RESULTSET_STUB_HXX + +#include <contentresultsetwrapper.hxx> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/ucb/XFetchProvider.hpp> +#include <com/sun/star/ucb/XFetchProviderForContentAccess.hpp> +#include <com/sun/star/ucb/XCachedContentResultSetStubFactory.hpp> + +#define CACHED_CRS_STUB_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSetStub" +#define CACHED_CRS_STUB_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetStubFactory" + +//========================================================================= + +class CachedContentResultSetStub + : public ContentResultSetWrapper + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo + , public com::sun::star::ucb::XFetchProvider + , public com::sun::star::ucb::XFetchProviderForContentAccess +{ +private: + sal_Int32 m_nColumnCount; + sal_Bool m_bColumnCountCached; + + //members to propagate fetchsize and direction: + sal_Bool m_bNeedToPropagateFetchSize; + sal_Bool m_bFirstFetchSizePropagationDone; + sal_Int32 m_nLastFetchSize; + sal_Bool m_bLastFetchDirection; + const rtl::OUString m_aPropertyNameForFetchSize; + const rtl::OUString m_aPropertyNameForFetchDirection; + + + void SAL_CALL + impl_getCurrentRowContent( + com::sun::star::uno::Any& rRowContent, + com::sun::star::uno::Reference< + com::sun::star::sdbc::XRow > xRow ) + throw ( com::sun::star::sdbc::SQLException + , com::sun::star::uno::RuntimeException ); + + sal_Int32 SAL_CALL + impl_getColumnCount(); + + void SAL_CALL + impl_getCurrentContentIdentifierString( + com::sun::star::uno::Any& rAny + , com::sun::star::uno::Reference< + com::sun::star::ucb::XContentAccess > xContentAccess ) + throw ( com::sun::star::uno::RuntimeException ); + + void SAL_CALL + impl_getCurrentContentIdentifier( + com::sun::star::uno::Any& rAny + , com::sun::star::uno::Reference< + com::sun::star::ucb::XContentAccess > xContentAccess ) + throw ( com::sun::star::uno::RuntimeException ); + + void SAL_CALL + impl_getCurrentContent( + com::sun::star::uno::Any& rAny + , com::sun::star::uno::Reference< + com::sun::star::ucb::XContentAccess > xContentAccess ) + throw ( com::sun::star::uno::RuntimeException ); + + void SAL_CALL + impl_propagateFetchSizeAndDirection( sal_Int32 nFetchSize, sal_Bool bFetchDirection ) + throw ( com::sun::star::uno::RuntimeException ); + +public: + CachedContentResultSetStub( com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > xOrigin ); + + virtual ~CachedContentResultSetStub(); + + + //----------------------------------------------------------------- + // XInterface inherited + //----------------------------------------------------------------- + XINTERFACE_DECL() + //----------------------------------------------------------------- + // own inherited + //----------------------------------------------------------------- + virtual void SAL_CALL + impl_propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent ) + throw( com::sun::star::beans::PropertyVetoException, + com::sun::star::uno::RuntimeException ); + //----------------------------------------------------------------- + // XTypeProvider + //----------------------------------------------------------------- + XTYPEPROVIDER_DECL() + //----------------------------------------------------------------- + // XServiceInfo + //----------------------------------------------------------------- + XSERVICEINFO_NOFACTORY_DECL() + + //----------------------------------------------------------------- + // XFetchProvider + //----------------------------------------------------------------- + + virtual com::sun::star::ucb::FetchResult SAL_CALL + fetch( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XFetchProviderForContentAccess + //----------------------------------------------------------------- + virtual com::sun::star::ucb::FetchResult SAL_CALL + fetchContentIdentifierStrings( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::ucb::FetchResult SAL_CALL + fetchContentIdentifiers( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::ucb::FetchResult SAL_CALL + fetchContents( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ); +}; + +//========================================================================= + +class CachedContentResultSetStubFactory + : public cppu::OWeakObject + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo + , public com::sun::star::ucb::XCachedContentResultSetStubFactory +{ +protected: + com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + +public: + + CachedContentResultSetStubFactory( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & rSMgr); + + virtual ~CachedContentResultSetStubFactory(); + + //----------------------------------------------------------------- + // XInterface + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XTypeProvider + XTYPEPROVIDER_DECL() + + //----------------------------------------------------------------- + // XServiceInfo + XSERVICEINFO_DECL() + + //----------------------------------------------------------------- + // XCachedContentResultSetStubFactory + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > SAL_CALL + createCachedContentResultSetStub( + const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > & xSource ) + throw( com::sun::star::uno::RuntimeException ); +}; + +#endif + diff --git a/ucb/source/cacher/cacheddynamicresultset.cxx b/ucb/source/cacher/cacheddynamicresultset.cxx new file mode 100644 index 000000000000..ad7bf9f9686c --- /dev/null +++ b/ucb/source/cacher/cacheddynamicresultset.cxx @@ -0,0 +1,206 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_ucb.hxx" + +#include <cacheddynamicresultset.hxx> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <cachedcontentresultset.hxx> +#include <osl/diagnose.h> + +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace rtl; + +CachedDynamicResultSet::CachedDynamicResultSet( + Reference< XDynamicResultSet > xOrigin + , const Reference< XContentIdentifierMapping > & xContentMapping + , const Reference< XMultiServiceFactory > & xSMgr ) + : DynamicResultSetWrapper( xOrigin, xSMgr ) + , m_xContentIdentifierMapping( xContentMapping ) +{ + impl_init(); +} + +CachedDynamicResultSet::~CachedDynamicResultSet() +{ + impl_deinit(); +} + +//virtual +void SAL_CALL CachedDynamicResultSet + ::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet ) +{ + DynamicResultSetWrapper::impl_InitResultSetOne( xResultSet ); + OSL_ENSURE( m_xSourceResultOne.is(), "need source resultset" ); + + Reference< XResultSet > xCache( + new CachedContentResultSet( m_xSMgr, m_xSourceResultOne, m_xContentIdentifierMapping ) ); + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_xMyResultOne = xCache; +} + +//virtual +void SAL_CALL CachedDynamicResultSet + ::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet ) +{ + DynamicResultSetWrapper::impl_InitResultSetTwo( xResultSet ); + OSL_ENSURE( m_xSourceResultTwo.is(), "need source resultset" ); + + Reference< XResultSet > xCache( + new CachedContentResultSet( m_xSMgr, m_xSourceResultTwo, m_xContentIdentifierMapping ) ); + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_xMyResultTwo = xCache; +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +XINTERFACE_COMMON_IMPL( CachedDynamicResultSet ) + +Any SAL_CALL CachedDynamicResultSet + ::queryInterface( const Type& rType ) + throw ( RuntimeException ) +{ + //list all interfaces inclusive baseclasses of interfaces + + Any aRet = DynamicResultSetWrapper::queryInterface( rType ); + if( aRet.hasValue() ) + return aRet; + + aRet = cppu::queryInterface( rType, + static_cast< XTypeProvider* >( this ) + , static_cast< XServiceInfo* >( this ) + ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- +//list all interfaces exclusive baseclasses +XTYPEPROVIDER_IMPL_4( CachedDynamicResultSet + , XTypeProvider + , XServiceInfo + , XDynamicResultSet + , XSourceInitialization + ); + +//-------------------------------------------------------------------------- +// XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSet, + OUString::createFromAscii( + "com.sun.star.comp.ucb.CachedDynamicResultSet" ), + OUString::createFromAscii( + CACHED_DRS_SERVICE_NAME ) ); + +//-------------------------------------------------------------------------- +// own methds. ( inherited ) +//-------------------------------------------------------------------------- +//virtual +void SAL_CALL CachedDynamicResultSet + ::impl_disposing( const EventObject& Source ) + throw( RuntimeException ) +{ + DynamicResultSetWrapper::impl_disposing( Source ); + m_xContentIdentifierMapping.clear(); +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CachedDynamicResultSetFactory +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedDynamicResultSetFactory::CachedDynamicResultSetFactory( + const Reference< XMultiServiceFactory > & rSMgr ) +{ + m_xSMgr = rSMgr; +} + +CachedDynamicResultSetFactory::~CachedDynamicResultSetFactory() +{ +} + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetFactory XInterface methods. +//-------------------------------------------------------------------------- + +XINTERFACE_IMPL_3( CachedDynamicResultSetFactory, + XTypeProvider, + XServiceInfo, + XCachedDynamicResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetFactory XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetFactory, + XTypeProvider, + XServiceInfo, + XCachedDynamicResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetFactory XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_IMPL_1( CachedDynamicResultSetFactory, + OUString::createFromAscii( + "com.sun.star.comp.ucb.CachedDynamicResultSetFactory" ), + OUString::createFromAscii( + CACHED_DRS_FACTORY_NAME ) ); + +//-------------------------------------------------------------------------- +// Service factory implementation. +//-------------------------------------------------------------------------- + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetFactory XCachedDynamicResultSetFactory methods. +//-------------------------------------------------------------------------- + +//virtual +Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetFactory + ::createCachedDynamicResultSet( + const Reference< XDynamicResultSet > & SourceStub + , const Reference< XContentIdentifierMapping > & ContentIdentifierMapping ) + throw( RuntimeException ) +{ + Reference< XDynamicResultSet > xRet; + xRet = new CachedDynamicResultSet( SourceStub, ContentIdentifierMapping, m_xSMgr ); + return xRet; +} + + diff --git a/ucb/source/cacher/cacheddynamicresultset.hxx b/ucb/source/cacher/cacheddynamicresultset.hxx new file mode 100644 index 000000000000..ba57238e47c0 --- /dev/null +++ b/ucb/source/cacher/cacheddynamicresultset.hxx @@ -0,0 +1,137 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CACHED_DYNAMIC_RESULTSET_HXX +#define _CACHED_DYNAMIC_RESULTSET_HXX + +#include <dynamicresultsetwrapper.hxx> +#include <com/sun/star/ucb/XContentIdentifierMapping.hpp> +#include <com/sun/star/ucb/XCachedDynamicResultSetFactory.hpp> + +#define CACHED_DRS_SERVICE_NAME "com.sun.star.ucb.CachedDynamicResultSet" +#define CACHED_DRS_FACTORY_NAME "com.sun.star.ucb.CachedDynamicResultSetFactory" + +//========================================================================= + +class CachedDynamicResultSet + : public DynamicResultSetWrapper + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo +{ + com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifierMapping > + m_xContentIdentifierMapping; + +protected: + virtual void SAL_CALL + impl_InitResultSetOne( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + virtual void SAL_CALL + impl_InitResultSetTwo( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + +public: + CachedDynamicResultSet( com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > xOrigin + , const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > & xContentMapping + , const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & xSMgr ); + + virtual ~CachedDynamicResultSet(); + + + //----------------------------------------------------------------- + // XInterface inherited + //----------------------------------------------------------------- + XINTERFACE_DECL() + //----------------------------------------------------------------- + // XTypeProvider + //----------------------------------------------------------------- + XTYPEPROVIDER_DECL() + //----------------------------------------------------------------- + // XServiceInfo + //----------------------------------------------------------------- + XSERVICEINFO_NOFACTORY_DECL() + + //----------------------------------------------------------------- + // own methods ( inherited ) + //----------------------------------------------------------------- + virtual void SAL_CALL + impl_disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); +}; + +//========================================================================= + +class CachedDynamicResultSetFactory + : public cppu::OWeakObject + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo + , public com::sun::star::ucb::XCachedDynamicResultSetFactory +{ +protected: + com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + +public: + + CachedDynamicResultSetFactory( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & rSMgr); + + virtual ~CachedDynamicResultSetFactory(); + + //----------------------------------------------------------------- + // XInterface + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XTypeProvider + XTYPEPROVIDER_DECL() + + //----------------------------------------------------------------- + // XServiceInfo + XSERVICEINFO_DECL() + + //----------------------------------------------------------------- + // XCachedDynamicResultSetFactory + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > SAL_CALL + createCachedDynamicResultSet( + const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > & + SourceStub + , const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > & + ContentIdentifierMapping + ) + throw( com::sun::star::uno::RuntimeException ); +}; + +#endif + diff --git a/ucb/source/cacher/cacheddynamicresultsetstub.cxx b/ucb/source/cacher/cacheddynamicresultsetstub.cxx new file mode 100644 index 000000000000..09c5f029d4ac --- /dev/null +++ b/ucb/source/cacher/cacheddynamicresultsetstub.cxx @@ -0,0 +1,245 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_ucb.hxx" + +#include <cacheddynamicresultsetstub.hxx> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <cachedcontentresultsetstub.hxx> +#include <com/sun/star/ucb/ContentResultSetCapability.hpp> +#include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp> +#include <osl/diagnose.h> + +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace rtl; + +CachedDynamicResultSetStub::CachedDynamicResultSetStub( + Reference< XDynamicResultSet > xOrigin + , const Reference< XMultiServiceFactory > & xSMgr ) + : DynamicResultSetWrapper( xOrigin, xSMgr ) +{ + OSL_ENSURE( m_xSMgr.is(), "need Multiservicefactory to create stub" ); + impl_init(); +} + +CachedDynamicResultSetStub::~CachedDynamicResultSetStub() +{ + impl_deinit(); +} + +//virtual +void SAL_CALL CachedDynamicResultSetStub + ::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet ) +{ + DynamicResultSetWrapper::impl_InitResultSetOne( xResultSet ); + OSL_ENSURE( m_xSourceResultOne.is(), "need source resultset" ); + + Reference< XResultSet > xStub( + new CachedContentResultSetStub( m_xSourceResultOne ) ); + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_xMyResultOne = xStub; +} + +//virtual +void SAL_CALL CachedDynamicResultSetStub + ::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet ) +{ + DynamicResultSetWrapper::impl_InitResultSetTwo( xResultSet ); + OSL_ENSURE( m_xSourceResultTwo.is(), "need source resultset" ); + + Reference< XResultSet > xStub( + new CachedContentResultSetStub( m_xSourceResultTwo ) ); + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_xMyResultTwo = xStub; +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +XINTERFACE_COMMON_IMPL( CachedDynamicResultSetStub ) + +Any SAL_CALL CachedDynamicResultSetStub + ::queryInterface( const Type& rType ) + throw ( RuntimeException ) +{ + //list all interfaces inclusive baseclasses of interfaces + + Any aRet = DynamicResultSetWrapper::queryInterface( rType ); + if( aRet.hasValue() ) + return aRet; + + aRet = cppu::queryInterface( rType, + static_cast< XTypeProvider* >( this ) + , static_cast< XServiceInfo* >( this ) + ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- +//list all interfaces exclusive baseclasses +XTYPEPROVIDER_IMPL_5( CachedDynamicResultSetStub + , XTypeProvider + , XServiceInfo + , XDynamicResultSet + , XDynamicResultSetListener + , XSourceInitialization + ); + +//-------------------------------------------------------------------------- +// XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSetStub, + OUString::createFromAscii( + "com.sun.star.comp.ucb.CachedDynamicResultSetStub" ), + OUString::createFromAscii( + CACHED_DRS_STUB_SERVICE_NAME ) ); + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CachedDynamicResultSetStubFactory +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedDynamicResultSetStubFactory::CachedDynamicResultSetStubFactory( + const Reference< XMultiServiceFactory > & rSMgr ) +{ + m_xSMgr = rSMgr; +} + +CachedDynamicResultSetStubFactory::~CachedDynamicResultSetStubFactory() +{ +} + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetStubFactory XInterface methods. +//-------------------------------------------------------------------------- + +XINTERFACE_IMPL_3( CachedDynamicResultSetStubFactory, + XTypeProvider, + XServiceInfo, + XCachedDynamicResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetStubFactory XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetStubFactory, + XTypeProvider, + XServiceInfo, + XCachedDynamicResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetStubFactory XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_IMPL_1( CachedDynamicResultSetStubFactory, + OUString::createFromAscii( + "com.sun.star.comp.ucb.CachedDynamicResultSetStubFactory" ), + OUString::createFromAscii( + CACHED_DRS_STUB_FACTORY_NAME ) ); + +//-------------------------------------------------------------------------- +// Service factory implementation. +//-------------------------------------------------------------------------- + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetStubFactory XCachedDynamicResultSetStubFactory methods. +//-------------------------------------------------------------------------- + +//virtual +Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetStubFactory + ::createCachedDynamicResultSetStub( + const Reference< XDynamicResultSet > & Source ) + throw( RuntimeException ) +{ + Reference< XDynamicResultSet > xRet; + xRet = new CachedDynamicResultSetStub( Source, m_xSMgr ); + return xRet; +} + +//virtual +void SAL_CALL CachedDynamicResultSetStubFactory + ::connectToCache( + const Reference< XDynamicResultSet > & Source + , const Reference< XDynamicResultSet > & TargetCache + , const Sequence< NumberedSortingInfo > & SortingInfo + , const Reference< XAnyCompareFactory > & CompareFactory + ) + throw ( ListenerAlreadySetException + , AlreadyInitializedException + , RuntimeException ) +{ + OSL_ENSURE( Source.is(), "a Source is needed" ); + OSL_ENSURE( TargetCache.is(), "a TargetCache is needed" ); + + Reference< XDynamicResultSet > xSource( Source ); + if( SortingInfo.getLength() && + !( xSource->getCapabilities() & ContentResultSetCapability::SORTED ) + ) + { + Reference< XSortedDynamicResultSetFactory > xSortFactory; + try + { + xSortFactory = Reference< XSortedDynamicResultSetFactory >( + m_xSMgr->createInstance( OUString::createFromAscii( + "com.sun.star.ucb.SortedDynamicResultSetFactory" ) ), + UNO_QUERY ); + } + catch ( Exception const & ) + { + } + + if( xSortFactory.is() ) + { + Reference< XDynamicResultSet > xSorted( + xSortFactory->createSortedDynamicResultSet( + Source, SortingInfo, CompareFactory ) ); + if( xSorted.is() ) + xSource = xSorted; + } + } + + Reference< XDynamicResultSet > xStub( + new CachedDynamicResultSetStub( xSource, m_xSMgr ) ); + + Reference< XSourceInitialization > xTarget( TargetCache, UNO_QUERY ); + OSL_ENSURE( xTarget.is(), "Target must have interface XSourceInitialization" ); + + xTarget->setSource( xStub ); +} + diff --git a/ucb/source/cacher/cacheddynamicresultsetstub.hxx b/ucb/source/cacher/cacheddynamicresultsetstub.hxx new file mode 100644 index 000000000000..33608e88f4e2 --- /dev/null +++ b/ucb/source/cacher/cacheddynamicresultsetstub.hxx @@ -0,0 +1,136 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CACHED_DYNAMIC_RESULTSET_STUB_HXX +#define _CACHED_DYNAMIC_RESULTSET_STUB_HXX + +#include <dynamicresultsetwrapper.hxx> +#include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp> + +#define CACHED_DRS_STUB_SERVICE_NAME "com.sun.star.ucb.CachedDynamicResultSetStub" +#define CACHED_DRS_STUB_FACTORY_NAME "com.sun.star.ucb.CachedDynamicResultSetStubFactory" + +//========================================================================= + +class CachedDynamicResultSetStub + : public DynamicResultSetWrapper + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo +{ +protected: + virtual void SAL_CALL + impl_InitResultSetOne( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + virtual void SAL_CALL + impl_InitResultSetTwo( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + +public: + CachedDynamicResultSetStub( com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > xOrigin + , const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & xSMgr ); + + virtual ~CachedDynamicResultSetStub(); + + + //----------------------------------------------------------------- + // XInterface inherited + //----------------------------------------------------------------- + XINTERFACE_DECL() + //----------------------------------------------------------------- + // XTypeProvider + //----------------------------------------------------------------- + XTYPEPROVIDER_DECL() + //----------------------------------------------------------------- + // XServiceInfo + //----------------------------------------------------------------- + XSERVICEINFO_NOFACTORY_DECL() +}; + +//========================================================================= + +class CachedDynamicResultSetStubFactory + : public cppu::OWeakObject + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo + , public com::sun::star::ucb::XCachedDynamicResultSetStubFactory +{ +protected: + com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + +public: + + CachedDynamicResultSetStubFactory( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & rSMgr); + + virtual ~CachedDynamicResultSetStubFactory(); + + //----------------------------------------------------------------- + // XInterface + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XTypeProvider + XTYPEPROVIDER_DECL() + + //----------------------------------------------------------------- + // XServiceInfo + XSERVICEINFO_DECL() + + //----------------------------------------------------------------- + // XCachedDynamicResultSetStubFactory + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > SAL_CALL + createCachedDynamicResultSetStub( + const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > & Source ) + throw( com::sun::star::uno::RuntimeException ); + + + virtual void SAL_CALL connectToCache( + const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > & Source + , const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > & TargetCache + , const com::sun::star::uno::Sequence< + com::sun::star::ucb::NumberedSortingInfo > & SortingInfo + , const com::sun::star::uno::Reference< + com::sun::star::ucb::XAnyCompareFactory > & CompareFactory + ) + throw ( + com::sun::star::ucb::ListenerAlreadySetException + , com::sun::star::ucb::AlreadyInitializedException + , com::sun::star::uno::RuntimeException + ); +}; + +#endif + diff --git a/ucb/source/cacher/cacheserv.cxx b/ucb/source/cacher/cacheserv.cxx new file mode 100644 index 000000000000..3aa0f1de5357 --- /dev/null +++ b/ucb/source/cacher/cacheserv.cxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_ucb.hxx" +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <cachedcontentresultset.hxx> +#include <cachedcontentresultsetstub.hxx> +#include <cacheddynamicresultset.hxx> +#include <cacheddynamicresultsetstub.hxx> + +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; + +//========================================================================= +static sal_Bool writeInfo( void * pRegistryKey, + const OUString & rImplementationName, + Sequence< OUString > const & rServiceNames ) +{ + OUString aKeyName( OUString::createFromAscii( "/" ) ); + aKeyName += rImplementationName; + aKeyName += OUString::createFromAscii( "/UNO/SERVICES" ); + + Reference< XRegistryKey > xKey; + try + { + xKey = static_cast< XRegistryKey * >( + pRegistryKey )->createKey( aKeyName ); + } + catch ( InvalidRegistryException const & ) + { + } + + if ( !xKey.is() ) + return sal_False; + + sal_Bool bSuccess = sal_True; + + for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n ) + { + try + { + xKey->createKey( rServiceNames[ n ] ); + } + catch ( InvalidRegistryException const & ) + { + bSuccess = sal_False; + break; + } + } + return bSuccess; +} + +//========================================================================= +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//========================================================================= +extern "C" sal_Bool SAL_CALL component_writeInfo( void *, void * pRegistryKey ) +{ + return pRegistryKey && + + ////////////////////////////////////////////////////////////////////// + // CachedContentResultSetFactory. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + CachedContentResultSetFactory::getImplementationName_Static(), + CachedContentResultSetFactory::getSupportedServiceNames_Static() ) && + + ////////////////////////////////////////////////////////////////////// + // CachedContentResultSetStubFactory. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + CachedContentResultSetStubFactory::getImplementationName_Static(), + CachedContentResultSetStubFactory::getSupportedServiceNames_Static() ) && + + ////////////////////////////////////////////////////////////////////// + // CachedDynamicResultSetFactory. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + CachedDynamicResultSetFactory::getImplementationName_Static(), + CachedDynamicResultSetFactory::getSupportedServiceNames_Static() ) && + + ////////////////////////////////////////////////////////////////////// + // CachedDynamicResultSetStubFactory. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + CachedDynamicResultSetStubFactory::getImplementationName_Static(), + CachedDynamicResultSetStubFactory::getSupportedServiceNames_Static() ); +} + +//========================================================================= +extern "C" void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * ) +{ + void * pRet = 0; + + Reference< XMultiServiceFactory > xSMgr( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) ); + Reference< XSingleServiceFactory > xFactory; + + ////////////////////////////////////////////////////////////////////// + // CachedContentResultSetFactory. + ////////////////////////////////////////////////////////////////////// + + if ( CachedContentResultSetFactory::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = CachedContentResultSetFactory::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + // CachedContentResultSetStubFactory. + ////////////////////////////////////////////////////////////////////// + + else if ( CachedContentResultSetStubFactory::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = CachedContentResultSetStubFactory::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + // CachedDynamicResultSetFactory. + ////////////////////////////////////////////////////////////////////// + + else if ( CachedDynamicResultSetFactory::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = CachedDynamicResultSetFactory::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + // CachedDynamicResultSetStubFactory. + ////////////////////////////////////////////////////////////////////// + + else if ( CachedDynamicResultSetStubFactory::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = CachedDynamicResultSetStubFactory::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} + diff --git a/ucb/source/cacher/contentresultsetwrapper.cxx b/ucb/source/cacher/contentresultsetwrapper.cxx new file mode 100644 index 000000000000..092fc3faf29f --- /dev/null +++ b/ucb/source/cacher/contentresultsetwrapper.cxx @@ -0,0 +1,1477 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_ucb.hxx" + +#include <contentresultsetwrapper.hxx> +#include <com/sun/star/sdbc/FetchDirection.hpp> +#include <com/sun/star/ucb/FetchError.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/sdbc/ResultSetType.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <rtl/ustring.hxx> +#include <osl/diagnose.h> + +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace cppu; +using namespace rtl; + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class ContentResultSetWrapper +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +ContentResultSetWrapper::ContentResultSetWrapper( + Reference< XResultSet > xOrigin ) + : m_xResultSetOrigin( xOrigin ) + , m_xRowOrigin( NULL ) + , m_xContentAccessOrigin( NULL ) + , m_xPropertySetOrigin( NULL ) + , m_xPropertySetInfo( NULL ) + , m_nForwardOnly( 2 ) + , m_xMetaDataFromOrigin( NULL ) + , m_bDisposed( sal_False ) + , m_bInDispose( sal_False ) + , m_pDisposeEventListeners( NULL ) + , m_pPropertyChangeListeners( NULL ) + , m_pVetoableChangeListeners( NULL ) +{ + m_pMyListenerImpl = new ContentResultSetWrapperListener( this ); + m_xMyListenerImpl = Reference< XPropertyChangeListener >( m_pMyListenerImpl ); + + OSL_ENSURE( m_xResultSetOrigin.is(), "XResultSet is required" ); + + //!! call impl_init() at the end of constructor of derived class +}; + + +void SAL_CALL ContentResultSetWrapper::impl_init_xRowOrigin() +{ + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if(m_xRowOrigin.is()) + return; + } + + Reference< XRow > xOrgig = + Reference< XRow >( m_xResultSetOrigin, UNO_QUERY ); + + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_xRowOrigin = xOrgig; + OSL_ENSURE( m_xRowOrigin.is(), "interface XRow is required" ); + } +} + +void SAL_CALL ContentResultSetWrapper::impl_init_xContentAccessOrigin() +{ + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if(m_xContentAccessOrigin.is()) + return; + } + + Reference< XContentAccess > xOrgig = + Reference< XContentAccess >( m_xResultSetOrigin, UNO_QUERY ); + + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_xContentAccessOrigin = xOrgig; + OSL_ENSURE( m_xContentAccessOrigin.is(), "interface XContentAccess is required" ); + } +} + + +void SAL_CALL ContentResultSetWrapper::impl_init_xPropertySetOrigin() +{ + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_xPropertySetOrigin.is() ) + return; + } + + Reference< XPropertySet > xOrig = + Reference< XPropertySet >( m_xResultSetOrigin, UNO_QUERY ); + + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_xPropertySetOrigin = xOrig; + OSL_ENSURE( m_xPropertySetOrigin.is(), "interface XPropertySet is required" ); + } +} + +void SAL_CALL ContentResultSetWrapper::impl_init() +{ + //call this at the end of constructor of derived class + // + + //listen to disposing from Origin: + Reference< XComponent > xComponentOrigin( m_xResultSetOrigin, UNO_QUERY ); + OSL_ENSURE( xComponentOrigin.is(), "interface XComponent is required" ); + xComponentOrigin->addEventListener( static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) ); +} + +ContentResultSetWrapper::~ContentResultSetWrapper() +{ + //call impl_deinit() at start of destructor of derived class + + delete m_pDisposeEventListeners; + delete m_pPropertyChangeListeners; + delete m_pVetoableChangeListeners; +}; + +void SAL_CALL ContentResultSetWrapper::impl_deinit() +{ + //call this at start of destructor of derived class + // + m_pMyListenerImpl->impl_OwnerDies(); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::impl_initPropertySetInfo() +{ + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_xPropertySetInfo.is() ) + return; + + impl_init_xPropertySetOrigin(); + if( !m_xPropertySetOrigin.is() ) + return; + } + + Reference< XPropertySetInfo > xOrig = + m_xPropertySetOrigin->getPropertySetInfo(); + + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_xPropertySetInfo = xOrig; + } +} + +void SAL_CALL ContentResultSetWrapper +::impl_EnsureNotDisposed() + throw( DisposedException, RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_bDisposed ) + throw DisposedException(); +} + +ContentResultSetWrapper::PropertyChangeListenerContainer_Impl* SAL_CALL + ContentResultSetWrapper + ::impl_getPropertyChangeListenerContainer() +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if ( !m_pPropertyChangeListeners ) + m_pPropertyChangeListeners = + new PropertyChangeListenerContainer_Impl( m_aContainerMutex ); + return m_pPropertyChangeListeners; +} + +ContentResultSetWrapper::PropertyChangeListenerContainer_Impl* SAL_CALL + ContentResultSetWrapper + ::impl_getVetoableChangeListenerContainer() +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if ( !m_pVetoableChangeListeners ) + m_pVetoableChangeListeners = + new PropertyChangeListenerContainer_Impl( m_aContainerMutex ); + return m_pVetoableChangeListeners; +} + +void SAL_CALL ContentResultSetWrapper + ::impl_notifyPropertyChangeListeners( + const PropertyChangeEvent& rEvt ) +{ + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( !m_pPropertyChangeListeners ) + return; + } + + // Notify listeners interested especially in the changed property. + OInterfaceContainerHelper* pContainer = + m_pPropertyChangeListeners->getContainer( rEvt.PropertyName ); + if( pContainer ) + { + OInterfaceIteratorHelper aIter( *pContainer ); + while( aIter.hasMoreElements() ) + { + Reference< XPropertyChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if( xListener.is() ) + xListener->propertyChange( rEvt ); + } + } + + // Notify listeners interested in all properties. + pContainer = m_pPropertyChangeListeners->getContainer( OUString() ); + if( pContainer ) + { + OInterfaceIteratorHelper aIter( *pContainer ); + while( aIter.hasMoreElements() ) + { + Reference< XPropertyChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if( xListener.is() ) + xListener->propertyChange( rEvt ); + } + } +} + +void SAL_CALL ContentResultSetWrapper + ::impl_notifyVetoableChangeListeners( const PropertyChangeEvent& rEvt ) + throw( PropertyVetoException, + RuntimeException ) +{ + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( !m_pVetoableChangeListeners ) + return; + } + + // Notify listeners interested especially in the changed property. + OInterfaceContainerHelper* pContainer = + m_pVetoableChangeListeners->getContainer( rEvt.PropertyName ); + if( pContainer ) + { + OInterfaceIteratorHelper aIter( *pContainer ); + while( aIter.hasMoreElements() ) + { + Reference< XVetoableChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if( xListener.is() ) + xListener->vetoableChange( rEvt ); + } + } + + // Notify listeners interested in all properties. + pContainer = m_pVetoableChangeListeners->getContainer( OUString() ); + if( pContainer ) + { + OInterfaceIteratorHelper aIter( *pContainer ); + while( aIter.hasMoreElements() ) + { + Reference< XVetoableChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if( xListener.is() ) + xListener->vetoableChange( rEvt ); + } + } +} + +sal_Bool SAL_CALL ContentResultSetWrapper + ::impl_isForwardOnly() +{ + //m_nForwardOnly == 2 -> don't know + //m_nForwardOnly == 1 -> YES + //m_nForwardOnly == 0 -> NO + + //@todo replace this with lines in comment + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_nForwardOnly = 0; + return false; + + + /* + ReacquireableGuard aGuard( m_aMutex ); + if( m_nForwardOnly == 2 ) + { + aGuard.clear(); + if( !getPropertySetInfo().is() ) + { + aGuard.reacquire(); + m_nForwardOnly = 0; + return m_nForwardOnly; + } + aGuard.reacquire(); + + rtl::OUString aName = OUString::createFromAscii( "ResultSetType" ); + //find out, if we are ForwardOnly and cache the value: + + impl_init_xPropertySetOrigin(); + if( !m_xPropertySetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + m_nForwardOnly = 0; + return m_nForwardOnly; + } + + aGuard.clear(); + Any aAny = m_xPropertySetOrigin->getPropertyValue( aName ); + + aGuard.reacquire(); + long nResultSetType; + if( ( aAny >>= nResultSetType ) && + ( nResultSetType == ResultSetType::FORWARD_ONLY ) ) + m_nForwardOnly = 1; + else + m_nForwardOnly = 0; + } + return m_nForwardOnly; + */ +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +//list all interfaces inclusive baseclasses of interfaces +QUERYINTERFACE_IMPL_START( ContentResultSetWrapper ) + + SAL_STATIC_CAST( XComponent*, this ), + SAL_STATIC_CAST( XCloseable*, this ), + SAL_STATIC_CAST( XResultSetMetaDataSupplier*, this ), + SAL_STATIC_CAST( XPropertySet*, this ), + + SAL_STATIC_CAST( XContentAccess*, this ), + SAL_STATIC_CAST( XResultSet*, this ), + SAL_STATIC_CAST( XRow*, this ) + +QUERYINTERFACE_IMPL_END + +//-------------------------------------------------------------------------- +// XComponent methods. +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::dispose() throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + ReacquireableGuard aGuard( m_aMutex ); + if( m_bInDispose || m_bDisposed ) + return; + m_bInDispose = sal_True; + + if( m_xPropertySetOrigin.is() ) + { + aGuard.clear(); + try + { + m_xPropertySetOrigin->removePropertyChangeListener( + OUString(), static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& ) + { + OSL_ENSURE( sal_False, "could not remove PropertyChangeListener" ); + } + try + { + m_xPropertySetOrigin->removeVetoableChangeListener( + OUString(), static_cast< XVetoableChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& ) + { + OSL_ENSURE( sal_False, "could not remove VetoableChangeListener" ); + } + + Reference< XComponent > xComponentOrigin( m_xResultSetOrigin, UNO_QUERY ); + OSL_ENSURE( xComponentOrigin.is(), "interface XComponent is required" ); + xComponentOrigin->removeEventListener( static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) ); + } + + aGuard.reacquire(); + if( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XComponent * >( this ); + + aGuard.clear(); + m_pDisposeEventListeners->disposeAndClear( aEvt ); + } + + aGuard.reacquire(); + if( m_pPropertyChangeListeners ) + { + EventObject aEvt; + aEvt.Source = static_cast< XPropertySet * >( this ); + + aGuard.clear(); + m_pPropertyChangeListeners->disposeAndClear( aEvt ); + } + + aGuard.reacquire(); + if( m_pVetoableChangeListeners ) + { + EventObject aEvt; + aEvt.Source = static_cast< XPropertySet * >( this ); + + aGuard.clear(); + m_pVetoableChangeListeners->disposeAndClear( aEvt ); + } + + aGuard.reacquire(); + m_bDisposed = sal_True; + m_bInDispose = sal_False; +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::addEventListener( const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pDisposeEventListeners ) + m_pDisposeEventListeners = + new OInterfaceContainerHelper( m_aContainerMutex ); + + m_pDisposeEventListeners->addInterface( Listener ); +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::removeEventListener( const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_pDisposeEventListeners ) + m_pDisposeEventListeners->removeInterface( Listener ); +} + +//-------------------------------------------------------------------------- +//XCloseable methods. +//-------------------------------------------------------------------------- +//virtual +void SAL_CALL ContentResultSetWrapper + ::close() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + dispose(); +} + +//-------------------------------------------------------------------------- +//XResultSetMetaDataSupplier methods. +//-------------------------------------------------------------------------- +//virtual +Reference< XResultSetMetaData > SAL_CALL ContentResultSetWrapper + ::getMetaData() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + ReacquireableGuard aGuard( m_aMutex ); + if( !m_xMetaDataFromOrigin.is() && m_xResultSetOrigin.is() ) + { + Reference< XResultSetMetaDataSupplier > xMetaDataSupplier + = Reference< XResultSetMetaDataSupplier >( + m_xResultSetOrigin, UNO_QUERY ); + + if( xMetaDataSupplier.is() ) + { + aGuard.clear(); + + Reference< XResultSetMetaData > xMetaData + = xMetaDataSupplier->getMetaData(); + + aGuard.reacquire(); + m_xMetaDataFromOrigin = xMetaData; + } + } + return m_xMetaDataFromOrigin; +} + + +//-------------------------------------------------------------------------- +// XPropertySet methods. +//-------------------------------------------------------------------------- +// virtual +Reference< XPropertySetInfo > SAL_CALL ContentResultSetWrapper + ::getPropertySetInfo() throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_xPropertySetInfo.is() ) + return m_xPropertySetInfo; + } + impl_initPropertySetInfo(); + return m_xPropertySetInfo; +} +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::setPropertyValue( const OUString& rPropertyName, const Any& rValue ) + throw( UnknownPropertyException, + PropertyVetoException, + IllegalArgumentException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + impl_init_xPropertySetOrigin(); + if( !m_xPropertySetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + m_xPropertySetOrigin->setPropertyValue( rPropertyName, rValue ); +} + +//-------------------------------------------------------------------------- +// virtual +Any SAL_CALL ContentResultSetWrapper + ::getPropertyValue( const OUString& rPropertyName ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + impl_init_xPropertySetOrigin(); + if( !m_xPropertySetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + return m_xPropertySetOrigin->getPropertyValue( rPropertyName ); +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::addPropertyChangeListener( + const OUString& aPropertyName, + const Reference< XPropertyChangeListener >& xListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !getPropertySetInfo().is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + + if( aPropertyName.getLength() ) + { + m_xPropertySetInfo->getPropertyByName( aPropertyName ); + //throws UnknownPropertyException, if so + } + + impl_getPropertyChangeListenerContainer(); + sal_Bool bNeedRegister = !m_pPropertyChangeListeners-> + getContainedTypes().getLength(); + m_pPropertyChangeListeners->addInterface( aPropertyName, xListener ); + if( bNeedRegister ) + { + impl_init_xPropertySetOrigin(); + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return; + } + } + try + { + m_xPropertySetOrigin->addPropertyChangeListener( + OUString(), static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& rEx ) + { + m_pPropertyChangeListeners->removeInterface( aPropertyName, xListener ); + throw rEx; + } + } +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::addVetoableChangeListener( + const OUString& rPropertyName, + const Reference< XVetoableChangeListener >& xListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !getPropertySetInfo().is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + if( rPropertyName.getLength() ) + { + m_xPropertySetInfo->getPropertyByName( rPropertyName ); + //throws UnknownPropertyException, if so + } + + impl_getVetoableChangeListenerContainer(); + sal_Bool bNeedRegister = !m_pVetoableChangeListeners-> + getContainedTypes().getLength(); + m_pVetoableChangeListeners->addInterface( rPropertyName, xListener ); + if( bNeedRegister ) + { + impl_init_xPropertySetOrigin(); + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return; + } + } + try + { + m_xPropertySetOrigin->addVetoableChangeListener( + OUString(), static_cast< XVetoableChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& rEx ) + { + m_pVetoableChangeListeners->removeInterface( rPropertyName, xListener ); + throw rEx; + } + } +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::removePropertyChangeListener( + const OUString& rPropertyName, + const Reference< XPropertyChangeListener >& xListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + { + //noop, if no listener registered + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( !m_pPropertyChangeListeners ) + return; + } + OInterfaceContainerHelper* pContainer = + m_pPropertyChangeListeners->getContainer( rPropertyName ); + + if( !pContainer ) + { + if( rPropertyName.getLength() ) + { + if( !getPropertySetInfo().is() ) + throw UnknownPropertyException(); + + m_xPropertySetInfo->getPropertyByName( rPropertyName ); + //throws UnknownPropertyException, if so + } + return; //the listener was not registered + } + + m_pPropertyChangeListeners->removeInterface( rPropertyName, xListener ); + + if( !m_pPropertyChangeListeners->getContainedTypes().getLength() ) + { + impl_init_xPropertySetOrigin(); + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return; + } + } + try + { + m_xPropertySetOrigin->removePropertyChangeListener( + OUString(), static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& ) + { + OSL_ENSURE( sal_False, "could not remove PropertyChangeListener" ); + } + } +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::removeVetoableChangeListener( + const OUString& rPropertyName, + const Reference< XVetoableChangeListener >& xListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + { + //noop, if no listener registered + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( !m_pVetoableChangeListeners ) + return; + } + OInterfaceContainerHelper* pContainer = + m_pVetoableChangeListeners->getContainer( rPropertyName ); + + if( !pContainer ) + { + if( rPropertyName.getLength() ) + { + if( !getPropertySetInfo().is() ) + throw UnknownPropertyException(); + + m_xPropertySetInfo->getPropertyByName( rPropertyName ); + //throws UnknownPropertyException, if so + } + return; //the listener was not registered + } + + m_pVetoableChangeListeners->removeInterface( rPropertyName, xListener ); + + if( !m_pVetoableChangeListeners->getContainedTypes().getLength() ) + { + impl_init_xPropertySetOrigin(); + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + return; + } + } + try + { + m_xPropertySetOrigin->removeVetoableChangeListener( + OUString(), static_cast< XVetoableChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& ) + { + OSL_ENSURE( sal_False, "could not remove VetoableChangeListener" ); + } + } +} + +//-------------------------------------------------------------------------- +// own methods. +//-------------------------------------------------------------------------- + +//virtual +void SAL_CALL ContentResultSetWrapper + ::impl_disposing( const EventObject& ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if( !m_xResultSetOrigin.is() ) + return; + + //release all references to the broadcaster: + m_xResultSetOrigin.clear(); + if(m_xRowOrigin.is()) + m_xRowOrigin.clear(); + if(m_xContentAccessOrigin.is()) + m_xContentAccessOrigin.clear(); + if(m_xPropertySetOrigin.is()) + m_xPropertySetOrigin.clear(); + m_xMetaDataFromOrigin.clear(); + if(m_xPropertySetInfo.is()) + m_xPropertySetInfo.clear(); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::impl_propertyChange( const PropertyChangeEvent& rEvt ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + PropertyChangeEvent aEvt( rEvt ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = sal_False; + impl_notifyPropertyChangeListeners( aEvt ); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::impl_vetoableChange( const PropertyChangeEvent& rEvt ) + throw( PropertyVetoException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + PropertyChangeEvent aEvt( rEvt ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = sal_False; + + impl_notifyVetoableChangeListeners( aEvt ); +} + +//-------------------------------------------------------------------------- +// XContentAccess methods. ( -- position dependent ) +//-------------------------------------------------------------------------- + +// virtual +OUString SAL_CALL ContentResultSetWrapper + ::queryContentIdentifierString() + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + impl_init_xContentAccessOrigin(); + if( !m_xContentAccessOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xContentAccessOrigin->queryContentIdentifierString(); +} + +//-------------------------------------------------------------------------- +// virtual +Reference< XContentIdentifier > SAL_CALL ContentResultSetWrapper + ::queryContentIdentifier() + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + impl_init_xContentAccessOrigin(); + if( !m_xContentAccessOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xContentAccessOrigin->queryContentIdentifier(); +} + +//-------------------------------------------------------------------------- +// virtual +Reference< XContent > SAL_CALL ContentResultSetWrapper + ::queryContent() + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + impl_init_xContentAccessOrigin(); + if( !m_xContentAccessOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xContentAccessOrigin->queryContent(); +} + +//----------------------------------------------------------------- +// XResultSet methods. +//----------------------------------------------------------------- +//virtual + +sal_Bool SAL_CALL ContentResultSetWrapper + ::next() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->next(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::previous() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->previous(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::absolute( sal_Int32 row ) + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->absolute( row ); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::relative( sal_Int32 rows ) + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->relative( rows ); +} + + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::first() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->first(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::last() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->last(); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::beforeFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + m_xResultSetOrigin->beforeFirst(); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::afterLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + m_xResultSetOrigin->afterLast(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::isAfterLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->isAfterLast(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::isBeforeFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->isBeforeFirst(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::isFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->isFirst(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::isLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->isLast(); +} + + +//virtual +sal_Int32 SAL_CALL ContentResultSetWrapper + ::getRow() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->getRow(); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::refreshRow() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + m_xResultSetOrigin->refreshRow(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::rowUpdated() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->rowUpdated(); +} +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::rowInserted() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->rowInserted(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::rowDeleted() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->rowDeleted(); +} + +//virtual +Reference< XInterface > SAL_CALL ContentResultSetWrapper + ::getStatement() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + //@todo ?return anything + return Reference< XInterface >(); +} + +//----------------------------------------------------------------- +// XRow methods. +//----------------------------------------------------------------- + +#define XROW_GETXXX( getXXX ) \ +impl_EnsureNotDisposed(); \ +impl_init_xRowOrigin(); \ +if( !m_xRowOrigin.is() ) \ +{ \ + OSL_ENSURE( sal_False, "broadcaster was disposed already" );\ + throw RuntimeException(); \ +} \ +return m_xRowOrigin->getXXX( columnIndex ); + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::wasNull() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + impl_init_xRowOrigin(); + if( !m_xRowOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xRowOrigin->wasNull(); +} + +//virtual +rtl::OUString SAL_CALL ContentResultSetWrapper + ::getString( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getString ); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::getBoolean( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBoolean ); +} + +//virtual +sal_Int8 SAL_CALL ContentResultSetWrapper + ::getByte( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getByte ); +} + +//virtual +sal_Int16 SAL_CALL ContentResultSetWrapper + ::getShort( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getShort ); +} + +//virtual +sal_Int32 SAL_CALL ContentResultSetWrapper + ::getInt( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getInt ); +} + +//virtual +sal_Int64 SAL_CALL ContentResultSetWrapper + ::getLong( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getLong ); +} + +//virtual +float SAL_CALL ContentResultSetWrapper + ::getFloat( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getFloat ); +} + +//virtual +double SAL_CALL ContentResultSetWrapper + ::getDouble( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getDouble ); +} + +//virtual +Sequence< sal_Int8 > SAL_CALL ContentResultSetWrapper + ::getBytes( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBytes ); +} + +//virtual +Date SAL_CALL ContentResultSetWrapper + ::getDate( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getDate ); +} + +//virtual +Time SAL_CALL ContentResultSetWrapper + ::getTime( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getTime ); +} + +//virtual +DateTime SAL_CALL ContentResultSetWrapper + ::getTimestamp( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getTimestamp ); +} + +//virtual +Reference< com::sun::star::io::XInputStream > + SAL_CALL ContentResultSetWrapper + ::getBinaryStream( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBinaryStream ); +} + +//virtual +Reference< com::sun::star::io::XInputStream > + SAL_CALL ContentResultSetWrapper + ::getCharacterStream( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getCharacterStream ); +} + +//virtual +Any SAL_CALL ContentResultSetWrapper + ::getObject( sal_Int32 columnIndex, + const Reference< + com::sun::star::container::XNameAccess >& typeMap ) + throw( SQLException, + RuntimeException ) +{ + //if you change this macro please pay attention to + //define XROW_GETXXX, where this is similar implemented + + impl_EnsureNotDisposed(); + impl_init_xRowOrigin(); + if( !m_xRowOrigin.is() ) + { + OSL_ENSURE( sal_False, "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xRowOrigin->getObject( columnIndex, typeMap ); +} + +//virtual +Reference< XRef > SAL_CALL ContentResultSetWrapper + ::getRef( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getRef ); +} + +//virtual +Reference< XBlob > SAL_CALL ContentResultSetWrapper + ::getBlob( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBlob ); +} + +//virtual +Reference< XClob > SAL_CALL ContentResultSetWrapper + ::getClob( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getClob ); +} + +//virtual +Reference< XArray > SAL_CALL ContentResultSetWrapper + ::getArray( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getArray ); +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class ContentResultSetWrapperListener +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +ContentResultSetWrapperListener::ContentResultSetWrapperListener( + ContentResultSetWrapper* pOwner ) + : m_pOwner( pOwner ) +{ +} + +ContentResultSetWrapperListener::~ContentResultSetWrapperListener() +{ +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +//list all interfaces inclusive baseclasses of interfaces +XINTERFACE_COMMON_IMPL( ContentResultSetWrapperListener ) +QUERYINTERFACE_IMPL_START( ContentResultSetWrapperListener ) + + static_cast< XEventListener * >( + static_cast< XPropertyChangeListener * >(this)) + , SAL_STATIC_CAST( XPropertyChangeListener*, this ) + , SAL_STATIC_CAST( XVetoableChangeListener*, this ) + +QUERYINTERFACE_IMPL_END + + +//-------------------------------------------------------------------------- +//XEventListener methods. +//-------------------------------------------------------------------------- + +//virtual +void SAL_CALL ContentResultSetWrapperListener + ::disposing( const EventObject& rEventObject ) + throw( RuntimeException ) +{ + if( m_pOwner ) + m_pOwner->impl_disposing( rEventObject ); +} + +//-------------------------------------------------------------------------- +//XPropertyChangeListener methods. +//-------------------------------------------------------------------------- + +//virtual +void SAL_CALL ContentResultSetWrapperListener + ::propertyChange( const PropertyChangeEvent& rEvt ) + throw( RuntimeException ) +{ + if( m_pOwner ) + m_pOwner->impl_propertyChange( rEvt ); +} + +//-------------------------------------------------------------------------- +//XVetoableChangeListener methods. +//-------------------------------------------------------------------------- +//virtual +void SAL_CALL ContentResultSetWrapperListener + ::vetoableChange( const PropertyChangeEvent& rEvt ) + throw( PropertyVetoException, + RuntimeException ) +{ + if( m_pOwner ) + m_pOwner->impl_vetoableChange( rEvt ); +} + +void SAL_CALL ContentResultSetWrapperListener + ::impl_OwnerDies() +{ + m_pOwner = NULL; +} + diff --git a/ucb/source/cacher/contentresultsetwrapper.hxx b/ucb/source/cacher/contentresultsetwrapper.hxx new file mode 100644 index 000000000000..b3608aca6f96 --- /dev/null +++ b/ucb/source/cacher/contentresultsetwrapper.hxx @@ -0,0 +1,587 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONTENT_RESULTSET_WRAPPER_HXX +#define _CONTENT_RESULTSET_WRAPPER_HXX + +#include <rtl/ustring.hxx> +#include <ucbhelper/macros.hxx> +#include <osl/mutex.hxx> +#include <cppuhelper/weak.hxx> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/ucb/XContentAccess.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <cppuhelper/interfacecontainer.hxx> + +//========================================================================= + +class ContentResultSetWrapperListener; +class ContentResultSetWrapper + : public cppu::OWeakObject + , public com::sun::star::lang::XComponent + , public com::sun::star::sdbc::XCloseable + , public com::sun::star::sdbc::XResultSetMetaDataSupplier + , public com::sun::star::beans::XPropertySet + , public com::sun::star::ucb::XContentAccess + , public com::sun::star::sdbc::XResultSet + , public com::sun::star::sdbc::XRow +{ +protected: + + //-------------------------------------------------------------------------- + //class PropertyChangeListenerContainer_Impl. + + struct equalStr_Impl + { + bool operator()( const rtl::OUString& s1, const rtl::OUString& s2 ) const + { + return !!( s1 == s2 ); + } + }; + + struct hashStr_Impl + { + size_t operator()( const rtl::OUString& rName ) const + { + return rName.hashCode(); + } + }; + + typedef cppu::OMultiTypeInterfaceContainerHelperVar + < rtl::OUString , hashStr_Impl , equalStr_Impl > + PropertyChangeListenerContainer_Impl; + //-------------------------------------------------------------------------- + // class ReacquireableGuard + + class ReacquireableGuard + { + protected: + osl::Mutex* pT; + public: + + ReacquireableGuard(osl::Mutex * t) : pT(t) + { + pT->acquire(); + } + + ReacquireableGuard(osl::Mutex& t) : pT(&t) + { + pT->acquire(); + } + + /** Releases mutex. */ + ~ReacquireableGuard() + { + if (pT) + pT->release(); + } + + /** Releases mutex. */ + void clear() + { + if(pT) + { + pT->release(); + pT = NULL; + } + } + + /** Reacquire mutex. */ + void reacquire() + { + if(pT) + { + pT->acquire(); + } + } + }; + + //----------------------------------------------------------------- + //members + + //my Mutex + osl::Mutex m_aMutex; + + //different Interfaces from Origin: + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + m_xResultSetOrigin; + com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > + m_xRowOrigin; //XRow-interface from m_xOrigin + //!! call impl_init_xRowOrigin() bevor you access this member + com::sun::star::uno::Reference< com::sun::star::ucb::XContentAccess > + m_xContentAccessOrigin; //XContentAccess-interface from m_xOrigin + //!! call impl_init_xContentAccessOrigin() bevor you access this member + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > + m_xPropertySetOrigin; //XPropertySet-interface from m_xOrigin + //!! call impl_init_xPropertySetOrigin() bevor you access this member + + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > + m_xPropertySetInfo; + //call impl_initPropertySetInfo() bevor you access this member + + sal_Int32 m_nForwardOnly; + +private: + com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener > + m_xMyListenerImpl; + ContentResultSetWrapperListener* + m_pMyListenerImpl; + + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSetMetaData > + m_xMetaDataFromOrigin; //XResultSetMetaData from m_xOrigin + + //management of listeners + sal_Bool m_bDisposed; ///Dispose call ready. + sal_Bool m_bInDispose;///In dispose call + osl::Mutex m_aContainerMutex; + cppu::OInterfaceContainerHelper* + m_pDisposeEventListeners; + PropertyChangeListenerContainer_Impl* + m_pPropertyChangeListeners; + PropertyChangeListenerContainer_Impl* + m_pVetoableChangeListeners; + + //----------------------------------------------------------------- + //methods: +private: + PropertyChangeListenerContainer_Impl* SAL_CALL + impl_getPropertyChangeListenerContainer(); + + PropertyChangeListenerContainer_Impl* SAL_CALL + impl_getVetoableChangeListenerContainer(); + +protected: + //----------------------------------------------------------------- + + ContentResultSetWrapper( com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > xOrigin ); + + virtual ~ContentResultSetWrapper(); + + void SAL_CALL impl_init(); + void SAL_CALL impl_deinit(); + + //-- + + void SAL_CALL impl_init_xRowOrigin(); + void SAL_CALL impl_init_xContentAccessOrigin(); + void SAL_CALL impl_init_xPropertySetOrigin(); + + //-- + + virtual void SAL_CALL impl_initPropertySetInfo(); //helping XPropertySet + + void SAL_CALL + impl_EnsureNotDisposed() + throw( com::sun::star::lang::DisposedException, + com::sun::star::uno::RuntimeException ); + + void SAL_CALL + impl_notifyPropertyChangeListeners( + const com::sun::star::beans::PropertyChangeEvent& rEvt ); + + void SAL_CALL + impl_notifyVetoableChangeListeners( + const com::sun::star::beans::PropertyChangeEvent& rEvt ) + throw( com::sun::star::beans::PropertyVetoException, + com::sun::star::uno::RuntimeException ); + + sal_Bool SAL_CALL impl_isForwardOnly(); + +public: + + //----------------------------------------------------------------- + // XInterface + //----------------------------------------------------------------- + virtual com::sun::star::uno::Any SAL_CALL + queryInterface( const com::sun::star::uno::Type & rType ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XComponent + //----------------------------------------------------------------- + virtual void SAL_CALL + dispose() throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addEventListener( const com::sun::star::uno::Reference< + com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removeEventListener( const com::sun::star::uno::Reference< + com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + //XCloseable + //----------------------------------------------------------------- + virtual void SAL_CALL + close() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + //XResultSetMetaDataSupplier + //----------------------------------------------------------------- + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSetMetaData > SAL_CALL + getMetaData() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XPropertySet + //----------------------------------------------------------------- + virtual com::sun::star::uno::Reference< + com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + setPropertyValue( const rtl::OUString& aPropertyName, + const com::sun::star::uno::Any& aValue ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::PropertyVetoException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Any SAL_CALL + getPropertyValue( const rtl::OUString& PropertyName ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addPropertyChangeListener( const rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removePropertyChangeListener( const rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addVetoableChangeListener( const rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removeVetoableChangeListener( const rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // own methods + //----------------------------------------------------------------- + virtual void SAL_CALL + impl_disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent ) + throw( com::sun::star::beans::PropertyVetoException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XContentAccess + //----------------------------------------------------------------- + virtual rtl::OUString SAL_CALL + queryContentIdentifierString() + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier > SAL_CALL + queryContentIdentifier() + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContent > SAL_CALL + queryContent() + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XResultSet + //----------------------------------------------------------------- + virtual sal_Bool SAL_CALL + next() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isBeforeFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isAfterLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + beforeFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + afterLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + first() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + last() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Int32 SAL_CALL + getRow() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + absolute( sal_Int32 row ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + relative( sal_Int32 rows ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + previous() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + refreshRow() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowUpdated() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowInserted() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowDeleted() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Reference< + com::sun::star::uno::XInterface > SAL_CALL + getStatement() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XRow + //----------------------------------------------------------------- + virtual sal_Bool SAL_CALL + wasNull() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual rtl::OUString SAL_CALL + getString( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL + getBoolean( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int8 SAL_CALL + getByte( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int16 SAL_CALL + getShort( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int32 SAL_CALL + getInt( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int64 SAL_CALL + getLong( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual float SAL_CALL + getFloat( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual double SAL_CALL + getDouble( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL + getBytes( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::Date SAL_CALL + getDate( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::Time SAL_CALL + getTime( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::DateTime SAL_CALL + getTimestamp( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::io::XInputStream > SAL_CALL + getBinaryStream( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::io::XInputStream > SAL_CALL + getCharacterStream( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Any SAL_CALL + getObject( sal_Int32 columnIndex, + const com::sun::star::uno::Reference< + com::sun::star::container::XNameAccess >& typeMap ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XRef > SAL_CALL + getRef( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XBlob > SAL_CALL + getBlob( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XClob > SAL_CALL + getClob( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XArray > SAL_CALL + getArray( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); +}; + +//========================================================================= + +class ContentResultSetWrapperListener + : public cppu::OWeakObject + , public com::sun::star::beans::XPropertyChangeListener + , public com::sun::star::beans::XVetoableChangeListener +{ +protected: + ContentResultSetWrapper* m_pOwner; + +public: + ContentResultSetWrapperListener( ContentResultSetWrapper* pOwner ); + + virtual ~ContentResultSetWrapperListener(); + + //----------------------------------------------------------------- + // XInterface + //----------------------------------------------------------------- + XINTERFACE_DECL() + + //----------------------------------------------------------------- + //XEventListener + //----------------------------------------------------------------- + virtual void SAL_CALL + disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + //XPropertyChangeListener + //----------------------------------------------------------------- + virtual void SAL_CALL + propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + //XVetoableChangeListener + //----------------------------------------------------------------- + virtual void SAL_CALL + vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent ) + throw( com::sun::star::beans::PropertyVetoException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // own methods: + void SAL_CALL impl_OwnerDies(); +}; + +#endif + diff --git a/ucb/source/cacher/dynamicresultsetwrapper.cxx b/ucb/source/cacher/dynamicresultsetwrapper.cxx new file mode 100644 index 000000000000..ab98c97bc4e2 --- /dev/null +++ b/ucb/source/cacher/dynamicresultsetwrapper.cxx @@ -0,0 +1,528 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_ucb.hxx" + +#include <dynamicresultsetwrapper.hxx> +#include <ucbhelper/macros.hxx> +#include <osl/diagnose.h> +#include <rtl/ustring.hxx> +#include <com/sun/star/ucb/ListActionType.hpp> +#include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp> +#include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp> + +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace cppu; +using namespace rtl; + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class DynamicResultSetWrapper +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +DynamicResultSetWrapper::DynamicResultSetWrapper( + Reference< XDynamicResultSet > xOrigin + , const Reference< XMultiServiceFactory > & xSMgr ) + + : m_bDisposed( sal_False ) + , m_bInDispose( sal_False ) + , m_pDisposeEventListeners( NULL ) + , m_xSMgr( xSMgr ) + , m_bStatic( sal_False ) + , m_bGotWelcome( sal_False ) + , m_xSource( xOrigin ) + , m_xSourceResultOne( NULL ) + , m_xSourceResultTwo( NULL ) + // , m_xSourceResultCurrent( NULL ) + // , m_bUseOne( NULL ) + , m_xMyResultOne( NULL ) + , m_xMyResultTwo( NULL ) + , m_xListener( NULL ) +{ + m_pMyListenerImpl = new DynamicResultSetWrapperListener( this ); + m_xMyListenerImpl = Reference< XDynamicResultSetListener >( m_pMyListenerImpl ); + //call impl_init() at the end of constructor of derived class +}; + +void SAL_CALL DynamicResultSetWrapper::impl_init() +{ + //call this at the end of constructor of derived class + // + + Reference< XDynamicResultSet > xSource = NULL; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + xSource = m_xSource; + m_xSource = NULL; + } + if( xSource.is() ) + setSource( xSource ); +} + +DynamicResultSetWrapper::~DynamicResultSetWrapper() +{ + //call impl_deinit() at start of destructor of derived class + + delete m_pDisposeEventListeners; +}; + +void SAL_CALL DynamicResultSetWrapper::impl_deinit() +{ + //call this at start of destructor of derived class + // + m_pMyListenerImpl->impl_OwnerDies(); +} + +void SAL_CALL DynamicResultSetWrapper +::impl_EnsureNotDisposed() + throw( DisposedException, RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_bDisposed ) + throw DisposedException(); +} + +//virtual +void SAL_CALL DynamicResultSetWrapper +::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + OSL_ENSURE( !m_xSourceResultOne.is(), "Source ResultSet One is set already" ); + m_xSourceResultOne = xResultSet; + m_xMyResultOne = xResultSet; +} + +//virtual +void SAL_CALL DynamicResultSetWrapper +::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + OSL_ENSURE( !m_xSourceResultTwo.is(), "Source ResultSet Two is set already" ); + m_xSourceResultTwo = xResultSet; + m_xMyResultTwo = xResultSet; +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +//list all interfaces inclusive baseclasses of interfaces +QUERYINTERFACE_IMPL_START( DynamicResultSetWrapper ) + SAL_STATIC_CAST( XComponent*, this ) //base of XDynamicResultSet + , SAL_STATIC_CAST( XDynamicResultSet*, this ) + , SAL_STATIC_CAST( XSourceInitialization*, this ) +QUERYINTERFACE_IMPL_END + +//-------------------------------------------------------------------------- +// XComponent methods. +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL DynamicResultSetWrapper + ::dispose() throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + Reference< XComponent > xSourceComponent; + { + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + if( m_bInDispose || m_bDisposed ) + return; + m_bInDispose = sal_True; + + xSourceComponent = Reference< XComponent >(m_xSource, UNO_QUERY); + + if( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XComponent * >( this ); + + aGuard.clear(); + m_pDisposeEventListeners->disposeAndClear( aEvt ); + } + } + + /* //@todo ?? ( only if java collection needs to long ) + if( xSourceComponent.is() ) + xSourceComponent->dispose(); + */ + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_bDisposed = sal_True; + m_bInDispose = sal_False; +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL DynamicResultSetWrapper + ::addEventListener( const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pDisposeEventListeners ) + m_pDisposeEventListeners = + new OInterfaceContainerHelper( m_aContainerMutex ); + + m_pDisposeEventListeners->addInterface( Listener ); +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL DynamicResultSetWrapper + ::removeEventListener( const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_pDisposeEventListeners ) + m_pDisposeEventListeners->removeInterface( Listener ); +} + +//-------------------------------------------------------------------------- +// own methods +//-------------------------------------------------------------------------- + +//virtual +void SAL_CALL DynamicResultSetWrapper + ::impl_disposing( const EventObject& ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if( !m_xSource.is() ) + return; + + //release all references to the broadcaster: + m_xSource.clear(); + m_xSourceResultOne.clear();//?? or only when not static?? + m_xSourceResultTwo.clear();//?? + //@todo m_xMyResultOne.clear(); ??? + //@todo m_xMyResultTwo.clear(); ??? +} + +//virtual +void SAL_CALL DynamicResultSetWrapper + ::impl_notify( const ListEvent& Changes ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + //@todo + /* + <p>The Listener is allowed to blockade this call, until he really want to go + to the new version. The only situation, where the listener has to return the + update call at once is, while he disposes his broadcaster or while he is + removing himsef as listener (otherwise you deadlock)!!! + */ + // handle the actions in the list + + ListEvent aNewEvent; + aNewEvent.Source = static_cast< XDynamicResultSet * >( this ); + aNewEvent.Changes = Changes.Changes; + + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + for( long i=0; !m_bGotWelcome && i<Changes.Changes.getLength(); i++ ) + { + ListAction& rAction = aNewEvent.Changes[i]; + switch( rAction.ListActionType ) + { + case ListActionType::WELCOME: + { + WelcomeDynamicResultSetStruct aWelcome; + if( rAction.ActionInfo >>= aWelcome ) + { + impl_InitResultSetOne( aWelcome.Old ); + impl_InitResultSetTwo( aWelcome.New ); + m_bGotWelcome = sal_True; + + aWelcome.Old = m_xMyResultOne; + aWelcome.New = m_xMyResultTwo; + + rAction.ActionInfo <<= aWelcome; + } + else + { + OSL_ENSURE( sal_False, "ListActionType was WELCOME but ActionInfo didn't contain a WelcomeDynamicResultSetStruct" ); + //throw RuntimeException(); + } + break; + } + } + } + OSL_ENSURE( m_bGotWelcome, "first notification was without WELCOME" ); + } + + if( !m_xListener.is() ) + m_aListenerSet.wait(); + m_xListener->notify( aNewEvent ); + + /* + m_bUseOne = !m_bUseOne; + if( m_bUseOne ) + m_xSourceResultCurrent = m_xSourceResultOne; + else + m_xSourceResultCurrent = m_xSourceResultTwo; + */ +} + +//-------------------------------------------------------------------------- +// XSourceInitialization +//-------------------------------------------------------------------------- +//virtual +void SAL_CALL DynamicResultSetWrapper + ::setSource( const Reference< XInterface > & Source ) + throw( AlreadyInitializedException, RuntimeException ) +{ + impl_EnsureNotDisposed(); + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_xSource.is() ) + { + throw AlreadyInitializedException(); + } + } + + Reference< XDynamicResultSet > xSourceDynamic( Source, UNO_QUERY ); + OSL_ENSURE( xSourceDynamic.is(), + "the given source is not of required type XDynamicResultSet" ); + + Reference< XDynamicResultSetListener > xListener = NULL; + Reference< XDynamicResultSetListener > xMyListenerImpl = NULL; + + sal_Bool bStatic = sal_False; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + m_xSource = xSourceDynamic; + xListener = m_xListener; + bStatic = m_bStatic; + xMyListenerImpl = m_xMyListenerImpl; + } + if( xListener.is() ) + xSourceDynamic->setListener( m_xMyListenerImpl ); + else if( bStatic ) + { + Reference< XComponent > xSourceComponent( Source, UNO_QUERY ); + xSourceComponent->addEventListener( Reference< XEventListener > ::query( xMyListenerImpl ) ); + } + m_aSourceSet.set(); +} + +//-------------------------------------------------------------------------- +// XDynamicResultSet +//-------------------------------------------------------------------------- +//virtual +Reference< XResultSet > SAL_CALL DynamicResultSetWrapper + ::getStaticResultSet() + throw( ListenerAlreadySetException, RuntimeException ) +{ + impl_EnsureNotDisposed(); + + Reference< XDynamicResultSet > xSource = NULL; + Reference< XEventListener > xMyListenerImpl = NULL; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_xListener.is() ) + throw ListenerAlreadySetException(); + + xSource = m_xSource; + m_bStatic = sal_True; + xMyListenerImpl = Reference< XEventListener > ::query( m_xMyListenerImpl ); + } + + if( xSource.is() ) + { + Reference< XComponent > xSourceComponent( xSource, UNO_QUERY ); + xSourceComponent->addEventListener( xMyListenerImpl ); + } + if( !xSource.is() ) + m_aSourceSet.wait(); + + + Reference< XResultSet > xResultSet = xSource->getStaticResultSet(); + impl_InitResultSetOne( xResultSet ); + return m_xMyResultOne; +} + +//virtual +void SAL_CALL DynamicResultSetWrapper + ::setListener( const Reference< + XDynamicResultSetListener > & Listener ) + throw( ListenerAlreadySetException, RuntimeException ) +{ + impl_EnsureNotDisposed(); + + Reference< XDynamicResultSet > xSource = NULL; + Reference< XDynamicResultSetListener > xMyListenerImpl = NULL; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if( m_xListener.is() ) + throw ListenerAlreadySetException(); + if( m_bStatic ) + throw ListenerAlreadySetException(); + + m_xListener = Listener; + addEventListener( Reference< XEventListener >::query( Listener ) ); + + xSource = m_xSource; + xMyListenerImpl = m_xMyListenerImpl; + } + if ( xSource.is() ) + xSource->setListener( xMyListenerImpl ); + + m_aListenerSet.set(); +} + +//virtual +void SAL_CALL DynamicResultSetWrapper + ::connectToCache( const Reference< XDynamicResultSet > & xCache ) + throw( ListenerAlreadySetException, AlreadyInitializedException, ServiceNotFoundException, RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( m_xListener.is() ) + throw ListenerAlreadySetException(); + if( m_bStatic ) + throw ListenerAlreadySetException(); + + Reference< XSourceInitialization > xTarget( xCache, UNO_QUERY ); + OSL_ENSURE( xTarget.is(), "The given Target dosn't have the required interface 'XSourceInitialization'" ); + if( xTarget.is() && m_xSMgr.is() ) + { + //@todo m_aSourceSet.wait();? + + Reference< XCachedDynamicResultSetStubFactory > xStubFactory; + try + { + xStubFactory = Reference< XCachedDynamicResultSetStubFactory >( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ) ), + UNO_QUERY ); + } + catch ( Exception const & ) + { + } + + if( xStubFactory.is() ) + { + xStubFactory->connectToCache( + this, xCache, Sequence< NumberedSortingInfo > (), NULL ); + return; + } + } + OSL_ENSURE( sal_False, "could not connect to cache" ); + throw ServiceNotFoundException(); +} + +//virtual +sal_Int16 SAL_CALL DynamicResultSetWrapper + ::getCapabilities() + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + m_aSourceSet.wait(); + Reference< XDynamicResultSet > xSource = NULL; + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + xSource = m_xSource; + } + return xSource->getCapabilities(); +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class DynamicResultSetWrapperListener +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +DynamicResultSetWrapperListener::DynamicResultSetWrapperListener( + DynamicResultSetWrapper* pOwner ) + : m_pOwner( pOwner ) +{ + +} + +DynamicResultSetWrapperListener::~DynamicResultSetWrapperListener() +{ + +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +//list all interfaces inclusive baseclasses of interfaces +XINTERFACE_IMPL_2( DynamicResultSetWrapperListener + , XDynamicResultSetListener + , XEventListener //base of XDynamicResultSetListener + ); + +//-------------------------------------------------------------------------- +// XDynamicResultSetListener methods: +//-------------------------------------------------------------------------- +//virtual +void SAL_CALL DynamicResultSetWrapperListener + ::disposing( const EventObject& rEventObject ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if( m_pOwner ) + m_pOwner->impl_disposing( rEventObject ); +} + +//virtual +void SAL_CALL DynamicResultSetWrapperListener + ::notify( const ListEvent& Changes ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if( m_pOwner ) + m_pOwner->impl_notify( Changes ); +} + +//-------------------------------------------------------------------------- +// own methods: +//-------------------------------------------------------------------------- + +void SAL_CALL DynamicResultSetWrapperListener + ::impl_OwnerDies() +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + m_pOwner = NULL; +} + diff --git a/ucb/source/cacher/dynamicresultsetwrapper.hxx b/ucb/source/cacher/dynamicresultsetwrapper.hxx new file mode 100644 index 000000000000..47ff822a6ce1 --- /dev/null +++ b/ucb/source/cacher/dynamicresultsetwrapper.hxx @@ -0,0 +1,229 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DYNAMIC_RESULTSET_WRAPPER_HXX +#define _DYNAMIC_RESULTSET_WRAPPER_HXX + +#include <osl/mutex.hxx> +#include <osl/conditn.hxx> +#include <ucbhelper/macros.hxx> +#include <cppuhelper/weak.hxx> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/interfacecontainer.hxx> +#include <com/sun/star/ucb/XDynamicResultSet.hpp> +#include <com/sun/star/ucb/XSourceInitialization.hpp> + +#ifndef __com_sun_star_lang_DisposedException_idl__ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#include <com/sun/star/ucb/XDynamicResultSetListener.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +//#define CACHED_CRS_STUB_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSetStub" +//#define CACHED_CRS_STUB_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetStubFactory" + +//========================================================================= + +class DynamicResultSetWrapperListener; +class DynamicResultSetWrapper + : public cppu::OWeakObject + , public com::sun::star::ucb::XDynamicResultSet + , public com::sun::star::ucb::XSourceInitialization +{ +private: + //management of listeners + sal_Bool m_bDisposed; ///Dispose call ready. + sal_Bool m_bInDispose;///In dispose call + osl::Mutex m_aContainerMutex; + cppu::OInterfaceContainerHelper* + m_pDisposeEventListeners; +protected: + com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener > + m_xMyListenerImpl; + DynamicResultSetWrapperListener* + m_pMyListenerImpl; + + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + m_xSMgr; + + osl::Mutex m_aMutex; + sal_Bool m_bStatic; + sal_Bool m_bGotWelcome; + + //different Interfaces from Origin: + com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSet > + m_xSource; + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + m_xSourceResultOne; + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + m_xSourceResultTwo; + //com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + // m_xSourceResultCurrent; + //sal_Bool m_bUseOne; + // + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + m_xMyResultOne; + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + m_xMyResultTwo; + // + com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener > + m_xListener; + + osl::Condition m_aSourceSet; + osl::Condition m_aListenerSet; + +protected: + void SAL_CALL impl_init(); + void SAL_CALL impl_deinit(); + void SAL_CALL + impl_EnsureNotDisposed() + throw( com::sun::star::lang::DisposedException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_InitResultSetOne( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + virtual void SAL_CALL + impl_InitResultSetTwo( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + +public: + + DynamicResultSetWrapper( + com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > xOrigin + , const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & xSMgr ); + + virtual ~DynamicResultSetWrapper(); + + //----------------------------------------------------------------- + // XInterface + virtual com::sun::star::uno::Any SAL_CALL + queryInterface( const com::sun::star::uno::Type & rType ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XDynamicResultSet + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > SAL_CALL + getStaticResultSet() + throw( com::sun::star::ucb::ListenerAlreadySetException + , com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + setListener( const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSetListener > & Listener ) + throw( com::sun::star::ucb::ListenerAlreadySetException + , com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + connectToCache( const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > & xCache ) + throw( com::sun::star::ucb::ListenerAlreadySetException + , com::sun::star::ucb::AlreadyInitializedException + , com::sun::star::ucb::ServiceNotFoundException + , com::sun::star::uno::RuntimeException ); + + virtual sal_Int16 SAL_CALL + getCapabilities() throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XComponent ( base of XDynamicResultSet ) + virtual void SAL_CALL + dispose() throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addEventListener( const com::sun::star::uno::Reference< + com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removeEventListener( const com::sun::star::uno::Reference< + com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XSourceInitialization + + virtual void SAL_CALL + setSource( const com::sun::star::uno::Reference< + com::sun::star::uno::XInterface > & Source ) + throw( com::sun::star::ucb::AlreadyInitializedException + , com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // own methods: + virtual void SAL_CALL + impl_disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_notify( const ::com::sun::star::ucb::ListEvent& Changes ) + throw( com::sun::star::uno::RuntimeException ); +}; + +//========================================================================= + +class DynamicResultSetWrapperListener + : public cppu::OWeakObject + , public com::sun::star::ucb::XDynamicResultSetListener +{ +protected: + DynamicResultSetWrapper* m_pOwner; + osl::Mutex m_aMutex; + +public: + DynamicResultSetWrapperListener( DynamicResultSetWrapper* pOwner ); + + virtual ~DynamicResultSetWrapperListener(); + + //----------------------------------------------------------------- + // XInterface + //----------------------------------------------------------------- + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XEventListener ( base of XDynamicResultSetListener ) + //----------------------------------------------------------------- + virtual void SAL_CALL + disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); + //----------------------------------------------------------------- + // XDynamicResultSetListener + virtual void SAL_CALL + notify( const ::com::sun::star::ucb::ListEvent& Changes ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // own methods: + void SAL_CALL impl_OwnerDies(); +}; + + +#endif + diff --git a/ucb/source/cacher/makefile.mk b/ucb/source/cacher/makefile.mk new file mode 100644 index 000000000000..600fefc174f7 --- /dev/null +++ b/ucb/source/cacher/makefile.mk @@ -0,0 +1,68 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=ucb +TARGET=cached +ENABLE_EXCEPTIONS=TRUE +NO_BSYMBOLIC=TRUE + +# Version +UCB_MAJOR=1 + +.INCLUDE: settings.mk +.IF "$(L10N_framework)"=="" + +SLOFILES=\ + $(SLO)$/contentresultsetwrapper.obj \ + $(SLO)$/cachedcontentresultsetstub.obj \ + $(SLO)$/cachedcontentresultset.obj \ + $(SLO)$/dynamicresultsetwrapper.obj \ + $(SLO)$/cacheddynamicresultsetstub.obj \ + $(SLO)$/cacheddynamicresultset.obj \ + $(SLO)$/cacheserv.obj + +LIB1TARGET=$(SLB)$/_$(TARGET).lib +LIB1OBJFILES=$(SLOFILES) + +SHL1TARGET=$(TARGET)$(UCB_MAJOR) +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +SHL1STDLIBS=\ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) + +SHL1LIBS=$(LIB1TARGET) +SHL1IMPLIB=i$(TARGET) + +SHL1VERSIONMAP=$(SOLARENV)/src/component.map + +DEF1NAME=$(SHL1TARGET) +.ENDIF # L10N_framework + +.INCLUDE: target.mk + |