Kaydet (Commit) b79017f4 authored tarafından Miklos Vajna's avatar Miklos Vajna

sw: move name of the embedded data source def from SwDBData to SwDBManager

The problem is that SwDBData just describes the current data source,
and when changing that, the embedded name doesn't change, so they should
be separate.

Change-Id: I2dd7e0a97b9f7d6a3a74a5752467515a0a09171a
üst 1096ca46
...@@ -199,6 +199,8 @@ friend class SwConnectionDisposedListener_Impl; ...@@ -199,6 +199,8 @@ friend class SwConnectionDisposedListener_Impl;
SwDSParamArr aDataSourceParams; SwDSParamArr aDataSourceParams;
SwDBManager_Impl* pImpl; SwDBManager_Impl* pImpl;
const SwXMailMerge* pMergeEvtSrc; ///< != 0 if mail merge events are to be send const SwXMailMerge* pMergeEvtSrc; ///< != 0 if mail merge events are to be send
/// Name of the embedded database that's included in the current document.
OUString m_sEmbeddedName;
SAL_DLLPRIVATE SwDSParam* FindDSData(const SwDBData& rData, bool bCreate); SAL_DLLPRIVATE SwDSParam* FindDSData(const SwDBData& rData, bool bCreate);
SAL_DLLPRIVATE SwDSParam* FindDSConnection(const OUString& rSource, bool bCreate); SAL_DLLPRIVATE SwDSParam* FindDSConnection(const OUString& rSource, bool bCreate);
...@@ -372,7 +374,7 @@ public: ...@@ -372,7 +374,7 @@ public:
const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet > *pSettings = 0); const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet > *pSettings = 0);
/// Load the embedded data source of the document and also register it. /// Load the embedded data source of the document and also register it.
static void LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const SwDocShell& rDocShell); void LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const SwDocShell& rDocShell);
/** try to get the data source from the given connection through the XChild interface. /** try to get the data source from the given connection through the XChild interface.
If this is not possible, the data source will be created through its name. If this is not possible, the data source will be created through its name.
...@@ -405,6 +407,9 @@ public: ...@@ -405,6 +407,9 @@ public:
sal_Int32 _nCommandType, sal_Int32 _nCommandType,
const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection
); );
void setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell);
OUString getEmbeddedName() const;
}; };
#endif #endif
......
...@@ -28,16 +28,14 @@ struct SwDBData ...@@ -28,16 +28,14 @@ struct SwDBData
OUString sDataSource; OUString sDataSource;
OUString sCommand; //table, query or statement OUString sCommand; //table, query or statement
sal_Int32 nCommandType; //com::sun::star::sdb::CommandType sal_Int32 nCommandType; //com::sun::star::sdb::CommandType
/// Name of the embedded database that's included in the current document.
OUString sEmbeddedName;
SwDBData() : SwDBData() :
nCommandType(0){} nCommandType(0){}
void dumpAsXml(struct _xmlTextWriter* pWriter) const; void dumpAsXml(struct _xmlTextWriter* pWriter) const;
bool operator !=(const SwDBData& rCmp) const bool operator !=(const SwDBData& rCmp) const
{return rCmp.sDataSource != sDataSource || rCmp.sCommand != sCommand || rCmp.nCommandType != nCommandType || rCmp.sEmbeddedName != sEmbeddedName;} {return rCmp.sDataSource != sDataSource || rCmp.sCommand != sCommand || rCmp.nCommandType != nCommandType;}
bool operator ==(const SwDBData& rCmp) const bool operator ==(const SwDBData& rCmp) const
{return rCmp.sDataSource == sDataSource && rCmp.sCommand == sCommand && rCmp.nCommandType == nCommandType && rCmp.sEmbeddedName == sEmbeddedName;} {return rCmp.sDataSource == sDataSource && rCmp.sCommand == sCommand && rCmp.nCommandType == nCommandType;}
}; };
#endif #endif
......
...@@ -494,15 +494,6 @@ void SwDoc::ChgDBData(const SwDBData& rNewData) ...@@ -494,15 +494,6 @@ void SwDoc::ChgDBData(const SwDBData& rNewData)
{ {
if( rNewData != maDBData ) if( rNewData != maDBData )
{ {
if (maDBData.sEmbeddedName != rNewData.sEmbeddedName && GetDocShell())
{
uno::Reference<embed::XStorage> xStorage = GetDocShell()->GetStorage();
// It's OK that we don't have the named sub-storage yet, in case
// we're in the process of creating it.
if (xStorage->hasByName(rNewData.sEmbeddedName))
SwDBManager::LoadAndRegisterEmbeddedDataSource(rNewData, *GetDocShell());
}
maDBData = rNewData; maDBData = rNewData;
getIDocumentState().SetModified(); getIDocumentState().SetModified();
} }
......
...@@ -1958,7 +1958,6 @@ void SwDBData::dumpAsXml(xmlTextWriterPtr pWriter) const ...@@ -1958,7 +1958,6 @@ void SwDBData::dumpAsXml(xmlTextWriterPtr pWriter) const
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("sDataSource"), BAD_CAST(sDataSource.toUtf8().getStr())); xmlTextWriterWriteAttribute(pWriter, BAD_CAST("sDataSource"), BAD_CAST(sDataSource.toUtf8().getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("sCommand"), BAD_CAST(sCommand.toUtf8().getStr())); xmlTextWriterWriteAttribute(pWriter, BAD_CAST("sCommand"), BAD_CAST(sCommand.toUtf8().getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nCommandType"), BAD_CAST(OString::number(nCommandType).getStr())); xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nCommandType"), BAD_CAST(OString::number(nCommandType).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("sEmbeddedName"), BAD_CAST(sEmbeddedName.toUtf8().getStr()));
xmlTextWriterEndElement(pWriter); xmlTextWriterEndElement(pWriter);
} }
......
...@@ -2667,6 +2667,12 @@ void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const ...@@ -2667,6 +2667,12 @@ void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const
{ {
uno::Reference<sdb::XDatabaseContext> xDatabaseContext = sdb::DatabaseContext::create(comphelper::getProcessComponentContext()); uno::Reference<sdb::XDatabaseContext> xDatabaseContext = sdb::DatabaseContext::create(comphelper::getProcessComponentContext());
OUString sDataSource = rData.sDataSource;
// Fallback, just in case the document would contain an embedded data source, but no DB fields.
if (sDataSource.isEmpty())
sDataSource = "EmbeddedDatabase";
if (xDatabaseContext->hasByName(rData.sDataSource)) if (xDatabaseContext->hasByName(rData.sDataSource))
xDatabaseContext->revokeObject(rData.sDataSource); xDatabaseContext->revokeObject(rData.sDataSource);
...@@ -2674,7 +2680,7 @@ void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const ...@@ -2674,7 +2680,7 @@ void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const
const INetURLObject& rURLObject = rDocShell.GetMedium()->GetURLObject(); const INetURLObject& rURLObject = rDocShell.GetMedium()->GetURLObject();
OUString aURL = "vnd.sun.star.pkg://"; OUString aURL = "vnd.sun.star.pkg://";
aURL += INetURLObject::encode(rURLObject.GetMainURL(INetURLObject::DECODE_WITH_CHARSET), INetURLObject::PART_AUTHORITY, INetURLObject::ENCODE_ALL); aURL += INetURLObject::encode(rURLObject.GetMainURL(INetURLObject::DECODE_WITH_CHARSET), INetURLObject::PART_AUTHORITY, INetURLObject::ENCODE_ALL);
aURL += "/" + INetURLObject::encode(rData.sEmbeddedName, INetURLObject::PART_FPATH, INetURLObject::ENCODE_ALL); aURL += "/" + INetURLObject::encode(m_sEmbeddedName, INetURLObject::PART_FPATH, INetURLObject::ENCODE_ALL);
uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY); uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY);
xDatabaseContext->registerObject(rData.sDataSource, xDataSource); xDatabaseContext->registerObject(rData.sDataSource, xDataSource);
...@@ -2966,6 +2972,27 @@ uno::Reference<XResultSet> SwDBManager::createCursor(const OUString& _sDataSourc ...@@ -2966,6 +2972,27 @@ uno::Reference<XResultSet> SwDBManager::createCursor(const OUString& _sDataSourc
return xResultSet; return xResultSet;
} }
void SwDBManager::setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell)
{
bool bLoad = m_sEmbeddedName != rEmbeddedName && !rEmbeddedName.isEmpty();
m_sEmbeddedName = rEmbeddedName;
if (bLoad)
{
uno::Reference<embed::XStorage> xStorage = rDocShell.GetStorage();
// It's OK that we don't have the named sub-storage yet, in case
// we're in the process of creating it.
if (xStorage->hasByName(rEmbeddedName))
LoadAndRegisterEmbeddedDataSource(rDocShell.GetDoc()->GetDBData(), rDocShell);
}
}
OUString SwDBManager::getEmbeddedName() const
{
return m_sEmbeddedName;
}
SwConnectionDisposedListener_Impl::SwConnectionDisposedListener_Impl(SwDBManager& rManager) SwConnectionDisposedListener_Impl::SwConnectionDisposedListener_Impl(SwDBManager& rManager)
: m_pDBManager(&rManager) : m_pDBManager(&rManager)
{ {
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "swmodule.hxx" #include "swmodule.hxx"
#include "cfgitems.hxx" #include "cfgitems.hxx"
#include "prtopt.hxx" #include "prtopt.hxx"
#include "dbmgr.hxx"
using namespace comphelper; using namespace comphelper;
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -508,9 +509,9 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf ...@@ -508,9 +509,9 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf
break; break;
case HANDLE_EMBEDDED_DATABASE_NAME: case HANDLE_EMBEDDED_DATABASE_NAME:
{ {
SwDBData aData = mpDoc->GetDBData(); OUString sEmbeddedName;
if (rValue >>= aData.sEmbeddedName) if (rValue >>= sEmbeddedName)
mpDoc->ChgDBData(aData); mpDoc->GetDBManager()->setEmbeddedName(sEmbeddedName, *mpDocSh);
} }
break; break;
case HANDLE_SAVE_VERSION_ON_CLOSE: case HANDLE_SAVE_VERSION_ON_CLOSE:
...@@ -988,8 +989,7 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf ...@@ -988,8 +989,7 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf
break; break;
case HANDLE_EMBEDDED_DATABASE_NAME: case HANDLE_EMBEDDED_DATABASE_NAME:
{ {
const SwDBData& rData = mpDoc->GetDBDesc(); rValue <<= mpDoc->GetDBManager()->getEmbeddedName();
rValue <<= rData.sEmbeddedName;
} }
break; break;
case HANDLE_SAVE_VERSION_ON_CLOSE: case HANDLE_SAVE_VERSION_ON_CLOSE:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment