summaryrefslogtreecommitdiff
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
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.
-rw-r--r--sc/inc/dpcachetable.hxx1
-rw-r--r--sc/inc/dpsdbtab.hxx5
-rw-r--r--sc/inc/dptablecache.hxx9
-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
8 files changed, 48 insertions, 21 deletions
diff --git a/sc/inc/dpcachetable.hxx b/sc/inc/dpcachetable.hxx
index 62efc84b7e41..695586f42874 100644
--- a/sc/inc/dpcachetable.hxx
+++ b/sc/inc/dpcachetable.hxx
@@ -175,7 +175,6 @@ public:
SCROW getOrder(long nDim, SCROW nIndex) const;
void clear();
bool empty() const;
- void setCache(const ScDPCache* p);
bool hasCache() const;
private:
diff --git a/sc/inc/dpsdbtab.hxx b/sc/inc/dpsdbtab.hxx
index 87c3ccd1ec5c..8be0cb9904fc 100644
--- a/sc/inc/dpsdbtab.hxx
+++ b/sc/inc/dpsdbtab.hxx
@@ -38,6 +38,7 @@
class ScDPCacheTable;
class ScDocument;
+class ScDPCache;
struct ScImportSourceDesc
{
@@ -69,8 +70,8 @@ private:
const ScImportSourceDesc& mrImport;
ScDPCacheTable aCacheTable;
public:
- ScDatabaseDPData(ScDocument* pDoc, const ScImportSourceDesc& rImport);
- virtual ~ScDatabaseDPData();
+ ScDatabaseDPData(ScDocument* pDoc, const ScImportSourceDesc& rImport, const ScDPCache* pCache);
+ virtual ~ScDatabaseDPData();
virtual long GetColumnCount();
virtual String getDimensionName(long nColumn);
diff --git a/sc/inc/dptablecache.hxx b/sc/inc/dptablecache.hxx
index 950cc5459bef..a67103d0f788 100644
--- a/sc/inc/dptablecache.hxx
+++ b/sc/inc/dptablecache.hxx
@@ -53,11 +53,17 @@ public:
private:
typedef ::boost::ptr_vector<DataListType> DataGridType;
typedef ::boost::ptr_vector< ::std::vector<SCROW> > RowGridType;
+ typedef std::set<ScDPObject*> ObjectSetType;
ScDocument* mpDoc;
long mnColumnCount;
/**
+ * All pivot table objects that references this cache.
+ */
+ mutable ObjectSetType maRefObjects;
+
+ /**
* This container stores only the unique instances of item data in each
* column. Duplicates are not allowed.
*/
@@ -88,6 +94,9 @@ private:
mutable ScDPItemDataPool maAdditionalData;
public:
+ void AddReference(ScDPObject* pObj) const;
+ void RemoveReference(ScDPObject* pObj) const;
+
SCROW GetIdByItemData( long nDim, const String& sItemData ) const;
SCROW GetIdByItemData( long nDim, const ScDPItemData& rData ) const;
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 )