summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/dbmgr.hxx9
-rw-r--r--sw/source/core/doc/docnew.cxx7
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx33
3 files changed, 44 insertions, 5 deletions
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index b0da6613add0..0947bf0e4804 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -259,6 +259,12 @@ class SW_DLLPUBLIC SwDBManager
/// Store last registrations to revoke or commit
static std::vector<std::pair<SwDocShell*, OUString>> m_aUncommitedRegistrations;
+ /// Not used connections.
+ std::vector<OUString> m_aNotUsedConnections;
+
+ /// Set connection as used.
+ void SetAsUsed(const OUString& rName);
+
/// The document that owns this manager.
SwDoc* m_pDoc;
@@ -485,6 +491,9 @@ public:
/// Accept not commited registrations
void CommitLastRegistrations();
+
+ /// Remove not used connections.
+ void RevokeNotUsedConnections();
};
#endif
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 5a53fc42f25a..86e5085692c8 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -525,6 +525,13 @@ SwDoc::~SwDoc()
mpDBManager->releaseRevokeListener();
SwDBManager::RevokeDataSource(maDBData.sDataSource);
}
+ else if (!mpDBManager->getEmbeddedName().isEmpty())
+ {
+ // Remove the revoke listener here first, so that we don't remove the data source from the document.
+ mpDBManager->releaseRevokeListener();
+ // Remove connections which was committed but not used.
+ mpDBManager->RevokeNotUsedConnections();
+ }
DELETEZ( mpDBManager );
#endif
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 3de0f42ac26b..bfb0a539df57 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -2517,6 +2517,7 @@ SwDSParam* SwDBManager::FindDSConnection(const OUString& rDataSource, bool bCre
//prefer merge data if available
if(pImpl->pMergeData && rDataSource == pImpl->pMergeData->sDataSource )
{
+ SetAsUsed(rDataSource);
return pImpl->pMergeData;
}
SwDSParam* pFound = nullptr;
@@ -2524,6 +2525,7 @@ SwDSParam* SwDBManager::FindDSConnection(const OUString& rDataSource, bool bCre
{
if(rDataSource == pParam->sDataSource)
{
+ SetAsUsed(rDataSource);
pFound = pParam.get();
break;
}
@@ -2533,6 +2535,7 @@ SwDSParam* SwDBManager::FindDSConnection(const OUString& rDataSource, bool bCre
SwDBData aData;
aData.sDataSource = rDataSource;
pFound = new SwDSParam(aData);
+ SetAsUsed(rDataSource);
m_DataSourceParams.push_back(std::unique_ptr<SwDSParam>(pFound));
try
{
@@ -3221,12 +3224,32 @@ void SwDBManager::RevokeLastRegistrations()
void SwDBManager::CommitLastRegistrations()
{
- auto predicate = [this](const std::pair<SwDocShell*, OUString>& x)
- { return x.first == this->m_pDoc->GetDocShell(); };
+ for (auto aIt = m_aUncommitedRegistrations.begin(); aIt != m_aUncommitedRegistrations.end();)
+ {
+ if (aIt->first == m_pDoc->GetDocShell())
+ {
+ m_aNotUsedConnections.push_back(aIt->second);
+ aIt = m_aUncommitedRegistrations.erase(aIt);
+ }
+ else
+ aIt++;
+ }
+}
- m_aUncommitedRegistrations.erase(
- std::remove_if(m_aUncommitedRegistrations.begin(), m_aUncommitedRegistrations.end(), predicate),
- m_aUncommitedRegistrations.end());
+void SwDBManager::SetAsUsed(const OUString& rName)
+{
+ auto aFound = std::find(m_aNotUsedConnections.begin(), m_aNotUsedConnections.end(), rName);
+ if (aFound != m_aNotUsedConnections.end())
+ m_aNotUsedConnections.erase(aFound);
+}
+
+void SwDBManager::RevokeNotUsedConnections()
+{
+ for (auto aIt = m_aNotUsedConnections.begin(); aIt != m_aNotUsedConnections.end();)
+ {
+ RevokeDataSource(*aIt);
+ aIt = m_aNotUsedConnections.erase(aIt);
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */