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

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

Generated by: LCOV version 1.10