LibreOffice Module sc (master)  1
dataprovider.hxx
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 
10 #pragma once
11 
12 #include <memory>
13 #include <salhelper/thread.hxx>
14 #include <rtl/ustring.hxx>
15 #include <rtl/ref.hxx>
16 #include <osl/mutex.hxx>
17 #include <document.hxx>
18 
19 #include <rtl/strbuf.hxx>
20 
21 #include <vector>
22 //#include <map>
23 
24 #include <orcus/csv_parser.hpp>
25 
26 class SvStream;
27 class ScDBData;
28 
29 namespace sc {
30 
31 class DataTransformation;
32 class ExternalDataSource;
33 
35 {
37  OUString maURL;
38 
40  osl::Mutex maMtxTerminate;
41 
42  orcus::csv::parser_config maConfig;
43 
44  std::vector<std::shared_ptr<sc::DataTransformation>> maDataTransformations;
45 
46  std::function<void()> maImportFinishedHdl;
47 
48 
49 public:
50  CSVFetchThread(ScDocument& rDoc, const OUString&, std::function<void()> aImportFinishedHdl,
51  const std::vector<std::shared_ptr<sc::DataTransformation>>& mrDataTransformations);
52  virtual ~CSVFetchThread() override;
53 
54  void RequestTerminate();
55  bool IsRequestedTerminate();
56  void Terminate();
57  void EndThread();
58 
59  virtual void execute() override;
60 };
61 
67 {
68 protected:
74 
75 public:
77 
78  virtual ~DataProvider();
79 
80  virtual void Import() = 0;
81 
82  virtual const OUString& GetURL() const = 0;
83 
84  static std::unique_ptr<SvStream> FetchStreamFromURL(const OUString&, OStringBuffer& rBuffer);
85 
86  void setDeterministic();
87 };
88 
90 {
94 
95  void Refresh();
96 
97 public:
99  virtual ~CSVDataProvider() override;
100 
101  virtual void Import() override;
102 
103  const OUString& GetURL() const override;
104  void ImportFinished();
105 };
106 
118 {
119  OUString maDBName;
121 
122 public:
123  ScDBDataManager(const OUString& rDBName, ScDocument* pDoc);
125 
126  void SetDatabase(const OUString& rDBName);
127 
128  ScDBData* getDBData();
129 
130  void WriteToDoc(ScDocument& rDoc);
131 };
132 
134 {
135 private:
136 
137  static bool isInternalDataProvider(const OUString& rProvider);
138 
139 public:
140 
141  static std::shared_ptr<DataProvider> getDataProvider(ScDocument* pDoc, sc::ExternalDataSource& rDataSource);
142 
143  static std::vector<OUString> getDataProviders();
144 };
145 
146 }
147 
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDocument & mrDocument
static std::vector< OUString > getDataProviders()
sc::ExternalDataSource & mrDataSource
std::function< void()> maImportFinishedHdl
CSVFetchThread(ScDocument &rDoc, const OUString &, std::function< void()> aImportFinishedHdl, const std::vector< std::shared_ptr< sc::DataTransformation >> &mrDataTransformations)
Abstract class for all data provider.
orcus::csv::parser_config maConfig
const OUString & GetURL() const override
ScDBDataManager(const OUString &rDBName, ScDocument *pDoc)
bool mbDeterministic
If true make the threaded import deterministic for the tests.
virtual void execute() override
virtual ~CSVDataProvider() override
This class handles the copying of the data from the imported temporary document to the actual documen...
static std::unique_ptr< SvStream > FetchStreamFromURL(const OUString &, OStringBuffer &rBuffer)
void WriteToDoc(ScDocument &rDoc)
static std::shared_ptr< DataProvider > getDataProvider(ScDocument *pDoc, sc::ExternalDataSource &rDataSource)
std::vector< std::shared_ptr< sc::DataTransformation > > maDataTransformations
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2613
void SetDatabase(const OUString &rDBName)
CSVDataProvider(ScDocument *pDoc, sc::ExternalDataSource &rDataSource)
rtl::Reference< CSVFetchThread > mxCSVFetchThread
virtual void Import()=0
osl::Mutex maMtxTerminate
DataProvider(sc::ExternalDataSource &rDataSource)
ScDocument * mpDocument
virtual ~DataProvider()
virtual void Import() override
virtual ~CSVFetchThread() override
static bool isInternalDataProvider(const OUString &rProvider)
ScDBData * getDBData()
ScDocumentUniquePtr mpDoc
virtual const OUString & GetURL() const =0