Tag: cws_src680_dba201b User: fs Date: 05/07/20 03:17:24 Modified: /dba/dbaccess/source/core/dataaccess/ datasource.cxx, datasource.hxx
Log: #i52171# better control over model ownership File Changes: Directory: /dba/dbaccess/source/core/dataaccess/ ================================================ File [changed]: datasource.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/datasource.cxx?r1=1.60.2.1&r2=1.60.2.2 Delta lines: +14 -22 --------------------- --- datasource.cxx 11 Jul 2005 13:37:00 -0000 1.60.2.1 +++ datasource.cxx 20 Jul 2005 10:17:21 -0000 1.60.2.2 @@ -2,9 +2,9 @@ * * $RCSfile: datasource.cxx,v $ * - * $Revision: 1.60.2.1 $ + * $Revision: 1.60.2.2 $ * - * last change: $Author: fs $ $Date: 2005/07/11 13:37:00 $ + * last change: $Author: fs $ $Date: 2005/07/20 10:17:21 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -1195,7 +1195,9 @@ { ResettableMutexGuard _rGuard(m_aMutex); ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed); - Reference< css::frame::XStorable> xStorable(getModelWithPossibleLeak(),UNO_QUERY); + + SharedModel xModel( impl_getModel( true ) ); + Reference< css::frame::XStorable> xStorable( xModel, UNO_QUERY ); if ( xStorable.is() ) xStorable->store(); @@ -1235,28 +1237,14 @@ m_pImpl->setModified(sal_True); } // ----------------------------------------------------------------------------- -Reference< XModel > ODatabaseSource::getModelWithPossibleLeak() +ODatabaseSource::SharedModel ODatabaseSource::impl_getModel( bool _bTakeOwnershipIfNewlyCreated ) { - Reference< XModel > xModel; + SharedModel xModel; if ( m_pImpl.is() ) { - xModel = m_pImpl->getModel_noCreate(); + xModel = SharedModel( m_pImpl->getModel_noCreate(), false /* don't take ownership if the model already existed */ ); if ( !xModel.is() ) - { - // In the course of #i50905#, the ownership of a XModel instance was more clearly - // defined and respected throughout all involved implementations. This place - // here is the last one where a fix wasn't easily possible within the restrictions - // which applied to the fix (time frame, risk) - // - // There's a pretty large comment in ODatabaseDocument::disconnectController - // explaining how this dilemma could be solved (which in fact suggests to - // get completely rid of the "sole ownership" concept, and replace it with - // shared ownership, and vetoable closing). - // - // #i50905# / 2005-06-20 / [EMAIL PROTECTED] - DBG_ERROR( "ODatabaseSource::getModelWithPossibleLeak: creating a model instance with undefined ownership! Probably a resource leak!" ); - xModel = m_pImpl->createNewModel_deliverOwnership(); - } + xModel = SharedModel( m_pImpl->createNewModel_deliverOwnership(), _bTakeOwnershipIfNewlyCreated ); } return xModel; } @@ -1264,7 +1252,11 @@ // XDocumentDataSource Reference< XOfficeDatabaseDocument > SAL_CALL ODatabaseSource::getDatabaseDocument() throw (RuntimeException) { - return Reference< XOfficeDatabaseDocument >( getModelWithPossibleLeak(), UNO_QUERY ); + return Reference< XOfficeDatabaseDocument >( impl_getModel( false ), UNO_QUERY ); + // by definition, clients of getDatabaseDocument are responsible for the model they obtain, + // including responsibility for (attempting to) close the model when they don't need it anymore. + // Thus the "false" parameter in the call to impl_getModel: We don't take the ownership + // of the model, even if it had to be newly created during this call. } // ----------------------------------------------------------------------------- //........................................................................ File [changed]: datasource.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/datasource.hxx?r1=1.30&r2=1.30.2.1 Delta lines: +24 -9 -------------------- --- datasource.hxx 8 Jul 2005 10:36:52 -0000 1.30 +++ datasource.hxx 20 Jul 2005 10:17:22 -0000 1.30.2.1 @@ -2,9 +2,9 @@ * * $RCSfile: datasource.hxx,v $ * - * $Revision: 1.30 $ + * $Revision: 1.30.2.1 $ * - * last change: $Author: obo $ $Date: 2005/07/08 10:36:52 $ + * last change: $Author: fs $ $Date: 2005/07/20 10:17:22 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -171,6 +171,9 @@ #ifndef _DBA_COREDATAACCESS_MODELIMPL_HXX_ #include "ModelImpl.hxx" #endif +#ifndef UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX +#include <unotools/sharedunocomponent.hxx> +#endif //........................................................................ namespace dbaccess @@ -211,15 +214,19 @@ friend ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > ODatabaseSource_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); -protected: +private: + typedef ::utl::SharedUNOComponent< ::com::sun::star::frame::XModel, ::utl::CloseableComponent > + SharedModel; + ::rtl::Reference<ODatabaseModelImpl> m_pImpl; OBookmarkContainer m_aBookmarks; ::cppu::OInterfaceContainerHelper m_aFlushListeners; void setMeAsParent(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xName); -protected: +private: virtual ~ODatabaseSource(); + public: ODatabaseSource(const ::rtl::Reference<ODatabaseModelImpl>& _pImpl); @@ -303,7 +310,7 @@ // XDocumentDataSource virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XOfficeDatabaseDocument > SAL_CALL getDatabaseDocument() throw (::com::sun::star::uno::RuntimeException); -protected: +private: // helper /** open a connection for the current settings. this is the simple connection we get from the driver manager, so it can be used as a master for a "high level" sdb connection. @@ -316,9 +323,17 @@ const rtl::OUString& user, const rtl::OUString& password ); - /// see the implementation for an explanation for the method's name ... - ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > - getModelWithPossibleLeak(); + /** retrieves the model we belong to + + If the model does not yet exist, it is created (->OModelImpl::createNewModel_deliverOwnership). + Using the SharedModel implies that when <arg>_bTakeOwnershipIfNewlyCreated</arg> is <TRUE/>, then when the + returned SharedModel dies (and has not been shared with other SharedModels in the meantime), + then a close attempt for the XModel is made. + + If there already exists a model, <arg>_bTakeOwnershipIfNewlyCreated</arg> is ignored, + and ownership of the model is not taken. + */ + SharedModel impl_getModel( bool _bTakeOwnershipIfNewlyCreated ); // other stuff void flushTables(); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
