LCOV - code coverage report
Current view: top level - dbaccess/source/core/dataaccess - ModelImpl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 426 518 82.2 %
Date: 2014-11-03 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         214 : VosMutexFacade::VosMutexFacade( ::osl::Mutex& _rMutex )
      91         214 :     :m_rMutex( _rMutex )
      92             : {
      93         214 : }
      94             : 
      95        2434 : void VosMutexFacade::acquire()
      96             : {
      97        2434 :     m_rMutex.acquire();
      98        2434 : }
      99             : 
     100        2434 : void VosMutexFacade::release()
     101             : {
     102        2434 :     m_rMutex.release();
     103        2434 : }
     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         264 :     DocumentStorageAccess( ODatabaseModelImpl& _rModelImplementation )
     125             :         :m_pModelImplementation( &_rModelImplementation )
     126             :         ,m_bPropagateCommitToRoot( true )
     127         264 :         ,m_bDisposingSubStorages( false )
     128             :     {
     129         264 :     }
     130             : 
     131             : protected:
     132         524 :     virtual ~DocumentStorageAccess()
     133         262 :     {
     134         524 :     }
     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         228 :     void impl_suspendCommitPropagation()
     167             :     {
     168             :         OSL_ENSURE( m_bPropagateCommitToRoot, "DocumentStorageAccess::impl_suspendCommitPropagation: already suspended" );
     169         228 :         m_bPropagateCommitToRoot = false;
     170         228 :     }
     171         228 :     void impl_resumeCommitPropagation()
     172             :     {
     173             :         OSL_ENSURE( !m_bPropagateCommitToRoot, "DocumentStorageAccess::impl_resumeCommitPropagation: not suspended" );
     174         228 :         m_bPropagateCommitToRoot = true;
     175         228 :     }
     176             : 
     177             : };
     178             : 
     179         262 : void DocumentStorageAccess::dispose()
     180             : {
     181         262 :     ::osl::MutexGuard aGuard( m_aMutex );
     182             : 
     183         786 :     for (   NamedStorages::iterator loop = m_aExposedStorages.begin();
     184         524 :             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         262 :     m_aExposedStorages.clear();
     201             : 
     202         262 :     m_pModelImplementation = NULL;
     203         262 : }
     204             : 
     205          80 : 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          80 :     Reference< XStorage > xStorage;
     210             :     try
     211             :     {
     212          80 :         Reference< XStorage > xRootStorage( m_pModelImplementation->getOrCreateRootStorage() );
     213          80 :         if ( xRootStorage.is() )
     214             :         {
     215          80 :             sal_Int32 nRealMode = m_pModelImplementation->m_bDocumentReadOnly ? ElementModes::READ : _nDesiredMode;
     216          80 :             if ( nRealMode == ElementModes::READ )
     217             :             {
     218           0 :                 if ( xRootStorage.is() && !xRootStorage->hasByName( _rStorageName ) )
     219           0 :                     return xStorage;
     220             :             }
     221             : 
     222          80 :             xStorage = xRootStorage->openStorageElement( _rStorageName, nRealMode );
     223             : 
     224          80 :             Reference< XTransactionBroadcaster > xBroad( xStorage, UNO_QUERY );
     225          80 :             if ( xBroad.is() )
     226          80 :                 xBroad->addTransactionListener( this );
     227          80 :         }
     228             :     }
     229           0 :     catch( const Exception& )
     230             :     {
     231             :         DBG_UNHANDLED_EXCEPTION();
     232             :     }
     233             : 
     234          80 :     return xStorage;
     235             : }
     236             : 
     237         438 : void DocumentStorageAccess::disposeStorages()
     238             : {
     239         438 :     m_bDisposingSubStorages = true;
     240             : 
     241         438 :     NamedStorages::iterator aEnd = m_aExposedStorages.end();
     242         510 :     for (   NamedStorages::iterator aIter = m_aExposedStorages.begin();
     243             :             aIter != aEnd ;
     244             :             ++aIter
     245             :         )
     246             :     {
     247             :         try
     248             :         {
     249          72 :             ::comphelper::disposeComponent( aIter->second );
     250             :         }
     251           0 :         catch( const Exception& )
     252             :         {
     253             :             DBG_UNHANDLED_EXCEPTION();
     254             :         }
     255             :     }
     256         438 :     m_aExposedStorages.clear();
     257             : 
     258         438 :     m_bDisposingSubStorages = false;
     259         438 : }
     260             : 
     261         360 : void DocumentStorageAccess::commitStorages()
     262             : {
     263             :     try
     264             :     {
     265        1098 :         for (   NamedStorages::const_iterator aIter = m_aExposedStorages.begin();
     266         732 :                 aIter != m_aExposedStorages.end();
     267             :                 ++aIter
     268             :             )
     269             :         {
     270           6 :             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         360 : }
     279             : 
     280         588 : bool DocumentStorageAccess::commitEmbeddedStorage( bool _bPreventRootCommits )
     281             : {
     282         588 :     if ( _bPreventRootCommits )
     283         228 :         impl_suspendCommitPropagation();
     284             : 
     285         588 :     bool bSuccess = false;
     286             :     try
     287             :     {
     288         588 :         NamedStorages::const_iterator pos = m_aExposedStorages.find( "database" );
     289         588 :         if ( pos != m_aExposedStorages.end() )
     290           6 :             bSuccess = tools::stor::commitStorageIfWriteable( pos->second );
     291             :     }
     292           0 :     catch( Exception& )
     293             :     {
     294             :         DBG_UNHANDLED_EXCEPTION();
     295             :     }
     296             : 
     297         588 :     if ( _bPreventRootCommits )
     298         228 :         impl_resumeCommitPropagation();
     299             : 
     300         588 :     return bSuccess;
     301             : 
     302             : }
     303             : 
     304          80 : Reference< XStorage > SAL_CALL DocumentStorageAccess::getDocumentSubStorage( const OUString& aStorageName, ::sal_Int32 _nDesiredMode ) throw (RuntimeException, std::exception)
     305             : {
     306          80 :     ::osl::MutexGuard aGuard( m_aMutex );
     307          80 :     NamedStorages::iterator pos = m_aExposedStorages.find( aStorageName );
     308          80 :     if ( pos == m_aExposedStorages.end() )
     309             :     {
     310          80 :         Reference< XStorage > xResult = impl_openSubStorage_nothrow( aStorageName, _nDesiredMode );
     311          80 :         pos = m_aExposedStorages.insert( NamedStorages::value_type( aStorageName, xResult ) ).first;
     312             :     }
     313             : 
     314          80 :     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          12 : void SAL_CALL DocumentStorageAccess::preCommit( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException, std::exception)
     337             : {
     338             :     // not interested in
     339          12 : }
     340             : 
     341          12 : void SAL_CALL DocumentStorageAccess::commited( const css::lang::EventObject& aEvent ) throw (RuntimeException, std::exception)
     342             : {
     343          12 :     ::osl::MutexGuard aGuard( m_aMutex );
     344             : 
     345          12 :     if ( m_pModelImplementation )
     346          12 :         m_pModelImplementation->setModified( true );
     347             : 
     348          12 :     if ( m_pModelImplementation && m_bPropagateCommitToRoot )
     349             :     {
     350           6 :         Reference< XStorage > xStorage( aEvent.Source, UNO_QUERY );
     351             : 
     352             :         // check if this is the dedicated "database" sub storage
     353           6 :         NamedStorages::const_iterator pos = m_aExposedStorages.find( "database" );
     354          18 :         if  (   ( pos != m_aExposedStorages.end() )
     355          18 :             &&  ( pos->second == xStorage )
     356             :             )
     357             :         {
     358             :             // if so, also commit the root storage
     359           0 :             m_pModelImplementation->commitRootStorage();
     360           6 :         }
     361          12 :     }
     362          12 : }
     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          72 : 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          72 :     if ( m_bDisposingSubStorages )
     379         144 :         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         196 : 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         196 :             ,m_nControllerLockCount(0)
     417             : {
     418             :     // some kind of default
     419         196 :     m_sConnectURL = "jdbc:";
     420         196 :     m_aTableFilter.realloc(1);
     421         196 :     m_aTableFilter[0] = "%";
     422         196 :     impl_construct_nothrow();
     423         196 : }
     424             : 
     425          18 : 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          18 :             ,m_nControllerLockCount(0)
     453             : {
     454          18 :     impl_construct_nothrow();
     455          18 : }
     456             : 
     457         424 : ODatabaseModelImpl::~ODatabaseModelImpl()
     458             : {
     459         424 : }
     460             : 
     461         214 : 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         214 :         Sequence< Type > aAllowedTypes(6);
     468         214 :         Type* pAllowedType = aAllowedTypes.getArray();
     469         214 :         *pAllowedType++ = ::cppu::UnoType<sal_Bool>::get();
     470         214 :         *pAllowedType++ = ::cppu::UnoType<double>::get();
     471         214 :         *pAllowedType++ = ::cppu::UnoType<OUString>::get();
     472         214 :         *pAllowedType++ = ::cppu::UnoType<sal_Int32>::get();
     473         214 :         *pAllowedType++ = ::cppu::UnoType<sal_Int16>::get();
     474         214 :         *pAllowedType++ = ::getCppuType( static_cast< Sequence< Any >* >( NULL ) );
     475             : 
     476         214 :         m_xSettings = PropertyBag::createWithTypes( m_aContext, aAllowedTypes, sal_False/*AllowEmptyPropertyName*/, sal_True/*AutomaticAddition*/ );
     477             : 
     478             :         // insert the default settings
     479         428 :         Reference< XPropertyContainer > xContainer( m_xSettings, UNO_QUERY_THROW );
     480         428 :         Reference< XSet > xSettingsSet( m_xSettings, UNO_QUERY_THROW );
     481         214 :         const AsciiPropertyValue* pSettings = getDefaultDataSourceSettings();
     482       11556 :         for ( ; pSettings->AsciiName; ++pSettings )
     483             :         {
     484       11342 :             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         642 :                 );
     492         642 :                 xSettingsSet->insert( makeAny( aProperty ) );
     493             :             }
     494             :             else
     495             :             {
     496       10700 :                 xContainer->addProperty(
     497             :                     OUString::createFromAscii( pSettings->AsciiName ),
     498             :                     PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
     499             :                     pSettings->DefaultValue
     500       10700 :                 );
     501             :             }
     502         214 :         }
     503             :     }
     504           0 :     catch( const Exception& )
     505             :     {
     506             :         DBG_UNHANDLED_EXCEPTION();
     507             :     }
     508         214 :     m_pDBContext->appendAtTerminateListener(*this);
     509         214 : }
     510             : 
     511             : namespace
     512             : {
     513         886 :     OUString lcl_getContainerStorageName_throw( ODatabaseModelImpl::ObjectType _eType )
     514             :     {
     515         886 :         const sal_Char* pAsciiName( NULL );
     516         886 :         switch ( _eType )
     517             :         {
     518         238 :         case ODatabaseModelImpl::E_FORM:   pAsciiName = "forms"; break;
     519         238 :         case ODatabaseModelImpl::E_REPORT: pAsciiName = "reports"; break;
     520         204 :         case ODatabaseModelImpl::E_QUERY:  pAsciiName = "queries"; break;
     521         206 :         case ODatabaseModelImpl::E_TABLE:  pAsciiName = "tables"; break;
     522             :         default:
     523           0 :             throw RuntimeException();
     524             :         }
     525         886 :         return OUString::createFromAscii( pAsciiName );
     526             :     }
     527             : 
     528          56 :     bool lcl_hasObjectWithMacros_throw( const ODefinitionContainer_Impl& _rObjectDefinitions, const Reference< XStorage >& _rxContainerStorage )
     529             :     {
     530          56 :         bool bSomeDocHasMacros = false;
     531             : 
     532         168 :         for (   ODefinitionContainer_Impl::const_iterator object = _rObjectDefinitions.begin();
     533         168 :                 ( 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          56 :         return bSomeDocHasMacros;
     554             :     }
     555             : 
     556          56 :     bool lcl_hasObjectsWithMacros_nothrow( ODatabaseModelImpl& _rModel, const ODatabaseModelImpl::ObjectType _eType )
     557             :     {
     558          56 :         bool bSomeDocHasMacros = false;
     559             : 
     560          56 :         const OContentHelper_Impl& rContainerData( *_rModel.getObjectContainer( _eType ).get() );
     561          56 :         const ODefinitionContainer_Impl& rObjectDefinitions = dynamic_cast< const ODefinitionContainer_Impl& >( rContainerData );
     562             : 
     563             :         try
     564             :         {
     565          56 :             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          56 :             if ( xContainerStorage.is() )
     575          56 :                 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          56 :         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          34 : void ODatabaseModelImpl::reset()
     612             : {
     613          34 :     m_bReadOnly = false;
     614          34 :     ::std::vector< TContentPtr > aEmptyContainers( 4 );
     615          34 :     m_aContainer.swap( aEmptyContainers );
     616             : 
     617          34 :     if ( m_pStorageAccess )
     618             :     {
     619          34 :         m_pStorageAccess->dispose();
     620          34 :         m_pStorageAccess->release();
     621          34 :         m_pStorageAccess = NULL;
     622          34 :     }
     623          34 : }
     624             : 
     625          54 : void SAL_CALL ODatabaseModelImpl::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException)
     626             : {
     627          54 :     Reference<XConnection> xCon(Source.Source,UNO_QUERY);
     628          54 :     if ( xCon.is() )
     629             :     {
     630          54 :         bool bStore = false;
     631          54 :         OWeakConnectionArray::iterator aEnd = m_aConnections.end();
     632          54 :         for (OWeakConnectionArray::iterator i = m_aConnections.begin(); aEnd != i; ++i)
     633             :         {
     634          54 :             if ( xCon == i->get() )
     635             :             {
     636          54 :                 *i = OWeakConnection();
     637          54 :                 bStore = true;
     638          54 :                 break;
     639             :             }
     640             :         }
     641             : 
     642          54 :         if ( bStore )
     643          54 :             commitRootStorage();
     644             :     }
     645             :     else
     646             :     {
     647             :         OSL_FAIL( "ODatabaseModelImpl::disposing: where does this come from?" );
     648          54 :     }
     649          54 : }
     650             : 
     651         262 : void ODatabaseModelImpl::clearConnections()
     652             : {
     653         262 :     OWeakConnectionArray aConnections;
     654         262 :     aConnections.swap( m_aConnections );
     655             : 
     656         524 :     Reference< XConnection > xConn;
     657         262 :     OWeakConnectionArray::iterator aEnd = aConnections.end();
     658         334 :     for ( OWeakConnectionArray::iterator i = aConnections.begin(); aEnd != i; ++i )
     659             :     {
     660          72 :         xConn = *i;
     661          72 :         if ( xConn.is() )
     662             :         {
     663             :             try
     664             :             {
     665          18 :                 xConn->close();
     666             :             }
     667           0 :             catch(const Exception&)
     668             :             {
     669             :                 DBG_UNHANDLED_EXCEPTION();
     670             :             }
     671             :         }
     672             :     }
     673             : 
     674         262 :     m_pSharedConnectionManager = NULL;
     675         524 :     m_xSharedConnectionManager = NULL;
     676         262 : }
     677             : 
     678         228 : void ODatabaseModelImpl::dispose()
     679             : {
     680             :     // dispose the data source and the model
     681             :     try
     682             :     {
     683         228 :         Reference< XDataSource > xDS( m_xDataSource );
     684         228 :         ::comphelper::disposeComponent( xDS );
     685             : 
     686         456 :         Reference< XModel > xModel( m_xModel );
     687         456 :         ::comphelper::disposeComponent( xModel );
     688             :     }
     689           0 :     catch( const Exception& )
     690             :     {
     691             :         DBG_UNHANDLED_EXCEPTION();
     692             :     }
     693         228 :     m_xDataSource = WeakReference<XDataSource>();
     694         228 :     m_xModel = WeakReference< XModel >();
     695             : 
     696         228 :     ::std::vector<TContentPtr>::iterator aIter = m_aContainer.begin();
     697         228 :     ::std::vector<TContentPtr>::iterator aEnd = m_aContainer.end();
     698        1076 :     for (;aIter != aEnd ; ++aIter)
     699             :     {
     700         848 :         if ( aIter->get() )
     701         822 :             (*aIter)->m_pDataSource = NULL;
     702             :     }
     703         228 :     m_aContainer.clear();
     704             : 
     705         228 :     clearConnections();
     706             : 
     707         228 :     m_xNumberFormatsSupplier = NULL;
     708             : 
     709             :     try
     710             :     {
     711         228 :         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         228 :         disposeStorages();
     715         228 :         if ( bCouldStore )
     716           6 :             commitRootStorage();
     717             : 
     718         228 :         impl_switchToStorage_throw( NULL );
     719             :     }
     720           0 :     catch( const Exception& )
     721             :     {
     722             :         DBG_UNHANDLED_EXCEPTION();
     723             :     }
     724             : 
     725         228 :     if ( m_pStorageAccess )
     726             :     {
     727         228 :         m_pStorageAccess->dispose();
     728         228 :         m_pStorageAccess->release();
     729         228 :         m_pStorageAccess = NULL;
     730             :     }
     731         228 : }
     732             : 
     733         612 : const Reference< XNumberFormatsSupplier > & ODatabaseModelImpl::getNumberFormatsSupplier()
     734             : {
     735         612 :     if (!m_xNumberFormatsSupplier.is())
     736             :     {
     737             :         // the arguments : the locale of the current user
     738         210 :         UserInformation aUserInfo;
     739         420 :         Locale aLocale = aUserInfo.getUserLanguage();
     740             : 
     741         420 :         m_xNumberFormatsSupplier.set( NumberFormatsSupplier::createWithLocale( m_aContext, aLocale ) );
     742             :     }
     743         612 :     return m_xNumberFormatsSupplier;
     744             : }
     745             : 
     746         184 : void ODatabaseModelImpl::setDocFileLocation( const OUString& i_rLoadedFrom )
     747             : {
     748         184 :     ENSURE_OR_THROW( !i_rLoadedFrom.isEmpty(), "invalid URL" );
     749         184 :     m_sDocFileLocation = i_rLoadedFrom;
     750         184 : }
     751             : 
     752         218 : void ODatabaseModelImpl::setResource( const OUString& i_rDocumentURL, const Sequence< PropertyValue >& _rArgs )
     753             : {
     754         218 :     ENSURE_OR_THROW( !i_rDocumentURL.isEmpty(), "invalid URL" );
     755             : 
     756         218 :     ::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         218 :     m_aMediaDescriptor = stripLoadArguments( aMediaDescriptor );
     772             : 
     773         218 :     impl_switchToLogicalURL( i_rDocumentURL );
     774         218 : }
     775             : 
     776         252 : ::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         252 :     ::comphelper::NamedValueCollection aMutableArgs( _rArguments );
     782         252 :     aMutableArgs.remove( "Model" );
     783         252 :     aMutableArgs.remove( "ViewName" );
     784         252 :     return aMutableArgs;
     785             : }
     786             : 
     787         438 : void ODatabaseModelImpl::disposeStorages()
     788             : {
     789         438 :     getDocumentStorageAccess()->disposeStorages();
     790         438 : }
     791             : 
     792         176 : Reference< XSingleServiceFactory > ODatabaseModelImpl::createStorageFactory() const
     793             : {
     794         176 :     return StorageFactory::create( m_aContext );
     795             : }
     796             : 
     797          60 : void ODatabaseModelImpl::commitRootStorage()
     798             : {
     799          60 :     Reference< XStorage > xStorage( getOrCreateRootStorage() );
     800          60 :     bool bSuccess = commitStorageIfWriteable_ignoreErrors( xStorage );
     801             :     SAL_WARN_IF(!bSuccess && xStorage.is(), "dbaccess",
     802          60 :         "ODatabaseModelImpl::commitRootStorage: could not commit the storage!");
     803          60 : }
     804             : 
     805         414 : Reference< XStorage > ODatabaseModelImpl::getOrCreateRootStorage()
     806             : {
     807         414 :     if ( !m_xDocumentStorage.is() )
     808             :     {
     809          34 :         Reference< XSingleServiceFactory> xStorageFactory = StorageFactory::create( m_aContext );
     810          68 :         Any aSource;
     811          34 :         aSource = m_aMediaDescriptor.get( "Stream" );
     812          34 :         if ( !aSource.hasValue() )
     813          34 :             aSource = m_aMediaDescriptor.get( "InputStream" );
     814          34 :         if ( !aSource.hasValue() && !m_sDocFileLocation.isEmpty() )
     815          34 :             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          34 :         if ( aSource.hasValue() )
     821             :         {
     822          34 :             Sequence< Any > aStorageCreationArgs(2);
     823          34 :             aStorageCreationArgs[0] = aSource;
     824          34 :             aStorageCreationArgs[1] <<= ElementModes::READWRITE;
     825             : 
     826          68 :             Reference< XStorage > xDocumentStorage;
     827             :             try
     828             :             {
     829          34 :                 xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
     830             :             }
     831           0 :             catch( const Exception& )
     832             :             {
     833           0 :                 m_bDocumentReadOnly = true;
     834           0 :                 aStorageCreationArgs[1] <<= ElementModes::READ;
     835             :                 try
     836             :                 {
     837           0 :                     xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
     838             :                 }
     839           0 :                 catch( const Exception& )
     840             :                 {
     841             :                     DBG_UNHANDLED_EXCEPTION();
     842             :                 }
     843             :             }
     844             : 
     845          68 :             impl_switchToStorage_throw( xDocumentStorage );
     846          34 :         }
     847             :     }
     848         414 :     return m_xDocumentStorage.getTyped();
     849             : }
     850             : 
     851        1466 : DocumentStorageAccess* ODatabaseModelImpl::getDocumentStorageAccess()
     852             : {
     853        1466 :     if ( !m_pStorageAccess )
     854             :     {
     855         264 :         m_pStorageAccess = new DocumentStorageAccess( *this );
     856         264 :         m_pStorageAccess->acquire();
     857             :     }
     858        1466 :     return m_pStorageAccess;
     859             : }
     860             : 
     861         210 : void ODatabaseModelImpl::modelIsDisposing( const bool _wasInitialized, ResetModelAccess )
     862             : {
     863         210 :     m_xModel.clear();
     864             : 
     865             :     // Basic libraries and Dialog libraries are a model facet, though held at this impl class.
     866             :     // They automatically dispose themself when the model they belong to is being disposed.
     867             :     // So, to not be tempted to do anything with them, again, we reset them.
     868         210 :     m_xBasicLibraries.clear();
     869         210 :     m_xDialogLibraries.clear();
     870             : 
     871         210 :     m_bDocumentInitialized = _wasInitialized;
     872         210 : }
     873             : 
     874          24 : Reference< XDocumentSubStorageSupplier > ODatabaseModelImpl::getDocumentSubStorageSupplier()
     875             : {
     876          24 :     return getDocumentStorageAccess();
     877             : }
     878             : 
     879         588 : bool ODatabaseModelImpl::commitEmbeddedStorage( bool _bPreventRootCommits )
     880             : {
     881         588 :     return getDocumentStorageAccess()->commitEmbeddedStorage( _bPreventRootCommits );
     882             : }
     883             : 
     884          60 : bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage )
     885             : {
     886          60 :     bool bSuccess = false;
     887             :     try
     888             :     {
     889          60 :         bSuccess = tools::stor::commitStorageIfWriteable( _rxStorage );
     890             :     }
     891           6 :     catch( const Exception& )
     892             :     {
     893             :         DBG_UNHANDLED_EXCEPTION();
     894             :     }
     895          60 :     return bSuccess;
     896             : }
     897             : 
     898        2500 : void ODatabaseModelImpl::setModified( bool _bModified )
     899             : {
     900        2500 :     if ( isModifyLocked() )
     901        4726 :         return;
     902             : 
     903             :     try
     904             :     {
     905         274 :         Reference< XModifiable > xModi( m_xModel.get(), UNO_QUERY );
     906         274 :         if ( xModi.is() )
     907          88 :             xModi->setModified( _bModified );
     908             :         else
     909         186 :             m_bModified = _bModified;
     910             :     }
     911           0 :     catch( const Exception& )
     912             :     {
     913             :         DBG_UNHANDLED_EXCEPTION();
     914             :     }
     915             : }
     916             : 
     917        1492 : Reference<XDataSource> ODatabaseModelImpl::getOrCreateDataSource()
     918             : {
     919        1492 :     Reference<XDataSource> xDs = m_xDataSource;
     920        1492 :     if ( !xDs.is() )
     921             :     {
     922         496 :         xDs = new ODatabaseSource(this);
     923         496 :         m_xDataSource = xDs;
     924             :     }
     925        1492 :     return xDs;
     926             : }
     927             : 
     928        3312 : Reference< XModel> ODatabaseModelImpl::getModel_noCreate() const
     929             : {
     930        3312 :     return m_xModel;
     931             : }
     932             : 
     933         210 : Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _bInitialize )
     934             : {
     935         210 :     Reference< XModel > xModel( m_xModel );
     936             :     OSL_PRECOND( !xModel.is(), "ODatabaseModelImpl::createNewModel_deliverOwnership: not to be called if there already is a model!" );
     937         210 :     if ( !xModel.is() )
     938             :     {
     939         210 :         bool bHadModelBefore = m_bDocumentInitialized;
     940             : 
     941         210 :         xModel = ODatabaseDocument::createDatabaseDocument( this, ODatabaseDocument::FactoryAccess() );
     942         210 :         m_xModel = xModel;
     943             : 
     944             :         try
     945             :         {
     946         210 :             Reference< XGlobalEventBroadcaster > xModelCollection = theGlobalEventBroadcaster::get( m_aContext );
     947         210 :             xModelCollection->insert( makeAny( xModel ) );
     948             :         }
     949           0 :         catch( const Exception& )
     950             :         {
     951             :             DBG_UNHANDLED_EXCEPTION();
     952             :         }
     953             : 
     954         210 :         if ( bHadModelBefore )
     955             :         {
     956             :             // do an attachResources
     957             :             // In case the document is loaded regularly, this is not necessary, as our loader will do it.
     958             :             // However, in case that the document is implicitly created by asking the data source for the document,
     959             :             // then nobody would call the doc's attachResource. So, we do it here, to ensure it's in a proper
     960             :             // state, fires all events, and so on.
     961             :             // #i105505#
     962           0 :             xModel->attachResource( xModel->getURL(), m_aMediaDescriptor.getPropertyValues() );
     963             :         }
     964             : 
     965         210 :         if ( _bInitialize )
     966             :         {
     967             :             try
     968             :             {
     969           0 :                 Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
     970           0 :                 xLoad->initNew();
     971             :             }
     972           0 :             catch( RuntimeException& ) { throw; }
     973           0 :             catch( const Exception& )
     974             :             {
     975             :                 DBG_UNHANDLED_EXCEPTION();
     976             :             }
     977             :         }
     978             :     }
     979         210 :     return xModel;
     980             : }
     981             : 
     982        1854 : void SAL_CALL ODatabaseModelImpl::acquire()
     983             : {
     984        1854 :     osl_atomic_increment(&m_refCount);
     985        1854 : }
     986             : 
     987        1640 : void SAL_CALL ODatabaseModelImpl::release()
     988             : {
     989        1640 :     if ( osl_atomic_decrement(&m_refCount) == 0 )
     990             :     {
     991         212 :         acquire();  // prevent multiple releases
     992         212 :         m_pDBContext->removeFromTerminateListener(*this);
     993         212 :         dispose();
     994         212 :         m_pDBContext->storeTransientProperties(*this);
     995         212 :         revokeDataSource();
     996         212 :         delete this;
     997             :     }
     998        1640 : }
     999             : 
    1000         360 : void ODatabaseModelImpl::commitStorages()
    1001             : {
    1002         360 :     getDocumentStorageAccess()->commitStorages();
    1003         360 : }
    1004             : 
    1005          56 : Reference< XStorage > ODatabaseModelImpl::getStorage( const ObjectType _eType, const sal_Int32 _nDesiredMode )
    1006             : {
    1007          56 :     return getDocumentStorageAccess()->getDocumentSubStorage( getObjectContainerStorageName( _eType ), _nDesiredMode );
    1008             : }
    1009             : 
    1010         284 : const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings()
    1011             : {
    1012             :     static const AsciiPropertyValue aKnownSettings[] =
    1013             :     {
    1014             :         // known JDBC settings
    1015             :         AsciiPropertyValue( "JavaDriverClass",            makeAny( OUString() ) ),
    1016             :         AsciiPropertyValue( "JavaDriverClassPath",        makeAny( OUString() ) ),
    1017             :         AsciiPropertyValue( "IgnoreCurrency",             makeAny( false ) ),
    1018             :         // known settings for file-based drivers
    1019             :         AsciiPropertyValue( "Extension",                  makeAny( OUString() ) ),
    1020             :         AsciiPropertyValue( "CharSet",                    makeAny( OUString() ) ),
    1021             :         AsciiPropertyValue( "HeaderLine",                 makeAny( true ) ),
    1022             :         AsciiPropertyValue( "FieldDelimiter",             makeAny( OUString( "," ) ) ),
    1023             :         AsciiPropertyValue( "StringDelimiter",            makeAny( OUString( "\"" ) ) ),
    1024             :         AsciiPropertyValue( "DecimalDelimiter",           makeAny( OUString( "." ) ) ),
    1025             :         AsciiPropertyValue( "ThousandDelimiter",          makeAny( OUString() ) ),
    1026             :         AsciiPropertyValue( "ShowDeleted",                makeAny( false ) ),
    1027             :         // known ODBC settings
    1028             :         AsciiPropertyValue( "SystemDriverSettings",       makeAny( OUString() ) ),
    1029             :         AsciiPropertyValue( "UseCatalog",                 makeAny( false ) ),
    1030             :         AsciiPropertyValue( "TypeInfoSettings",           makeAny( Sequence< Any >()) ),
    1031             :         // settings related to auto increment handling
    1032             :         AsciiPropertyValue( "AutoIncrementCreation",      makeAny( OUString() ) ),
    1033             :         AsciiPropertyValue( "AutoRetrievingStatement",    makeAny( OUString() ) ),
    1034             :         AsciiPropertyValue( "IsAutoRetrievingEnabled",    makeAny( false ) ),
    1035             :         // known LDAP driver settings
    1036             :         AsciiPropertyValue( "HostName",                   makeAny( OUString() ) ),
    1037             :         AsciiPropertyValue( "PortNumber",                 makeAny( (sal_Int32)389 ) ),
    1038             :         AsciiPropertyValue( "BaseDN",                     makeAny( OUString() ) ),
    1039             :         AsciiPropertyValue( "MaxRowCount",                makeAny( (sal_Int32)100 ) ),
    1040             :         // known MySQLNative driver settings
    1041             :         AsciiPropertyValue( "LocalSocket",                makeAny( OUString() ) ),
    1042             :         AsciiPropertyValue( "NamedPipe",                  makeAny( OUString() ) ),
    1043             :         // misc known driver settings
    1044             :         AsciiPropertyValue( "ParameterNameSubstitution",  makeAny( false ) ),
    1045             :         AsciiPropertyValue( "AddIndexAppendix",           makeAny( true ) ),
    1046             :         AsciiPropertyValue( "IgnoreDriverPrivileges",     makeAny( true ) ),
    1047          26 :         AsciiPropertyValue( "ImplicitCatalogRestriction", ::cppu::UnoType< OUString >::get() ),
    1048          26 :         AsciiPropertyValue( "ImplicitSchemaRestriction",  ::cppu::UnoType< OUString >::get() ),
    1049          26 :         AsciiPropertyValue( "PrimaryKeySupport",          ::cppu::UnoType< sal_Bool >::get() ),
    1050             :         AsciiPropertyValue( "ShowColumnDescription",      makeAny( false ) ),
    1051             :         // known SDB level settings
    1052             :         AsciiPropertyValue( "NoNameLengthLimit",          makeAny( false ) ),
    1053             :         AsciiPropertyValue( "AppendTableAliasName",       makeAny( false ) ),
    1054             :         AsciiPropertyValue( "GenerateASBeforeCorrelationName",  makeAny( false ) ),
    1055             :         AsciiPropertyValue( "ColumnAliasInOrderBy",       makeAny( true ) ),
    1056             :         AsciiPropertyValue( "EnableSQL92Check",           makeAny( false ) ),
    1057             :         AsciiPropertyValue( "BooleanComparisonMode",      makeAny( BooleanComparisonMode::EQUAL_INTEGER ) ),
    1058             :         AsciiPropertyValue( "TableTypeFilterMode",        makeAny( (sal_Int32)3 ) ),
    1059             :         AsciiPropertyValue( "RespectDriverResultSetType", makeAny( false ) ),
    1060             :         AsciiPropertyValue( "UseSchemaInSelect",          makeAny( true ) ),
    1061             :         AsciiPropertyValue( "UseCatalogInSelect",         makeAny( true ) ),
    1062             :         AsciiPropertyValue( "EnableOuterJoinEscape",      makeAny( true ) ),
    1063             :         AsciiPropertyValue( "PreferDosLikeLineEnds",      makeAny( false ) ),
    1064             :         AsciiPropertyValue( "FormsCheckRequiredFields",   makeAny( true ) ),
    1065             :         AsciiPropertyValue( "EscapeDateTime",             makeAny( true ) ),
    1066             : 
    1067             :         // known services to handle database tasks
    1068             :         AsciiPropertyValue( "TableAlterationServiceName", makeAny( OUString() ) ),
    1069             :         AsciiPropertyValue( "TableRenameServiceName",     makeAny( OUString() ) ),
    1070             :         AsciiPropertyValue( "ViewAlterationServiceName",  makeAny( OUString() ) ),
    1071             :         AsciiPropertyValue( "ViewAccessServiceName",      makeAny( OUString() ) ),
    1072             :         AsciiPropertyValue( "CommandDefinitions",         makeAny( OUString() ) ),
    1073             :         AsciiPropertyValue( "Forms",                      makeAny( OUString() ) ),
    1074             :         AsciiPropertyValue( "Reports",                    makeAny( OUString() ) ),
    1075             :         AsciiPropertyValue( "KeyAlterationServiceName",   makeAny( OUString() ) ),
    1076             :         AsciiPropertyValue( "IndexAlterationServiceName", makeAny( OUString() ) ),
    1077             : 
    1078             :         AsciiPropertyValue()
    1079         388 :     };
    1080         284 :     return aKnownSettings;
    1081             : }
    1082             : 
    1083        1504 : TContentPtr& ODatabaseModelImpl::getObjectContainer( ObjectType _eType )
    1084             : {
    1085             :     OSL_PRECOND( _eType >= E_FORM && _eType <= E_TABLE, "ODatabaseModelImpl::getObjectContainer: illegal index!" );
    1086        1504 :     TContentPtr& rContentPtr = m_aContainer[ _eType ];
    1087             : 
    1088        1504 :     if ( !rContentPtr.get() )
    1089             :     {
    1090         830 :         rContentPtr = TContentPtr( new ODefinitionContainer_Impl );
    1091         830 :         rContentPtr->m_pDataSource = this;
    1092         830 :         rContentPtr->m_aProps.aTitle = lcl_getContainerStorageName_throw( _eType );
    1093             :     }
    1094        1504 :     return rContentPtr;
    1095             : }
    1096             : 
    1097         212 : void ODatabaseModelImpl::revokeDataSource() const
    1098             : {
    1099         212 :     if ( m_pDBContext && !m_sDocumentURL.isEmpty() )
    1100         208 :         m_pDBContext->revokeDatabaseDocument( *this );
    1101         212 : }
    1102             : 
    1103           0 : bool ODatabaseModelImpl::adjustMacroMode_AutoReject()
    1104             : {
    1105           0 :     return m_aMacroMode.adjustMacroMode( NULL );
    1106             : }
    1107             : 
    1108          16 : bool ODatabaseModelImpl::checkMacrosOnLoading()
    1109             : {
    1110          16 :     Reference< XInteractionHandler > xInteraction;
    1111          16 :     xInteraction = m_aMediaDescriptor.getOrDefault( "InteractionHandler", xInteraction );
    1112          16 :     return m_aMacroMode.checkMacrosOnLoading( xInteraction );
    1113             : }
    1114             : 
    1115         210 : void ODatabaseModelImpl::resetMacroExecutionMode()
    1116             : {
    1117         210 :     m_aMacroMode = ::sfx2::DocumentMacroMode( *this );
    1118         210 : }
    1119             : 
    1120          22 : Reference< XStorageBasedLibraryContainer > ODatabaseModelImpl::getLibraryContainer( bool _bScript )
    1121             : {
    1122          22 :     Reference< XStorageBasedLibraryContainer >& rxContainer( _bScript ? m_xBasicLibraries : m_xDialogLibraries );
    1123          22 :     if ( rxContainer.is() )
    1124           0 :         return rxContainer;
    1125             : 
    1126          22 :     Reference< XStorageBasedDocument > xDocument( getModel_noCreate(), UNO_QUERY_THROW );
    1127             :         // this is only to be called if there already exists a document model - in fact, it is
    1128             :         // to be called by the document model only
    1129             : 
    1130             :     try
    1131             :     {
    1132             :         Reference< XStorageBasedLibraryContainer > (*Factory)( const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&)
    1133          22 :             = _bScript ? &DocumentScriptLibraryContainer::create : &DocumentDialogLibraryContainer::create;
    1134             : 
    1135             :         rxContainer.set(
    1136             :             (*Factory)( m_aContext, xDocument ),
    1137             :             UNO_QUERY_THROW
    1138          22 :         );
    1139             :     }
    1140           0 :     catch( const RuntimeException& )
    1141             :     {
    1142           0 :         throw;
    1143             :     }
    1144           0 :     catch( const Exception& )
    1145             :     {
    1146             :         throw WrappedTargetRuntimeException(
    1147             :             OUString(),
    1148             :             xDocument,
    1149             :             ::cppu::getCaughtException()
    1150           0 :         );
    1151             :     }
    1152          22 :     return rxContainer;
    1153             : }
    1154             : 
    1155         184 : void ODatabaseModelImpl::storeLibraryContainersTo( const Reference< XStorage >& _rxToRootStorage )
    1156             : {
    1157         184 :     if ( m_xBasicLibraries.is() )
    1158           6 :         m_xBasicLibraries->storeLibrariesToStorage( _rxToRootStorage );
    1159             : 
    1160         184 :     if ( m_xDialogLibraries.is() )
    1161           6 :         m_xDialogLibraries->storeLibrariesToStorage( _rxToRootStorage );
    1162         184 : }
    1163             : 
    1164         176 : Reference< XStorage > ODatabaseModelImpl::switchToStorage( const Reference< XStorage >& _rxNewRootStorage )
    1165             : {
    1166         176 :     if ( !_rxNewRootStorage.is() )
    1167           0 :         throw IllegalArgumentException();
    1168             : 
    1169         176 :     return impl_switchToStorage_throw( _rxNewRootStorage );
    1170             : }
    1171             : 
    1172             : namespace
    1173             : {
    1174         944 :     void lcl_modifyListening( ::sfx2::IModifiableDocument& _rDocument,
    1175             :         const Reference< XStorage >& _rxStorage, ::rtl::Reference< ::sfx2::DocumentStorageModifyListener >& _inout_rListener,
    1176             :         comphelper::SolarMutex& _rMutex, bool _bListen )
    1177             :     {
    1178         944 :         Reference< XModifiable > xModify( _rxStorage, UNO_QUERY );
    1179             :         OSL_ENSURE( xModify.is() || !_rxStorage.is(), "lcl_modifyListening: storage can't notify us!" );
    1180             : 
    1181         944 :         if ( xModify.is() && !_bListen && _inout_rListener.is() )
    1182             :         {
    1183         208 :             xModify->removeModifyListener( _inout_rListener.get() );
    1184             :         }
    1185             : 
    1186         944 :         if ( _inout_rListener.is() )
    1187             :         {
    1188         208 :             _inout_rListener->dispose();
    1189         208 :             _inout_rListener = NULL;
    1190             :         }
    1191             : 
    1192         944 :         if ( xModify.is() && _bListen )
    1193             :         {
    1194         210 :             _inout_rListener = new ::sfx2::DocumentStorageModifyListener( _rDocument, _rMutex );
    1195         210 :             xModify->addModifyListener( _inout_rListener.get() );
    1196         944 :         }
    1197         944 :     }
    1198             : }
    1199             : 
    1200             : namespace
    1201             : {
    1202         944 :     static void lcl_rebaseScriptStorage_throw( const Reference< XStorageBasedLibraryContainer >& _rxContainer,
    1203             :         const Reference< XStorage >& _rxNewRootStorage )
    1204             :     {
    1205         944 :         if ( _rxContainer.is() )
    1206             :         {
    1207           0 :             if ( _rxNewRootStorage.is() )
    1208           0 :                 _rxContainer->setRootStorage( _rxNewRootStorage );
    1209             : //            else
    1210             :                    // TODO: what to do here? dispose the container?
    1211             :         }
    1212         944 :     }
    1213             : }
    1214             : 
    1215         472 : Reference< XStorage > ODatabaseModelImpl::impl_switchToStorage_throw( const Reference< XStorage >& _rxNewRootStorage )
    1216             : {
    1217             :     // stop listening for modifications at the old storage
    1218         472 :     lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, false );
    1219             : 
    1220             :     // set new storage
    1221         472 :     m_xDocumentStorage.reset( _rxNewRootStorage, SharedStorage::TakeOwnership );
    1222             : 
    1223             :     // start listening for modifications
    1224         472 :     lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, true );
    1225             : 
    1226             :     // forward new storage to Basic and Dialog library containers
    1227         472 :     lcl_rebaseScriptStorage_throw( m_xBasicLibraries, m_xDocumentStorage.getTyped() );
    1228         472 :     lcl_rebaseScriptStorage_throw( m_xDialogLibraries, m_xDocumentStorage.getTyped() );
    1229             : 
    1230         472 :     m_bReadOnly = !tools::stor::storageIsWritable_nothrow( m_xDocumentStorage.getTyped() );
    1231             :     // TODO: our data source, if it exists, must broadcast the change of its ReadOnly property
    1232             : 
    1233         472 :     return m_xDocumentStorage.getTyped();
    1234             : }
    1235             : 
    1236         218 : void ODatabaseModelImpl::impl_switchToLogicalURL( const OUString& i_rDocumentURL )
    1237             : {
    1238         218 :     if ( i_rDocumentURL == m_sDocumentURL )
    1239         226 :         return;
    1240             : 
    1241         210 :     const OUString sOldURL( m_sDocumentURL );
    1242             :     // update our name, if necessary
    1243         420 :     if  (   ( m_sName == m_sDocumentURL )   // our name is our old URL
    1244         210 :         ||  ( m_sName.isEmpty() )        // we do not have a name, yet (i.e. are not registered at the database context)
    1245             :         )
    1246             :     {
    1247         192 :         INetURLObject aURL( i_rDocumentURL );
    1248         192 :         if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
    1249             :         {
    1250         192 :             m_sName = i_rDocumentURL;
    1251             :             // TODO: our data source must broadcast the change of the Name property
    1252         192 :         }
    1253             :     }
    1254             : 
    1255             :     // remember URL
    1256         210 :     m_sDocumentURL = i_rDocumentURL;
    1257             : 
    1258             :     // update our location, if necessary
    1259         210 :     if  ( m_sDocFileLocation.isEmpty() )
    1260          34 :         m_sDocFileLocation = m_sDocumentURL;
    1261             : 
    1262             :     // register at the database context, or change registration
    1263         210 :     if ( m_pDBContext )
    1264             :     {
    1265         210 :         if ( !sOldURL.isEmpty() )
    1266           0 :             m_pDBContext->databaseDocumentURLChange( sOldURL, m_sDocumentURL );
    1267             :         else
    1268         210 :             m_pDBContext->registerDatabaseDocument( *this );
    1269         210 :     }
    1270             : }
    1271             : 
    1272          56 : OUString ODatabaseModelImpl::getObjectContainerStorageName( const ObjectType _eType )
    1273             : {
    1274          56 :     return lcl_getContainerStorageName_throw( _eType );
    1275             : }
    1276             : 
    1277          16 : sal_Int16 ODatabaseModelImpl::getCurrentMacroExecMode() const
    1278             : {
    1279          16 :     sal_Int16 nCurrentMode = MacroExecMode::NEVER_EXECUTE;
    1280             :     try
    1281             :     {
    1282          16 :         nCurrentMode = m_aMediaDescriptor.getOrDefault( "MacroExecutionMode", nCurrentMode );
    1283             :     }
    1284           0 :     catch( const Exception& )
    1285             :     {
    1286             :         DBG_UNHANDLED_EXCEPTION();
    1287             :     }
    1288          16 :     return nCurrentMode;
    1289             : }
    1290             : 
    1291           8 : bool ODatabaseModelImpl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
    1292             : {
    1293           8 :     m_aMediaDescriptor.put( "MacroExecutionMode", nMacroMode );
    1294           8 :     return true;
    1295             : }
    1296             : 
    1297           0 : OUString ODatabaseModelImpl::getDocumentLocation() const
    1298             : {
    1299           0 :     return getURL();
    1300             :     // formerly, we returned getDocFileLocation here, which is the location of the file from which we
    1301             :     // recovered the "real" document.
    1302             :     // However, during CWS autorecovery evolving, we clarified (with MAV/MT) the role of XModel::getURL and
    1303             :     // XStorable::getLocation. In this course, we agreed that for a macro security check, the *document URL*
    1304             :     // (not the recovery file URL) is to be used: The recovery file lies in the backup folder, and by definition,
    1305             :     // this folder is considered to be secure. So, the document URL needs to be used to decide about the security.
    1306             : }
    1307             : 
    1308           0 : Reference< XStorage > ODatabaseModelImpl::getZipStorageToSign()
    1309             : {
    1310             :     // we do not support signing the scripting storages, so we're allowed to
    1311             :     // return <NULL/> here.
    1312           0 :     return Reference< XStorage >();
    1313             : }
    1314             : 
    1315          50 : ODatabaseModelImpl::EmbeddedMacros ODatabaseModelImpl::determineEmbeddedMacros()
    1316             : {
    1317          50 :     if ( !m_aEmbeddedMacros )
    1318             :     {
    1319          34 :         if ( ::sfx2::DocumentMacroMode::storageHasMacros( const_cast< ODatabaseModelImpl* >( this )->getOrCreateRootStorage() ) )
    1320             :         {
    1321           6 :             m_aEmbeddedMacros.reset( eDocumentWideMacros );
    1322             :         }
    1323          56 :         else if (   lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_FORM )
    1324          28 :                 ||  lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_REPORT )
    1325             :                 )
    1326             :         {
    1327           0 :             m_aEmbeddedMacros.reset( eSubDocumentMacros );
    1328             :         }
    1329             :         else
    1330             :         {
    1331          28 :             m_aEmbeddedMacros.reset( eNoMacros );
    1332             :         }
    1333             :     }
    1334          50 :     return *m_aEmbeddedMacros;
    1335             : }
    1336             : 
    1337          16 : bool ODatabaseModelImpl::documentStorageHasMacros() const
    1338             : {
    1339          16 :     const_cast< ODatabaseModelImpl* >( this )->determineEmbeddedMacros();
    1340          16 :     return ( *m_aEmbeddedMacros != eNoMacros );
    1341             : }
    1342             : 
    1343          10 : Reference< XEmbeddedScripts > ODatabaseModelImpl::getEmbeddedDocumentScripts() const
    1344             : {
    1345          10 :     return Reference< XEmbeddedScripts >( getModel_noCreate(), UNO_QUERY );
    1346             : }
    1347             : 
    1348           0 : sal_Int16 ODatabaseModelImpl::getScriptingSignatureState()
    1349             : {
    1350             :     // no support for signatures at the moment
    1351           0 :     return SIGNATURESTATE_NOSIGNATURES;
    1352             : }
    1353             : 
    1354           0 : bool ODatabaseModelImpl::hasTrustedScriptingSignature( bool /*bAllowUIToAddAuthor*/ )
    1355             : {
    1356             :     // no support for signatures at the moment
    1357           0 :     return false;
    1358             : }
    1359             : 
    1360           0 : void ODatabaseModelImpl::showBrokenSignatureWarning( const Reference< XInteractionHandler >& /*_rxInteraction*/ ) const
    1361             : {
    1362             :     OSL_FAIL( "ODatabaseModelImpl::showBrokenSignatureWarning: signatures can't be broken - we do not support them!" );
    1363           0 : }
    1364             : 
    1365        2226 : void ODatabaseModelImpl::storageIsModified()
    1366             : {
    1367        2226 :     setModified( true );
    1368        2226 : }
    1369             : 
    1370         706 : ModelDependentComponent::ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model )
    1371             :     :m_pImpl( _model )
    1372         706 :     ,m_aMutex( _model->getSharedMutex() )
    1373             : {
    1374         706 : }
    1375             : 
    1376         690 : ModelDependentComponent::~ModelDependentComponent()
    1377             : {
    1378         690 : }
    1379             : 
    1380             : }   // namespace dbaccess
    1381             : 
    1382             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10