Tag: cws_src680_qiq User: fs Date: 06/05/24 07:54:42 Modified: /dba/dbaccess/source/core/api/ querycontainer.cxx
Log: #i51143# be an XContainerApproveListener at the command definition container, to prevent somebody inserting a command definition with a name conflicting with a table (in case tables and queries share the same namespace) File Changes: Directory: /dba/dbaccess/source/core/api/ ========================================= File [changed]: querycontainer.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/querycontainer.cxx?r1=1.23.4.2&r2=1.23.4.3 Delta lines: +82 -86 --------------------- --- querycontainer.cxx 24 May 2006 09:10:44 -0000 1.23.4.2 +++ querycontainer.cxx 24 May 2006 14:54:39 -0000 1.23.4.3 @@ -4,9 +4,9 @@ * * $RCSfile: querycontainer.cxx,v $ * - * $Revision: 1.23.4.2 $ + * $Revision: 1.23.4.3 $ * - * last change: $Author: fs $ $Date: 2006/05/24 09:10:44 $ + * last change: $Author: fs $ $Date: 2006/05/24 14:54:39 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -42,6 +42,12 @@ #ifndef _DBA_COREAPI_QUERY_HXX_ #include "query.hxx" #endif +#ifndef DBACCESS_OBJECTNAMEAPPROVAL_HXX +#include "objectnameapproval.hxx" +#endif +#ifndef DBA_CONTAINERLISTENER_HXX +#include "ContainerListener.hxx" +#endif /** === begin UNO includes === **/ #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ @@ -53,11 +59,8 @@ #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ #include <com/sun/star/sdbc/XConnection.hpp> #endif -#ifndef _COM_SUN_STAR_SDB_TOOLS_XCONNECTIONTOOLS_HPP_ -#include <com/sun/star/sdb/tools/XConnectionTools.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_ -#include <com/sun/star/sdb/CommandType.hpp> +#ifndef _COM_SUN_STAR_CONTAINER_XCONTAINERAPPROVEBROADCASTER_HPP_ +#include <com/sun/star/container/XContainerApproveBroadcaster.hpp> #endif /** === end UNO includes === **/ @@ -83,16 +86,12 @@ #ifndef _COMPHELPER_EXTRACT_HXX_ #include <comphelper/extract.hxx> #endif -#ifndef _CPPUHELPER_EXC_HLP_HXX_ -#include <cppuhelper/exc_hlp.hxx> -#endif using namespace dbtools; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::ucb; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdb::tools; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdbcx; @@ -124,14 +123,15 @@ DBG_CTOR(OQueryContainer, NULL); increment(m_refCount); - - m_pCommandsListener = new OCommandsListener(this); + { + m_pCommandsListener = new OContainerListener( *this, m_aMutex ); m_pCommandsListener->acquire(); - { - Reference< XContainer > xContainer(m_xCommandDefinitions, UNO_QUERY); - DBG_ASSERT(xContainer.is(), "OQueryContainer::OQueryContainer : the CommandDefinitions container is invalid !"); - xContainer->addContainerListener(m_pCommandsListener); + Reference< XContainer > xContainer( m_xCommandDefinitions, UNO_QUERY_THROW ); + xContainer->addContainerListener( m_pCommandsListener ); + + Reference< XContainerApproveBroadcaster > xContainerApprove( m_xCommandDefinitions, UNO_QUERY_THROW ); + xContainerApprove->addContainerApproveListener( m_pCommandsListener ); // fill my structures ODefinitionContainer_Impl* pItem = static_cast<ODefinitionContainer_Impl*>(m_pImpl.get()); @@ -145,6 +145,8 @@ } } decrement(m_refCount); + + setElementApproval( PContainerApprove( new ObjectNameApproval( _rxConn, ObjectNameApproval::TypeQuery ) ) ); } //------------------------------------------------------------------------------ @@ -161,14 +163,22 @@ { ODefinitionContainer::disposing(); MutexGuard aGuard(m_aMutex); + if ( !m_xCommandDefinitions.is() ) + // already disposed + return; - // say our listeners goobye - Reference< XContainer > xContainer(m_xCommandDefinitions, UNO_QUERY); - if (xContainer.is()) - xContainer->removeContainerListener(m_pCommandsListener); - if(m_pCommandsListener) + if ( m_pCommandsListener ) + { + Reference< XContainer > xContainer( m_xCommandDefinitions, UNO_QUERY ); + xContainer->removeContainerListener( m_pCommandsListener ); + Reference< XContainerApproveBroadcaster > xContainerApprove( m_xCommandDefinitions, UNO_QUERY ); + xContainerApprove->removeContainerApproveListener( m_pCommandsListener ); + + m_pCommandsListener->dispose(); m_pCommandsListener->release(); m_pCommandsListener = NULL; + } + m_xCommandDefinitions = NULL; m_xConnection = NULL; } @@ -188,49 +198,41 @@ //------------------------------------------------------------------------------ void SAL_CALL OQueryContainer::appendByDescriptor( const Reference< XPropertySet >& _rxDesc ) throw(SQLException, ElementExistException, RuntimeException) { - Reference< XContent> xNewObject; - ::rtl::OUString sNewObjectName; + ResettableMutexGuard aGuard(m_aMutex); + if ( !m_xCommandDefinitions.is() ) + throw DisposedException( ::rtl::OUString(), *this ); - ClearableMutexGuard aGuard(m_aMutex); + // first clone this object's CommandDefinition part + Reference< XPropertySet > xCommandDefinitionPart( m_xORB->createInstance( SERVICE_SDB_QUERYDEFINITION ), UNO_QUERY_THROW ); + ::comphelper::copyProperties( _rxDesc, xCommandDefinitionPart ); + // TODO : the columns part of the descriptor has to be copied - OQueryDescriptor* pImpl = NULL; - comphelper::getImplementation(pImpl, Reference< XInterface >(_rxDesc.get())); - DBG_ASSERT(pImpl != NULL, "OQueryContainer::appendByDescriptor : can't fully handle this descriptor !"); + // create a wrapper for the object (*before* inserting into our command definition container) + Reference< XContent > xNewObject( implCreateWrapper( Reference< XContent>( xCommandDefinitionPart, UNO_QUERY_THROW ) ) ); - // first clone this object's CommandDefinition part - if (!m_xCommandDefinitions.is()) + ::rtl::OUString sNewObjectName; + _rxDesc->getPropertyValue(PROPERTY_NAME) >>= sNewObjectName; + + try { - DBG_ERROR("OQueryContainer::appendByDescriptor : have no CommandDefinition container anymore !"); - // perhaps somebody modified the DataSource, so all connections were separated - throwGenericSQLException(::rtl::OUString::createFromAscii("Unable to insert objects into containers of standalone connections (not belonging to a data source)."), *this); - // TODO : resource + notifyByName( aGuard, sNewObjectName, xNewObject, NULL, E_INSERTED, ApproveListeners ); } - - Reference< XPropertySet > xCommandDefinitionPart(m_xORB->createInstance(SERVICE_SDB_QUERYDEFINITION), UNO_QUERY); - if (!xCommandDefinitionPart.is()) + catch( const Exception& ) { - DBG_ERROR("OQueryContainer::appendByDescriptor : could not create a CommandDefinition object !"); - throwGenericSQLException(::rtl::OUString::createFromAscii("Unable to create an object supporting the com.sun.star.sdb.CommandDefinition service"), *this); - // TODO : resource + disposeComponent( xNewObject ); + disposeComponent( xCommandDefinitionPart ); + throw; } - ::comphelper::copyProperties(_rxDesc, xCommandDefinitionPart); - // TODO : the columns part of the descriptor has to be copied - - // create a wrapper for the object (*before* inserting into our command definition container) - xNewObject = implCreateWrapper(Reference< XContent>(xCommandDefinitionPart,UNO_QUERY)); - // insert the basic object into the definition container - _rxDesc->getPropertyValue(PROPERTY_NAME) >>= sNewObjectName; { m_eDoingCurrently = INSERTING; OAutoActionReset aAutoReset(this); m_xCommandDefinitions->insertByName(sNewObjectName, makeAny(xCommandDefinitionPart)); } - implAppend(sNewObjectName, xNewObject); - - notifyByName(aGuard,sNewObjectName,xNewObject,NULL,E_INSERTED); + implAppend( sNewObjectName, xNewObject ); + notifyByName( aGuard, sNewObjectName, xNewObject, NULL, E_INSERTED, ContainerListemers ); } // XDrop @@ -242,12 +244,7 @@ throw NoSuchElementException(_rName,*this); if ( !m_xCommandDefinitions.is() ) - { - DBG_ERROR("OQueryContainer::dropByIndex : have no CommandDefinition container anymore !"); - // perhaps somebody modified the DataSource, so all connections were separated - throwGenericSQLException(::rtl::OUString::createFromAscii("Unable to remove objects from containers of standalone connections (not belonging to a data source)."), *this); - // TODO : resource - } + throw DisposedException( ::rtl::OUString(), *this ); // now simply forward the remove request to the CommandDefinition container, we're a listener for the removal // and thus we do everything neccessary in ::elementRemoved @@ -261,6 +258,9 @@ if ((_nIndex<0) || (_nIndex>getCount())) throw IndexOutOfBoundsException(); + if ( !m_xCommandDefinitions.is() ) + throw DisposedException( ::rtl::OUString(), *this ); + ::rtl::OUString sName; Reference<XPropertySet> xProp(Reference<XIndexAccess>(m_xCommandDefinitions,UNO_QUERY)->getByIndex(_nIndex),UNO_QUERY); if ( xProp.is() ) @@ -327,6 +327,27 @@ } //------------------------------------------------------------------------------ +void SAL_CALL OQueryContainer::approveInsertElement( const ContainerEvent& Event ) throw (WrappedTargetException, RuntimeException) +{ + ::rtl::OUString sName; + OSL_VERIFY( Event.Accessor >>= sName ); + Reference< XContent > xElement( Event.Element, UNO_QUERY_THROW ); + getElementApproval()->approveElement( sName, xElement.get() ); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OQueryContainer::approveReplaceElement( const ContainerEvent& Event ) throw (WrappedTargetException, RuntimeException) +{ + // not interested in +} + +//------------------------------------------------------------------------------ +void SAL_CALL OQueryContainer::approveRemoveElement( const ContainerEvent& Event ) throw (WrappedTargetException, RuntimeException) +{ + // not interested in +} + +//------------------------------------------------------------------------------ void SAL_CALL OQueryContainer::disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw(::com::sun::star::uno::RuntimeException) { if (_rSource.Source.get() == Reference< XInterface >(m_xCommandDefinitions, UNO_QUERY).get()) @@ -421,31 +442,6 @@ MutexGuard aGuard(m_aMutex); return m_xCommandDefinitions->getElementNames(); -} - -// ----------------------------------------------------------------------------- -void OQueryContainer::approveNewObject( const ::rtl::OUString& _sName, const Reference< XContent >& _rxObject) const -{ - ODefinitionContainer::approveNewObject( _sName, _rxObject ); - - Reference< XConnectionTools > xConnectionTools( m_xConnection, UNO_QUERY_THROW ); - Reference< XObjectNames > xObjectNames( xConnectionTools->createObjectNames(), UNO_QUERY_THROW ); - try - { - xObjectNames->checkNameIsUsed( CommandType::QUERY, _sName ); - // this is a little bit overkill, since it will also check whether the given name is already - // used as query name - which is what ODefinitionContainer::approveNewObject already did. - // However, the main functionality here is that checkNameIsUsed also checks for conflicts with - // table names, in case we belong to a connection where queries and tables share the - // same namespace - } - catch( const SQLException& ) - { - WrappedTargetException aWrapped; - aWrapped.Context = *this; - aWrapped.TargetException = ::cppu::getCaughtException(); - throw aWrapped; - } } //........................................................................ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
