LCOV - code coverage report
Current view: top level - dbaccess/source/core/dataaccess - ModelImpl.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 58 0.0 %
Date: 2014-04-14 Functions: 0 31 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             : #ifndef INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_MODELIMPL_HXX
      21             : #define INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_MODELIMPL_HXX
      22             : 
      23             : #include "apitools.hxx"
      24             : #include "bookmarkcontainer.hxx"
      25             : #include "ContentHelper.hxx"
      26             : #include "core_resource.hxx"
      27             : #include "documentevents.hxx"
      28             : 
      29             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      30             : #include <com/sun/star/beans/PropertyValue.hpp>
      31             : #include <com/sun/star/beans/XPropertyBag.hpp>
      32             : #include <com/sun/star/container/XContainerListener.hpp>
      33             : #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
      34             : #include <com/sun/star/document/XEventListener.hpp>
      35             : #include <com/sun/star/document/XStorageBasedDocument.hpp>
      36             : #include <com/sun/star/embed/ElementModes.hpp>
      37             : #include <com/sun/star/embed/XStorage.hpp>
      38             : #include <com/sun/star/embed/XTransactionListener.hpp>
      39             : #include <com/sun/star/frame/XModel.hpp>
      40             : #include <com/sun/star/frame/XStorable.hpp>
      41             : #include <com/sun/star/lang/NotInitializedException.hpp>
      42             : #include <com/sun/star/lang/XServiceInfo.hpp>
      43             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      44             : #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
      45             : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      46             : #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp>
      47             : #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
      48             : #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp>
      49             : #include <com/sun/star/sdbc/XDataSource.hpp>
      50             : #include <com/sun/star/sdbc/XIsolatedConnection.hpp>
      51             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      52             : #include <com/sun/star/util/XCloseable.hpp>
      53             : #include <com/sun/star/util/XFlushable.hpp>
      54             : #include <com/sun/star/util/XModifiable.hpp>
      55             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      56             : #include <com/sun/star/util/XNumberFormatter.hpp>
      57             : #include <com/sun/star/util/XRefreshable.hpp>
      58             : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
      59             : #include <com/sun/star/frame/DoubleInitializationException.hpp>
      60             : 
      61             : #include <comphelper/broadcasthelper.hxx>
      62             : #include <comphelper/namedvaluecollection.hxx>
      63             : #include <comphelper/proparrhlp.hxx>
      64             : #include <comphelper/sharedmutex.hxx>
      65             : #include <comphelper/solarmutex.hxx>
      66             : #include <connectivity/CommonTools.hxx>
      67             : #include <cppuhelper/propshlp.hxx>
      68             : #include <cppuhelper/weakref.hxx>
      69             : #include <sfx2/docmacromode.hxx>
      70             : #include <sfx2/docstoragemodifylistener.hxx>
      71             : #include <unotools/sharedunocomponent.hxx>
      72             : #include <rtl/ref.hxx>
      73             : 
      74             : namespace comphelper
      75             : {
      76             :     class NamedValueCollection;
      77             : }
      78             : 
      79             : namespace dbaccess
      80             : {
      81             : 
      82             : typedef ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XConnection > OWeakConnection;
      83             : typedef std::vector< OWeakConnection > OWeakConnectionArray;
      84             : 
      85           0 : struct AsciiPropertyValue
      86             : {
      87             :     // note: the canonic member order would be AsciiName / DefaultValue, but
      88             :     // this crashes on unxlngi6.pro, since there's a bug which somehow results in
      89             :     // getDefaultDataSourceSettings returning corrupted Any instances then.
      90             :     ::com::sun::star::uno::Any          DefaultValue;
      91             :     const sal_Char*                     AsciiName;
      92             :     const ::com::sun::star::uno::Type&  ValueType;
      93             : 
      94           0 :     AsciiPropertyValue()
      95             :         :DefaultValue( )
      96             :         ,AsciiName( NULL )
      97           0 :         ,ValueType( ::cppu::UnoType< ::cppu::UnoVoidType >::get() )
      98             :     {
      99           0 :     }
     100             : 
     101           0 :     AsciiPropertyValue( const sal_Char* _pAsciiName, const ::com::sun::star::uno::Any& _rDefaultValue )
     102             :         :DefaultValue( _rDefaultValue )
     103             :         ,AsciiName( _pAsciiName )
     104           0 :         ,ValueType( _rDefaultValue.getValueType() )
     105             :     {
     106             :         OSL_ENSURE( ValueType.getTypeClass() != ::com::sun::star::uno::TypeClass_VOID,
     107             :             "AsciiPropertyValue::AsciiPropertyValue: NULL values not allowed here, use the other CTOR for this!" );
     108           0 :     }
     109           0 :     AsciiPropertyValue( const sal_Char* _pAsciiName, const ::com::sun::star::uno::Type& _rValeType )
     110             :         :DefaultValue()
     111             :         ,AsciiName( _pAsciiName )
     112           0 :         ,ValueType( _rValeType )
     113             :     {
     114             :         OSL_ENSURE( ValueType.getTypeClass() != ::com::sun::star::uno::TypeClass_VOID,
     115             :             "AsciiPropertyValue::AsciiPropertyValue: VOID property values not supported!" );
     116           0 :     }
     117             : };
     118             : 
     119             : class ODatabaseContext;
     120             : class OSharedConnectionManager;
     121             : 
     122             : // VosMutexFacade
     123             : /** a class which provides an IMutex interface to an OSL-based mutex
     124             : */
     125           0 : class VosMutexFacade : public comphelper::SolarMutex
     126             : {
     127             : public:
     128             :     /** beware of life time: the mutex you pass here must live as least as long
     129             :         as the VosMutexFacade instance lives.
     130             :     */
     131             :     VosMutexFacade( ::osl::Mutex& _rMutex );
     132             : 
     133             :     virtual void acquire() SAL_OVERRIDE;
     134             :     virtual void release() SAL_OVERRIDE;
     135             :     virtual bool tryToAcquire() SAL_OVERRIDE;
     136             : 
     137             : private:
     138             :     ::osl::Mutex&   m_rMutex;
     139             : };
     140             : 
     141             : // ODatabaseModelImpl
     142             : typedef ::utl::SharedUNOComponent< ::com::sun::star::embed::XStorage >  SharedStorage;
     143             : 
     144             : class ODatabaseContext;
     145             : class DocumentStorageAccess;
     146             : class OSharedConnectionManager;
     147             : class ODatabaseModelImpl    :public ::rtl::IReference
     148             :                             ,public ::sfx2::IMacroDocumentAccess
     149             :                             ,public ::sfx2::IModifiableDocument
     150             : {
     151             : public:
     152             :     enum ObjectType
     153             :     {
     154             :         E_FORM   = 0,
     155             :         E_REPORT = 1,
     156             :         E_QUERY  = 2,
     157             :         E_TABLE  = 3
     158             :     };
     159             : 
     160             :     enum EmbeddedMacros
     161             :     {
     162             :         // the database document (storage) itself contains macros
     163             :         eDocumentWideMacros,
     164             :         // there are sub document( storage)s containing macros
     165             :         eSubDocumentMacros,
     166             :         // there are no known macro( storage)s
     167             :         eNoMacros
     168             :     };
     169             : 
     170             : private:
     171             :     OModuleClient                                                               m_aModuleClient;
     172             :     ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel >     m_xModel;
     173             :     ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDataSource > m_xDataSource;
     174             : 
     175             :     DocumentStorageAccess*                                                      m_pStorageAccess;
     176             :     ::comphelper::SharedMutex                                                   m_aMutex;
     177             :     VosMutexFacade                                                              m_aMutexFacade;
     178             :     ::std::vector< TContentPtr >                                                m_aContainer;   // one for each ObjectType
     179             :     ::sfx2::DocumentMacroMode                                                   m_aMacroMode;
     180             :     sal_Int16                                                                   m_nImposedMacroExecMode;
     181             : 
     182             :     ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer > m_xBasicLibraries;
     183             :     ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer > m_xDialogLibraries;
     184             : 
     185             :     SharedStorage                                                               m_xDocumentStorage;
     186             :     ::rtl::Reference< ::sfx2::DocumentStorageModifyListener >                   m_pStorageModifyListener;
     187             :     ODatabaseContext*                                                           m_pDBContext;
     188             :     DocumentEventsData                                                          m_aDocumentEvents;
     189             : 
     190             :     ::comphelper::NamedValueCollection                                          m_aMediaDescriptor;
     191             :     /// the URL the document was loaded from
     192             :     OUString                                                             m_sDocFileLocation;
     193             : 
     194             :     oslInterlockedCount                                 m_refCount;
     195             : 
     196             :     /// do we have any object (forms/reports) which contains macros?
     197             :     ::boost::optional< EmbeddedMacros >                 m_aEmbeddedMacros;
     198             : 
     199             :     /// true if setting the Modified flag of the document is currently locked
     200             :     bool                                                m_bModificationLock;
     201             : 
     202             :     /// true if and only if a database document existed previously (though meanwhile disposed), and was already initialized
     203             :     bool                                                m_bDocumentInitialized;
     204             : 
     205             :     /** the URL which the document should report as its URL
     206             : 
     207             :         This might differ from ->m_sDocFileLocation in case the document was loaded
     208             :         as part of a crash recovery process. In this case, ->m_sDocFileLocation points to
     209             :         the temporary file where the DB had been saved to, after a crash.
     210             :         ->m_sDocumentURL then is the URL of the document which actually had
     211             :         been recovered.
     212             :     */
     213             :     OUString                                     m_sDocumentURL;
     214             : 
     215             : public:
     216             :     OWeakConnectionArray                                                        m_aConnections;
     217             :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_aContext;
     218             : 
     219             : public:
     220             :     ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess >    m_xCommandDefinitions;
     221             :     ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess >    m_xTableDefinitions;
     222             : 
     223             :     ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >
     224             :                                                         m_xNumberFormatsSupplier;
     225             :     OUString                                     m_sConnectURL;
     226             :     OUString                                     m_sName;        // transient, our creator has to tell us the title
     227             :     OUString                                     m_sUser;
     228             :     OUString                                     m_aPassword;    // transient !
     229             :     OUString                                     m_sFailedPassword;
     230             :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>
     231             :                                                         m_aLayoutInformation;
     232             :     sal_Int32                                           m_nLoginTimeout;
     233             :     sal_Bool                                            m_bReadOnly : 1;
     234             :     sal_Bool                                            m_bPasswordRequired : 1;
     235             :     sal_Bool                                            m_bSuppressVersionColumns : 1;
     236             :     sal_Bool                                            m_bModified : 1;
     237             :     sal_Bool                                            m_bDocumentReadOnly : 1;
     238             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyBag >
     239             :                                                         m_xSettings;
     240             :     ::com::sun::star::uno::Sequence< OUString >  m_aTableFilter;
     241             :     ::com::sun::star::uno::Sequence< OUString >  m_aTableTypeFilter;
     242             :     OSharedConnectionManager*                           m_pSharedConnectionManager;
     243             :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >
     244             :                                                         m_xSharedConnectionManager;
     245             :     sal_uInt16                                          m_nControllerLockCount;
     246             : 
     247             :     void reset();
     248             : 
     249             :     /** determines whether the database document has an embedded data storage
     250             :     */
     251           0 :     inline bool isEmbeddedDatabase() const { return ( m_sConnectURL.startsWith("sdbc:embedded:") ); }
     252             : 
     253             :     /** stores the embedded storage ("database")
     254             : 
     255             :         @param _bPreventRootCommits
     256             :             Normally, committing the embedded storage results in also commiting the root storage
     257             :             - this is an automatism for data safety reasons.
     258             :             If you pass <TRUE/> here, committing the root storage is prevented for this particular
     259             :             call.
     260             :         @return <TRUE/> if the storage could be commited, otherwise <FALSE/>
     261             :     */
     262             :     bool        commitEmbeddedStorage( bool _bPreventRootCommits = false );
     263             : 
     264             :     /// commits all sub storages
     265             :     void commitStorages()
     266             :             SAL_THROW(( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException ));
     267             : 
     268             :     ODatabaseModelImpl(
     269             :         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
     270             :         ODatabaseContext& _pDBContext
     271             :     );
     272             :     virtual ~ODatabaseModelImpl();
     273             : 
     274             :     ODatabaseModelImpl(
     275             :         const OUString& _rRegistrationName,
     276             :         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
     277             :         ODatabaseContext& _rDBContext
     278             :         );
     279             : 
     280             :     // XEventListener
     281             :     void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
     282             : 
     283             :     void setModified( sal_Bool bModified );
     284             : 
     285             :     void dispose();
     286             : 
     287           0 :     inline OUString getURL() const               { return m_sDocumentURL;     }
     288           0 :     inline OUString getDocFileLocation() const   { return m_sDocFileLocation; }
     289             : 
     290             :     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
     291             :             getStorage(
     292             :                 const ObjectType _eType, const sal_Int32 _nDesiredMode = ::com::sun::star::embed::ElementModes::READWRITE );
     293             : 
     294             : // helper
     295             :     const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >&
     296             :             getNumberFormatsSupplier();
     297             : 
     298             :     DocumentEventsData&
     299           0 :             getDocumentEvents() { return m_aDocumentEvents; }
     300             : 
     301             :     const ::comphelper::NamedValueCollection&
     302           0 :             getMediaDescriptor() const { return m_aMediaDescriptor; }
     303             : 
     304             :     void    setResource(
     305             :                 const OUString& _rURL,
     306             :                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs
     307             :             );
     308             :     void    setDocFileLocation(
     309             :                 const OUString& i_rLoadedFrom
     310             :             );
     311             : 
     312             :     static ::comphelper::NamedValueCollection
     313             :             stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments );
     314             : 
     315             : // other stuff
     316             :     void    flushTables();
     317             : 
     318             :     // disposes all elements in m_aStorages, and clears it
     319             :     void    disposeStorages() SAL_THROW(());
     320             : 
     321             :     /// creates a ->com::sun::star::embed::StorageFactory
     322             :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >
     323             :             createStorageFactory() const;
     324             : 
     325             :     /// commits our storage
     326             :     void    commitRootStorage();
     327             : 
     328             :     /// commits a given storage if it's not readonly, ignoring (but asserting) all errors
     329             :     static  bool    commitStorageIfWriteable_ignoreErrors(
     330             :                 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage
     331             :             )
     332             :             SAL_THROW(());
     333             : 
     334             :     void clearConnections();
     335             : 
     336             :             ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getOrCreateRootStorage();
     337           0 :     inline  ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getRootStorage() const { return m_xDocumentStorage.getTyped(); }
     338           0 :     inline  void resetRootStorage() { impl_switchToStorage_throw( NULL ); }
     339             : 
     340             :     /** returns the data source. If it doesn't exist it will be created
     341             :     */
     342             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> getOrCreateDataSource();
     343             : 
     344             :     /** returns the model, if there already exists one
     345             :     */
     346             :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > getModel_noCreate() const;
     347             : 
     348             :     /** returns a new ->ODatabaseDocument
     349             : 
     350             :         @param _bInitializeIfNecessary
     351             :             calls XLoadable::initNew on the newly created model, if necessary
     352             : 
     353             :         @precond
     354             :             No ->ODatabaseDocument exists so far
     355             : 
     356             :         @seealso
     357             :             getModel_noCreate
     358             :     */
     359             :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > createNewModel_deliverOwnership( bool _bInitialize );
     360             : 
     361           0 :     struct ResetModelAccess { friend class ODatabaseDocument; private: ResetModelAccess() { } };
     362             : 
     363             :     /** resets the model to NULL
     364             : 
     365             :         Only to be called when the model is being disposed
     366             :     */
     367             :     void    modelIsDisposing( const bool _wasInitialized, ResetModelAccess );
     368             : 
     369           0 :     bool    hadInitializedDocument() const { return m_bDocumentInitialized; }
     370             : 
     371             :     DocumentStorageAccess*
     372             :             getDocumentStorageAccess();
     373             : 
     374             :     ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentSubStorageSupplier >
     375             :             getDocumentSubStorageSupplier();
     376             : 
     377           0 :     inline const ::comphelper::SharedMutex& getSharedMutex() const { return m_aMutex; }
     378             : 
     379             :     /** @see osl_incrementInterlockedCount.
     380             :      */
     381             :     virtual oslInterlockedCount SAL_CALL acquire() SAL_OVERRIDE;
     382             : 
     383             :     /** @see osl_decrementInterlockedCount.
     384             :      */
     385             :     virtual oslInterlockedCount SAL_CALL release() SAL_OVERRIDE;
     386             : 
     387             :     /// returns a all known data source settings, including their default values
     388             :     static const AsciiPropertyValue* getDefaultDataSourceSettings();
     389             : 
     390             :     /** retrieves the requested container of objects (forms/reports/tables/queries)
     391             :     */
     392             :     TContentPtr&    getObjectContainer( const ObjectType _eType );
     393             : 
     394             :     /** returns the name of the storage which is used to stored objects of the given type, if applicable
     395             :     */
     396             :     static OUString
     397             :                     getObjectContainerStorageName( const ObjectType _eType );
     398             : 
     399             :     /** revokes the data source registration at the database context
     400             :     */
     401             :     void            revokeDataSource() const;
     402             : 
     403             :     /** determines whether a given object storage contains macros
     404             :     */
     405             :     static bool     objectHasMacros(
     406             :                         const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxContainerStorage,
     407             :                         const OUString& _rPersistentName
     408             :                     );
     409             : 
     410             :     /** determines which kind of embedded macros are present in the document
     411             :     */
     412             :     EmbeddedMacros  determineEmbeddedMacros();
     413             : 
     414             :     /** checks our document's macro execution mode, using the interaction handler as supplied with our
     415             :         load arguments
     416             :     */
     417             :     bool            checkMacrosOnLoading();
     418             : 
     419             :     /** adjusts our document's macro execution mode, without using any UI, assuming the user
     420             :         would reject execution of macros, if she would have been asked.
     421             : 
     422             :         If checkMacrosOnLoading has been called before (and thus the macro execution mode
     423             :         is already adjusted), then the current execution mode is simply returned.
     424             : 
     425             :         @return
     426             :             whether or not macro execution is allowed
     427             :     */
     428             :     bool            adjustMacroMode_AutoReject();
     429             : 
     430             :     /** resets our macro execute mode, so next time  the checkMacrosOnLoading is called, it will
     431             :         behave as if it has never been called before
     432             :     */
     433             :     void            resetMacroExecutionMode();
     434             : 
     435             :     /** ensures that ->m_xBasicLibraries resp. m_xDialogLibraries exists
     436             : 
     437             :         @return
     438             :             the requested library container. Is never <NULL/>.
     439             : 
     440             :         @throws RuntimeException
     441             :             if something does wrong, which indicates a server error in the installation
     442             :     */
     443             :     ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer >
     444             :             getLibraryContainer( bool _bScript );
     445             : 
     446             :     /** lets our library containers store themself into the given root storage
     447             :     */
     448             :     void    storeLibraryContainersTo( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxToRootStorage );
     449             : 
     450             :     /** rebases the document to the given storage
     451             : 
     452             :         No actual committing, copying, saving, whatsoever happens. The storage is just remembered as the documents
     453             :         new storage, nothing more.
     454             : 
     455             :         @throws ::com::sun::star::lang::IllegalArgumentException
     456             :             if the given storage is <NULL/>
     457             :         @throws ::com::sun::star::lang::RuntimeException
     458             :             if any of the invoked operations does so
     459             :     */
     460             :     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
     461             :             switchToStorage(
     462             :                 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage
     463             :             );
     464             : 
     465             :     /** returns the macro mode imposed by an external instance, which passed it to attachResource
     466             :     */
     467           0 :     sal_Int16       getImposedMacroExecMode() const
     468             :     {
     469           0 :         return m_nImposedMacroExecMode;
     470             :     }
     471           0 :     void            setImposedMacroExecMode( const sal_Int16 _nMacroMode )
     472             :     {
     473           0 :         m_nImposedMacroExecMode = _nMacroMode;
     474           0 :     }
     475             : 
     476             : public:
     477             :     // IMacroDocumentAccess overridables
     478             :     virtual sal_Int16 getCurrentMacroExecMode() const SAL_OVERRIDE;
     479             :     virtual bool setCurrentMacroExecMode( sal_uInt16 ) SAL_OVERRIDE;
     480             :     virtual OUString getDocumentLocation() const SAL_OVERRIDE;
     481             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getZipStorageToSign() SAL_OVERRIDE;
     482             :     virtual bool documentStorageHasMacros() const SAL_OVERRIDE;
     483             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > getEmbeddedDocumentScripts() const SAL_OVERRIDE;
     484             :     virtual sal_Int16 getScriptingSignatureState() SAL_OVERRIDE;
     485             :     virtual bool hasTrustedScriptingSignature( bool bAllowUIToAddAuthor ) SAL_OVERRIDE;
     486             :     virtual void showBrokenSignatureWarning( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction ) const SAL_OVERRIDE;
     487             : 
     488             :     // IModifiableDocument
     489             :     virtual void storageIsModified() SAL_OVERRIDE;
     490             : 
     491             :     // don't use directly, use the ModifyLock class instead
     492           0 :     void    lockModify()              { m_bModificationLock = true; }
     493           0 :     void    unlockModify()            { m_bModificationLock = false; }
     494           0 :     bool    isModifyLocked() const    { return m_bModificationLock; }
     495             : 
     496             : private:
     497             :     void    impl_construct_nothrow();
     498             :     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
     499             :             impl_switchToStorage_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage );
     500             : 
     501             :     /** switches to the given document URL, which denotes the logical URL of the document, not necessariy the
     502             :         URL where the doc was loaded/recovered from
     503             :     */
     504             :     void    impl_switchToLogicalURL(
     505             :                 const OUString& i_rDocumentURL
     506             :             );
     507             : 
     508             : };
     509             : 
     510             : /** a small base class for UNO components whose functionality depends on a ODatabaseModelImpl
     511             : */
     512             : class ModelDependentComponent
     513             : {
     514             : protected:
     515             :     ::rtl::Reference< ODatabaseModelImpl >  m_pImpl;
     516             :     mutable ::comphelper::SharedMutex       m_aMutex;
     517             : 
     518             : protected:
     519             :     ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model );
     520             :     virtual ~ModelDependentComponent();
     521             : 
     522             :     /** returns the component itself
     523             :     */
     524             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getThis() const = 0;
     525             : 
     526           0 :     inline ::osl::Mutex& getMutex() const
     527             :     {
     528           0 :         return m_aMutex;
     529             :     }
     530             : 
     531             : public:
     532           0 :     struct GuardAccess { friend class ModelMethodGuard; private: GuardAccess() { } };
     533             : 
     534             :     /** returns the mutex used for thread safety
     535             : 
     536             :         @throws ::com::sun::star::lang::DisposedException
     537             :             if m_pImpl is <NULL/>. Usually, you will set this member in your derived
     538             :             component's <code>dispose</code> method to <NULL/>.
     539             :     */
     540           0 :     inline ::osl::Mutex& getMutex( GuardAccess ) const
     541             :     {
     542           0 :         return getMutex();
     543             :     }
     544             :     inline ::rtl::Reference< ODatabaseModelImpl > getImpl( GuardAccess ) const
     545             :     {
     546             :         return m_pImpl;
     547             :     }
     548             : 
     549             :     /// checks whether the component is already disposed, throws a DisposedException if so
     550           0 :     inline void checkDisposed() const
     551             :     {
     552           0 :         if ( !m_pImpl.is() )
     553           0 :             throw ::com::sun::star::lang::DisposedException( "Component is already disposed.", getThis() );
     554           0 :     }
     555             : 
     556           0 :     inline void lockModify()
     557             :     {
     558           0 :         m_pImpl->lockModify();
     559           0 :     }
     560             : 
     561           0 :     inline void unlockModify()
     562             :     {
     563           0 :         m_pImpl->unlockModify();
     564           0 :     }
     565             : };
     566             : 
     567             : class ModifyLock
     568             : {
     569             : public:
     570           0 :     ModifyLock( ModelDependentComponent& _component )
     571           0 :         :m_rComponent( _component )
     572             :     {
     573           0 :         m_rComponent.lockModify();
     574           0 :     }
     575             : 
     576           0 :     ~ModifyLock()
     577             :     {
     578           0 :         m_rComponent.unlockModify();
     579           0 :     }
     580             : 
     581             : private:
     582             :     ModelDependentComponent&    m_rComponent;
     583             : };
     584             : 
     585             : /** a guard for public methods of objects dependent on a ODatabaseModelImpl instance
     586             : 
     587             :     Just put this guard onto the stack at the beginning of your method. Don't bother yourself
     588             :     with a MutexGuard, checks for being disposed, and the like.
     589             : */
     590             : class ModelMethodGuard : public ::osl::ResettableMutexGuard
     591             : {
     592             : private:
     593             :     typedef ::osl::ResettableMutexGuard             BaseMutexGuard;
     594             : 
     595             : public:
     596             :     /** constructs the guard
     597             : 
     598             :         @param _component
     599             :             the component whose functionality depends on a ODatabaseModelImpl instance
     600             : 
     601             :         @throws ::com::sun::star::lang::DisposedException
     602             :             If the given component is already disposed
     603             :     */
     604           0 :     ModelMethodGuard( const ModelDependentComponent& _component )
     605           0 :         :BaseMutexGuard( _component.getMutex( ModelDependentComponent::GuardAccess() ) )
     606             :     {
     607           0 :         _component.checkDisposed();
     608           0 :     }
     609             : 
     610           0 :     ~ModelMethodGuard()
     611           0 :     {
     612           0 :     }
     613             : };
     614             : 
     615             : }   // namespace dbaccess
     616             : 
     617             : #endif // _DBA_COREDATAACCESS_DATALINK_HXX_
     618             : 
     619             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10