From 84808b634c4950b4940925d2fcddf051f4d039a9 Mon Sep 17 00:00:00 2001 From: "Frank Schönheit [fs]" Date: Tue, 3 Nov 2009 14:53:24 +0100 Subject: final step for #i67020# --- dbaccess/source/core/api/columnsettings.cxx | 29 +++- dbaccess/source/core/api/definitioncolumn.cxx | 110 ++++++++++++-- dbaccess/source/core/api/query.cxx | 2 +- dbaccess/source/core/inc/ContainerMediator.hxx | 17 +-- dbaccess/source/core/inc/PropertyForward.hxx | 36 +++-- dbaccess/source/core/inc/columnsettings.hxx | 3 +- dbaccess/source/core/inc/definitioncolumn.hxx | 19 ++- dbaccess/source/core/misc/ContainerMediator.cxx | 126 +++++---------- dbaccess/source/core/misc/PropertyForward.cxx | 194 ++++++++++++------------ 9 files changed, 305 insertions(+), 231 deletions(-) diff --git a/dbaccess/source/core/api/columnsettings.cxx b/dbaccess/source/core/api/columnsettings.cxx index b6a242127..ceae240bd 100644 --- a/dbaccess/source/core/api/columnsettings.cxx +++ b/dbaccess/source/core/api/columnsettings.cxx @@ -124,7 +124,7 @@ namespace dbaccess } //------------------------------------------------------------------------------ - bool OColumnSettings::isMine( const sal_Int32 _nPropertyHandle ) const + bool OColumnSettings::isColumnSettingProperty( const sal_Int32 _nPropertyHandle ) { return ( _nPropertyHandle == PROPERTY_ID_ALIGN ) || ( _nPropertyHandle == PROPERTY_ID_NUMBERFORMAT ) @@ -136,6 +136,33 @@ namespace dbaccess || ( _nPropertyHandle == PROPERTY_ID_HIDDEN ); } + //------------------------------------------------------------------------------ + bool OColumnSettings::isDefaulted( const sal_Int32 _nPropertyHandle, const Any& _rPropertyValue ) + { + switch ( _nPropertyHandle ) + { + case PROPERTY_ID_ALIGN: + case PROPERTY_ID_NUMBERFORMAT: + case PROPERTY_ID_RELATIVEPOSITION: + case PROPERTY_ID_WIDTH: + case PROPERTY_ID_HELPTEXT: + case PROPERTY_ID_CONTROLDEFAULT: + return !_rPropertyValue.hasValue(); + + case PROPERTY_ID_CONTROLMODEL: + return !Reference< XPropertySet >( _rPropertyValue, UNO_QUERY ).is(); + + case PROPERTY_ID_HIDDEN: + { + sal_Bool bHidden = sal_False; + OSL_VERIFY( _rPropertyValue >>= bHidden ); + return !bHidden; + } + } + OSL_ENSURE( false, "OColumnSettings::isDefaulted: illegal property handle!" ); + return sal_False; + } + //------------------------------------------------------------------------------ sal_Bool OColumnSettings::isDefaulted() const { diff --git a/dbaccess/source/core/api/definitioncolumn.cxx b/dbaccess/source/core/api/definitioncolumn.cxx index 3c31f60be..6d0a9b886 100644 --- a/dbaccess/source/core/api/definitioncolumn.cxx +++ b/dbaccess/source/core/api/definitioncolumn.cxx @@ -36,18 +36,24 @@ #include "definitioncolumn.hxx" #include "sdbcoretools.hxx" +/** === begin UNO includes === **/ #include +#include +/** === end UNO includes === **/ #include #include +#include #include #include #include using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::container; using namespace ::cppu; using namespace ::comphelper; using namespace ::osl; @@ -195,7 +201,7 @@ rtl::OUString OTableColumn::getImplementationName( ) throw (RuntimeException) DBG_NAME( OQueryColumn ); // ------------------------------------------------------------------------- -OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn ) +OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn, const Reference< XConnection >& _rxConnection ) :OTableColumnDescriptor( false /* do not act as descriptor */ ) { const sal_Int32 nPropAttr = PropertyAttribute::READONLY; @@ -220,21 +226,14 @@ OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn ) if ( xPSI->hasPropertyByName( PROPERTY_DEFAULTVALUE ) ) OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_DEFAULTVALUE ) >>= m_aDefaultValue ); - // if the source column also has column settings, copy those - struct ColumnSettingDescriptor + // copy some optional properties from the parser column + struct PropertyDescriptor { ::rtl::OUString sName; sal_Int32 nHandle; }; - ColumnSettingDescriptor aProps[] = + PropertyDescriptor aProps[] = { - { PROPERTY_WIDTH, PROPERTY_ID_WIDTH }, - { PROPERTY_NUMBERFORMAT, PROPERTY_ID_NUMBERFORMAT }, - { PROPERTY_RELATIVEPOSITION, PROPERTY_ID_RELATIVEPOSITION }, - { PROPERTY_ALIGN, PROPERTY_ID_ALIGN }, - { PROPERTY_HELPTEXT, PROPERTY_ID_HELPTEXT }, - { PROPERTY_CONTROLDEFAULT, PROPERTY_ID_CONTROLDEFAULT }, - { PROPERTY_HIDDEN, PROPERTY_ID_HIDDEN }, { PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME }, { PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME }, { PROPERTY_TABLENAME, PROPERTY_ID_TABLENAME }, @@ -243,8 +242,15 @@ OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn ) for ( size_t i=0; i < sizeof( aProps ) / sizeof( aProps[0] ); ++i ) { if ( xPSI->hasPropertyByName( aProps[i].sName ) ) - OTableColumnDescriptor::setFastPropertyValue_NoBroadcast( aProps[i].nHandle, _rxParserColumn->getPropertyValue( aProps[i].sName ) ); + setFastPropertyValue_NoBroadcast( aProps[i].nHandle, _rxParserColumn->getPropertyValue( aProps[i].sName ) ); } + + // determine the table column we're based on + osl_incrementInterlockedCount( &m_refCount ); + { + m_xOriginalTableColumn = impl_determineOriginalTableColumn( _rxConnection ); + } + osl_decrementInterlockedCount( &m_refCount ); } //-------------------------------------------------------------------------- @@ -253,6 +259,51 @@ OQueryColumn::~OQueryColumn() DBG_DTOR( OQueryColumn, NULL ); } +//-------------------------------------------------------------------------- +Reference< XPropertySet > OQueryColumn::impl_determineOriginalTableColumn( const Reference< XConnection >& _rxConnection ) +{ + OSL_PRECOND( _rxConnection.is(), "OQueryColumn::impl_determineOriginalTableColumn: illegal connection!" ); + if ( !_rxConnection.is() ) + return NULL; + + Reference< XPropertySet > xOriginalTableColumn; + try + { + // determine the composed table name, plus the column name, as indicated by the + // respective properties + ::rtl::OUString sCatalog, sSchema, sTable; + OSL_VERIFY( getPropertyValue( PROPERTY_CATALOGNAME ) >>= sCatalog ); + OSL_VERIFY( getPropertyValue( PROPERTY_SCHEMANAME ) >>= sSchema ); + OSL_VERIFY( getPropertyValue( PROPERTY_TABLENAME ) >>= sTable ); + if ( !sCatalog.getLength() && !sSchema.getLength() && !sTable.getLength() ) + return NULL; + + ::rtl::OUString sComposedTableName = ::dbtools::composeTableName( + _rxConnection->getMetaData(), sCatalog, sSchema, sTable, sal_False, ::dbtools::eComplete ); + + // retrieve the table in question + Reference< XTablesSupplier > xSuppTables( _rxConnection, UNO_QUERY_THROW ); + Reference< XNameAccess > xTables( xSuppTables->getTables(), UNO_QUERY_THROW ); + if ( !xTables->hasByName( sComposedTableName ) ) + return NULL; + + Reference< XColumnsSupplier > xSuppCols( xTables->getByName( sComposedTableName ), UNO_QUERY_THROW ); + Reference< XNameAccess > xColumns( xSuppCols->getColumns(), UNO_QUERY_THROW ); + + ::rtl::OUString sColumn; + OSL_VERIFY( getPropertyValue( PROPERTY_REALNAME ) >>= sColumn ); + if ( !xColumns->hasByName( sColumn ) ) + return NULL; + + xOriginalTableColumn.set( xColumns->getByName( sColumn ), UNO_QUERY ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return xOriginalTableColumn; +} + //-------------------------------------------------------------------------- IMPLEMENT_GET_IMPLEMENTATION_ID( OQueryColumn ) @@ -274,6 +325,39 @@ IMPLEMENT_GET_IMPLEMENTATION_ID( OQueryColumn ) return OTableColumnDescriptor::createArrayHelper(); } +//-------------------------------------------------------------------------- +void SAL_CALL OQueryColumn::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const +{ + OTableColumnDescriptor::getFastPropertyValue( _rValue, _nHandle ); + + // special treatment for column settings: + if ( !OColumnSettings::isColumnSettingProperty( _nHandle ) ) + return; + + // If the setting has its default value, then try to obtain the value from the table column which + // this query column is based on + if ( !OColumnSettings::isDefaulted( _nHandle, _rValue ) ) + return; + + if ( !m_xOriginalTableColumn.is() ) + return; + + try + { + // determine original property name + ::rtl::OUString sPropName; + sal_Int16 nAttributes( 0 ); + const_cast< OQueryColumn* >( this )->getInfoHelper().fillPropertyMembersByHandle( &sPropName, &nAttributes, _nHandle ); + OSL_ENSURE( sPropName.getLength(), "OColumnWrapper::impl_getPropertyNameFromHandle: property not found!" ); + + _rValue = m_xOriginalTableColumn->getPropertyValue( sPropName ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } +} + //========================================================================== //= OColumnWrapper //========================================================================== @@ -578,11 +662,9 @@ OTableColumnWrapper::~OTableColumnWrapper() { } -// com::sun::star::lang::XTypeProvider //-------------------------------------------------------------------------- IMPLEMENT_GET_IMPLEMENTATION_ID( OTableColumnWrapper ) -// ::com::sun::star::lang::XServiceInfo //------------------------------------------------------------------------------ rtl::OUString OTableColumnWrapper::getImplementationName( ) throw (RuntimeException) { diff --git a/dbaccess/source/core/api/query.cxx b/dbaccess/source/core/api/query.cxx index 28d63f19d..924a4c24f 100644 --- a/dbaccess/source/core/api/query.cxx +++ b/dbaccess/source/core/api/query.cxx @@ -241,7 +241,7 @@ void OQuery::rebuildColumns() for ( ;pBegin != pEnd; ++pBegin) { Reference xSource(xColumns->getByName( *pBegin ),UNO_QUERY); - OQueryColumn* pColumn = new OQueryColumn( xSource ); + OQueryColumn* pColumn = new OQueryColumn( xSource, m_xConnection ); Reference< XChild > xChild( *pColumn, UNO_QUERY_THROW ); xChild->setParent( *this ); diff --git a/dbaccess/source/core/inc/ContainerMediator.hxx b/dbaccess/source/core/inc/ContainerMediator.hxx index 625b56b84..e77f092f5 100644 --- a/dbaccess/source/core/inc/ContainerMediator.hxx +++ b/dbaccess/source/core/inc/ContainerMediator.hxx @@ -112,23 +112,12 @@ namespace dbaccess */ void impl_cleanup_nothrow(); - /** retrieves the settings object to initialize a container element - - Normally, this object will simply retrieve the object with the given name from our settings - container. Hiowever, for columns, there's a fallback in case this settings object does - not yet exist: Then, we check if the given destination object refers to a table column, via its - TableName and RealName property. If so, this table column is used as initialization object. - - @param _rName - the name of the destination object in its container - @param _rxDestination - the destination object to initialize + /** initializes the properties of the given object from its counterpart in our settings container */ - ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > - impl_getSettingsForInitialization_nothrow( + void impl_initSettings_nothrow( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDestination - ) const; + ); }; //........................................................................ } // namespace dbaccess diff --git a/dbaccess/source/core/inc/PropertyForward.hxx b/dbaccess/source/core/inc/PropertyForward.hxx index 0ca98fec6..746648c4e 100644 --- a/dbaccess/source/core/inc/PropertyForward.hxx +++ b/dbaccess/source/core/inc/PropertyForward.hxx @@ -55,24 +55,31 @@ namespace dbaccess { //........................................................................ + + // =================================================================== + // = OPropertyForward + // =================================================================== typedef ::cppu::WeakImplHelper1 < ::com::sun::star::beans::XPropertyChangeListener > OPropertyForward_Base; - class OPropertyForward : public ::comphelper::OBaseMutex + class OPropertyForward :public ::comphelper::OBaseMutex ,public OPropertyForward_Base { - ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xSource; - ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xDest; - ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo> m_xDestInfo; - ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xDestContainer; - ::rtl::OUString m_sName; - sal_Bool m_bInInsert; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xSource; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xDest; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > m_xDestInfo; + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xDestContainer; + ::rtl::OUString m_sName; + sal_Bool m_bInInsert; + protected: virtual ~OPropertyForward(); + public: - OPropertyForward(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xSource - ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xDestContainer - ,const ::rtl::OUString& _sName - ,const ::std::vector< ::rtl::OUString>& _aPropertyList = ::std::vector< ::rtl::OUString>()); + OPropertyForward( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xSource, + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xDestContainer, + const ::rtl::OUString& _sName, + const ::std::vector< ::rtl::OUString >& _aPropertyList + ); // ::com::sun::star::beans::XPropertyChangeListener virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw(::com::sun::star::uno::RuntimeException); @@ -80,10 +87,11 @@ namespace dbaccess // ::com::sun::star::lang::XEventListener virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException); - inline void setName(const ::rtl::OUString& _sName) { m_sName = _sName; } - void setDefinition(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest); - inline ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getDefinition() const { return m_xDest;} + inline void setName( const ::rtl::OUString& _sName ) { m_sName = _sName; } + void setDefinition( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xDest); + inline ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getDefinition() const { return m_xDest; } }; + //........................................................................ } // namespace dbaccess //........................................................................ diff --git a/dbaccess/source/core/inc/columnsettings.hxx b/dbaccess/source/core/inc/columnsettings.hxx index c44b6cdaf..639fd96ea 100644 --- a/dbaccess/source/core/inc/columnsettings.hxx +++ b/dbaccess/source/core/inc/columnsettings.hxx @@ -95,7 +95,8 @@ namespace dbaccess /** determines whether the property with the given handle is handled by the class */ - bool isMine( const sal_Int32 _nPropertyHandle ) const; + static bool isColumnSettingProperty( const sal_Int32 _nPropertyHandle ); + static bool isDefaulted( const sal_Int32 _nPropertyHandle, const ::com::sun::star::uno::Any& _rPropertyValue ); public: /** check if the persistent settings have their default value diff --git a/dbaccess/source/core/inc/definitioncolumn.hxx b/dbaccess/source/core/inc/definitioncolumn.hxx index 4cbdeec66..cfc61b34c 100644 --- a/dbaccess/source/core/inc/definitioncolumn.hxx +++ b/dbaccess/source/core/inc/definitioncolumn.hxx @@ -117,9 +117,6 @@ namespace dbaccess private: void impl_registerProperties(); - - protected: - using OColumn::getFastPropertyValue; }; // ========================================================================= @@ -166,11 +163,16 @@ namespace dbaccess ::rtl::OUString m_sRealName; // + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xOriginalTableColumn; + protected: ~OQueryColumn(); public: - OQueryColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxParserColumn ); + OQueryColumn( + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxParserColumn, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection + ); // XTypeProvider virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException); @@ -178,9 +180,16 @@ namespace dbaccess // XServiceInfo virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); - // OPropertyArrayUsageHelper + // *Property* virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const; + virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const; + + private: + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > + impl_determineOriginalTableColumn( + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection + ); }; // ========================================================================= diff --git a/dbaccess/source/core/misc/ContainerMediator.cxx b/dbaccess/source/core/misc/ContainerMediator.cxx index 883926a26..29e85d0b4 100644 --- a/dbaccess/source/core/misc/ContainerMediator.cxx +++ b/dbaccess/source/core/misc/ContainerMediator.cxx @@ -128,7 +128,7 @@ void OContainerMediator::impl_cleanup_nothrow() xContainer = m_xContainer; if ( xContainer.is() ) xContainer->removeContainerListener( this ); - m_xContainer.clear();//WeakReference< XContainer >(); + m_xContainer.clear(); m_aForwardList.clear(); } @@ -214,117 +214,69 @@ void SAL_CALL OContainerMediator::disposing( const EventObject& /*Source*/ ) thr { ::osl::MutexGuard aGuard(m_aMutex); -// Reference< XContainer > xContainer = m_xContainer; -// if ( Source.Source == xContainer || Source.Source == m_xSettings ) - // this can only be one of them :-) So no check needed here impl_cleanup_nothrow(); } // ----------------------------------------------------------------------------- -Reference< XPropertySet > OContainerMediator::impl_getSettingsForInitialization_nothrow( const ::rtl::OUString& _rName, - const Reference< XPropertySet >& _rxDestination ) const +void OContainerMediator::impl_initSettings_nothrow( const ::rtl::OUString& _rName, const Reference< XPropertySet >& _rxDestination ) { - Reference< XPropertySet > xSettings; try { if ( m_xSettings.is() && m_xSettings->hasByName( _rName ) ) { - OSL_VERIFY( m_xSettings->getByName( _rName ) >>= xSettings ); - } - else if ( m_eType == eColumns ) - { - do // artifial loop for easier flow control - { - - Reference< XConnection > xConnection( m_aConnection ); - if ( !xConnection.is() ) - break; - - Reference< XPropertySetInfo > xPSI( _rxDestination->getPropertySetInfo(), UNO_QUERY_THROW ); - if ( !xPSI->hasPropertyByName( PROPERTY_TABLENAME ) - || !xPSI->hasPropertyByName( PROPERTY_REALNAME ) - ) - break; - - // determine the composed table name, plus the column name, as indicated by the - // respective properties at the destination object - ::rtl::OUString sCatalog, sSchema, sTable, sColumn; - if ( xPSI->hasPropertyByName( PROPERTY_CATALOGNAME ) ) - { - OSL_VERIFY( _rxDestination->getPropertyValue( PROPERTY_CATALOGNAME ) >>= sCatalog ); - } - if ( xPSI->hasPropertyByName( PROPERTY_SCHEMANAME ) ) - { - OSL_VERIFY( _rxDestination->getPropertyValue( PROPERTY_SCHEMANAME ) >>= sSchema ); - } - OSL_VERIFY( _rxDestination->getPropertyValue( PROPERTY_TABLENAME ) >>= sTable ); - OSL_VERIFY( _rxDestination->getPropertyValue( PROPERTY_REALNAME ) >>= sColumn ); - - ::rtl::OUString sComposedTableName = ::dbtools::composeTableName( - xConnection->getMetaData(), sCatalog, sSchema, sTable, sal_False, ::dbtools::eComplete ); - - // retrieve the table in question - Reference< XTablesSupplier > xSuppTables( xConnection, UNO_QUERY_THROW ); - Reference< XNameAccess > xTables( xSuppTables->getTables(), UNO_QUERY_THROW ); - if ( !xTables->hasByName( sComposedTableName ) ) - break; - - Reference< XColumnsSupplier > xSuppCols( xTables->getByName( sComposedTableName ), UNO_QUERY_THROW ); - Reference< XNameAccess > xColumns( xSuppCols->getColumns(), UNO_QUERY_THROW ); - if ( !xColumns->hasByName( sColumn ) ) - break; - - xSettings.set( xColumns->getByName( sColumn ), UNO_QUERY ); - - } - while ( false ); + Reference< XPropertySet > xSettings( m_xSettings->getByName( _rName ), UNO_QUERY_THROW ); + ::comphelper::copyProperties( xSettings, _rxDestination ); } } catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); } - return xSettings; } // ----------------------------------------------------------------------------- -void OContainerMediator::notifyElementCreated(const ::rtl::OUString& _sName,const Reference& _xDest) +void OContainerMediator::notifyElementCreated( const ::rtl::OUString& _sName, const Reference< XPropertySet >& _xDest ) { - PropertyForwardList::iterator aFind = m_aForwardList.find(_sName); - if ( (aFind == m_aForwardList.end() || !aFind->second->getDefinition().is() )&& m_xSettings.is() ) - { - ::std::vector< ::rtl::OUString> aPropertyList; + if ( !m_xSettings.is() ) + return; - try - { - // initially copy from the settings object (if existent) to the newly created object - Reference< XPropertySet > xSetting( impl_getSettingsForInitialization_nothrow( _sName, _xDest ) ); - if ( xSetting.is() ) - ::comphelper::copyProperties( xSetting, _xDest ); + PropertyForwardList::iterator aFind = m_aForwardList.find( _sName ); + if ( aFind != m_aForwardList.end() + && aFind->second->getDefinition().is() + ) + { + OSL_ENSURE( false, "OContainerMediator::notifyElementCreated: is this really a valid case?" ); + return; + } - // collect the to-be-monitored properties - Reference< XPropertySetInfo > xPSI( _xDest->getPropertySetInfo(), UNO_QUERY_THROW ); - Sequence< Property > aProperties( xPSI->getProperties() ); - const Property* property = aProperties.getConstArray(); - const Property* propertyEnd = aProperties.getConstArray() + aProperties.getLength(); - for ( ; property != propertyEnd; ++property ) - { - if ( ( property->Attributes & PropertyAttribute::READONLY ) != 0 ) - continue; - if ( ( property->Attributes & PropertyAttribute::BOUND ) == 0 ) - continue; + ::std::vector< ::rtl::OUString > aPropertyList; + try + { + // initially copy from the settings object (if existent) to the newly created object + impl_initSettings_nothrow( _sName, _xDest ); - aPropertyList.push_back( property->Name ); - } - } - catch( const Exception& ) + // collect the to-be-monitored properties + Reference< XPropertySetInfo > xPSI( _xDest->getPropertySetInfo(), UNO_QUERY_THROW ); + Sequence< Property > aProperties( xPSI->getProperties() ); + const Property* property = aProperties.getConstArray(); + const Property* propertyEnd = aProperties.getConstArray() + aProperties.getLength(); + for ( ; property != propertyEnd; ++property ) { - DBG_UNHANDLED_EXCEPTION(); + if ( ( property->Attributes & PropertyAttribute::READONLY ) != 0 ) + continue; + if ( ( property->Attributes & PropertyAttribute::BOUND ) == 0 ) + continue; + + aPropertyList.push_back( property->Name ); } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } - ::rtl::Reference< OPropertyForward > pForward( new OPropertyForward( _xDest, m_xSettings, _sName, aPropertyList ) ); - m_aForwardList[_sName] = pForward; - } // if ( aFind == m_aForwardList.end() && m_xSettings.is() ) + ::rtl::Reference< OPropertyForward > pForward( new OPropertyForward( _xDest, m_xSettings, _sName, aPropertyList ) ); + m_aForwardList[ _sName ] = pForward; } // ----------------------------------------------------------------------------- //........................................................................ diff --git a/dbaccess/source/core/misc/PropertyForward.cxx b/dbaccess/source/core/misc/PropertyForward.cxx index 697519295..d145aa983 100644 --- a/dbaccess/source/core/misc/PropertyForward.cxx +++ b/dbaccess/source/core/misc/PropertyForward.cxx @@ -30,140 +30,146 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_dbaccess.hxx" -#ifndef DBA_PROPERTYSETFORWARD_HXX + #include "PropertyForward.hxx" -#endif -#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ -#include -#endif -#ifndef DBACCESS_SHARED_DBASTRINGS_HRC #include "dbastrings.hrc" -#endif -#ifndef _COMPHELPER_PROPERTY_HXX_ -#include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_ + +#include #include -#endif -#ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_ #include -#endif -#ifndef _TOOLS_DEBUG_HXX + +#include #include -#endif +#include //........................................................................ namespace dbaccess { //........................................................................ + using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; using namespace ::com::sun::star::sdbcx; + using namespace ::com::sun::star::lang; -DBG_NAME(OPropertyForward) -OPropertyForward::OPropertyForward(const Reference< XPropertySet>& _xSource - ,const Reference< XNameAccess>& _xDestContainer - ,const ::rtl::OUString& _sName - ,const ::std::vector< ::rtl::OUString>& _aPropertyList) - : m_xSource(_xSource) - , m_xDestContainer(_xDestContainer) - , m_sName(_sName) - , m_bInInsert(sal_False) -{ - DBG_CTOR(OPropertyForward,NULL); - OSL_ENSURE(_xDestContainer.is(),"OPropertyForward::OPropertyForward: destination should be valid!"); - OSL_ENSURE(m_xSource.is(),"OPropertyForward::OPropertyForward: source must be valid!"); - osl_incrementInterlockedCount(&m_refCount); - try + DBG_NAME(OPropertyForward) + + //------------------------------------------------------------------------ + OPropertyForward::OPropertyForward( const Reference< XPropertySet>& _xSource, const Reference< XNameAccess>& _xDestContainer, + const ::rtl::OUString& _sName, const ::std::vector< ::rtl::OUString>& _aPropertyList ) + :m_xSource( _xSource, UNO_SET_THROW ) + ,m_xDestContainer( _xDestContainer, UNO_SET_THROW ) + ,m_sName( _sName ) + ,m_bInInsert( sal_False ) { - if ( _aPropertyList.empty() ) - _xSource->addPropertyChangeListener(::rtl::OUString(), this); - else + DBG_CTOR(OPropertyForward,NULL); + + osl_incrementInterlockedCount(&m_refCount); + try { - ::std::vector< ::rtl::OUString>::const_iterator aIter = _aPropertyList.begin(); - ::std::vector< ::rtl::OUString>::const_iterator aEnd = _aPropertyList.end(); - for (; aIter != aEnd ; ++aIter ) - _xSource->addPropertyChangeListener(*aIter, this); + if ( _aPropertyList.empty() ) + _xSource->addPropertyChangeListener( ::rtl::OUString(), this ); + else + { + ::std::vector< ::rtl::OUString >::const_iterator aIter = _aPropertyList.begin(); + ::std::vector< ::rtl::OUString >::const_iterator aEnd = _aPropertyList.end(); + for (; aIter != aEnd ; ++aIter ) + _xSource->addPropertyChangeListener( *aIter, this ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); } + osl_decrementInterlockedCount( &m_refCount ); } - catch(Exception&) + + // ----------------------------------------------------------------------------- + OPropertyForward::~OPropertyForward() { - OSL_ENSURE(sal_False, "OPropertyForward::OPropertyForward: caught an exception!"); + DBG_DTOR(OPropertyForward,NULL); } - osl_decrementInterlockedCount(&m_refCount); -} -// ----------------------------------------------------------------------------- -OPropertyForward::~OPropertyForward() -{ - DBG_DTOR(OPropertyForward,NULL); -} -// ----------------------------------------------------------------------------- -void SAL_CALL OPropertyForward::propertyChange( const PropertyChangeEvent& evt ) throw(RuntimeException) -{ - ::osl::MutexGuard aGuard(m_aMutex); - if ( m_xDestContainer.is() ) + + // ----------------------------------------------------------------------------- + void SAL_CALL OPropertyForward::propertyChange( const PropertyChangeEvent& evt ) throw(RuntimeException) { - if ( m_xDestContainer->hasByName(m_sName) ) - { - m_xDest.set(m_xDestContainer->getByName(m_sName),UNO_QUERY); - } - else + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_xDestContainer.is() ) + throw DisposedException( ::rtl::OUString(), *this ); + + try { - Reference xFactory(m_xDestContainer,UNO_QUERY); - if ( xFactory.is() ) + if ( !m_xDest.is() ) { - m_xDest = xFactory->createDataDescriptor(); - if ( m_xDest.is() ) + if ( m_xDestContainer->hasByName( m_sName ) ) + { + m_xDest.set( m_xDestContainer->getByName( m_sName ), UNO_QUERY_THROW ); + } + else { - ::comphelper::copyProperties(m_xSource,m_xDest); + Reference< XDataDescriptorFactory > xFactory( m_xDestContainer, UNO_QUERY_THROW ); + m_xDest.set( xFactory->createDataDescriptor(), UNO_SET_THROW ); + + ::comphelper::copyProperties( m_xSource, m_xDest ); + m_bInInsert = sal_True; - Reference xAppend(m_xDestContainer,UNO_QUERY); - if ( xAppend.is() ) - xAppend->appendByDescriptor(m_xDest); + Reference< XAppend > xAppend( m_xDestContainer, UNO_QUERY_THROW ); + xAppend->appendByDescriptor( m_xDest ); m_bInInsert = sal_False; } + + m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW ); + } + + if ( m_xDestInfo->hasPropertyByName( evt.PropertyName ) ) + { + m_xDest->setPropertyValue( evt.PropertyName, evt.NewValue ); } } - if ( m_xDest.is() ) - m_xDestInfo = m_xDest->getPropertySetInfo(); - } - - if ( m_xDestInfo.is() && m_xDestInfo->hasPropertyByName(evt.PropertyName) ) - { - m_xDest->setPropertyValue(evt.PropertyName,evt.NewValue); + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } -} -// ----------------------------------------------------------------------------- -void SAL_CALL OPropertyForward::disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ ) throw (RuntimeException) -{ - ::osl::MutexGuard aGuard(m_aMutex); - if ( m_xSource.is() ) + + // ----------------------------------------------------------------------------- + void SAL_CALL OPropertyForward::disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ ) throw (RuntimeException) { - m_xSource->removePropertyChangeListener(::rtl::OUString(), this); + ::osl::MutexGuard aGuard(m_aMutex); + + if ( !m_xSource.is() ) + throw DisposedException( ::rtl::OUString(), *this ); + + m_xSource->removePropertyChangeListener( ::rtl::OUString(), this ); m_xSource = NULL; + m_xDestContainer = NULL; + m_xDestInfo = NULL; + m_xDest = NULL; } - m_xDestContainer = NULL; - m_xDestInfo = NULL; - m_xDest = NULL; -} -// ----------------------------------------------------------------------------- -void OPropertyForward::setDefinition(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest) -{ - ::osl::MutexGuard aGuard(m_aMutex); - if ( !m_bInInsert ) + + // ----------------------------------------------------------------------------- + void OPropertyForward::setDefinition( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest ) { - OSL_ENSURE( !m_xDest.is(),"Definition object is already set!"); + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bInInsert ) + return; - m_xDest = _xDest; - if ( m_xDest.is() ) + OSL_ENSURE( !m_xDest.is(), "OPropertyForward::setDefinition: definition object is already set!" ); + try { - m_xDestInfo = m_xDest->getPropertySetInfo(); - ::comphelper::copyProperties(m_xDest,m_xSource); + m_xDest.set( _xDest, UNO_SET_THROW ); + m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW ); + ::comphelper::copyProperties( m_xDest, m_xSource ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); } } -} + //........................................................................ } // namespace dbaccess //........................................................................ -- cgit v1.2.3