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