Tag: cws_src680_dba20blocker User: fs Date: 05/07/04 01:21:52 Modified: /dba/dbaccess/source/core/dataaccess/ ModelImpl.cxx
Log: RESYNC: (1.4-1.5); FILE MERGED 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.52.1&r2=1.4.52.2 Delta lines: +55 -35 --------------------- --- ModelImpl.cxx 23 Jun 2005 13:56:40 -0000 1.4.52.1 +++ ModelImpl.cxx 4 Jul 2005 08:21:49 -0000 1.4.52.2 @@ -613,17 +613,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() @@ -740,25 +735,53 @@ m_pStorageAccess->suspendCommitPropagation(); sal_Bool bStore = sal_False; - try - { TStorages::iterator aFind = m_aStorages.find(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("database"))); if ( aFind != m_aStorages.end() ) + bStore = commitStorageIfWriteable_ignoreErrors( aFind->second ); + + if ( _bPreventRootCommits && m_pStorageAccess ) + m_pStorageAccess->resumeCommitPropagation(); + + return bStore; +} +// ----------------------------------------------------------------------------- +bool ODatabaseModelImpl::commitStorageIfWriteable( const Reference< XStorage >& _rxStorage ) SAL_THROW(( IOException, WrappedTargetException, RuntimeException )) +{ + bool bSuccess = false; + Reference<XTransactedObject> xTrans( _rxStorage, UNO_QUERY ); + if ( xTrans.is() ) + { + sal_Int32 nMode = ElementModes::READ; + try { - Reference<XTransactedObject> xTrans(aFind->second,UNO_QUERY); - if ( bStore = xTrans.is() ) + Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW ); + xStorageProps->getPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nMode; + } + catch( const Exception& ) + { + 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!" ); } - - if ( _bPreventRootCommits && m_pStorageAccess ) - m_pStorageAccess->resumeCommitPropagation(); - - return bStore; + return bSuccess; } // ----------------------------------------------------------------------------- void ODatabaseModelImpl::setModified( sal_Bool _bModified ) @@ -832,21 +855,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(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
