Tag: cws_src680_hslqdb3 User: fs Date: 05/06/21 07:37:44 Modified: /dba/dbaccess/source/core/dataaccess/ ModelImpl.cxx, ModelImpl.hxx
Log: #i45749# only commit storages if they're not readonly File Changes: Directory: /dba/dbaccess/source/core/dataaccess/ ================================================ File [changed]: ModelImpl.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.cxx?r1=1.4&r2=1.4.50.1 Delta lines: +54 -34 --------------------- --- ModelImpl.cxx 30 Mar 2005 11:54:58 -0000 1.4 +++ ModelImpl.cxx 21 Jun 2005 14:37:40 -0000 1.4.50.1 @@ -2,9 +2,9 @@ * * $RCSfile: ModelImpl.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.4.50.1 $ * - * last change: $Author: rt $ $Date: 2005/03/30 11:54:58 $ + * last change: $Author: fs $ $Date: 2005/06/21 14:37:40 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -430,17 +430,12 @@ // ----------------------------------------------------------------------------- void ODatabaseModelImpl::commitRootStorage() { - try - { - Reference< XTransactedObject > xTransact( getStorage(), UNO_QUERY ); - OSL_ENSURE( xTransact.is() || !getStorage().is(), "ODatabaseModelImpl::commitRootStorage: cannot commit the storage (missing interface)!" ); - if ( xTransact.is() ) - xTransact->commit(); - } - catch(Exception) - { - OSL_ENSURE( false, "ODatabaseModelImpl::commitRootStorage: caught an exception!" ); - } +#if OSL_DEBUG_LEVEL > 0 + bool bSuccess = +#endif + commitStorageIfWriteable_ignoreErrors( getStorage() ); + OSL_ENSURE( bSuccess || !getStorage().is(), + "ODatabaseModelImpl::commitRootStorage: could commit the storage!" ); } // ----------------------------------------------------------------------------- Reference<XStorage> ODatabaseModelImpl::getStorage() @@ -537,23 +532,51 @@ return xStorage; } // ----------------------------------------------------------------------------- -sal_Bool ODatabaseModelImpl::commitEmbeddedStorage() +bool ODatabaseModelImpl::commitStorageIfWriteable( const Reference< XStorage >& _rxStorage ) SAL_THROW(( IOException, WrappedTargetException, RuntimeException )) { - sal_Bool bStore = sal_False; + bool bSuccess = false; + Reference<XTransactedObject> xTrans( _rxStorage, UNO_QUERY ); + if ( xTrans.is() ) + { + sal_Int32 nMode = ElementModes::READ; try { - TStorages::iterator aFind = m_aStorages.find(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("database"))); - if ( aFind != m_aStorages.end() ) + Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW ); + xStorageProps->getPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nMode; + } + catch( const Exception& ) { - Reference<XTransactedObject> xTrans(aFind->second,UNO_QUERY); - if ( bStore = xTrans.is() ) + OSL_ENSURE( sal_False, "ODatabaseModelImpl::commitStorageIfWriteable: could not determine the OpenMode of the storage!" ); + } + + if ( ( nMode & ElementModes::WRITE ) != 0 ) xTrans->commit(); + bSuccess = true; } + return bSuccess; +} +// ----------------------------------------------------------------------------- +bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage ) SAL_THROW(()) +{ + bool bSuccess = false; + try + { + bSuccess = commitStorageIfWriteable( _rxStorage ); } - catch(Exception&) + catch( const Exception& ) { - OSL_ENSURE(0,"Exception Caught: Could not store embedded database!"); + OSL_ENSURE( sal_False, "ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors: caught an exception!" ); } + return bSuccess; +} +// ----------------------------------------------------------------------------- +sal_Bool ODatabaseModelImpl::commitEmbeddedStorage() +{ + sal_Bool bStore = sal_False; + TStorages::iterator aFind = m_aStorages.find(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("database"))); + if ( aFind != m_aStorages.end() ) + bStore = commitStorageIfWriteable_ignoreErrors( aFind->second ); return bStore; } // ----------------------------------------------------------------------------- @@ -639,21 +662,18 @@ return m_refCount; } // ----------------------------------------------------------------------------- -void ODatabaseModelImpl::commitStorages() +void ODatabaseModelImpl::commitStorages() SAL_THROW(( IOException, RuntimeException )) { try { TStorages::iterator aIter = m_aStorages.begin(); TStorages::iterator aEnd = m_aStorages.end(); for (; aIter != aEnd ; ++aIter) - { - Reference<XTransactedObject> xTrans(aIter->second,UNO_QUERY); - if ( xTrans.is() ) - xTrans->commit(); - } + commitStorageIfWriteable( aIter->second ); } catch(WrappedTargetException) { + // WrappedTargetException not allowed to leave throw IOException(); } } File [changed]: ModelImpl.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.hxx?r1=1.4&r2=1.4.50.1 Delta lines: +22 -4 -------------------- --- ModelImpl.hxx 30 Mar 2005 11:55:09 -0000 1.4 +++ ModelImpl.hxx 21 Jun 2005 14:37:41 -0000 1.4.50.1 @@ -2,9 +2,9 @@ * * $RCSfile: ModelImpl.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.4.50.1 $ * - * last change: $Author: rt $ $Date: 2005/03/30 11:55:09 $ + * last change: $Author: fs $ $Date: 2005/06/21 14:37:41 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -292,7 +292,9 @@ /** commits all storages */ - void commitStorages(); + void commitStorages() + SAL_THROW(( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException )); + /** dispose all frames for registered controllers */ @@ -378,6 +380,22 @@ /// commits our storage void commitRootStorage(); + + /// commits a given storage if it's not readonly + static bool commitStorageIfWriteable( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage + ) + SAL_THROW(( + ::com::sun::star::io::IOException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException + )); + + /// commits a given storage if it's not readonly, ignoring (but asserting) all errors + static bool commitStorageIfWriteable_ignoreErrors( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage + ) + SAL_THROW(()); void clearConnections(); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
