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

Generated by: LCOV version 1.11