diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2017-09-08 10:57:55 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2017-09-12 21:57:15 +0200 |
commit | e2cfcd56ca8f3de4480ee85712cff3182999635c (patch) | |
tree | 55019e8c513ef31f077aaa9cfa3343bfd1fe30a1 | |
parent | 348bc3c6a8142ed605e260ae930d76e6cec7f656 (diff) |
tdf#108572 remove connections only for current shell
Also remove connections to temp files.
Change-Id: Ie5c09eb365d1246e053dc52884c72687ac226f3c
Reviewed-on: https://gerrit.libreoffice.org/42095
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/42208
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r-- | compilerplugins/clang/badstatics.cxx | 1 | ||||
-rw-r--r-- | sw/inc/dbmgr.hxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/app/apphdl.cxx | 8 | ||||
-rw-r--r-- | sw/source/uibase/dbui/dbmgr.cxx | 46 |
4 files changed, 43 insertions, 16 deletions
diff --git a/compilerplugins/clang/badstatics.cxx b/compilerplugins/clang/badstatics.cxx index f10200a93c2f..e551d6be5c5b 100644 --- a/compilerplugins/clang/badstatics.cxx +++ b/compilerplugins/clang/badstatics.cxx @@ -197,6 +197,7 @@ public: // ScAddInAsync* keys if that set is not empty at exit || name == "g_aWindowList" //vcl/unx/gtk/a11y/atkutil.cxx, asserted empty at exit + || name == "m_aUncommitedRegistrations" // sw/source/uibase/dbui/dbmgr.cxx || (loplugin::DeclCheck(pVarDecl).Var("aAllListeners") .Class("ScAddInListener").GlobalNamespace()) // not owning ) // these variables appear unproblematic diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx index d4797b303e23..b80f051a4d55 100644 --- a/sw/inc/dbmgr.hxx +++ b/sw/inc/dbmgr.hxx @@ -259,7 +259,7 @@ friend class SwConnectionDisposedListener_Impl; OUString m_sEmbeddedName; /// Store last registrations to revoke or commit - static std::vector<OUString> m_aUncommitedRegistrations; + static std::vector<std::pair<SwDocShell*, OUString>> m_aUncommitedRegistrations; /// The document that owns this manager. SwDoc* m_pDoc; @@ -486,7 +486,7 @@ public: void RevokeLastRegistrations(); /// Accept not commited registrations - static void CommitLastRegistrations(); + void CommitLastRegistrations(); }; #endif diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx index 0b029e6e5a04..619c202a6039 100644 --- a/sw/source/uibase/app/apphdl.cxx +++ b/sw/source/uibase/app/apphdl.cxx @@ -489,7 +489,13 @@ void SwMailMergeWizardExecutor::ExecutionFinished() if (xMMConfig) xMMConfig->Commit(); - SwDBManager::CommitLastRegistrations(); + SwDoc* pDoc = m_pView->GetDocShell()->GetDoc(); + if (pDoc) + { + SwDBManager* pDbManager = pDoc->GetDBManager(); + if (pDbManager) + pDbManager->CommitLastRegistrations(); + } // release/destroy asynchronously Application::PostUserEvent( LINK( this, SwMailMergeWizardExecutor, DestroyDialogHdl ) ); diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index 410fb02e6ade..b959a5d7b5f5 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -165,7 +165,7 @@ void lcl_emitEvent(sal_uInt16 nEventId, sal_Int32 nStrId, SfxObjectShell* pDocSh } -std::vector<OUString> SwDBManager::m_aUncommitedRegistrations; +std::vector<std::pair<SwDocShell*, OUString>> SwDBManager::m_aUncommitedRegistrations; enum class SwDBNextRecord { NEXT, FIRST }; static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action = SwDBNextRecord::NEXT ); @@ -811,7 +811,9 @@ SwDBManager::SwDBManager(SwDoc* pDoc) SwDBManager::~SwDBManager() { - // copy required, m_DataSourceParams can be modifed while disposing components + RevokeLastRegistrations(); + + // copy required, m_DataSourceParams can be modified while disposing components std::vector<uno::Reference<sdbc::XConnection>> aCopiedConnections; for (auto & pParam : m_DataSourceParams) { @@ -2627,7 +2629,7 @@ OUString SwDBManager::LoadAndRegisterDataSource(SwDocShell* pDocShell) } sFind = LoadAndRegisterDataSource( type, aURLAny, DBCONN_FLAT == type ? &aSettings : nullptr, aURI, nullptr, nullptr, pDocShell ); - m_aUncommitedRegistrations.push_back(sFind); + m_aUncommitedRegistrations.push_back(std::pair<SwDocShell*, OUString>(pDocShell, sFind)); } return sFind; } @@ -2884,6 +2886,10 @@ void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY); xDatabaseContext->registerObject( sDataSource, xDataSource ); + + // temp file - don't remember connection + if (rData.sDataSource.isEmpty()) + m_aUncommitedRegistrations.push_back(std::pair<SwDocShell*, OUString>(nullptr, sDataSource)); } void SwDBManager::ExecuteFormLetter( SwWrtShell& rSh, @@ -3208,24 +3214,38 @@ void SwDBManager::RevokeLastRegistrations() { if (m_aUncommitedRegistrations.size()) { - SwView* pView = m_pDoc->GetDocShell()->GetView(); - std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem(); - if (xConfigItem) + SwView* pView = ( m_pDoc && m_pDoc->GetDocShell() ) ? m_pDoc->GetDocShell()->GetView() : nullptr; + if (pView) { - xConfigItem->DisposeResultSet(); - xConfigItem->DocumentReloaded(); + std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem(); + if (xConfigItem) + { + xConfigItem->DisposeResultSet(); + xConfigItem->DocumentReloaded(); + } } - for (const OUString& rName : m_aUncommitedRegistrations) - RevokeDataSource(rName); - - m_aUncommitedRegistrations.clear(); + for (auto it = m_aUncommitedRegistrations.begin(); it != m_aUncommitedRegistrations.end();) + { + if ((m_pDoc && it->first == m_pDoc->GetDocShell()) || it->first == nullptr) + { + RevokeDataSource(it->second); + it = m_aUncommitedRegistrations.erase(it); + } + else + it++; + } } } void SwDBManager::CommitLastRegistrations() { - m_aUncommitedRegistrations.clear(); + auto predicate = [this](const std::pair<SwDocShell*, OUString>& x) + { return x.first == this->m_pDoc->GetDocShell(); }; + + m_aUncommitedRegistrations.erase( + std::remove_if(m_aUncommitedRegistrations.begin(), m_aUncommitedRegistrations.end(), predicate), + m_aUncommitedRegistrations.end()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |