Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "dpsdbtab.hxx"
30 : : #include "global.hxx"
31 : : #include "globstr.hrc"
32 : : #include "dpcachetable.hxx"
33 : : #include "dptabres.hxx"
34 : : #include "document.hxx"
35 : : #include "dpobject.hxx"
36 : :
37 : : #include <com/sun/star/sheet/DataImportMode.hpp>
38 : : #include <com/sun/star/sdb/CommandType.hpp>
39 : :
40 : : using namespace com::sun::star;
41 : :
42 : : using ::std::vector;
43 : : using ::com::sun::star::uno::Sequence;
44 : : using ::com::sun::star::uno::Any;
45 : :
46 : 0 : sal_Int32 ScImportSourceDesc::GetCommandType() const
47 : : {
48 : 0 : sal_Int32 nSdbType = -1;
49 : :
50 [ # # # # ]: 0 : switch ( nType )
51 : : {
52 : 0 : case sheet::DataImportMode_SQL: nSdbType = sdb::CommandType::COMMAND; break;
53 : 0 : case sheet::DataImportMode_TABLE: nSdbType = sdb::CommandType::TABLE; break;
54 : 0 : case sheet::DataImportMode_QUERY: nSdbType = sdb::CommandType::QUERY; break;
55 : : default:
56 : : ;
57 : : }
58 : 0 : return nSdbType;
59 : : }
60 : :
61 : 0 : const ScDPCache* ScImportSourceDesc::CreateCache(const ScDPDimensionSaveData* pDimData) const
62 : : {
63 [ # # ]: 0 : if (!mpDoc)
64 : 0 : return NULL;
65 : :
66 : 0 : sal_Int32 nSdbType = GetCommandType();
67 [ # # ]: 0 : if (nSdbType < 0)
68 : 0 : return NULL;
69 : :
70 : 0 : ScDPCollection::DBCaches& rCaches = mpDoc->GetDPCollection()->GetDBCaches();
71 : 0 : return rCaches.getCache(nSdbType, aDBName, aObject, pDimData);
72 : : }
73 : :
74 : 0 : ScDatabaseDPData::ScDatabaseDPData(
75 : : ScDocument* pDoc, const ScImportSourceDesc& rImport, const ScDPCache* pCache) :
76 : : ScDPTableData(pDoc),
77 : : mrImport(rImport),
78 [ # # ]: 0 : aCacheTable(pCache)
79 : : {
80 : 0 : }
81 : :
82 [ # # ]: 0 : ScDatabaseDPData::~ScDatabaseDPData()
83 : : {
84 [ # # ]: 0 : }
85 : :
86 : 0 : void ScDatabaseDPData::DisposeData()
87 : : {
88 : : //! use OpenDatabase here?
89 : 0 : aCacheTable.clear();
90 : 0 : }
91 : :
92 : 0 : long ScDatabaseDPData::GetColumnCount()
93 : : {
94 : 0 : CreateCacheTable();
95 : 0 : return GetCacheTable().getColSize();
96 : : }
97 : :
98 : :
99 : 0 : rtl::OUString ScDatabaseDPData::getDimensionName(long nColumn)
100 : : {
101 [ # # ]: 0 : if (getIsDataLayoutDimension(nColumn))
102 : : {
103 : : //! different internal and display names?
104 : : //return "Data";
105 : 0 : return ScGlobal::GetRscString(STR_PIVOT_DATA);
106 : : }
107 : :
108 : 0 : CreateCacheTable();
109 : 0 : return aCacheTable.getFieldName(static_cast<SCCOL>(nColumn));
110 : : }
111 : :
112 : 0 : sal_Bool ScDatabaseDPData::getIsDataLayoutDimension(long nColumn)
113 : : {
114 : 0 : return ( nColumn == GetCacheTable().getColSize());
115 : : }
116 : :
117 : 0 : sal_Bool ScDatabaseDPData::IsDateDimension(long /* nDim */)
118 : : {
119 : : //! later...
120 : 0 : return false;
121 : : }
122 : :
123 : 0 : void ScDatabaseDPData::SetEmptyFlags( sal_Bool /* bIgnoreEmptyRows */, sal_Bool /* bRepeatIfEmpty */ )
124 : : {
125 : : // not used for database data
126 : : //! disable flags
127 : 0 : }
128 : :
129 : 0 : void ScDatabaseDPData::CreateCacheTable()
130 : : {
131 [ # # ]: 0 : if (!aCacheTable.empty())
132 : : // cache table already created.
133 : 0 : return;
134 : :
135 [ # # ]: 0 : if (!aCacheTable.hasCache())
136 : : {
137 : : OSL_FAIL("Cache table should be created with a live data cache instance at all times.");
138 : : // This better not happen!! Cache table should be created with a live
139 : : // data cache instance at all times.
140 : 0 : return;
141 : : }
142 : :
143 : 0 : aCacheTable.fillTable();
144 : : }
145 : :
146 : 0 : void ScDatabaseDPData::FilterCacheTable(const vector<ScDPCacheTable::Criterion>& rCriteria, const boost::unordered_set<sal_Int32>& rCatDims)
147 : : {
148 : 0 : CreateCacheTable();
149 : : aCacheTable.filterByPageDimension(
150 [ # # ][ # # ]: 0 : rCriteria, (IsRepeatIfEmpty() ? rCatDims : boost::unordered_set<sal_Int32>()));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
[ # # ]
151 : 0 : }
152 : :
153 : 0 : void ScDatabaseDPData::GetDrillDownData(const vector<ScDPCacheTable::Criterion>& rCriteria, const boost::unordered_set<sal_Int32>& rCatDims, Sequence< Sequence<Any> >& rData)
154 : : {
155 : 0 : CreateCacheTable();
156 : 0 : sal_Int32 nRowSize = aCacheTable.getRowSize();
157 [ # # ]: 0 : if (!nRowSize)
158 : 0 : return;
159 : :
160 : : aCacheTable.filterTable(
161 [ # # ][ # # ]: 0 : rCriteria, rData, IsRepeatIfEmpty() ? rCatDims : boost::unordered_set<sal_Int32>());
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # #
# # ]
162 : : }
163 : :
164 : 0 : void ScDatabaseDPData::CalcResults(CalcInfo& rInfo, bool bAutoShow)
165 : : {
166 : 0 : CreateCacheTable();
167 : 0 : CalcResultsFromCacheTable( aCacheTable, rInfo, bAutoShow);
168 : 0 : }
169 : :
170 : 0 : const ScDPCacheTable& ScDatabaseDPData::GetCacheTable() const
171 : : {
172 : 0 : return aCacheTable;
173 : : }
174 : :
175 : 0 : void ScDatabaseDPData::ReloadCacheTable()
176 : : {
177 : 0 : aCacheTable.clear();
178 : 0 : CreateCacheTable();
179 [ + - ][ + - ]: 153 : }
180 : :
181 : : // -----------------------------------------------------------------------
182 : :
183 : :
184 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|