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>
This commit is contained in:
Szymon Kłos
2017-09-08 10:57:55 +02:00
parent a45800f010
commit 97477ee5e1
4 changed files with 42 additions and 15 deletions

View File

@@ -198,6 +198,7 @@ public:
|| name == "g_aWindowList" || name == "g_aWindowList"
//vcl/unx/gtk/a11y/atkutil.cxx, asserted empty at exit //vcl/unx/gtk/a11y/atkutil.cxx, asserted empty at exit
|| name == "aLogger" // FormulaLogger& FormulaLogger::get() in sc/source/core/tool/formulalogger.cxx || name == "aLogger" // FormulaLogger& FormulaLogger::get() in sc/source/core/tool/formulalogger.cxx
|| name == "m_aUncommitedRegistrations" // sw/source/uibase/dbui/dbmgr.cxx
|| (loplugin::DeclCheck(pVarDecl).Var("aAllListeners") || (loplugin::DeclCheck(pVarDecl).Var("aAllListeners")
.Class("ScAddInListener").GlobalNamespace()) // not owning .Class("ScAddInListener").GlobalNamespace()) // not owning
) // these variables appear unproblematic ) // these variables appear unproblematic

View File

@@ -257,7 +257,7 @@ class SW_DLLPUBLIC SwDBManager
OUString m_sEmbeddedName; OUString m_sEmbeddedName;
/// Store last registrations to revoke or commit /// 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. /// The document that owns this manager.
SwDoc* m_pDoc; SwDoc* m_pDoc;
@@ -484,7 +484,7 @@ public:
void RevokeLastRegistrations(); void RevokeLastRegistrations();
/// Accept not commited registrations /// Accept not commited registrations
static void CommitLastRegistrations(); void CommitLastRegistrations();
}; };
#endif #endif

View File

@@ -479,7 +479,13 @@ void SwMailMergeWizardExecutor::ExecutionFinished()
if (xMMConfig) if (xMMConfig)
xMMConfig->Commit(); xMMConfig->Commit();
SwDBManager::CommitLastRegistrations(); SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
if (pDoc)
{
SwDBManager* pDbManager = pDoc->GetDBManager();
if (pDbManager)
pDbManager->CommitLastRegistrations();
}
// release/destroy asynchronously // release/destroy asynchronously
Application::PostUserEvent( LINK( this, SwMailMergeWizardExecutor, DestroyDialogHdl ) ); Application::PostUserEvent( LINK( this, SwMailMergeWizardExecutor, DestroyDialogHdl ) );

View File

@@ -161,7 +161,7 @@ void lcl_emitEvent(SfxEventHintId nEventId, sal_Int32 nStrId, SfxObjectShell* pD
} }
std::vector<OUString> SwDBManager::m_aUncommitedRegistrations; std::vector<std::pair<SwDocShell*, OUString>> SwDBManager::m_aUncommitedRegistrations;
enum class SwDBNextRecord { NEXT, FIRST }; enum class SwDBNextRecord { NEXT, FIRST };
static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action = SwDBNextRecord::NEXT ); static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action = SwDBNextRecord::NEXT );
@@ -804,6 +804,8 @@ SwDBManager::SwDBManager(SwDoc* pDoc)
SwDBManager::~SwDBManager() SwDBManager::~SwDBManager()
{ {
RevokeLastRegistrations();
// copy required, m_DataSourceParams can be modified while disposing components // copy required, m_DataSourceParams can be modified while disposing components
std::vector<uno::Reference<sdbc::XConnection>> aCopiedConnections; std::vector<uno::Reference<sdbc::XConnection>> aCopiedConnections;
for (auto & pParam : m_DataSourceParams) for (auto & pParam : m_DataSourceParams)
@@ -2615,7 +2617,7 @@ OUString SwDBManager::LoadAndRegisterDataSource(const vcl::Window* pParent, SwDo
} }
sFind = LoadAndRegisterDataSource( type, aURLAny, DBCONN_FLAT == type ? &aSettings : nullptr, aURI, nullptr, nullptr, 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; return sFind;
} }
@@ -2872,6 +2874,10 @@ void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const
uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY); uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY);
xDatabaseContext->registerObject( sDataSource, xDataSource ); 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, void SwDBManager::ExecuteFormLetter( SwWrtShell& rSh,
@@ -3189,24 +3195,38 @@ void SwDBManager::RevokeLastRegistrations()
{ {
if (m_aUncommitedRegistrations.size()) if (m_aUncommitedRegistrations.size())
{ {
SwView* pView = m_pDoc->GetDocShell()->GetView(); SwView* pView = ( m_pDoc && m_pDoc->GetDocShell() ) ? m_pDoc->GetDocShell()->GetView() : nullptr;
std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem(); if (pView)
if (xConfigItem)
{ {
xConfigItem->DisposeResultSet(); std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
xConfigItem->DocumentReloaded(); if (xConfigItem)
{
xConfigItem->DisposeResultSet();
xConfigItem->DocumentReloaded();
}
} }
for (const OUString& rName : m_aUncommitedRegistrations) for (auto it = m_aUncommitedRegistrations.begin(); it != m_aUncommitedRegistrations.end();)
RevokeDataSource(rName); {
if ((m_pDoc && it->first == m_pDoc->GetDocShell()) || it->first == nullptr)
m_aUncommitedRegistrations.clear(); {
RevokeDataSource(it->second);
it = m_aUncommitedRegistrations.erase(it);
}
else
it++;
}
} }
} }
void SwDBManager::CommitLastRegistrations() 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */