LibreOffice Module sc (master)  1
dpsdbtab.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <dpsdbtab.hxx>
21 #include <globstr.hrc>
22 #include <scresid.hxx>
23 #include <dpfilteredcache.hxx>
24 #include <document.hxx>
25 #include <dpobject.hxx>
26 
27 #include <com/sun/star/sdb/CommandType.hpp>
28 
29 using namespace com::sun::star;
30 
31 using ::std::vector;
32 using ::com::sun::star::uno::Sequence;
33 using ::com::sun::star::uno::Any;
34 
36 {
37  sal_Int32 nSdbType = -1;
38 
39  switch ( nType )
40  {
41  case sheet::DataImportMode_SQL: nSdbType = sdb::CommandType::COMMAND; break;
42  case sheet::DataImportMode_TABLE: nSdbType = sdb::CommandType::TABLE; break;
43  case sheet::DataImportMode_QUERY: nSdbType = sdb::CommandType::QUERY; break;
44  default:
45  ;
46  }
47  return nSdbType;
48 }
49 
51 {
52  if (!mpDoc)
53  return nullptr;
54 
55  sal_Int32 nSdbType = GetCommandType();
56  if (nSdbType < 0)
57  return nullptr;
58 
59  ScDPCollection::DBCaches& rCaches = mpDoc->GetDPCollection()->GetDBCaches();
60  return rCaches.getCache(nSdbType, aDBName, aObject, pDimData);
61 }
62 
64  const ScDocument* pDoc, const ScDPCache& rCache) :
65  ScDPTableData(pDoc),
66  aCacheTable(rCache)
67 {
68 }
69 
71 {
72 }
73 
75 {
76  //TODO: use OpenDatabase here?
78 }
79 
81 {
83  return GetCacheTable().getColSize();
84 }
85 
87 {
88  if (getIsDataLayoutDimension(nColumn))
89  {
90  //TODO: different internal and display names?
91  //return "Data";
92  return ScResId(STR_PIVOT_DATA);
93  }
94 
96  return aCacheTable.getFieldName(static_cast<SCCOL>(nColumn));
97 }
98 
100 {
101  return ( nColumn == GetCacheTable().getColSize());
102 }
103 
105 {
106  //TODO: later...
107  return false;
108 }
109 
110 void ScDatabaseDPData::SetEmptyFlags( bool /* bIgnoreEmptyRows */, bool /* bRepeatIfEmpty */ )
111 {
112  // not used for database data
113  //TODO: disable flags
114 }
115 
117 {
118  if (!aCacheTable.empty())
119  // cache table already created.
120  return;
121 
123 }
124 
125 void ScDatabaseDPData::FilterCacheTable(const vector<ScDPFilteredCache::Criterion>& rCriteria, const std::unordered_set<sal_Int32>& rCatDims)
126 {
129  rCriteria, (IsRepeatIfEmpty() ? rCatDims : std::unordered_set<sal_Int32>()));
130 }
131 
132 void ScDatabaseDPData::GetDrillDownData(const vector<ScDPFilteredCache::Criterion>& rCriteria, const std::unordered_set<sal_Int32>& rCatDims, Sequence< Sequence<Any> >& rData)
133 {
135  sal_Int32 nRowSize = aCacheTable.getRowSize();
136  if (!nRowSize)
137  return;
138 
140  rCriteria, rData, IsRepeatIfEmpty() ? rCatDims : std::unordered_set<sal_Int32>());
141 }
142 
143 void ScDatabaseDPData::CalcResults(CalcInfo& rInfo, bool bAutoShow)
144 {
146  CalcResultsFromCacheTable( aCacheTable, rInfo, bAutoShow);
147 }
148 
150 {
151  return aCacheTable;
152 }
153 
155 {
156  aCacheTable.clear();
158 }
159 
160 #if DUMP_PIVOT_TABLE
161 
162 void ScDatabaseDPData::Dump() const
163 {
164  // TODO : Implement this.
165 }
166 
167 #endif
168 
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString getFieldName(SCCOL nIndex) const
ScDPFilteredCache aCacheTable
Definition: dpsdbtab.hxx:61
virtual bool IsRepeatIfEmpty()
Definition: dptabdat.cxx:102
This class has to do with handling exclusively grouped dimensions? TODO: Find out what this class doe...
Definition: dpdimsave.hxx:160
sal_Int32 getRowSize() const
virtual void Dump() const override
void fillTable(const ScQueryParam &rQuery, bool bIgnoreEmptyRows, bool bRepeatIfEmpty)
long Long
const ContentProperties & rData
virtual void ReloadCacheTable() override
Definition: dpsdbtab.cxx:154
virtual void FilterCacheTable(const ::std::vector< ScDPFilteredCache::Criterion > &rCriteria, const std::unordered_set< sal_Int32 > &rDataDims) override
Definition: dpsdbtab.cxx:125
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:48
const ScDPCache * CreateCache(const ScDPDimensionSaveData *pDimData) const
Definition: dpsdbtab.cxx:50
Data caches for external database sources.
Definition: dpobject.hxx:357
virtual void GetDrillDownData(const ::std::vector< ScDPFilteredCache::Criterion > &rCriteria, const std::unordered_set< sal_Int32 > &rCatDims, css::uno::Sequence< css::uno::Sequence< css::uno::Any > > &rData) override
Definition: dpsdbtab.cxx:132
virtual void CalcResults(CalcInfo &rInfo, bool bAutoShow) override
Definition: dpsdbtab.cxx:143
void CalcResultsFromCacheTable(const ScDPFilteredCache &rCacheTable, CalcInfo &rInfo, bool bAutoShow)
Definition: dptabdat.cxx:199
This structure stores dimension information used when calculating results.
Definition: dptabdat.hxx:70
virtual void CreateCacheTable() override
Definition: dpsdbtab.cxx:116
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
ScDatabaseDPData(const ScDocument *pDoc, const ScDPCache &rCache)
Definition: dpsdbtab.cxx:63
virtual void SetEmptyFlags(bool bIgnoreEmptyRows, bool bRepeatIfEmpty) override
Definition: dpsdbtab.cxx:110
virtual tools::Long GetColumnCount() override
use (new) typed collection instead of ScStrCollection or separate Str and ValueCollection ...
Definition: dpsdbtab.cxx:80
virtual void DisposeData() override
Definition: dpsdbtab.cxx:74
virtual bool getIsDataLayoutDimension(tools::Long nColumn) override
Definition: dpsdbtab.cxx:99
Base class that abstracts different data source types of a datapilot table.
Definition: dptabdat.hxx:57
sal_Int32 getColSize() const
virtual ~ScDatabaseDPData() override
Definition: dpsdbtab.cxx:70
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:401
virtual OUString getDimensionName(tools::Long nColumn) override
Definition: dpsdbtab.cxx:86
virtual bool IsDateDimension(tools::Long nDim) override
Definition: dpsdbtab.cxx:104
void filterTable(const std::vector< Criterion > &rCriteria, css::uno::Sequence< css::uno::Sequence< css::uno::Any > > &rTabData, const std::unordered_set< sal_Int32 > &rRepeatIfEmptyDims)
Filter the table based on the specified criteria, and copy the result to rTabData.
This class is only a wrapper to the actual cache, to provide filtering on the raw data based on the q...
void filterByPageDimension(const std::vector< Criterion > &rCriteria, const std::unordered_set< sal_Int32 > &rRepeatIfEmptyDims)
Set filter on/off flag to each row to control visibility.
sal_Int32 GetCommandType() const
Definition: dpsdbtab.cxx:35
const ScDPCache * getCache(sal_Int32 nSdbType, const OUString &rDBName, const OUString &rCommand, const ScDPDimensionSaveData *pDimData)
Definition: dpobject.cxx:3178
virtual const ScDPFilteredCache & GetCacheTable() const override
Definition: dpsdbtab.cxx:149