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