LCOV - code coverage report
Current view: top level - dbaccess/source/core/dataaccess - ModelImpl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 426 518 82.2 %
Date: 2014-04-11 Functions: 72 84 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "commandcontainer.hxx"
      21             : #include "connection.hxx"
      22             : #include "core_resource.hrc"
      23             : #include "core_resource.hxx"
      24             : #include "databasecontext.hxx"
      25             : #include "databasedocument.hxx"
      26             : #include "datasource.hxx"
      27             : #include "dbastrings.hrc"
      28             : #include "ModelImpl.hxx"
      29             : #include "userinformation.hxx"
      30             : #include "sdbcoretools.hxx"
      31             : 
      32             : #include <com/sun/star/beans/PropertyBag.hpp>
      33             : #include <com/sun/star/container/XSet.hpp>
      34             : #include <com/sun/star/document/MacroExecMode.hpp>
      35             : #include <com/sun/star/embed/XTransactedObject.hpp>
      36             : #include <com/sun/star/embed/XTransactionBroadcaster.hpp>
      37             : #include <com/sun/star/embed/StorageFactory.hpp>
      38             : #include <com/sun/star/form/XLoadable.hpp>
      39             : #include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
      40             : #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
      41             : #include <com/sun/star/sdb/BooleanComparisonMode.hpp>
      42             : #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
      43             : #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
      44             : #include <com/sun/star/util/NumberFormatsSupplier.hpp>
      45             : 
      46             : #include <comphelper/interaction.hxx>
      47             : #include <comphelper/seqstream.hxx>
      48             : #include <comphelper/sequence.hxx>
      49             : #include <connectivity/dbexception.hxx>
      50             : #include <cppuhelper/exc_hlp.hxx>
      51             : #include <cppuhelper/typeprovider.hxx>
      52             : #include <rtl/digest.h>
      53             : #include <sfx2/signaturestate.hxx>
      54             : #include <tools/debug.hxx>
      55             : #include <tools/diagnose_ex.h>
      56             : #include <osl/diagnose.h>
      57             : #include <tools/errcode.hxx>
      58             : #include <tools/urlobj.hxx>
      59             : #include <unotools/sharedunocomponent.hxx>
      60             : 
      61             : #include <algorithm>
      62             : 
      63             : using namespace ::com::sun::star::document;
      64             : using namespace ::com::sun::star::sdbc;
      65             : using namespace ::com::sun::star::sdbcx;
      66             : using namespace ::com::sun::star::sdb;
      67             : using namespace ::com::sun::star::beans;
      68             : using namespace ::com::sun::star::uno;
      69             : using namespace ::com::sun::star::lang;
      70             : using namespace ::com::sun::star::embed;
      71             : using namespace ::com::sun::star::container;
      72             : using namespace ::com::sun::star::util;
      73             : using namespace ::com::sun::star::io;
      74             : using namespace ::com::sun::star::ucb;
      75             : using namespace ::com::sun::star::frame;
      76             : using namespace ::com::sun::star::view;
      77             : using namespace ::com::sun::star::task;
      78             : using namespace ::com::sun::star::reflection;
      79             : using namespace ::com::sun::star::script;
      80             : using namespace ::cppu;
      81             : using namespace ::osl;
      82             : using namespace ::dbtools;
      83             : using namespace ::comphelper;
      84             : 
      85             : namespace dbaccess
      86             : {
      87             : 
      88             : // VosMutexFacade
      89         102 : VosMutexFacade::VosMutexFacade( ::osl::Mutex& _rMutex )
      90         102 :     :m_rMutex( _rMutex )
      91             : {
      92         102 : }
      93             : 
      94        1159 : void VosMutexFacade::acquire()
      95             : {
      96        1159 :     m_rMutex.acquire();
      97        1159 : }
      98             : 
      99        1159 : void VosMutexFacade::release()
     100             : {
     101        1159 :     m_rMutex.release();
     102        1159 : }
     103             : 
     104           0 : bool VosMutexFacade::tryToAcquire()
     105             : {
     106           0 :     return m_rMutex.tryToAcquire();
     107             : }
     108             : 
     109             : // DocumentStorageAccess
     110             : class DocumentStorageAccess : public ::cppu::WeakImplHelper2<   XDocumentSubStorageSupplier
     111             :                                                             ,   XTransactionListener >
     112             : {
     113             :     typedef ::std::map< OUString, Reference< XStorage > >    NamedStorages;
     114             : 
     115             :     ::osl::Mutex        m_aMutex;
     116             :     /// all sub storages which we ever gave to the outer world
     117             :     NamedStorages       m_aExposedStorages;
     118             :     ODatabaseModelImpl* m_pModelImplementation;
     119             :     bool                m_bPropagateCommitToRoot;
     120             :     bool                m_bDisposingSubStorages;
     121             : 
     122             : public:
     123         122 :     DocumentStorageAccess( ODatabaseModelImpl& _rModelImplementation )
     124             :         :m_pModelImplementation( &_rModelImplementation )
     125             :         ,m_bPropagateCommitToRoot( true )
     126         122 :         ,m_bDisposingSubStorages( false )
     127             :     {
     128         122 :     }
     129             : 
     130             : protected:
     131         240 :     virtual ~DocumentStorageAccess()
     132         120 :     {
     133         240 :     }
     134             : 
     135             : public:
     136             :     void dispose();
     137             : 
     138             :     // XDocumentSubStorageSupplier
     139             :     virtual Reference< XStorage > SAL_CALL getDocumentSubStorage( const OUString& aStorageName, ::sal_Int32 _nMode ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     140             :     virtual Sequence< OUString > SAL_CALL getDocumentSubStoragesNames(  ) throw (IOException, RuntimeException, std::exception) SAL_OVERRIDE;
     141             : 
     142             :     // XTransactionListener
     143             :     virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     144             :     virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     145             :     virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     146             :     virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     147             : 
     148             :     // XEventListener
     149             :     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     150             : 
     151             :     /// disposes all storages managed by this instance
     152             :     void disposeStorages();
     153             : 
     154             :     /// disposes all known sub storages
     155             :     void commitStorages() SAL_THROW(( IOException, RuntimeException ));
     156             : 
     157             :     /// commits the dedicated "database" storage
     158             :     bool commitEmbeddedStorage( bool _bPreventRootCommits );
     159             : 
     160             : private:
     161             :     /** opens the sub storage with the given name, in the given mode
     162             :     */
     163             :     Reference< XStorage > impl_openSubStorage_nothrow( const OUString& _rStorageName, sal_Int32 _nMode );
     164             : 
     165         106 :     void impl_suspendCommitPropagation()
     166             :     {
     167             :         OSL_ENSURE( m_bPropagateCommitToRoot, "DocumentStorageAccess::impl_suspendCommitPropagation: already suspended" );
     168         106 :         m_bPropagateCommitToRoot = false;
     169         106 :     }
     170         106 :     void impl_resumeCommitPropagation()
     171             :     {
     172             :         OSL_ENSURE( !m_bPropagateCommitToRoot, "DocumentStorageAccess::impl_resumeCommitPropagation: not suspended" );
     173         106 :         m_bPropagateCommitToRoot = true;
     174         106 :     }
     175             : 
     176             : };
     177             : 
     178         120 : void DocumentStorageAccess::dispose()
     179             : {
     180         120 :     ::osl::MutexGuard aGuard( m_aMutex );
     181             : 
     182         360 :     for (   NamedStorages::iterator loop = m_aExposedStorages.begin();
     183         240 :             loop != m_aExposedStorages.end();
     184             :             ++loop
     185             :         )
     186             :     {
     187             :         try
     188             :         {
     189           0 :             Reference< XTransactionBroadcaster > xBroadcaster( loop->second, UNO_QUERY );
     190           0 :             if ( xBroadcaster.is() )
     191           0 :                 xBroadcaster->removeTransactionListener( this );
     192             :         }
     193           0 :         catch( const Exception& )
     194             :         {
     195             :             DBG_UNHANDLED_EXCEPTION();
     196             :         }
     197             :     }
     198             : 
     199         120 :     m_aExposedStorages.clear();
     200             : 
     201         120 :     m_pModelImplementation = NULL;
     202         120 : }
     203             : 
     204          34 : Reference< XStorage > DocumentStorageAccess::impl_openSubStorage_nothrow( const OUString& _rStorageName, sal_Int32 _nDesiredMode )
     205             : {
     206             :     OSL_ENSURE( !_rStorageName.isEmpty(),"ODatabaseModelImpl::impl_openSubStorage_nothrow: Invalid storage name!" );
     207             : 
     208          34 :     Reference< XStorage > xStorage;
     209             :     try
     210             :     {
     211          34 :         Reference< XStorage > xRootStorage( m_pModelImplementation->getOrCreateRootStorage() );
     212          34 :         if ( xRootStorage.is() )
     213             :         {
     214          34 :             sal_Int32 nRealMode = m_pModelImplementation->m_bDocumentReadOnly ? ElementModes::READ : _nDesiredMode;
     215          34 :             if ( nRealMode == ElementModes::READ )
     216             :             {
     217           0 :                 if ( xRootStorage.is() && !xRootStorage->hasByName( _rStorageName ) )
     218           0 :                     return xStorage;
     219             :             }
     220             : 
     221          34 :             xStorage = xRootStorage->openStorageElement( _rStorageName, nRealMode );
     222             : 
     223          34 :             Reference< XTransactionBroadcaster > xBroad( xStorage, UNO_QUERY );
     224          34 :             if ( xBroad.is() )
     225          34 :                 xBroad->addTransactionListener( this );
     226          34 :         }
     227             :     }
     228           0 :     catch( const Exception& )
     229             :     {
     230             :         DBG_UNHANDLED_EXCEPTION();
     231             :     }
     232             : 
     233          34 :     return xStorage;
     234             : }
     235             : 
     236         206 : void DocumentStorageAccess::disposeStorages()
     237             : {
     238         206 :     m_bDisposingSubStorages = true;
     239             : 
     240         206 :     NamedStorages::iterator aEnd = m_aExposedStorages.end();
     241         240 :     for (   NamedStorages::iterator aIter = m_aExposedStorages.begin();
     242             :             aIter != aEnd ;
     243             :             ++aIter
     244             :         )
     245             :     {
     246             :         try
     247             :         {
     248          34 :             ::comphelper::disposeComponent( aIter->second );
     249             :         }
     250           0 :         catch( const Exception& )
     251             :         {
     252             :             DBG_UNHANDLED_EXCEPTION();
     253             :         }
     254             :     }
     255         206 :     m_aExposedStorages.clear();
     256             : 
     257         206 :     m_bDisposingSubStorages = false;
     258         206 : }
     259             : 
     260         174 : void DocumentStorageAccess::commitStorages() SAL_THROW(( IOException, RuntimeException ))
     261             : {
     262             :     try
     263             :     {
     264         525 :         for (   NamedStorages::const_iterator aIter = m_aExposedStorages.begin();
     265         350 :                 aIter != m_aExposedStorages.end();
     266             :                 ++aIter
     267             :             )
     268             :         {
     269           1 :             tools::stor::commitStorageIfWriteable( aIter->second );
     270             :         }
     271             :     }
     272           0 :     catch(const WrappedTargetException&)
     273             :     {
     274             :         // WrappedTargetException not allowed to leave
     275           0 :         throw IOException();
     276             :     }
     277         174 : }
     278             : 
     279         280 : bool DocumentStorageAccess::commitEmbeddedStorage( bool _bPreventRootCommits )
     280             : {
     281         280 :     if ( _bPreventRootCommits )
     282         106 :         impl_suspendCommitPropagation();
     283             : 
     284         280 :     bool bSuccess = false;
     285             :     try
     286             :     {
     287         280 :         NamedStorages::const_iterator pos = m_aExposedStorages.find( "database" );
     288         280 :         if ( pos != m_aExposedStorages.end() )
     289           3 :             bSuccess = tools::stor::commitStorageIfWriteable( pos->second );
     290             :     }
     291           0 :     catch( Exception& )
     292             :     {
     293             :         DBG_UNHANDLED_EXCEPTION();
     294             :     }
     295             : 
     296         280 :     if ( _bPreventRootCommits )
     297         106 :         impl_resumeCommitPropagation();
     298             : 
     299         280 :     return bSuccess;
     300             : 
     301             : }
     302             : 
     303          34 : Reference< XStorage > SAL_CALL DocumentStorageAccess::getDocumentSubStorage( const OUString& aStorageName, ::sal_Int32 _nDesiredMode ) throw (RuntimeException, std::exception)
     304             : {
     305          34 :     ::osl::MutexGuard aGuard( m_aMutex );
     306          34 :     NamedStorages::iterator pos = m_aExposedStorages.find( aStorageName );
     307          34 :     if ( pos == m_aExposedStorages.end() )
     308             :     {
     309          34 :         Reference< XStorage > xResult = impl_openSubStorage_nothrow( aStorageName, _nDesiredMode );
     310          34 :         pos = m_aExposedStorages.insert( NamedStorages::value_type( aStorageName, xResult ) ).first;
     311             :     }
     312             : 
     313          34 :     return pos->second;
     314             : }
     315             : 
     316           0 : Sequence< OUString > SAL_CALL DocumentStorageAccess::getDocumentSubStoragesNames(  ) throw (IOException, RuntimeException, std::exception)
     317             : {
     318           0 :     Reference< XStorage > xRootStor( m_pModelImplementation->getRootStorage() );
     319           0 :     if ( !xRootStor.is() )
     320           0 :         return Sequence< OUString >();
     321             : 
     322           0 :     ::std::vector< OUString > aNames;
     323             : 
     324           0 :     Sequence< OUString > aElementNames( xRootStor->getElementNames() );
     325           0 :     for ( sal_Int32 i=0; i<aElementNames.getLength(); ++i )
     326             :     {
     327           0 :         if ( xRootStor->isStorageElement( aElementNames[i] ) )
     328           0 :             aNames.push_back( aElementNames[i] );
     329             :     }
     330           0 :     return aNames.empty()
     331             :         ?  Sequence< OUString >()
     332           0 :         :  Sequence< OUString >( &aNames[0], aNames.size() );
     333             : }
     334             : 
     335           4 : void SAL_CALL DocumentStorageAccess::preCommit( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException, std::exception)
     336             : {
     337             :     // not interested in
     338           4 : }
     339             : 
     340           4 : void SAL_CALL DocumentStorageAccess::commited( const css::lang::EventObject& aEvent ) throw (RuntimeException, std::exception)
     341             : {
     342           4 :     ::osl::MutexGuard aGuard( m_aMutex );
     343             : 
     344           4 :     if ( m_pModelImplementation )
     345           4 :         m_pModelImplementation->setModified( sal_True );
     346             : 
     347           4 :     if ( m_pModelImplementation && m_bPropagateCommitToRoot )
     348             :     {
     349           1 :         Reference< XStorage > xStorage( aEvent.Source, UNO_QUERY );
     350             : 
     351             :         // check if this is the dedicated "database" sub storage
     352           1 :         NamedStorages::const_iterator pos = m_aExposedStorages.find( "database" );
     353           3 :         if  (   ( pos != m_aExposedStorages.end() )
     354           3 :             &&  ( pos->second == xStorage )
     355             :             )
     356             :         {
     357             :             // if so, also commit the root storage
     358           0 :             m_pModelImplementation->commitRootStorage();
     359           1 :         }
     360           4 :     }
     361           4 : }
     362             : 
     363           0 : void SAL_CALL DocumentStorageAccess::preRevert( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException, std::exception)
     364             : {
     365             :     // not interested in
     366           0 : }
     367             : 
     368           0 : void SAL_CALL DocumentStorageAccess::reverted( const css::lang::EventObject& /*aEvent*/ ) throw (RuntimeException, std::exception)
     369             : {
     370             :     // not interested in
     371           0 : }
     372             : 
     373          34 : void SAL_CALL DocumentStorageAccess::disposing( const css::lang::EventObject& Source ) throw ( RuntimeException, std::exception )
     374             : {
     375             :     OSL_ENSURE( Reference< XStorage >( Source.Source, UNO_QUERY ).is(), "DocumentStorageAccess::disposing: No storage? What's this?" );
     376             : 
     377          34 :     if ( m_bDisposingSubStorages )
     378          68 :         return;
     379             : 
     380           0 :     for (   NamedStorages::iterator find = m_aExposedStorages.begin();
     381           0 :             find != m_aExposedStorages.end();
     382             :             ++find
     383             :         )
     384           0 :         if ( find->second == Source.Source )
     385             :         {
     386           0 :             m_aExposedStorages.erase( find );
     387           0 :             break;
     388             :         }
     389             : }
     390             : 
     391             : // ODatabaseModelImpl
     392             : 
     393          93 : ODatabaseModelImpl::ODatabaseModelImpl( const Reference< XComponentContext >& _rxContext, ODatabaseContext& _rDBContext )
     394             :             :m_xModel()
     395             :             ,m_xDataSource()
     396             :             ,m_pStorageAccess( NULL )
     397             :             ,m_aMutex()
     398             :             ,m_aMutexFacade( m_aMutex )
     399             :             ,m_aContainer(4)
     400             :             ,m_aMacroMode( *this )
     401             :             ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
     402             :             ,m_pDBContext( &_rDBContext )
     403             :             ,m_refCount(0)
     404             :             ,m_aEmbeddedMacros()
     405             :             ,m_bModificationLock( false )
     406             :             ,m_bDocumentInitialized( false )
     407             :             ,m_aContext( _rxContext )
     408             :             ,m_nLoginTimeout(0)
     409             :             ,m_bReadOnly(sal_False)
     410             :             ,m_bPasswordRequired(sal_False)
     411             :             ,m_bSuppressVersionColumns(sal_True)
     412             :             ,m_bModified(sal_False)
     413             :             ,m_bDocumentReadOnly(sal_False)
     414             :             ,m_pSharedConnectionManager(NULL)
     415          93 :             ,m_nControllerLockCount(0)
     416             : {
     417             :     // some kind of default
     418          93 :     m_sConnectURL = "jdbc:";
     419          93 :     m_aTableFilter.realloc(1);
     420          93 :     m_aTableFilter[0] = "%";
     421          93 :     impl_construct_nothrow();
     422          93 : }
     423             : 
     424           9 : ODatabaseModelImpl::ODatabaseModelImpl(
     425             :                     const OUString& _rRegistrationName,
     426             :                     const Reference< XComponentContext >& _rxContext,
     427             :                     ODatabaseContext& _rDBContext
     428             :                     )
     429             :             :m_xModel()
     430             :             ,m_xDataSource()
     431             :             ,m_pStorageAccess( NULL )
     432             :             ,m_aMutex()
     433             :             ,m_aMutexFacade( m_aMutex )
     434             :             ,m_aContainer(4)
     435             :             ,m_aMacroMode( *this )
     436             :             ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
     437             :             ,m_pDBContext( &_rDBContext )
     438             :             ,m_refCount(0)
     439             :             ,m_aEmbeddedMacros()
     440             :             ,m_bModificationLock( false )
     441             :             ,m_bDocumentInitialized( false )
     442             :             ,m_aContext( _rxContext )
     443             :             ,m_sName(_rRegistrationName)
     444             :             ,m_nLoginTimeout(0)
     445             :             ,m_bReadOnly(sal_False)
     446             :             ,m_bPasswordRequired(sal_False)
     447             :             ,m_bSuppressVersionColumns(sal_True)
     448             :             ,m_bModified(sal_False)
     449             :             ,m_bDocumentReadOnly(sal_False)
     450             :             ,m_pSharedConnectionManager(NULL)
     451           9 :             ,m_nControllerLockCount(0)
     452             : {
     453           9 :     impl_construct_nothrow();
     454           9 : }
     455             : 
     456         200 : ODatabaseModelImpl::~ODatabaseModelImpl()
     457             : {
     458         200 : }
     459             : 
     460         102 : void ODatabaseModelImpl::impl_construct_nothrow()
     461             : {
     462             :     // create the property bag to hold the settings (also known as "Info" property)
     463             :     try
     464             :     {
     465             :         // the set of property value types in the bag is limited:
     466         102 :         Sequence< Type > aAllowedTypes(6);
     467         102 :         Type* pAllowedType = aAllowedTypes.getArray();
     468         102 :         *pAllowedType++ = ::getCppuType( static_cast< sal_Bool* >( NULL ) );
     469         102 :         *pAllowedType++ = ::getCppuType( static_cast< double* >( NULL ) );
     470         102 :         *pAllowedType++ = ::getCppuType( static_cast< OUString* >( NULL ) );
     471         102 :         *pAllowedType++ = ::getCppuType( static_cast< sal_Int32* >( NULL ) );
     472         102 :         *pAllowedType++ = ::getCppuType( static_cast< sal_Int16* >( NULL ) );
     473         102 :         *pAllowedType++ = ::getCppuType( static_cast< Sequence< Any >* >( NULL ) );
     474             : 
     475         102 :         m_xSettings = PropertyBag::createWithTypes( m_aContext, aAllowedTypes, sal_False/*AllowEmptyPropertyName*/, sal_True/*AutomaticAddition*/ );
     476             : 
     477             :         // insert the default settings
     478         204 :         Reference< XPropertyContainer > xContainer( m_xSettings, UNO_QUERY_THROW );
     479         204 :         Reference< XSet > xSettingsSet( m_xSettings, UNO_QUERY_THROW );
     480         102 :         const AsciiPropertyValue* pSettings = getDefaultDataSourceSettings();
     481        5508 :         for ( ; pSettings->AsciiName; ++pSettings )
     482             :         {
     483        5406 :             if ( !pSettings->DefaultValue.hasValue() )
     484             :             {
     485             :                 Property aProperty(
     486             :                     OUString::createFromAscii( pSettings->AsciiName ),
     487             :                     -1,
     488             :                     pSettings->ValueType,
     489             :                     PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT | PropertyAttribute::MAYBEVOID
     490         306 :                 );
     491         306 :                 xSettingsSet->insert( makeAny( aProperty ) );
     492             :             }
     493             :             else
     494             :             {
     495        5100 :                 xContainer->addProperty(
     496             :                     OUString::createFromAscii( pSettings->AsciiName ),
     497             :                     PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
     498             :                     pSettings->DefaultValue
     499        5100 :                 );
     500             :             }
     501         102 :         }
     502             :     }
     503           0 :     catch( const Exception& )
     504             :     {
     505             :         DBG_UNHANDLED_EXCEPTION();
     506             :     }
     507         102 :     m_pDBContext->appendAtTerminateListener(*this);
     508         102 : }
     509             : 
     510             : namespace
     511             : {
     512         421 :     OUString lcl_getContainerStorageName_throw( ODatabaseModelImpl::ObjectType _eType )
     513             :     {
     514         421 :         const sal_Char* pAsciiName( NULL );
     515         421 :         switch ( _eType )
     516             :         {
     517         113 :         case ODatabaseModelImpl::E_FORM:   pAsciiName = "forms"; break;
     518         113 :         case ODatabaseModelImpl::E_REPORT: pAsciiName = "reports"; break;
     519          97 :         case ODatabaseModelImpl::E_QUERY:  pAsciiName = "queries"; break;
     520          98 :         case ODatabaseModelImpl::E_TABLE:  pAsciiName = "tables"; break;
     521             :         default:
     522           0 :             throw RuntimeException();
     523             :         }
     524         421 :         return OUString::createFromAscii( pAsciiName );
     525             :     }
     526             : 
     527          26 :     bool lcl_hasObjectWithMacros_throw( const ODefinitionContainer_Impl& _rObjectDefinitions, const Reference< XStorage >& _rxContainerStorage )
     528             :     {
     529          26 :         bool bSomeDocHasMacros = false;
     530             : 
     531          78 :         for (   ODefinitionContainer_Impl::const_iterator object = _rObjectDefinitions.begin();
     532          78 :                 ( object != _rObjectDefinitions.end() ) && !bSomeDocHasMacros;
     533             :                 ++object
     534             :             )
     535             :         {
     536             : #if OSL_DEBUG_LEVEL > 0
     537             :             const OUString& rName( object->first ); (void)rName;
     538             : #endif
     539             : 
     540           0 :             const TContentPtr& rDefinition( object->second );
     541           0 :             const OUString& rPersistentName( rDefinition->m_aProps.sPersistentName );
     542             : 
     543           0 :             if ( rPersistentName.isEmpty() )
     544             :             {   // it's a logical sub folder used to organize the real objects
     545           0 :                 const ODefinitionContainer_Impl& rSubFoldersObjectDefinitions( dynamic_cast< const ODefinitionContainer_Impl& >( *rDefinition.get() ) );
     546           0 :                 bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rSubFoldersObjectDefinitions, _rxContainerStorage );
     547           0 :                 continue;
     548             :             }
     549             : 
     550           0 :             bSomeDocHasMacros = ODatabaseModelImpl::objectHasMacros( _rxContainerStorage, rPersistentName );
     551             :         }
     552          26 :         return bSomeDocHasMacros;
     553             :     }
     554             : 
     555          26 :     bool lcl_hasObjectsWithMacros_nothrow( ODatabaseModelImpl& _rModel, const ODatabaseModelImpl::ObjectType _eType )
     556             :     {
     557          26 :         bool bSomeDocHasMacros = false;
     558             : 
     559          26 :         const OContentHelper_Impl& rContainerData( *_rModel.getObjectContainer( _eType ).get() );
     560          26 :         const ODefinitionContainer_Impl& rObjectDefinitions = dynamic_cast< const ODefinitionContainer_Impl& >( rContainerData );
     561             : 
     562             :         try
     563             :         {
     564          26 :             Reference< XStorage > xContainerStorage( _rModel.getStorage( _eType, ElementModes::READWRITE ) );
     565             :             // note the READWRITE here: If the storage already existed before, then the OpenMode will
     566             :             // be ignored, anyway.
     567             :             // If the storage did not yet exist, then it will be created. If the database document
     568             :             // is read-only, the OpenMode will be automatically downgraded to READ. Otherwise,
     569             :             // the storage will in fact be created as READWRITE. While this is not strictly necessary
     570             :             // for this particular use case here, it is required since the storage is *cached*, and
     571             :             // later use cases will need the READWRITE mode.
     572             : 
     573          26 :             if ( xContainerStorage.is() )
     574          26 :                 bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rObjectDefinitions, xContainerStorage );
     575             :         }
     576           0 :         catch( const Exception& )
     577             :         {
     578             :             DBG_UNHANDLED_EXCEPTION();
     579             :             // be on the safe side: If we can't reliably determine whether there are macros,
     580             :             // assume there actually are. Better this way, than the other way round.
     581           0 :             bSomeDocHasMacros = true;
     582             :         }
     583             : 
     584          26 :         return bSomeDocHasMacros;
     585             :     }
     586             : }
     587             : 
     588           0 : bool ODatabaseModelImpl::objectHasMacros( const Reference< XStorage >& _rxContainerStorage, const OUString& _rPersistentName )
     589             : {
     590             :     OSL_PRECOND( _rxContainerStorage.is(), "ODatabaseModelImpl::objectHasMacros: this will crash!" );
     591             : 
     592           0 :     bool bHasMacros = true;
     593             :     try
     594             :     {
     595           0 :         if ( !_rxContainerStorage->hasByName( _rPersistentName ) )
     596           0 :             return false;
     597             : 
     598           0 :         Reference< XStorage > xObjectStor( _rxContainerStorage->openStorageElement(
     599           0 :             _rPersistentName, ElementModes::READ ) );
     600             : 
     601           0 :         bHasMacros = ::sfx2::DocumentMacroMode::storageHasMacros( xObjectStor );
     602             :     }
     603           0 :     catch( const Exception& )
     604             :     {
     605             :         DBG_UNHANDLED_EXCEPTION();
     606             :     }
     607           0 :     return bHasMacros;
     608             : }
     609             : 
     610          14 : void ODatabaseModelImpl::reset()
     611             : {
     612          14 :     m_bReadOnly = sal_False;
     613          14 :     ::std::vector< TContentPtr > aEmptyContainers( 4 );
     614          14 :     m_aContainer.swap( aEmptyContainers );
     615             : 
     616          14 :     if ( m_pStorageAccess )
     617             :     {
     618          14 :         m_pStorageAccess->dispose();
     619          14 :         m_pStorageAccess->release();
     620          14 :         m_pStorageAccess = NULL;
     621          14 :     }
     622          14 : }
     623             : 
     624          25 : void SAL_CALL ODatabaseModelImpl::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException)
     625             : {
     626          25 :     Reference<XConnection> xCon(Source.Source,UNO_QUERY);
     627          25 :     if ( xCon.is() )
     628             :     {
     629          25 :         bool bStore = false;
     630          25 :         OWeakConnectionArray::iterator aEnd = m_aConnections.end();
     631          25 :         for (OWeakConnectionArray::iterator i = m_aConnections.begin(); aEnd != i; ++i)
     632             :         {
     633          25 :             if ( xCon == i->get() )
     634             :             {
     635          25 :                 *i = OWeakConnection();
     636          25 :                 bStore = true;
     637          25 :                 break;
     638             :             }
     639             :         }
     640             : 
     641          25 :         if ( bStore )
     642          25 :             commitRootStorage();
     643             :     }
     644             :     else
     645             :     {
     646             :         OSL_FAIL( "ODatabaseModelImpl::disposing: where does this come from?" );
     647          25 :     }
     648          25 : }
     649             : 
     650         120 : void ODatabaseModelImpl::clearConnections()
     651             : {
     652         120 :     OWeakConnectionArray aConnections;
     653         120 :     aConnections.swap( m_aConnections );
     654             : 
     655         240 :     Reference< XConnection > xConn;
     656         120 :     OWeakConnectionArray::iterator aEnd = aConnections.end();
     657         152 :     for ( OWeakConnectionArray::iterator i = aConnections.begin(); aEnd != i; ++i )
     658             :     {
     659          32 :         xConn = *i;
     660          32 :         if ( xConn.is() )
     661             :         {
     662             :             try
     663             :             {
     664           9 :                 xConn->close();
     665             :             }
     666           0 :             catch(const Exception&)
     667             :             {
     668             :                 DBG_UNHANDLED_EXCEPTION();
     669             :             }
     670             :         }
     671             :     }
     672             : 
     673         120 :     m_pSharedConnectionManager = NULL;
     674         240 :     m_xSharedConnectionManager = NULL;
     675         120 : }
     676             : 
     677         106 : void ODatabaseModelImpl::dispose()
     678             : {
     679             :     // dispose the data source and the model
     680             :     try
     681             :     {
     682         106 :         Reference< XDataSource > xDS( m_xDataSource );
     683         106 :         ::comphelper::disposeComponent( xDS );
     684             : 
     685         212 :         Reference< XModel > xModel( m_xModel );
     686         212 :         ::comphelper::disposeComponent( xModel );
     687             :     }
     688           0 :     catch( const Exception& )
     689             :     {
     690             :         DBG_UNHANDLED_EXCEPTION();
     691             :     }
     692         106 :     m_xDataSource = WeakReference<XDataSource>();
     693         106 :     m_xModel = WeakReference< XModel >();
     694             : 
     695         106 :     ::std::vector<TContentPtr>::iterator aIter = m_aContainer.begin();
     696         106 :     ::std::vector<TContentPtr>::iterator aEnd = m_aContainer.end();
     697         506 :     for (;aIter != aEnd ; ++aIter)
     698             :     {
     699         400 :         if ( aIter->get() )
     700         387 :             (*aIter)->m_pDataSource = NULL;
     701             :     }
     702         106 :     m_aContainer.clear();
     703             : 
     704         106 :     clearConnections();
     705             : 
     706         106 :     m_xNumberFormatsSupplier = NULL;
     707             : 
     708             :     try
     709             :     {
     710         106 :         sal_Bool bCouldStore = commitEmbeddedStorage( true );
     711             :             // "true" means that committing the embedded storage should not trigger committing the root
     712             :             // storage. This is because we are going to commit the root storage ourself, anyway
     713         106 :         disposeStorages();
     714         106 :         if ( bCouldStore )
     715           3 :             commitRootStorage();
     716             : 
     717         106 :         impl_switchToStorage_throw( NULL );
     718             :     }
     719           0 :     catch( const Exception& )
     720             :     {
     721             :         DBG_UNHANDLED_EXCEPTION();
     722             :     }
     723             : 
     724         106 :     if ( m_pStorageAccess )
     725             :     {
     726         106 :         m_pStorageAccess->dispose();
     727         106 :         m_pStorageAccess->release();
     728         106 :         m_pStorageAccess = NULL;
     729             :     }
     730         106 : }
     731             : 
     732         285 : const Reference< XNumberFormatsSupplier > & ODatabaseModelImpl::getNumberFormatsSupplier()
     733             : {
     734         285 :     if (!m_xNumberFormatsSupplier.is())
     735             :     {
     736             :         // the arguments : the locale of the current user
     737         100 :         UserInformation aUserInfo;
     738         200 :         Locale aLocale = aUserInfo.getUserLanguage();
     739             : 
     740         200 :         m_xNumberFormatsSupplier.set( NumberFormatsSupplier::createWithLocale( m_aContext, aLocale ) );
     741             :     }
     742         285 :     return m_xNumberFormatsSupplier;
     743             : }
     744             : 
     745          88 : void ODatabaseModelImpl::setDocFileLocation( const OUString& i_rLoadedFrom )
     746             : {
     747          88 :     ENSURE_OR_THROW( !i_rLoadedFrom.isEmpty(), "invalid URL" );
     748          88 :     m_sDocFileLocation = i_rLoadedFrom;
     749          88 : }
     750             : 
     751         102 : void ODatabaseModelImpl::setResource( const OUString& i_rDocumentURL, const Sequence< PropertyValue >& _rArgs )
     752             : {
     753         102 :     ENSURE_OR_THROW( !i_rDocumentURL.isEmpty(), "invalid URL" );
     754             : 
     755         102 :     ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs );
     756             : #if OSL_DEBUG_LEVEL > 0
     757             :     if ( aMediaDescriptor.has( "SalvagedFile" ) )
     758             :     {
     759             :         OUString sSalvagedFile( aMediaDescriptor.getOrDefault( "SalvagedFile", OUString() ) );
     760             :         // If SalvagedFile is an empty string, this indicates "the document is being recovered, but i_rDocumentURL already
     761             :         // is the real document URL, not the temporary document location"
     762             :         if ( sSalvagedFile.isEmpty() )
     763             :             sSalvagedFile = i_rDocumentURL;
     764             : 
     765             :         OSL_ENSURE( sSalvagedFile == i_rDocumentURL, "ODatabaseModelImpl::setResource: inconsistency!" );
     766             :             // nowadays, setResource should only be called with the logical URL of the document
     767             :     }
     768             : #endif
     769             : 
     770         102 :     m_aMediaDescriptor = stripLoadArguments( aMediaDescriptor );
     771             : 
     772         102 :     impl_switchToLogicalURL( i_rDocumentURL );
     773         102 : }
     774             : 
     775         116 : ::comphelper::NamedValueCollection ODatabaseModelImpl::stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments )
     776             : {
     777             :     OSL_ENSURE( !_rArguments.has( "Model" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (1)!" );
     778             :     OSL_ENSURE( !_rArguments.has( "ViewName" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (2)!" );
     779             : 
     780         116 :     ::comphelper::NamedValueCollection aMutableArgs( _rArguments );
     781         116 :     aMutableArgs.remove( "Model" );
     782         116 :     aMutableArgs.remove( "ViewName" );
     783         116 :     return aMutableArgs;
     784             : }
     785             : 
     786         206 : void ODatabaseModelImpl::disposeStorages() SAL_THROW(())
     787             : {
     788         206 :     getDocumentStorageAccess()->disposeStorages();
     789         206 : }
     790             : 
     791          86 : Reference< XSingleServiceFactory > ODatabaseModelImpl::createStorageFactory() const
     792             : {
     793          86 :     return StorageFactory::create( m_aContext );
     794             : }
     795             : 
     796          28 : void ODatabaseModelImpl::commitRootStorage()
     797             : {
     798          28 :     Reference< XStorage > xStorage( getOrCreateRootStorage() );
     799             : #if OSL_DEBUG_LEVEL > 0
     800             :     bool bSuccess =
     801             : #endif
     802          28 :     commitStorageIfWriteable_ignoreErrors( xStorage );
     803             :     OSL_ENSURE( bSuccess || !xStorage.is(),
     804          28 :         "ODatabaseModelImpl::commitRootStorage: could commit the storage!" );
     805          28 : }
     806             : 
     807         176 : Reference< XStorage > ODatabaseModelImpl::getOrCreateRootStorage()
     808             : {
     809         176 :     if ( !m_xDocumentStorage.is() )
     810             :     {
     811          14 :         Reference< XSingleServiceFactory> xStorageFactory = StorageFactory::create( m_aContext );
     812          28 :         Any aSource;
     813          14 :         aSource = m_aMediaDescriptor.get( "Stream" );
     814          14 :         if ( !aSource.hasValue() )
     815          14 :             aSource = m_aMediaDescriptor.get( "InputStream" );
     816          14 :         if ( !aSource.hasValue() && !m_sDocFileLocation.isEmpty() )
     817          14 :             aSource <<= m_sDocFileLocation;
     818             :         // TODO: shouldn't we also check URL?
     819             : 
     820             :         OSL_ENSURE( aSource.hasValue(), "ODatabaseModelImpl::getOrCreateRootStorage: no source to create the storage from!" );
     821             : 
     822          14 :         if ( aSource.hasValue() )
     823             :         {
     824          14 :             Sequence< Any > aStorageCreationArgs(2);
     825          14 :             aStorageCreationArgs[0] = aSource;
     826          14 :             aStorageCreationArgs[1] <<= ElementModes::READWRITE;
     827             : 
     828          28 :             Reference< XStorage > xDocumentStorage;
     829             :             try
     830             :             {
     831          14 :                 xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
     832             :             }
     833           0 :             catch( const Exception& )
     834             :             {
     835           0 :                 m_bDocumentReadOnly = sal_True;
     836           0 :                 aStorageCreationArgs[1] <<= ElementModes::READ;
     837             :                 try
     838             :                 {
     839           0 :                     xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
     840             :                 }
     841           0 :                 catch( const Exception& )
     842             :                 {
     843             :                     DBG_UNHANDLED_EXCEPTION();
     844             :                 }
     845             :             }
     846             : 
     847          28 :             impl_switchToStorage_throw( xDocumentStorage );
     848          14 :         }
     849             :     }
     850         176 :     return m_xDocumentStorage.getTyped();
     851             : }
     852             : 
     853         694 : DocumentStorageAccess* ODatabaseModelImpl::getDocumentStorageAccess()
     854             : {
     855         694 :     if ( !m_pStorageAccess )
     856             :     {
     857         122 :         m_pStorageAccess = new DocumentStorageAccess( *this );
     858         122 :         m_pStorageAccess->acquire();
     859             :     }
     860         694 :     return m_pStorageAccess;
     861             : }
     862             : 
     863         100 : void ODatabaseModelImpl::modelIsDisposing( const bool _wasInitialized, ResetModelAccess )
     864             : {
     865         100 :     m_xModel.clear();
     866             : 
     867             :     // Basic libraries and Dialog libraries are a model facet, though held at this impl class.
     868             :     // They automatically dispose themself when the model they belong to is being disposed.
     869             :     // So, to not be tempted to do anything with them, again, we reset them.
     870         100 :     m_xBasicLibraries.clear();
     871         100 :     m_xDialogLibraries.clear();
     872             : 
     873         100 :     m_bDocumentInitialized = _wasInitialized;
     874         100 : }
     875             : 
     876           8 : Reference< XDocumentSubStorageSupplier > ODatabaseModelImpl::getDocumentSubStorageSupplier()
     877             : {
     878           8 :     return getDocumentStorageAccess();
     879             : }
     880             : 
     881         280 : bool ODatabaseModelImpl::commitEmbeddedStorage( bool _bPreventRootCommits )
     882             : {
     883         280 :     return getDocumentStorageAccess()->commitEmbeddedStorage( _bPreventRootCommits );
     884             : }
     885             : 
     886          28 : bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage ) SAL_THROW(())
     887             : {
     888          28 :     bool bSuccess = false;
     889             :     try
     890             :     {
     891          28 :         bSuccess = tools::stor::commitStorageIfWriteable( _rxStorage );
     892             :     }
     893           3 :     catch( const Exception& )
     894             :     {
     895             :         DBG_UNHANDLED_EXCEPTION();
     896             :     }
     897          28 :     return bSuccess;
     898             : }
     899             : 
     900        1188 : void ODatabaseModelImpl::setModified( sal_Bool _bModified )
     901             : {
     902        1188 :     if ( isModifyLocked() )
     903        2247 :         return;
     904             : 
     905             :     try
     906             :     {
     907         129 :         Reference< XModifiable > xModi( m_xModel.get(), UNO_QUERY );
     908         129 :         if ( xModi.is() )
     909          38 :             xModi->setModified( _bModified );
     910             :         else
     911          91 :             m_bModified = _bModified;
     912             :     }
     913           0 :     catch( const Exception& )
     914             :     {
     915             :         DBG_UNHANDLED_EXCEPTION();
     916             :     }
     917             : }
     918             : 
     919         709 : Reference<XDataSource> ODatabaseModelImpl::getOrCreateDataSource()
     920             : {
     921         709 :     Reference<XDataSource> xDs = m_xDataSource;
     922         709 :     if ( !xDs.is() )
     923             :     {
     924         229 :         xDs = new ODatabaseSource(this);
     925         229 :         m_xDataSource = xDs;
     926             :     }
     927         709 :     return xDs;
     928             : }
     929             : 
     930        1615 : Reference< XModel> ODatabaseModelImpl::getModel_noCreate() const
     931             : {
     932        1615 :     return m_xModel;
     933             : }
     934             : 
     935         100 : Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _bInitialize )
     936             : {
     937         100 :     Reference< XModel > xModel( m_xModel );
     938             :     OSL_PRECOND( !xModel.is(), "ODatabaseModelImpl::createNewModel_deliverOwnership: not to be called if there already is a model!" );
     939         100 :     if ( !xModel.is() )
     940             :     {
     941         100 :         bool bHadModelBefore = m_bDocumentInitialized;
     942             : 
     943         100 :         xModel = ODatabaseDocument::createDatabaseDocument( this, ODatabaseDocument::FactoryAccess() );
     944         100 :         m_xModel = xModel;
     945             : 
     946             :         try
     947             :         {
     948         100 :             Reference< XGlobalEventBroadcaster > xModelCollection = theGlobalEventBroadcaster::get( m_aContext );
     949         100 :             xModelCollection->insert( makeAny( xModel ) );
     950             :         }
     951           0 :         catch( const Exception& )
     952             :         {
     953             :             DBG_UNHANDLED_EXCEPTION();
     954             :         }
     955             : 
     956         100 :         if ( bHadModelBefore )
     957             :         {
     958             :             // do an attachResources
     959             :             // In case the document is loaded regularly, this is not necessary, as our loader will do it.
     960             :             // However, in case that the document is implicitly created by asking the data source for the document,
     961             :             // then nobody would call the doc's attachResource. So, we do it here, to ensure it's in a proper
     962             :             // state, fires all events, and so on.
     963             :             // #i105505#
     964           0 :             xModel->attachResource( xModel->getURL(), m_aMediaDescriptor.getPropertyValues() );
     965             :         }
     966             : 
     967         100 :         if ( _bInitialize )
     968             :         {
     969             :             try
     970             :             {
     971           0 :                 Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
     972           0 :                 xLoad->initNew();
     973             :             }
     974           0 :             catch( RuntimeException& ) { throw; }
     975           0 :             catch( const Exception& )
     976             :             {
     977             :                 DBG_UNHANDLED_EXCEPTION();
     978             :             }
     979             :         }
     980             :     }
     981         100 :     return xModel;
     982             : }
     983             : 
     984         866 : oslInterlockedCount SAL_CALL ODatabaseModelImpl::acquire()
     985             : {
     986         866 :     return osl_atomic_increment(&m_refCount);
     987             : }
     988             : 
     989         764 : oslInterlockedCount SAL_CALL ODatabaseModelImpl::release()
     990             : {
     991         764 :     if ( osl_atomic_decrement(&m_refCount) == 0 )
     992             :     {
     993         100 :         acquire();  // prevent multiple releases
     994         100 :         m_pDBContext->removeFromTerminateListener(*this);
     995         100 :         dispose();
     996         100 :         m_pDBContext->storeTransientProperties(*this);
     997         100 :         revokeDataSource();
     998         100 :         delete this;
     999         100 :         return 0;
    1000             :     }
    1001         664 :     return m_refCount;
    1002             : }
    1003             : 
    1004         174 : void ODatabaseModelImpl::commitStorages() SAL_THROW(( IOException, RuntimeException ))
    1005             : {
    1006         174 :     getDocumentStorageAccess()->commitStorages();
    1007         174 : }
    1008             : 
    1009          26 : Reference< XStorage > ODatabaseModelImpl::getStorage( const ObjectType _eType, const sal_Int32 _nDesiredMode )
    1010             : {
    1011          26 :     return getDocumentStorageAccess()->getDocumentSubStorage( getObjectContainerStorageName( _eType ), _nDesiredMode );
    1012             : }
    1013             : 
    1014         134 : const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings()
    1015             : {
    1016             :     static const AsciiPropertyValue aKnownSettings[] =
    1017             :     {
    1018             :         // known JDBC settings
    1019             :         AsciiPropertyValue( "JavaDriverClass",            makeAny( OUString() ) ),
    1020             :         AsciiPropertyValue( "JavaDriverClassPath",       makeAny( OUString() ) ),
    1021             :         AsciiPropertyValue( "IgnoreCurrency",             makeAny( (sal_Bool)sal_False ) ),
    1022             :         // known settings for file-based drivers
    1023             :         AsciiPropertyValue( "Extension",                  makeAny( OUString() ) ),
    1024             :         AsciiPropertyValue( "CharSet",                    makeAny( OUString() ) ),
    1025             :         AsciiPropertyValue( "HeaderLine",                 makeAny( (sal_Bool)sal_True ) ),
    1026             :         AsciiPropertyValue( "FieldDelimiter",             makeAny( OUString( "," ) ) ),
    1027             :         AsciiPropertyValue( "StringDelimiter",            makeAny( OUString( "\"" ) ) ),
    1028             :         AsciiPropertyValue( "DecimalDelimiter",           makeAny( OUString( "." ) ) ),
    1029             :         AsciiPropertyValue( "ThousandDelimiter",          makeAny( OUString() ) ),
    1030             :         AsciiPropertyValue( "ShowDeleted",                makeAny( (sal_Bool)sal_False ) ),
    1031             :         // known ODBC settings
    1032             :         AsciiPropertyValue( "SystemDriverSettings",       makeAny( OUString() ) ),
    1033             :         AsciiPropertyValue( "UseCatalog",                 makeAny( (sal_Bool)sal_False ) ),
    1034             :         AsciiPropertyValue( "TypeInfoSettings",           makeAny( Sequence< Any >()) ),
    1035             :         // settings related to auto increment handling
    1036             :         AsciiPropertyValue( "AutoIncrementCreation",      makeAny( OUString() ) ),
    1037             :         AsciiPropertyValue( "AutoRetrievingStatement",    makeAny( OUString() ) ),
    1038             :         AsciiPropertyValue( "IsAutoRetrievingEnabled",    makeAny( (sal_Bool)sal_False ) ),
    1039             :         // known LDAP driver settings
    1040             :         AsciiPropertyValue( "HostName",                   makeAny( OUString() ) ),
    1041             :         AsciiPropertyValue( "PortNumber",                 makeAny( (sal_Int32)389 ) ),
    1042             :         AsciiPropertyValue( "BaseDN",                     makeAny( OUString() ) ),
    1043             :         AsciiPropertyValue( "MaxRowCount",                makeAny( (sal_Int32)100 ) ),
    1044             :         // known MySQLNative driver settings
    1045             :         AsciiPropertyValue( "LocalSocket",                makeAny( OUString() ) ),
    1046             :         AsciiPropertyValue( "NamedPipe",                  makeAny( OUString() ) ),
    1047             :         // misc known driver settings
    1048             :         AsciiPropertyValue( "ParameterNameSubstitution",  makeAny( (sal_Bool)sal_False ) ),
    1049             :         AsciiPropertyValue( "AddIndexAppendix",           makeAny( (sal_Bool)sal_True ) ),
    1050             :         AsciiPropertyValue( "IgnoreDriverPrivileges",     makeAny( (sal_Bool)sal_True ) ),
    1051           9 :         AsciiPropertyValue( "ImplicitCatalogRestriction", ::cppu::UnoType< OUString >::get() ),
    1052           9 :         AsciiPropertyValue( "ImplicitSchemaRestriction",  ::cppu::UnoType< OUString >::get() ),
    1053           9 :         AsciiPropertyValue( "PrimaryKeySupport",          ::cppu::UnoType< sal_Bool >::get() ),
    1054             :         AsciiPropertyValue( "ShowColumnDescription",      makeAny( (sal_Bool)sal_False ) ),
    1055             :         // known SDB level settings
    1056             :         AsciiPropertyValue( "NoNameLengthLimit",          makeAny( (sal_Bool)sal_False ) ),
    1057             :         AsciiPropertyValue( "AppendTableAliasName",       makeAny( (sal_Bool)sal_False ) ),
    1058             :         AsciiPropertyValue( "GenerateASBeforeCorrelationName",  makeAny( (sal_Bool)sal_True ) ),
    1059             :         AsciiPropertyValue( "ColumnAliasInOrderBy",       makeAny( (sal_Bool)sal_True ) ),
    1060             :         AsciiPropertyValue( "EnableSQL92Check",           makeAny( (sal_Bool)sal_False ) ),
    1061             :         AsciiPropertyValue( "BooleanComparisonMode",      makeAny( BooleanComparisonMode::EQUAL_INTEGER ) ),
    1062             :         AsciiPropertyValue( "TableTypeFilterMode",        makeAny( (sal_Int32)3 ) ),
    1063             :         AsciiPropertyValue( "RespectDriverResultSetType", makeAny( (sal_Bool)sal_False ) ),
    1064             :         AsciiPropertyValue( "UseSchemaInSelect",          makeAny( (sal_Bool)sal_True ) ),
    1065             :         AsciiPropertyValue( "UseCatalogInSelect",         makeAny( (sal_Bool)sal_True ) ),
    1066             :         AsciiPropertyValue( "EnableOuterJoinEscape",      makeAny( (sal_Bool)sal_True ) ),
    1067             :         AsciiPropertyValue( "PreferDosLikeLineEnds",      makeAny( (sal_Bool)sal_False ) ),
    1068             :         AsciiPropertyValue( "FormsCheckRequiredFields",   makeAny( (sal_Bool)sal_True ) ),
    1069             :         AsciiPropertyValue( "EscapeDateTime",             makeAny( (sal_Bool)sal_True ) ),
    1070             : 
    1071             :         // known services to handle database tasks
    1072             :         AsciiPropertyValue( "TableAlterationServiceName", makeAny( OUString() ) ),
    1073             :         AsciiPropertyValue( "TableRenameServiceName",     makeAny( OUString() ) ),
    1074             :         AsciiPropertyValue( "ViewAlterationServiceName",  makeAny( OUString() ) ),
    1075             :         AsciiPropertyValue( "ViewAccessServiceName",      makeAny( OUString() ) ),
    1076             :         AsciiPropertyValue( "CommandDefinitions",         makeAny( OUString() ) ),
    1077             :         AsciiPropertyValue( "Forms",                      makeAny( OUString() ) ),
    1078             :         AsciiPropertyValue( "Reports",                    makeAny( OUString() ) ),
    1079             :         AsciiPropertyValue( "KeyAlterationServiceName",   makeAny( OUString() ) ),
    1080             :         AsciiPropertyValue( "IndexAlterationServiceName", makeAny( OUString() ) ),
    1081             : 
    1082             :         AsciiPropertyValue()
    1083         170 :     };
    1084         134 :     return aKnownSettings;
    1085             : }
    1086             : 
    1087         710 : TContentPtr& ODatabaseModelImpl::getObjectContainer( ObjectType _eType )
    1088             : {
    1089             :     OSL_PRECOND( _eType >= E_FORM && _eType <= E_TABLE, "ODatabaseModelImpl::getObjectContainer: illegal index!" );
    1090         710 :     TContentPtr& rContentPtr = m_aContainer[ _eType ];
    1091             : 
    1092         710 :     if ( !rContentPtr.get() )
    1093             :     {
    1094         395 :         rContentPtr = TContentPtr( new ODefinitionContainer_Impl );
    1095         395 :         rContentPtr->m_pDataSource = this;
    1096         395 :         rContentPtr->m_aProps.aTitle = lcl_getContainerStorageName_throw( _eType );
    1097             :     }
    1098         710 :     return rContentPtr;
    1099             : }
    1100             : 
    1101         100 : void ODatabaseModelImpl::revokeDataSource() const
    1102             : {
    1103         100 :     if ( m_pDBContext && !m_sDocumentURL.isEmpty() )
    1104          98 :         m_pDBContext->revokeDatabaseDocument( *this );
    1105         100 : }
    1106             : 
    1107           0 : bool ODatabaseModelImpl::adjustMacroMode_AutoReject()
    1108             : {
    1109           0 :     return m_aMacroMode.adjustMacroMode( NULL );
    1110             : }
    1111             : 
    1112           5 : bool ODatabaseModelImpl::checkMacrosOnLoading()
    1113             : {
    1114           5 :     Reference< XInteractionHandler > xInteraction;
    1115           5 :     xInteraction = m_aMediaDescriptor.getOrDefault( "InteractionHandler", xInteraction );
    1116           5 :     return m_aMacroMode.checkMacrosOnLoading( xInteraction );
    1117             : }
    1118             : 
    1119         100 : void ODatabaseModelImpl::resetMacroExecutionMode()
    1120             : {
    1121         100 :     m_aMacroMode = ::sfx2::DocumentMacroMode( *this );
    1122         100 : }
    1123             : 
    1124           6 : Reference< XStorageBasedLibraryContainer > ODatabaseModelImpl::getLibraryContainer( bool _bScript )
    1125             : {
    1126           6 :     Reference< XStorageBasedLibraryContainer >& rxContainer( _bScript ? m_xBasicLibraries : m_xDialogLibraries );
    1127           6 :     if ( rxContainer.is() )
    1128           0 :         return rxContainer;
    1129             : 
    1130           6 :     Reference< XStorageBasedDocument > xDocument( getModel_noCreate(), UNO_QUERY_THROW );
    1131             :         // this is only to be called if there already exists a document model - in fact, it is
    1132             :         // to be called by the document model only
    1133             : 
    1134             :     try
    1135             :     {
    1136             :         Reference< XStorageBasedLibraryContainer > (*Factory)( const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&)
    1137           6 :             = _bScript ? &DocumentScriptLibraryContainer::create : &DocumentDialogLibraryContainer::create;
    1138             : 
    1139             :         rxContainer.set(
    1140             :             (*Factory)( m_aContext, xDocument ),
    1141             :             UNO_QUERY_THROW
    1142           6 :         );
    1143             :     }
    1144           0 :     catch( const RuntimeException& )
    1145             :     {
    1146           0 :         throw;
    1147             :     }
    1148           0 :     catch( const Exception& )
    1149             :     {
    1150             :         throw WrappedTargetRuntimeException(
    1151             :             OUString(),
    1152             :             xDocument,
    1153             :             ::cppu::getCaughtException()
    1154           0 :         );
    1155             :     }
    1156           6 :     return rxContainer;
    1157             : }
    1158             : 
    1159          88 : void ODatabaseModelImpl::storeLibraryContainersTo( const Reference< XStorage >& _rxToRootStorage )
    1160             : {
    1161          88 :     if ( m_xBasicLibraries.is() )
    1162           1 :         m_xBasicLibraries->storeLibrariesToStorage( _rxToRootStorage );
    1163             : 
    1164          88 :     if ( m_xDialogLibraries.is() )
    1165           1 :         m_xDialogLibraries->storeLibrariesToStorage( _rxToRootStorage );
    1166          88 : }
    1167             : 
    1168          86 : Reference< XStorage > ODatabaseModelImpl::switchToStorage( const Reference< XStorage >& _rxNewRootStorage )
    1169             : {
    1170          86 :     if ( !_rxNewRootStorage.is() )
    1171           0 :         throw IllegalArgumentException();
    1172             : 
    1173          86 :     return impl_switchToStorage_throw( _rxNewRootStorage );
    1174             : }
    1175             : 
    1176             : namespace
    1177             : {
    1178         440 :     void lcl_modifyListening( ::sfx2::IModifiableDocument& _rDocument,
    1179             :         const Reference< XStorage >& _rxStorage, ::rtl::Reference< ::sfx2::DocumentStorageModifyListener >& _inout_rListener,
    1180             :         comphelper::SolarMutex& _rMutex, bool _bListen )
    1181             :     {
    1182         440 :         Reference< XModifiable > xModify( _rxStorage, UNO_QUERY );
    1183             :         OSL_ENSURE( xModify.is() || !_rxStorage.is(), "lcl_modifyListening: storage can't notify us!" );
    1184             : 
    1185         440 :         if ( xModify.is() && !_bListen && _inout_rListener.is() )
    1186             :         {
    1187          98 :             xModify->removeModifyListener( _inout_rListener.get() );
    1188             :         }
    1189             : 
    1190         440 :         if ( _inout_rListener.is() )
    1191             :         {
    1192          98 :             _inout_rListener->dispose();
    1193          98 :             _inout_rListener = NULL;
    1194             :         }
    1195             : 
    1196         440 :         if ( xModify.is() && _bListen )
    1197             :         {
    1198         100 :             _inout_rListener = new ::sfx2::DocumentStorageModifyListener( _rDocument, _rMutex );
    1199         100 :             xModify->addModifyListener( _inout_rListener.get() );
    1200         440 :         }
    1201         440 :     }
    1202             : }
    1203             : 
    1204             : namespace
    1205             : {
    1206         440 :     static void lcl_rebaseScriptStorage_throw( const Reference< XStorageBasedLibraryContainer >& _rxContainer,
    1207             :         const Reference< XStorage >& _rxNewRootStorage )
    1208             :     {
    1209         440 :         if ( _rxContainer.is() )
    1210             :         {
    1211           0 :             if ( _rxNewRootStorage.is() )
    1212           0 :                 _rxContainer->setRootStorage( _rxNewRootStorage );
    1213             : //            else
    1214             :                    // TODO: what to do here? dispose the container?
    1215             :         }
    1216         440 :     }
    1217             : }
    1218             : 
    1219         220 : Reference< XStorage > ODatabaseModelImpl::impl_switchToStorage_throw( const Reference< XStorage >& _rxNewRootStorage )
    1220             : {
    1221             :     // stop listening for modifications at the old storage
    1222         220 :     lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, false );
    1223             : 
    1224             :     // set new storage
    1225         220 :     m_xDocumentStorage.reset( _rxNewRootStorage, SharedStorage::TakeOwnership );
    1226             : 
    1227             :     // start listening for modifications
    1228         220 :     lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, true );
    1229             : 
    1230             :     // forward new storage to Basic and Dialog library containers
    1231         220 :     lcl_rebaseScriptStorage_throw( m_xBasicLibraries, m_xDocumentStorage.getTyped() );
    1232         220 :     lcl_rebaseScriptStorage_throw( m_xDialogLibraries, m_xDocumentStorage.getTyped() );
    1233             : 
    1234         220 :     m_bReadOnly = !tools::stor::storageIsWritable_nothrow( m_xDocumentStorage.getTyped() );
    1235             :     // TODO: our data source, if it exists, must broadcast the change of its ReadOnly property
    1236             : 
    1237         220 :     return m_xDocumentStorage.getTyped();
    1238             : }
    1239             : 
    1240         102 : void ODatabaseModelImpl::impl_switchToLogicalURL( const OUString& i_rDocumentURL )
    1241             : {
    1242         102 :     if ( i_rDocumentURL == m_sDocumentURL )
    1243         104 :         return;
    1244             : 
    1245         100 :     const OUString sOldURL( m_sDocumentURL );
    1246             :     // update our name, if necessary
    1247         200 :     if  (   ( m_sName == m_sDocumentURL )   // our name is our old URL
    1248         100 :         ||  ( m_sName.isEmpty() )        // we do not have a name, yet (i.e. are not registered at the database context)
    1249             :         )
    1250             :     {
    1251          91 :         INetURLObject aURL( i_rDocumentURL );
    1252          91 :         if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
    1253             :         {
    1254          91 :             m_sName = i_rDocumentURL;
    1255             :             // TODO: our data source must broadcast the change of the Name property
    1256          91 :         }
    1257             :     }
    1258             : 
    1259             :     // remember URL
    1260         100 :     m_sDocumentURL = i_rDocumentURL;
    1261             : 
    1262             :     // update our location, if necessary
    1263         100 :     if  ( m_sDocFileLocation.isEmpty() )
    1264          14 :         m_sDocFileLocation = m_sDocumentURL;
    1265             : 
    1266             :     // register at the database context, or change registration
    1267         100 :     if ( m_pDBContext )
    1268             :     {
    1269         100 :         if ( !sOldURL.isEmpty() )
    1270           0 :             m_pDBContext->databaseDocumentURLChange( sOldURL, m_sDocumentURL );
    1271             :         else
    1272         100 :             m_pDBContext->registerDatabaseDocument( *this );
    1273         100 :     }
    1274             : }
    1275             : 
    1276          26 : OUString ODatabaseModelImpl::getObjectContainerStorageName( const ObjectType _eType )
    1277             : {
    1278          26 :     return lcl_getContainerStorageName_throw( _eType );
    1279             : }
    1280             : 
    1281           5 : sal_Int16 ODatabaseModelImpl::getCurrentMacroExecMode() const
    1282             : {
    1283           5 :     sal_Int16 nCurrentMode = MacroExecMode::NEVER_EXECUTE;
    1284             :     try
    1285             :     {
    1286           5 :         nCurrentMode = m_aMediaDescriptor.getOrDefault( "MacroExecutionMode", nCurrentMode );
    1287             :     }
    1288           0 :     catch( const Exception& )
    1289             :     {
    1290             :         DBG_UNHANDLED_EXCEPTION();
    1291             :     }
    1292           5 :     return nCurrentMode;
    1293             : }
    1294             : 
    1295           4 : bool ODatabaseModelImpl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
    1296             : {
    1297           4 :     m_aMediaDescriptor.put( "MacroExecutionMode", nMacroMode );
    1298           4 :     return true;
    1299             : }
    1300             : 
    1301           0 : OUString ODatabaseModelImpl::getDocumentLocation() const
    1302             : {
    1303           0 :     return getURL();
    1304             :     // formerly, we returned getDocFileLocation here, which is the location of the file from which we
    1305             :     // recovered the "real" document.
    1306             :     // However, during CWS autorecovery evolving, we clarified (with MAV/MT) the role of XModel::getURL and
    1307             :     // XStorable::getLocation. In this course, we agreed that for a macro security check, the *document URL*
    1308             :     // (not the recovery file URL) is to be used: The recovery file lies in the backup folder, and by definition,
    1309             :     // this folder is considered to be secure. So, the document URL needs to be used to decide about the security.
    1310             : }
    1311             : 
    1312           0 : Reference< XStorage > ODatabaseModelImpl::getZipStorageToSign()
    1313             : {
    1314             :     // we do not support signing the scripting storages, so we're allowed to
    1315             :     // return <NULL/> here.
    1316           0 :     return Reference< XStorage >();
    1317             : }
    1318             : 
    1319          19 : ODatabaseModelImpl::EmbeddedMacros ODatabaseModelImpl::determineEmbeddedMacros()
    1320             : {
    1321          19 :     if ( !m_aEmbeddedMacros )
    1322             :     {
    1323          14 :         if ( ::sfx2::DocumentMacroMode::storageHasMacros( const_cast< ODatabaseModelImpl* >( this )->getOrCreateRootStorage() ) )
    1324             :         {
    1325           1 :             m_aEmbeddedMacros.reset( eDocumentWideMacros );
    1326             :         }
    1327          26 :         else if (   lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_FORM )
    1328          13 :                 ||  lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_REPORT )
    1329             :                 )
    1330             :         {
    1331           0 :             m_aEmbeddedMacros.reset( eSubDocumentMacros );
    1332             :         }
    1333             :         else
    1334             :         {
    1335          13 :             m_aEmbeddedMacros.reset( eNoMacros );
    1336             :         }
    1337             :     }
    1338          19 :     return *m_aEmbeddedMacros;
    1339             : }
    1340             : 
    1341           5 : bool ODatabaseModelImpl::documentStorageHasMacros() const
    1342             : {
    1343           5 :     const_cast< ODatabaseModelImpl* >( this )->determineEmbeddedMacros();
    1344           5 :     return ( *m_aEmbeddedMacros != eNoMacros );
    1345             : }
    1346             : 
    1347           4 : Reference< XEmbeddedScripts > ODatabaseModelImpl::getEmbeddedDocumentScripts() const
    1348             : {
    1349           4 :     return Reference< XEmbeddedScripts >( getModel_noCreate(), UNO_QUERY );
    1350             : }
    1351             : 
    1352           0 : sal_Int16 ODatabaseModelImpl::getScriptingSignatureState()
    1353             : {
    1354             :     // no support for signatures at the moment
    1355           0 :     return SIGNATURESTATE_NOSIGNATURES;
    1356             : }
    1357             : 
    1358           0 : bool ODatabaseModelImpl::hasTrustedScriptingSignature( bool /*bAllowUIToAddAuthor*/ )
    1359             : {
    1360             :     // no support for signatures at the moment
    1361           0 :     return false;
    1362             : }
    1363             : 
    1364           0 : void ODatabaseModelImpl::showBrokenSignatureWarning( const Reference< XInteractionHandler >& /*_rxInteraction*/ ) const
    1365             : {
    1366             :     OSL_FAIL( "ODatabaseModelImpl::showBrokenSignatureWarning: signatures can't be broken - we do not support them!" );
    1367           0 : }
    1368             : 
    1369        1061 : void ODatabaseModelImpl::storageIsModified()
    1370             : {
    1371        1061 :     setModified( sal_True );
    1372        1061 : }
    1373             : 
    1374         329 : ModelDependentComponent::ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model )
    1375             :     :m_pImpl( _model )
    1376         329 :     ,m_aMutex( _model->getSharedMutex() )
    1377             : {
    1378         329 : }
    1379             : 
    1380         322 : ModelDependentComponent::~ModelDependentComponent()
    1381             : {
    1382         322 : }
    1383             : 
    1384             : }   // namespace dbaccess
    1385             : 
    1386             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10