build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / dbaccess / source / core / dataaccess / ModelImpl.cxx
blobf76875ac54454dd29edfadf863b9933942aaa902
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "commandcontainer.hxx"
21 #include "connection.hxx"
22 #include "core_resource.hrc"
23 #include "core_resource.hxx"
24 #include "databasecontext.hxx"
25 #include "databasedocument.hxx"
26 #include "datasource.hxx"
27 #include "dbastrings.hrc"
28 #include "ModelImpl.hxx"
29 #include "userinformation.hxx"
30 #include "sdbcoretools.hxx"
32 #include <com/sun/star/beans/PropertyBag.hpp>
33 #include <com/sun/star/container/XSet.hpp>
34 #include <com/sun/star/document/MacroExecMode.hpp>
35 #include <com/sun/star/embed/XTransactedObject.hpp>
36 #include <com/sun/star/embed/XTransactionBroadcaster.hpp>
37 #include <com/sun/star/embed/StorageFactory.hpp>
38 #include <com/sun/star/form/XLoadable.hpp>
39 #include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
40 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
41 #include <com/sun/star/sdb/BooleanComparisonMode.hpp>
42 #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
43 #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
44 #include <com/sun/star/util/NumberFormatsSupplier.hpp>
46 #include <comphelper/interaction.hxx>
47 #include <comphelper/seqstream.hxx>
48 #include <comphelper/sequence.hxx>
49 #include <connectivity/dbexception.hxx>
50 #include <cppuhelper/exc_hlp.hxx>
51 #include <cppuhelper/implbase.hxx>
52 #include <cppuhelper/typeprovider.hxx>
53 #include <rtl/digest.h>
54 #include <sfx2/signaturestate.hxx>
55 #include <tools/debug.hxx>
56 #include <tools/diagnose_ex.h>
57 #include <osl/diagnose.h>
58 #include <sal/log.hxx>
59 #include <tools/errcode.hxx>
60 #include <tools/urlobj.hxx>
61 #include <unotools/sharedunocomponent.hxx>
63 #include <algorithm>
65 using namespace ::com::sun::star::document;
66 using namespace ::com::sun::star::sdbc;
67 using namespace ::com::sun::star::sdbcx;
68 using namespace ::com::sun::star::sdb;
69 using namespace ::com::sun::star::beans;
70 using namespace ::com::sun::star::uno;
71 using namespace ::com::sun::star::lang;
72 using namespace ::com::sun::star::embed;
73 using namespace ::com::sun::star::container;
74 using namespace ::com::sun::star::util;
75 using namespace ::com::sun::star::io;
76 using namespace ::com::sun::star::ucb;
77 using namespace ::com::sun::star::frame;
78 using namespace ::com::sun::star::view;
79 using namespace ::com::sun::star::task;
80 using namespace ::com::sun::star::reflection;
81 using namespace ::com::sun::star::script;
82 using namespace ::cppu;
83 using namespace ::osl;
84 using namespace ::dbtools;
85 using namespace ::comphelper;
87 namespace dbaccess
90 // VosMutexFacade
91 VosMutexFacade::VosMutexFacade( ::osl::Mutex& _rMutex )
92 :m_rMutex( _rMutex )
96 void VosMutexFacade::acquire()
98 m_rMutex.acquire();
101 void VosMutexFacade::release()
103 m_rMutex.release();
106 bool VosMutexFacade::tryToAcquire()
108 return m_rMutex.tryToAcquire();
111 // DocumentStorageAccess
112 class DocumentStorageAccess : public ::cppu::WeakImplHelper< XDocumentSubStorageSupplier
113 , XTransactionListener >
115 typedef ::std::map< OUString, Reference< XStorage > > NamedStorages;
117 ::osl::Mutex m_aMutex;
118 /// all sub storages which we ever gave to the outer world
119 NamedStorages m_aExposedStorages;
120 ODatabaseModelImpl* m_pModelImplementation;
121 bool m_bPropagateCommitToRoot;
122 bool m_bDisposingSubStorages;
124 public:
125 explicit DocumentStorageAccess( ODatabaseModelImpl& _rModelImplementation )
126 :m_pModelImplementation( &_rModelImplementation )
127 ,m_bPropagateCommitToRoot( true )
128 ,m_bDisposingSubStorages( false )
132 protected:
133 virtual ~DocumentStorageAccess() override
137 public:
138 void dispose();
140 // XDocumentSubStorageSupplier
141 virtual Reference< XStorage > SAL_CALL getDocumentSubStorage( const OUString& aStorageName, ::sal_Int32 _nMode ) throw (RuntimeException, std::exception) override;
142 virtual Sequence< OUString > SAL_CALL getDocumentSubStoragesNames( ) throw (IOException, RuntimeException, std::exception) override;
144 // XTransactionListener
145 virtual void SAL_CALL preCommit( const css::lang::EventObject& aEvent ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) override;
146 virtual void SAL_CALL commited( const css::lang::EventObject& aEvent ) throw (css::uno::RuntimeException, std::exception) override;
147 virtual void SAL_CALL preRevert( const css::lang::EventObject& aEvent ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) override;
148 virtual void SAL_CALL reverted( const css::lang::EventObject& aEvent ) throw (css::uno::RuntimeException, std::exception) override;
150 // XEventListener
151 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) throw (css::uno::RuntimeException, std::exception) override;
153 /// disposes all storages managed by this instance
154 void disposeStorages();
156 /// disposes all known sub storages
157 void commitStorages();
159 /// commits the dedicated "database" storage
160 bool commitEmbeddedStorage( bool _bPreventRootCommits );
162 private:
163 /** opens the sub storage with the given name, in the given mode
165 Reference< XStorage > impl_openSubStorage_nothrow( const OUString& _rStorageName, sal_Int32 _nMode );
167 void impl_suspendCommitPropagation()
169 OSL_ENSURE( m_bPropagateCommitToRoot, "DocumentStorageAccess::impl_suspendCommitPropagation: already suspended" );
170 m_bPropagateCommitToRoot = false;
172 void impl_resumeCommitPropagation()
174 OSL_ENSURE( !m_bPropagateCommitToRoot, "DocumentStorageAccess::impl_resumeCommitPropagation: not suspended" );
175 m_bPropagateCommitToRoot = true;
180 void DocumentStorageAccess::dispose()
182 ::osl::MutexGuard aGuard( m_aMutex );
184 for ( NamedStorages::const_iterator loop = m_aExposedStorages.begin();
185 loop != m_aExposedStorages.end();
186 ++loop
191 Reference< XTransactionBroadcaster > xBroadcaster( loop->second, UNO_QUERY );
192 if ( xBroadcaster.is() )
193 xBroadcaster->removeTransactionListener( this );
195 catch( const Exception& )
197 DBG_UNHANDLED_EXCEPTION();
201 m_aExposedStorages.clear();
203 m_pModelImplementation = nullptr;
206 Reference< XStorage > DocumentStorageAccess::impl_openSubStorage_nothrow( const OUString& _rStorageName, sal_Int32 _nDesiredMode )
208 OSL_ENSURE( !_rStorageName.isEmpty(),"ODatabaseModelImpl::impl_openSubStorage_nothrow: Invalid storage name!" );
210 Reference< XStorage > xStorage;
213 Reference< XStorage > xRootStorage( m_pModelImplementation->getOrCreateRootStorage() );
214 if ( xRootStorage.is() )
216 sal_Int32 nRealMode = m_pModelImplementation->m_bDocumentReadOnly ? ElementModes::READ : _nDesiredMode;
217 if ( nRealMode == ElementModes::READ )
219 if ( xRootStorage.is() && !xRootStorage->hasByName( _rStorageName ) )
220 return xStorage;
223 xStorage = xRootStorage->openStorageElement( _rStorageName, nRealMode );
225 Reference< XTransactionBroadcaster > xBroad( xStorage, UNO_QUERY );
226 if ( xBroad.is() )
227 xBroad->addTransactionListener( this );
230 catch( const Exception& )
232 DBG_UNHANDLED_EXCEPTION();
235 return xStorage;
238 void DocumentStorageAccess::disposeStorages()
240 m_bDisposingSubStorages = true;
242 NamedStorages::const_iterator aEnd = m_aExposedStorages.end();
243 for ( NamedStorages::iterator aIter = m_aExposedStorages.begin();
244 aIter != aEnd ;
245 ++aIter
250 ::comphelper::disposeComponent( aIter->second );
252 catch( const Exception& )
254 DBG_UNHANDLED_EXCEPTION();
257 m_aExposedStorages.clear();
259 m_bDisposingSubStorages = false;
262 void DocumentStorageAccess::commitStorages()
266 for ( NamedStorages::const_iterator aIter = m_aExposedStorages.begin();
267 aIter != m_aExposedStorages.end();
268 ++aIter
271 tools::stor::commitStorageIfWriteable( aIter->second );
274 catch(const WrappedTargetException&)
276 // WrappedTargetException not allowed to leave
277 throw IOException();
281 bool DocumentStorageAccess::commitEmbeddedStorage( bool _bPreventRootCommits )
283 if ( _bPreventRootCommits )
284 impl_suspendCommitPropagation();
286 bool bSuccess = false;
289 NamedStorages::const_iterator pos = m_aExposedStorages.find( "database" );
290 if ( pos != m_aExposedStorages.end() )
291 bSuccess = tools::stor::commitStorageIfWriteable( pos->second );
293 catch( Exception& )
295 DBG_UNHANDLED_EXCEPTION();
298 if ( _bPreventRootCommits )
299 impl_resumeCommitPropagation();
301 return bSuccess;
305 Reference< XStorage > SAL_CALL DocumentStorageAccess::getDocumentSubStorage( const OUString& aStorageName, ::sal_Int32 _nDesiredMode ) throw (RuntimeException, std::exception)
307 ::osl::MutexGuard aGuard( m_aMutex );
308 NamedStorages::const_iterator pos = m_aExposedStorages.find( aStorageName );
309 if ( pos == m_aExposedStorages.end() )
311 Reference< XStorage > xResult = impl_openSubStorage_nothrow( aStorageName, _nDesiredMode );
312 pos = m_aExposedStorages.insert( NamedStorages::value_type( aStorageName, xResult ) ).first;
315 return pos->second;
318 Sequence< OUString > SAL_CALL DocumentStorageAccess::getDocumentSubStoragesNames( ) throw (IOException, RuntimeException, std::exception)
320 Reference< XStorage > xRootStor( m_pModelImplementation->getRootStorage() );
321 if ( !xRootStor.is() )
322 return Sequence< OUString >();
324 ::std::vector< OUString > aNames;
326 Sequence< OUString > aElementNames( xRootStor->getElementNames() );
327 for ( sal_Int32 i=0; i<aElementNames.getLength(); ++i )
329 if ( xRootStor->isStorageElement( aElementNames[i] ) )
330 aNames.push_back( aElementNames[i] );
332 return aNames.empty()
333 ? Sequence< OUString >()
334 : Sequence< OUString >( &aNames[0], aNames.size() );
337 void SAL_CALL DocumentStorageAccess::preCommit( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException, std::exception)
339 // not interested in
342 void SAL_CALL DocumentStorageAccess::commited( const css::lang::EventObject& aEvent ) throw (RuntimeException, std::exception)
344 ::osl::MutexGuard aGuard( m_aMutex );
346 if ( m_pModelImplementation )
347 m_pModelImplementation->setModified( true );
349 if ( m_pModelImplementation && m_bPropagateCommitToRoot )
351 Reference< XStorage > xStorage( aEvent.Source, UNO_QUERY );
353 // check if this is the dedicated "database" sub storage
354 NamedStorages::const_iterator pos = m_aExposedStorages.find( "database" );
355 if ( ( pos != m_aExposedStorages.end() )
356 && ( pos->second == xStorage )
359 // if so, also commit the root storage
360 m_pModelImplementation->commitRootStorage();
365 void SAL_CALL DocumentStorageAccess::preRevert( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException, std::exception)
367 // not interested in
370 void SAL_CALL DocumentStorageAccess::reverted( const css::lang::EventObject& /*aEvent*/ ) throw (RuntimeException, std::exception)
372 // not interested in
375 void SAL_CALL DocumentStorageAccess::disposing( const css::lang::EventObject& Source ) throw ( RuntimeException, std::exception )
377 OSL_ENSURE( Reference< XStorage >( Source.Source, UNO_QUERY ).is(), "DocumentStorageAccess::disposing: No storage? What's this?" );
379 if ( m_bDisposingSubStorages )
380 return;
382 for ( NamedStorages::const_iterator find = m_aExposedStorages.begin();
383 find != m_aExposedStorages.end();
384 ++find
386 if ( find->second == Source.Source )
388 m_aExposedStorages.erase( find );
389 break;
393 // ODatabaseModelImpl
395 ODatabaseModelImpl::ODatabaseModelImpl( const Reference< XComponentContext >& _rxContext, ODatabaseContext& _rDBContext )
396 :m_xModel()
397 ,m_xDataSource()
398 ,m_aMutex()
399 ,m_aMutexFacade( m_aMutex )
400 ,m_aContainer(4)
401 ,m_aMacroMode( *this )
402 ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
403 ,m_rDBContext( _rDBContext )
404 ,m_refCount(0)
405 ,m_aEmbeddedMacros()
406 ,m_bModificationLock( false )
407 ,m_bDocumentInitialized( false )
408 ,m_aContext( _rxContext )
409 ,m_nLoginTimeout(0)
410 ,m_bReadOnly(false)
411 ,m_bPasswordRequired(false)
412 ,m_bSuppressVersionColumns(true)
413 ,m_bModified(false)
414 ,m_bDocumentReadOnly(false)
415 ,m_pSharedConnectionManager(nullptr)
416 ,m_nControllerLockCount(0)
418 // some kind of default
419 m_sConnectURL = "jdbc:";
420 m_aTableFilter.realloc(1);
421 m_aTableFilter[0] = "%";
422 impl_construct_nothrow();
425 ODatabaseModelImpl::ODatabaseModelImpl(
426 const OUString& _rRegistrationName,
427 const Reference< XComponentContext >& _rxContext,
428 ODatabaseContext& _rDBContext
430 :m_xModel()
431 ,m_xDataSource()
432 ,m_aMutex()
433 ,m_aMutexFacade( m_aMutex )
434 ,m_aContainer(4)
435 ,m_aMacroMode( *this )
436 ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
437 ,m_rDBContext( _rDBContext )
438 ,m_refCount(0)
439 ,m_aEmbeddedMacros()
440 ,m_bModificationLock( false )
441 ,m_bDocumentInitialized( false )
442 ,m_aContext( _rxContext )
443 ,m_sName(_rRegistrationName)
444 ,m_nLoginTimeout(0)
445 ,m_bReadOnly(false)
446 ,m_bPasswordRequired(false)
447 ,m_bSuppressVersionColumns(true)
448 ,m_bModified(false)
449 ,m_bDocumentReadOnly(false)
450 ,m_pSharedConnectionManager(nullptr)
451 ,m_nControllerLockCount(0)
453 impl_construct_nothrow();
456 ODatabaseModelImpl::~ODatabaseModelImpl()
460 void ODatabaseModelImpl::impl_construct_nothrow()
462 // create the property bag to hold the settings (also known as "Info" property)
465 // the set of property value types in the bag is limited:
466 Sequence< Type > aAllowedTypes(6);
467 Type* pAllowedType = aAllowedTypes.getArray();
468 *pAllowedType++ = ::cppu::UnoType<sal_Bool>::get();
469 *pAllowedType++ = ::cppu::UnoType<double>::get();
470 *pAllowedType++ = ::cppu::UnoType<OUString>::get();
471 *pAllowedType++ = ::cppu::UnoType<sal_Int32>::get();
472 *pAllowedType++ = ::cppu::UnoType<sal_Int16>::get();
473 *pAllowedType++ = cppu::UnoType<Sequence< Any >>::get();
475 m_xSettings = PropertyBag::createWithTypes( m_aContext, aAllowedTypes, false/*AllowEmptyPropertyName*/, true/*AutomaticAddition*/ );
477 // insert the default settings
478 Reference< XPropertyContainer > xContainer( m_xSettings, UNO_QUERY_THROW );
479 Reference< XSet > xSettingsSet( m_xSettings, UNO_QUERY_THROW );
480 const AsciiPropertyValue* pSettings = getDefaultDataSourceSettings();
481 for ( ; pSettings->AsciiName; ++pSettings )
483 if ( !pSettings->DefaultValue.hasValue() )
485 Property aProperty(
486 OUString::createFromAscii( pSettings->AsciiName ),
488 pSettings->ValueType,
489 PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT | PropertyAttribute::MAYBEVOID
491 xSettingsSet->insert( makeAny( aProperty ) );
493 else
495 xContainer->addProperty(
496 OUString::createFromAscii( pSettings->AsciiName ),
497 PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
498 pSettings->DefaultValue
503 catch( const Exception& )
505 DBG_UNHANDLED_EXCEPTION();
507 m_rDBContext.appendAtTerminateListener(*this);
510 namespace
512 OUString lcl_getContainerStorageName_throw( ODatabaseModelImpl::ObjectType _eType )
514 const sal_Char* pAsciiName( nullptr );
515 switch ( _eType )
517 case ODatabaseModelImpl::E_FORM: pAsciiName = "forms"; break;
518 case ODatabaseModelImpl::E_REPORT: pAsciiName = "reports"; break;
519 case ODatabaseModelImpl::E_QUERY: pAsciiName = "queries"; break;
520 case ODatabaseModelImpl::E_TABLE: pAsciiName = "tables"; break;
521 default:
522 throw RuntimeException();
524 return OUString::createFromAscii( pAsciiName );
527 bool lcl_hasObjectWithMacros_throw( const ODefinitionContainer_Impl& _rObjectDefinitions, const Reference< XStorage >& _rxContainerStorage )
529 bool bSomeDocHasMacros = false;
531 for ( ODefinitionContainer_Impl::const_iterator object = _rObjectDefinitions.begin();
532 ( object != _rObjectDefinitions.end() ) && !bSomeDocHasMacros;
533 ++object
536 #if OSL_DEBUG_LEVEL > 0
537 const OUString& rName( object->first ); (void)rName;
538 #endif
540 const TContentPtr& rDefinition( object->second );
541 const OUString& rPersistentName( rDefinition->m_aProps.sPersistentName );
543 if ( rPersistentName.isEmpty() )
544 { // it's a logical sub folder used to organize the real objects
545 const ODefinitionContainer_Impl& rSubFoldersObjectDefinitions( dynamic_cast< const ODefinitionContainer_Impl& >( *rDefinition.get() ) );
546 bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rSubFoldersObjectDefinitions, _rxContainerStorage );
547 continue;
550 bSomeDocHasMacros = ODatabaseModelImpl::objectHasMacros( _rxContainerStorage, rPersistentName );
552 return bSomeDocHasMacros;
555 bool lcl_hasObjectsWithMacros_nothrow( ODatabaseModelImpl& _rModel, const ODatabaseModelImpl::ObjectType _eType )
557 bool bSomeDocHasMacros = false;
559 const OContentHelper_Impl& rContainerData( *_rModel.getObjectContainer( _eType ).get() );
560 const ODefinitionContainer_Impl& rObjectDefinitions = dynamic_cast< const ODefinitionContainer_Impl& >( rContainerData );
564 Reference< XStorage > xContainerStorage( _rModel.getStorage( _eType ) );
565 // note the READWRITE here: If the storage already existed before, then the OpenMode will
566 // be ignored, anyway.
567 // If the storage did not yet exist, then it will be created. If the database document
568 // is read-only, the OpenMode will be automatically downgraded to READ. Otherwise,
569 // the storage will in fact be created as READWRITE. While this is not strictly necessary
570 // for this particular use case here, it is required since the storage is *cached*, and
571 // later use cases will need the READWRITE mode.
573 if ( xContainerStorage.is() )
574 bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rObjectDefinitions, xContainerStorage );
576 catch( const Exception& )
578 DBG_UNHANDLED_EXCEPTION();
579 // be on the safe side: If we can't reliably determine whether there are macros,
580 // assume there actually are. Better this way, than the other way round.
581 bSomeDocHasMacros = true;
584 return bSomeDocHasMacros;
588 bool ODatabaseModelImpl::objectHasMacros( const Reference< XStorage >& _rxContainerStorage, const OUString& _rPersistentName )
590 OSL_PRECOND( _rxContainerStorage.is(), "ODatabaseModelImpl::objectHasMacros: this will crash!" );
592 bool bHasMacros = true;
595 if ( !_rxContainerStorage->hasByName( _rPersistentName ) )
596 return false;
598 Reference< XStorage > xObjectStor( _rxContainerStorage->openStorageElement(
599 _rPersistentName, ElementModes::READ ) );
601 bHasMacros = ::sfx2::DocumentMacroMode::storageHasMacros( xObjectStor );
603 catch( const Exception& )
605 DBG_UNHANDLED_EXCEPTION();
607 return bHasMacros;
610 void ODatabaseModelImpl::reset()
612 m_bReadOnly = false;
613 ::std::vector< TContentPtr > aEmptyContainers( 4 );
614 m_aContainer.swap( aEmptyContainers );
616 if ( m_pStorageAccess.is() )
618 m_pStorageAccess->dispose();
619 m_pStorageAccess.clear();
623 void SAL_CALL ODatabaseModelImpl::disposing( const css::lang::EventObject& Source ) throw(RuntimeException)
625 Reference<XConnection> xCon(Source.Source,UNO_QUERY);
626 if ( xCon.is() )
628 bool bStore = false;
629 for (OWeakConnectionArray::iterator i = m_aConnections.begin(); i != m_aConnections.end(); )
631 css::uno::Reference< css::sdbc::XConnection > xIterConn ( *i );
632 if ( !xIterConn.is())
634 i = m_aConnections.erase(i);
636 else if ( xCon == xIterConn )
638 *i = css::uno::WeakReference< css::sdbc::XConnection >();
639 bStore = true;
640 break;
641 } else
642 ++i;
645 if ( bStore )
646 commitRootStorage();
648 else
650 OSL_FAIL( "ODatabaseModelImpl::disposing: where does this come from?" );
654 void ODatabaseModelImpl::clearConnections()
656 OWeakConnectionArray aConnections;
657 aConnections.swap( m_aConnections );
659 Reference< XConnection > xConn;
660 OWeakConnectionArray::const_iterator aEnd = aConnections.end();
661 for ( OWeakConnectionArray::const_iterator i = aConnections.begin(); aEnd != i; ++i )
663 xConn = *i;
664 if ( xConn.is() )
668 xConn->close();
670 catch(const Exception&)
672 DBG_UNHANDLED_EXCEPTION();
677 m_pSharedConnectionManager = nullptr;
678 m_xSharedConnectionManager = nullptr;
681 void ODatabaseModelImpl::dispose()
683 // dispose the data source and the model
686 Reference< XDataSource > xDS( m_xDataSource );
687 ::comphelper::disposeComponent( xDS );
689 Reference< XModel > xModel( m_xModel );
690 ::comphelper::disposeComponent( xModel );
692 catch( const Exception& )
694 DBG_UNHANDLED_EXCEPTION();
696 m_xDataSource = WeakReference<XDataSource>();
697 m_xModel = WeakReference< XModel >();
699 ::std::vector<TContentPtr>::const_iterator aIter = m_aContainer.begin();
700 ::std::vector<TContentPtr>::const_iterator aEnd = m_aContainer.end();
701 for (;aIter != aEnd ; ++aIter)
703 if ( aIter->get() )
704 (*aIter)->m_pDataSource = nullptr;
706 m_aContainer.clear();
708 clearConnections();
710 m_xNumberFormatsSupplier = nullptr;
714 bool bCouldStore = commitEmbeddedStorage( true );
715 // "true" means that committing the embedded storage should not trigger committing the root
716 // storage. This is because we are going to commit the root storage ourself, anyway
717 disposeStorages();
718 if ( bCouldStore )
719 commitRootStorage();
721 impl_switchToStorage_throw( nullptr );
723 catch( const Exception& )
725 DBG_UNHANDLED_EXCEPTION();
728 if ( m_pStorageAccess.is() )
730 m_pStorageAccess->dispose();
731 m_pStorageAccess.clear();
735 const Reference< XNumberFormatsSupplier > & ODatabaseModelImpl::getNumberFormatsSupplier()
737 if (!m_xNumberFormatsSupplier.is())
739 // the arguments : the locale of the current user
740 UserInformation aUserInfo;
741 Locale aLocale = aUserInfo.getUserLanguage();
743 m_xNumberFormatsSupplier.set( NumberFormatsSupplier::createWithLocale( m_aContext, aLocale ) );
745 return m_xNumberFormatsSupplier;
748 void ODatabaseModelImpl::setDocFileLocation( const OUString& i_rLoadedFrom )
750 ENSURE_OR_THROW( !i_rLoadedFrom.isEmpty(), "invalid URL" );
751 m_sDocFileLocation = i_rLoadedFrom;
754 void ODatabaseModelImpl::setResource( const OUString& i_rDocumentURL, const Sequence< PropertyValue >& _rArgs )
756 ENSURE_OR_THROW( !i_rDocumentURL.isEmpty(), "invalid URL" );
758 ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs );
759 #if OSL_DEBUG_LEVEL > 0
760 if ( aMediaDescriptor.has( "SalvagedFile" ) )
762 OUString sSalvagedFile( aMediaDescriptor.getOrDefault( "SalvagedFile", OUString() ) );
763 // If SalvagedFile is an empty string, this indicates "the document is being recovered, but i_rDocumentURL already
764 // is the real document URL, not the temporary document location"
765 if ( sSalvagedFile.isEmpty() )
766 sSalvagedFile = i_rDocumentURL;
768 OSL_ENSURE( sSalvagedFile == i_rDocumentURL, "ODatabaseModelImpl::setResource: inconsistency!" );
769 // nowadays, setResource should only be called with the logical URL of the document
771 #endif
773 m_aMediaDescriptor = stripLoadArguments( aMediaDescriptor );
775 impl_switchToLogicalURL( i_rDocumentURL );
778 ::comphelper::NamedValueCollection ODatabaseModelImpl::stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments )
780 OSL_ENSURE( !_rArguments.has( "Model" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (1)!" );
781 OSL_ENSURE( !_rArguments.has( "ViewName" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (2)!" );
783 ::comphelper::NamedValueCollection aMutableArgs( _rArguments );
784 aMutableArgs.remove( "Model" );
785 aMutableArgs.remove( "ViewName" );
786 return aMutableArgs;
789 void ODatabaseModelImpl::disposeStorages()
791 getDocumentStorageAccess()->disposeStorages();
794 Reference< XSingleServiceFactory > ODatabaseModelImpl::createStorageFactory() const
796 return StorageFactory::create( m_aContext );
799 void ODatabaseModelImpl::commitRootStorage()
801 Reference< XStorage > xStorage( getOrCreateRootStorage() );
802 bool bSuccess = commitStorageIfWriteable_ignoreErrors( xStorage );
803 SAL_WARN_IF(!bSuccess && xStorage.is(), "dbaccess",
804 "ODatabaseModelImpl::commitRootStorage: could not commit the storage!");
807 Reference< XStorage > ODatabaseModelImpl::getOrCreateRootStorage()
809 if ( !m_xDocumentStorage.is() )
811 Reference< XSingleServiceFactory> xStorageFactory = StorageFactory::create( m_aContext );
812 Any aSource;
813 aSource = m_aMediaDescriptor.get( "Stream" );
814 if ( !aSource.hasValue() )
815 aSource = m_aMediaDescriptor.get( "InputStream" );
816 if ( !aSource.hasValue() && !m_sDocFileLocation.isEmpty() )
817 aSource <<= m_sDocFileLocation;
818 // TODO: shouldn't we also check URL?
820 OSL_ENSURE( aSource.hasValue(), "ODatabaseModelImpl::getOrCreateRootStorage: no source to create the storage from!" );
822 if ( aSource.hasValue() )
824 Sequence< Any > aStorageCreationArgs(2);
825 aStorageCreationArgs[0] = aSource;
826 aStorageCreationArgs[1] <<= ElementModes::READWRITE;
828 Reference< XStorage > xDocumentStorage;
829 OUString sURL;
830 aSource >>= sURL;
831 // Don't try to load a meta-URL as-is.
832 if (!sURL.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:"))
836 xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
838 catch( const Exception& )
840 m_bDocumentReadOnly = true;
841 aStorageCreationArgs[1] <<= ElementModes::READ;
844 xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
846 catch( const Exception& )
848 DBG_UNHANDLED_EXCEPTION();
853 impl_switchToStorage_throw( xDocumentStorage );
856 return m_xDocumentStorage.getTyped();
859 DocumentStorageAccess* ODatabaseModelImpl::getDocumentStorageAccess()
861 if ( !m_pStorageAccess.is() )
863 m_pStorageAccess = new DocumentStorageAccess( *this );
865 return m_pStorageAccess.get();
868 void ODatabaseModelImpl::modelIsDisposing( const bool _wasInitialized, ResetModelAccess )
870 m_xModel.clear();
872 // Basic libraries and Dialog libraries are a model facet, though held at this impl class.
873 // They automatically dispose themself when the model they belong to is being disposed.
874 // So, to not be tempted to do anything with them, again, we reset them.
875 m_xBasicLibraries.clear();
876 m_xDialogLibraries.clear();
878 m_bDocumentInitialized = _wasInitialized;
881 Reference< XDocumentSubStorageSupplier > ODatabaseModelImpl::getDocumentSubStorageSupplier()
883 return getDocumentStorageAccess();
886 bool ODatabaseModelImpl::commitEmbeddedStorage( bool _bPreventRootCommits )
888 return getDocumentStorageAccess()->commitEmbeddedStorage( _bPreventRootCommits );
891 bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage )
893 bool bSuccess = false;
896 bSuccess = tools::stor::commitStorageIfWriteable( _rxStorage );
898 catch( const Exception& )
900 DBG_UNHANDLED_EXCEPTION();
902 return bSuccess;
905 void ODatabaseModelImpl::setModified( bool _bModified )
907 if ( isModifyLocked() )
908 return;
912 Reference< XModifiable > xModi( m_xModel.get(), UNO_QUERY );
913 if ( xModi.is() )
914 xModi->setModified( _bModified );
915 else
916 m_bModified = _bModified;
918 catch( const Exception& )
920 DBG_UNHANDLED_EXCEPTION();
924 Reference<XDataSource> ODatabaseModelImpl::getOrCreateDataSource()
926 Reference<XDataSource> xDs = m_xDataSource;
927 if ( !xDs.is() )
929 xDs = new ODatabaseSource(this);
930 m_xDataSource = xDs;
932 return xDs;
935 Reference< XModel> ODatabaseModelImpl::getModel_noCreate() const
937 return m_xModel;
940 Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership()
942 Reference< XModel > xModel( m_xModel );
943 OSL_PRECOND( !xModel.is(), "ODatabaseModelImpl::createNewModel_deliverOwnership: not to be called if there already is a model!" );
944 if ( !xModel.is() )
946 bool bHadModelBefore = m_bDocumentInitialized;
948 xModel = ODatabaseDocument::createDatabaseDocument( this, ODatabaseDocument::FactoryAccess() );
949 m_xModel = xModel;
953 Reference< XGlobalEventBroadcaster > xModelCollection = theGlobalEventBroadcaster::get( m_aContext );
954 xModelCollection->insert( makeAny( xModel ) );
956 catch( const Exception& )
958 DBG_UNHANDLED_EXCEPTION();
961 if ( bHadModelBefore )
963 // do an attachResources
964 // In case the document is loaded regularly, this is not necessary, as our loader will do it.
965 // However, in case that the document is implicitly created by asking the data source for the document,
966 // then nobody would call the doc's attachResource. So, we do it here, to ensure it's in a proper
967 // state, fires all events, and so on.
968 // #i105505#
969 xModel->attachResource( xModel->getURL(), m_aMediaDescriptor.getPropertyValues() );
972 return xModel;
975 void SAL_CALL ODatabaseModelImpl::acquire()
977 osl_atomic_increment(&m_refCount);
980 void SAL_CALL ODatabaseModelImpl::release()
982 if ( osl_atomic_decrement(&m_refCount) == 0 )
984 acquire(); // prevent multiple releases
985 m_rDBContext.removeFromTerminateListener(*this);
986 dispose();
987 m_rDBContext.storeTransientProperties(*this);
988 if (!m_sDocumentURL.isEmpty())
989 m_rDBContext.revokeDatabaseDocument(*this);
990 delete this;
994 void ODatabaseModelImpl::commitStorages()
996 getDocumentStorageAccess()->commitStorages();
999 Reference< XStorage > ODatabaseModelImpl::getStorage( const ObjectType _eType )
1001 return getDocumentStorageAccess()->getDocumentSubStorage( getObjectContainerStorageName( _eType ),
1002 css::embed::ElementModes::READWRITE );
1005 const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings()
1007 static const AsciiPropertyValue aKnownSettings[] =
1009 // known JDBC settings
1010 AsciiPropertyValue( "JavaDriverClass", makeAny( OUString() ) ),
1011 AsciiPropertyValue( "JavaDriverClassPath", makeAny( OUString() ) ),
1012 AsciiPropertyValue( "IgnoreCurrency", makeAny( false ) ),
1013 // known settings for file-based drivers
1014 AsciiPropertyValue( "Extension", makeAny( OUString() ) ),
1015 AsciiPropertyValue( "CharSet", makeAny( OUString() ) ),
1016 AsciiPropertyValue( "HeaderLine", makeAny( true ) ),
1017 AsciiPropertyValue( "FieldDelimiter", makeAny( OUString( "," ) ) ),
1018 AsciiPropertyValue( "StringDelimiter", makeAny( OUString( "\"" ) ) ),
1019 AsciiPropertyValue( "DecimalDelimiter", makeAny( OUString( "." ) ) ),
1020 AsciiPropertyValue( "ThousandDelimiter", makeAny( OUString() ) ),
1021 AsciiPropertyValue( "ShowDeleted", makeAny( false ) ),
1022 // known ODBC settings
1023 AsciiPropertyValue( "SystemDriverSettings", makeAny( OUString() ) ),
1024 AsciiPropertyValue( "UseCatalog", makeAny( false ) ),
1025 AsciiPropertyValue( "TypeInfoSettings", makeAny( Sequence< Any >()) ),
1026 // settings related to auto increment handling
1027 AsciiPropertyValue( "AutoIncrementCreation", makeAny( OUString() ) ),
1028 AsciiPropertyValue( "AutoRetrievingStatement", makeAny( OUString() ) ),
1029 AsciiPropertyValue( "IsAutoRetrievingEnabled", makeAny( false ) ),
1030 // known LDAP driver settings
1031 AsciiPropertyValue( "HostName", makeAny( OUString() ) ),
1032 AsciiPropertyValue( "PortNumber", makeAny( (sal_Int32)389 ) ),
1033 AsciiPropertyValue( "BaseDN", makeAny( OUString() ) ),
1034 AsciiPropertyValue( "MaxRowCount", makeAny( (sal_Int32)100 ) ),
1035 // known MySQLNative driver settings
1036 AsciiPropertyValue( "LocalSocket", makeAny( OUString() ) ),
1037 AsciiPropertyValue( "NamedPipe", makeAny( OUString() ) ),
1038 // misc known driver settings
1039 AsciiPropertyValue( "ParameterNameSubstitution", makeAny( false ) ),
1040 AsciiPropertyValue( "AddIndexAppendix", makeAny( true ) ),
1041 AsciiPropertyValue( "IgnoreDriverPrivileges", makeAny( true ) ),
1042 AsciiPropertyValue( "ImplicitCatalogRestriction", ::cppu::UnoType< OUString >::get() ),
1043 AsciiPropertyValue( "ImplicitSchemaRestriction", ::cppu::UnoType< OUString >::get() ),
1044 AsciiPropertyValue( "PrimaryKeySupport", ::cppu::UnoType< sal_Bool >::get() ),
1045 AsciiPropertyValue( "ShowColumnDescription", makeAny( false ) ),
1046 // known SDB level settings
1047 AsciiPropertyValue( "NoNameLengthLimit", makeAny( false ) ),
1048 AsciiPropertyValue( "AppendTableAliasName", makeAny( false ) ),
1049 AsciiPropertyValue( "GenerateASBeforeCorrelationName", makeAny( false ) ),
1050 AsciiPropertyValue( "ColumnAliasInOrderBy", makeAny( true ) ),
1051 AsciiPropertyValue( "EnableSQL92Check", makeAny( false ) ),
1052 AsciiPropertyValue( "BooleanComparisonMode", makeAny( BooleanComparisonMode::EQUAL_INTEGER ) ),
1053 AsciiPropertyValue( "TableTypeFilterMode", makeAny( (sal_Int32)3 ) ),
1054 AsciiPropertyValue( "RespectDriverResultSetType", makeAny( false ) ),
1055 AsciiPropertyValue( "UseSchemaInSelect", makeAny( true ) ),
1056 AsciiPropertyValue( "UseCatalogInSelect", makeAny( true ) ),
1057 AsciiPropertyValue( "EnableOuterJoinEscape", makeAny( true ) ),
1058 AsciiPropertyValue( "PreferDosLikeLineEnds", makeAny( false ) ),
1059 AsciiPropertyValue( "FormsCheckRequiredFields", makeAny( true ) ),
1060 AsciiPropertyValue( "EscapeDateTime", makeAny( true ) ),
1062 // known services to handle database tasks
1063 AsciiPropertyValue( "TableAlterationServiceName", makeAny( OUString() ) ),
1064 AsciiPropertyValue( "TableRenameServiceName", makeAny( OUString() ) ),
1065 AsciiPropertyValue( "ViewAlterationServiceName", makeAny( OUString() ) ),
1066 AsciiPropertyValue( "ViewAccessServiceName", makeAny( OUString() ) ),
1067 AsciiPropertyValue( "CommandDefinitions", makeAny( OUString() ) ),
1068 AsciiPropertyValue( "Forms", makeAny( OUString() ) ),
1069 AsciiPropertyValue( "Reports", makeAny( OUString() ) ),
1070 AsciiPropertyValue( "KeyAlterationServiceName", makeAny( OUString() ) ),
1071 AsciiPropertyValue( "IndexAlterationServiceName", makeAny( OUString() ) ),
1073 AsciiPropertyValue()
1075 return aKnownSettings;
1078 TContentPtr& ODatabaseModelImpl::getObjectContainer( ObjectType _eType )
1080 OSL_PRECOND( _eType >= E_FORM && _eType <= E_TABLE, "ODatabaseModelImpl::getObjectContainer: illegal index!" );
1081 TContentPtr& rContentPtr = m_aContainer[ _eType ];
1083 if ( !rContentPtr.get() )
1085 rContentPtr = TContentPtr( new ODefinitionContainer_Impl );
1086 rContentPtr->m_pDataSource = this;
1087 rContentPtr->m_aProps.aTitle = lcl_getContainerStorageName_throw( _eType );
1089 return rContentPtr;
1092 bool ODatabaseModelImpl::adjustMacroMode_AutoReject()
1094 return m_aMacroMode.adjustMacroMode( nullptr );
1097 bool ODatabaseModelImpl::checkMacrosOnLoading()
1099 Reference< XInteractionHandler > xInteraction;
1100 xInteraction = m_aMediaDescriptor.getOrDefault( "InteractionHandler", xInteraction );
1101 return m_aMacroMode.checkMacrosOnLoading( xInteraction );
1104 void ODatabaseModelImpl::resetMacroExecutionMode()
1106 m_aMacroMode = ::sfx2::DocumentMacroMode( *this );
1109 Reference< XStorageBasedLibraryContainer > ODatabaseModelImpl::getLibraryContainer( bool _bScript )
1111 Reference< XStorageBasedLibraryContainer >& rxContainer( _bScript ? m_xBasicLibraries : m_xDialogLibraries );
1112 if ( rxContainer.is() )
1113 return rxContainer;
1115 Reference< XStorageBasedDocument > xDocument( getModel_noCreate(), UNO_QUERY_THROW );
1116 // this is only to be called if there already exists a document model - in fact, it is
1117 // to be called by the document model only
1121 Reference< XStorageBasedLibraryContainer > (*Factory)( const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&)
1122 = _bScript ? &DocumentScriptLibraryContainer::create : &DocumentDialogLibraryContainer::create;
1124 rxContainer.set(
1125 (*Factory)( m_aContext, xDocument ),
1126 UNO_QUERY_THROW
1129 catch( const RuntimeException& )
1131 throw;
1133 catch( const Exception& )
1135 throw WrappedTargetRuntimeException(
1136 OUString(),
1137 xDocument,
1138 ::cppu::getCaughtException()
1141 return rxContainer;
1144 void ODatabaseModelImpl::storeLibraryContainersTo( const Reference< XStorage >& _rxToRootStorage )
1146 if ( m_xBasicLibraries.is() )
1147 m_xBasicLibraries->storeLibrariesToStorage( _rxToRootStorage );
1149 if ( m_xDialogLibraries.is() )
1150 m_xDialogLibraries->storeLibrariesToStorage( _rxToRootStorage );
1153 Reference< XStorage > ODatabaseModelImpl::switchToStorage( const Reference< XStorage >& _rxNewRootStorage )
1155 if ( !_rxNewRootStorage.is() )
1156 throw IllegalArgumentException();
1158 return impl_switchToStorage_throw( _rxNewRootStorage );
1161 namespace
1163 void lcl_modifyListening( ::sfx2::IModifiableDocument& _rDocument,
1164 const Reference< XStorage >& _rxStorage, ::rtl::Reference< ::sfx2::DocumentStorageModifyListener >& _inout_rListener,
1165 comphelper::SolarMutex& _rMutex, bool _bListen )
1167 Reference< XModifiable > xModify( _rxStorage, UNO_QUERY );
1168 OSL_ENSURE( xModify.is() || !_rxStorage.is(), "lcl_modifyListening: storage can't notify us!" );
1170 if ( xModify.is() && !_bListen && _inout_rListener.is() )
1172 xModify->removeModifyListener( _inout_rListener.get() );
1175 if ( _inout_rListener.is() )
1177 _inout_rListener->dispose();
1178 _inout_rListener = nullptr;
1181 if ( xModify.is() && _bListen )
1183 _inout_rListener = new ::sfx2::DocumentStorageModifyListener( _rDocument, _rMutex );
1184 xModify->addModifyListener( _inout_rListener.get() );
1189 namespace
1191 void lcl_rebaseScriptStorage_throw( const Reference< XStorageBasedLibraryContainer >& _rxContainer,
1192 const Reference< XStorage >& _rxNewRootStorage )
1194 if ( _rxContainer.is() )
1196 if ( _rxNewRootStorage.is() )
1197 _rxContainer->setRootStorage( _rxNewRootStorage );
1198 // else
1199 // TODO: what to do here? dispose the container?
1204 Reference< XStorage > ODatabaseModelImpl::impl_switchToStorage_throw( const Reference< XStorage >& _rxNewRootStorage )
1206 // stop listening for modifications at the old storage
1207 lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, false );
1209 // set new storage
1210 m_xDocumentStorage.reset( _rxNewRootStorage, SharedStorage::TakeOwnership );
1212 // start listening for modifications
1213 lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, true );
1215 // forward new storage to Basic and Dialog library containers
1216 lcl_rebaseScriptStorage_throw( m_xBasicLibraries, m_xDocumentStorage.getTyped() );
1217 lcl_rebaseScriptStorage_throw( m_xDialogLibraries, m_xDocumentStorage.getTyped() );
1219 m_bReadOnly = !tools::stor::storageIsWritable_nothrow( m_xDocumentStorage.getTyped() );
1220 // TODO: our data source, if it exists, must broadcast the change of its ReadOnly property
1222 return m_xDocumentStorage.getTyped();
1225 void ODatabaseModelImpl::impl_switchToLogicalURL( const OUString& i_rDocumentURL )
1227 if ( i_rDocumentURL == m_sDocumentURL )
1228 return;
1230 const OUString sOldURL( m_sDocumentURL );
1231 // update our name, if necessary
1232 if ( ( m_sName == m_sDocumentURL ) // our name is our old URL
1233 || ( m_sName.isEmpty() ) // we do not have a name, yet (i.e. are not registered at the database context)
1236 INetURLObject aURL( i_rDocumentURL );
1237 if ( aURL.GetProtocol() != INetProtocol::NotValid )
1239 m_sName = i_rDocumentURL;
1240 // TODO: our data source must broadcast the change of the Name property
1244 // remember URL
1245 m_sDocumentURL = i_rDocumentURL;
1247 // update our location, if necessary
1248 if ( m_sDocFileLocation.isEmpty() )
1249 m_sDocFileLocation = m_sDocumentURL;
1251 // register at the database context, or change registration
1252 if (!sOldURL.isEmpty())
1253 m_rDBContext.databaseDocumentURLChange( sOldURL, m_sDocumentURL );
1254 else
1255 m_rDBContext.registerDatabaseDocument( *this );
1258 OUString ODatabaseModelImpl::getObjectContainerStorageName( const ObjectType _eType )
1260 return lcl_getContainerStorageName_throw( _eType );
1263 sal_Int16 ODatabaseModelImpl::getCurrentMacroExecMode() const
1265 sal_Int16 nCurrentMode = MacroExecMode::NEVER_EXECUTE;
1268 nCurrentMode = m_aMediaDescriptor.getOrDefault( "MacroExecutionMode", nCurrentMode );
1270 catch( const Exception& )
1272 DBG_UNHANDLED_EXCEPTION();
1274 return nCurrentMode;
1277 void ODatabaseModelImpl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
1279 m_aMediaDescriptor.put( "MacroExecutionMode", nMacroMode );
1282 OUString ODatabaseModelImpl::getDocumentLocation() const
1284 return getURL();
1285 // formerly, we returned getDocFileLocation here, which is the location of the file from which we
1286 // recovered the "real" document.
1287 // However, during CWS autorecovery evolving, we clarified (with MAV/MT) the role of XModel::getURL and
1288 // XStorable::getLocation. In this course, we agreed that for a macro security check, the *document URL*
1289 // (not the recovery file URL) is to be used: The recovery file lies in the backup folder, and by definition,
1290 // this folder is considered to be secure. So, the document URL needs to be used to decide about the security.
1293 ODatabaseModelImpl::EmbeddedMacros ODatabaseModelImpl::determineEmbeddedMacros()
1295 if ( !m_aEmbeddedMacros )
1297 if ( ::sfx2::DocumentMacroMode::storageHasMacros( getOrCreateRootStorage() ) )
1299 m_aEmbeddedMacros.reset( eDocumentWideMacros );
1301 else if ( lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_FORM )
1302 || lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_REPORT )
1305 m_aEmbeddedMacros.reset( eSubDocumentMacros );
1307 else
1309 m_aEmbeddedMacros.reset( eNoMacros );
1312 return *m_aEmbeddedMacros;
1315 bool ODatabaseModelImpl::documentStorageHasMacros() const
1317 const_cast< ODatabaseModelImpl* >( this )->determineEmbeddedMacros();
1318 return ( *m_aEmbeddedMacros != eNoMacros );
1321 Reference< XEmbeddedScripts > ODatabaseModelImpl::getEmbeddedDocumentScripts() const
1323 return Reference< XEmbeddedScripts >( getModel_noCreate(), UNO_QUERY );
1326 SignatureState ODatabaseModelImpl::getScriptingSignatureState()
1328 // no support for signatures at the moment
1329 return SignatureState::NOSIGNATURES;
1332 bool ODatabaseModelImpl::hasTrustedScriptingSignature( bool /*bAllowUIToAddAuthor*/ )
1334 // no support for signatures at the moment
1335 return false;
1338 void ODatabaseModelImpl::showBrokenSignatureWarning( const Reference< XInteractionHandler >& /*_rxInteraction*/ ) const
1340 OSL_FAIL( "ODatabaseModelImpl::showBrokenSignatureWarning: signatures can't be broken - we do not support them!" );
1343 void ODatabaseModelImpl::storageIsModified()
1345 setModified( true );
1348 ModelDependentComponent::ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model )
1349 :m_pImpl( _model )
1350 ,m_aMutex( _model->getSharedMutex() )
1354 ModelDependentComponent::~ModelDependentComponent()
1358 } // namespace dbaccess
1360 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */