summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@suse.com>2012-01-12 14:09:32 -0500
committerKohei Yoshida <kohei.yoshida@suse.com>2012-01-12 21:51:52 -0500
commit29cfe42f6473fa2e7351f98d5f3480ffbd9904fe (patch)
tree3dfd20f6d6527aa9463a8d6da1fef4ef94fbf811 /sc/source
parent659d0ebda52cb7252590d9b11ebe0ef461df89a9 (diff)
fdo#43077: Have cache instance keep track of who is referencing it.
With this change, ScDPCacheTable should never clear pointer to the data cache instance; it should keep the same data cache instance that it is instantiated with.
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/core/data/dpcachetable.cxx10
-rw-r--r--sc/source/core/data/dpobject.cxx12
-rw-r--r--sc/source/core/data/dpsdbtab.cxx15
-rw-r--r--sc/source/core/data/dpshttab.cxx7
-rw-r--r--sc/source/core/data/dptablecache.cxx10
5 files changed, 36 insertions, 18 deletions
diff --git a/sc/source/core/data/dpcachetable.cxx b/sc/source/core/data/dpcachetable.cxx
index adc3cffe6693..ae9ca7615f01 100644
--- a/sc/source/core/data/dpcachetable.cxx
+++ b/sc/source/core/data/dpcachetable.cxx
@@ -414,24 +414,18 @@ void ScDPCacheTable::filterTable(const vector<Criterion>& rCriteria, Sequence< S
SCROW ScDPCacheTable::getOrder(long nDim, SCROW nIndex) const
{
- return mpCache ? getCache()->GetOrder(nDim, nIndex) : 0;
+ return mpCache->GetOrder(nDim, nIndex);
}
void ScDPCacheTable::clear()
{
maFieldEntries.clear();
maRowFlags.clear();
- mpCache = NULL;
}
bool ScDPCacheTable::empty() const
{
- return mpCache == NULL || maFieldEntries.empty();
-}
-
-void ScDPCacheTable::setCache(const ScDPCache* p)
-{
- mpCache = p;
+ return maFieldEntries.empty();
}
bool ScDPCacheTable::hasCache() const
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index a6f48db37ea6..3999d55c6d91 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -460,7 +460,12 @@ ScDPTableData* ScDPObject::GetTableData()
if ( pImpDesc )
{
// database data
- pData.reset(new ScDatabaseDPData(pDoc, *pImpDesc));
+ const ScDPCache* pCache = pImpDesc->CreateCache();
+ if (pCache)
+ {
+ pCache->AddReference(this);
+ pData.reset(new ScDatabaseDPData(pDoc, *pImpDesc, pCache));
+ }
}
else
{
@@ -478,7 +483,10 @@ ScDPTableData* ScDPObject::GetTableData()
DisableGetPivotData aSwitch(*this, mbEnableGetPivotData);
const ScDPCache* pCache = pSheetDesc->CreateCache();
if (pCache)
+ {
+ pCache->AddReference(this);
pData.reset(new ScSheetDPData(pDoc, *pSheetDesc, pCache));
+ }
}
}
@@ -572,6 +580,8 @@ void ScDPObject::ClearSource()
}
}
xSource = NULL;
+ if (mpTableData)
+ mpTableData->GetCacheTable().getCache()->RemoveReference(this);
mpTableData.reset();
}
diff --git a/sc/source/core/data/dpsdbtab.cxx b/sc/source/core/data/dpsdbtab.cxx
index 0f410e191213..1cfa2f8966e7 100644
--- a/sc/source/core/data/dpsdbtab.cxx
+++ b/sc/source/core/data/dpsdbtab.cxx
@@ -77,10 +77,11 @@ const ScDPCache* ScImportSourceDesc::CreateCache() const
return rCaches.getCache(nSdbType, aDBName, aObject);
}
-ScDatabaseDPData::ScDatabaseDPData(ScDocument* pDoc, const ScImportSourceDesc& rImport) :
+ScDatabaseDPData::ScDatabaseDPData(
+ ScDocument* pDoc, const ScImportSourceDesc& rImport, const ScDPCache* pCache) :
ScDPTableData(pDoc),
mrImport(rImport),
- aCacheTable(rImport.CreateCache())
+ aCacheTable(pCache)
{
}
@@ -139,12 +140,10 @@ void ScDatabaseDPData::CreateCacheTable()
if (!aCacheTable.hasCache())
{
- const ScDPCache* pCache = mrImport.CreateCache();
- if (!pCache)
- // Cache creation failed. Perhaps invalid database connection.
- return;
-
- aCacheTable.setCache(pCache);
+ fprintf(stdout, "ScDatabaseDPData::CreateCacheTable: NOT GOOD!\n");
+ // This better not happen!! Cache table should be created with a live
+ // data cache instance at all times.
+ return;
}
aCacheTable.fillTable();
diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index a04bb5a8f988..14a6f7b56f6b 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -191,7 +191,12 @@ void ScSheetDPData::CreateCacheTable()
return;
if (!aCacheTable.hasCache())
- aCacheTable.setCache(mrDesc.CreateCache());
+ {
+ fprintf(stdout, "ScSheetDPData::CreateCacheTable: NOT GOOD!!!\n");
+ // This better not happen!! The cache table should be created with a
+ // live data cache at all times.
+ return;
+ }
aCacheTable.fillTable(aQuery, bIgnoreEmptyRows, bRepeatIfEmpty);
}
diff --git a/sc/source/core/data/dptablecache.cxx b/sc/source/core/data/dptablecache.cxx
index d0ca15c959d3..683a8750387a 100644
--- a/sc/source/core/data/dptablecache.cxx
+++ b/sc/source/core/data/dptablecache.cxx
@@ -985,6 +985,16 @@ SCCOL ScDPCache::GetDimensionIndex(String sName) const
return -1;
}
+void ScDPCache::AddReference(ScDPObject* pObj) const
+{
+ maRefObjects.insert(pObj);
+}
+
+void ScDPCache::RemoveReference(ScDPObject* pObj) const
+{
+ maRefObjects.erase(pObj);
+}
+
SCROW ScDPCache::GetIdByItemData(long nDim, const String& sItemData ) const
{
if ( nDim < mnColumnCount && nDim >=0 )