GCBM
cbmaggregatorpostgresqlwriter.h
Go to the documentation of this file.
1 #ifndef MOJA_MODULES_CBM_CBMAGGREGATORPOSTGRESQLWRITER_H_
2 #define MOJA_MODULES_CBM_CBMAGGREGATORPOSTGRESQLWRITER_H_
3 
4 #include "moja/modules/cbm/_modules.cbm_exports.h"
7 
8 #include <moja/flint/spatiallocationinfo.h>
9 
10 #include <Poco/Data/Session.h>
11 #include <vector>
12 
13 namespace moja {
14 namespace flint {
15  template<class TPersistable, class TRecord>
16  class RecordAccumulatorWithMutex2;
17 }
18 
19 namespace modules {
20 namespace cbm {
21 
23  public:
25  std::shared_ptr<flint::RecordAccumulatorWithMutex2<DateRow, DateRecord>> dateDimension,
26  std::shared_ptr<flint::RecordAccumulatorWithMutex2<PoolInfoRow, PoolInfoRecord>> poolInfoDimension,
33  std::shared_ptr<std::vector<std::string>> classifierNames,
34  std::shared_ptr<flint::RecordAccumulatorWithMutex2<PoolRow, PoolRecord>> poolDimension,
35  std::shared_ptr<flint::RecordAccumulatorWithMutex2<FluxRow, FluxRecord>> fluxDimension,
36  std::shared_ptr<flint::RecordAccumulatorWithMutex2<AgeClassRow, AgeClassRecord>> ageClassDimension,
37  std::shared_ptr<flint::RecordAccumulatorWithMutex2<AgeAreaRow, AgeAreaRecord>> ageAreaDimension,
38  std::shared_ptr<flint::RecordAccumulatorWithMutex2<ErrorRow, ErrorRecord>> errorDimension,
40  bool isPrimary = false)
41  : CBMModuleBase(),
42  _dateDimension(dateDimension),
43  _poolInfoDimension(poolInfoDimension),
44  _classifierSetDimension(classifierSetDimension),
45  _landClassDimension(landClassDimension),
46  _locationDimension(locationDimension),
47  _moduleInfoDimension(moduleInfoDimension),
48  _disturbanceTypeDimension(disturbanceTypeDimension),
49  _disturbanceDimension(disturbanceDimension),
50  _classifierNames(classifierNames),
51  _poolDimension(poolDimension),
52  _fluxDimension(fluxDimension),
53  _ageClassDimension(ageClassDimension),
54  _ageAreaDimension(ageAreaDimension),
55  _errorDimension(errorDimension),
56  _locationErrorDimension(locationErrorDimension),
57  _isPrimaryAggregator(isPrimary),
58  _dropSchema(true) {}
59 
60  virtual ~CBMAggregatorPostgreSQLWriter() = default;
61 
62  void configure(const DynamicObject& config) override;
63  void subscribe(NotificationCenter& notificationCenter) override;
64 
65  flint::ModuleTypes moduleType() override { return flint::ModuleTypes::System; };
66 
67  void doSystemInit() override;
68  void doSystemShutdown() override;
69 
70  private:
71  std::shared_ptr<flint::RecordAccumulatorWithMutex2<DateRow, DateRecord>> _dateDimension;
72  std::shared_ptr<flint::RecordAccumulatorWithMutex2<PoolInfoRow, PoolInfoRecord>> _poolInfoDimension;
73  std::shared_ptr<flint::RecordAccumulatorWithMutex2<ClassifierSetRow, ClassifierSetRecord>> _classifierSetDimension;
74  std::shared_ptr<flint::RecordAccumulatorWithMutex2<LandClassRow, LandClassRecord>> _landClassDimension;
75  std::shared_ptr<flint::RecordAccumulatorWithMutex2<TemporalLocationRow, TemporalLocationRecord>> _locationDimension;
76  std::shared_ptr<flint::RecordAccumulatorWithMutex2<ModuleInfoRow, ModuleInfoRecord>> _moduleInfoDimension;
77  std::shared_ptr<flint::RecordAccumulatorWithMutex2<PoolRow, PoolRecord>> _poolDimension;
78  std::shared_ptr<flint::RecordAccumulatorWithMutex2<FluxRow, FluxRecord>> _fluxDimension;
79  std::shared_ptr<flint::RecordAccumulatorWithMutex2<AgeClassRow, AgeClassRecord>> _ageClassDimension;
80  std::shared_ptr<flint::RecordAccumulatorWithMutex2<AgeAreaRow, AgeAreaRecord>> _ageAreaDimension;
81  std::shared_ptr<flint::RecordAccumulatorWithMutex2<DisturbanceTypeRow, DisturbanceTypeRecord>> _disturbanceTypeDimension;
82  std::shared_ptr<flint::RecordAccumulatorWithMutex2<DisturbanceRow, DisturbanceRecord>> _disturbanceDimension;
83  std::shared_ptr<flint::RecordAccumulatorWithMutex2<ErrorRow, ErrorRecord>> _errorDimension;
84  std::shared_ptr<flint::RecordAccumulatorWithMutex2<LocationErrorRow, LocationErrorRecord>> _locationErrorDimension;
85  std::shared_ptr<std::vector<std::string>> _classifierNames;
86 
87  std::shared_ptr<const flint::SpatialLocationInfo> _spatialLocationInfo;
88 
89  std::string _connectionString;
90  std::string _schema;
91  Int64 _schemaLock;
92  Int64 _jobId;
95 
96  template<typename TAccumulator>
97  void load(Poco::Data::Session& session,
98  Int64 jobId,
99  const std::string& table,
100  std::shared_ptr<TAccumulator> dataDimension);
101 
102  static void tryExecute(Poco::Data::Session& session,
103  std::function<void(Poco::Data::Session&)> fn);
104  };
105 
106 }}} // namespace moja::modules::cbm
107 
108 #endif // MOJA_MODULES_CBM_CBMAGGREGATORPOSTGRESQLWRITER_H_
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_jobId
Int64 _jobId
Definition: cbmaggregatorpostgresqlwriter.h:92
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_locationDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< TemporalLocationRow, TemporalLocationRecord > > _locationDimension
Definition: cbmaggregatorpostgresqlwriter.h:75
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_landClassDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< LandClassRow, LandClassRecord > > _landClassDimension
Definition: cbmaggregatorpostgresqlwriter.h:74
moja::modules::cbm
Definition: ageclasshelper.cpp:12
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_dateDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< DateRow, DateRecord > > _dateDimension
Definition: cbmaggregatorpostgresqlwriter.h:71
moja::flint::RecordAccumulatorWithMutex2
Definition: cbmaggregatorcsvwriter.h:21
moja::modules::cbm::CBMModuleBase
Definition: cbmmodulebase.h:22
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_disturbanceDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< DisturbanceRow, DisturbanceRecord > > _disturbanceDimension
Definition: cbmaggregatorpostgresqlwriter.h:82
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_poolDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< PoolRow, PoolRecord > > _poolDimension
Definition: cbmaggregatorpostgresqlwriter.h:77
record.h
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_fluxDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< FluxRow, FluxRecord > > _fluxDimension
Definition: cbmaggregatorpostgresqlwriter.h:78
moja::modules::cbm::CBMAggregatorPostgreSQLWriter
Definition: cbmaggregatorpostgresqlwriter.h:22
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_schemaLock
Int64 _schemaLock
Definition: cbmaggregatorpostgresqlwriter.h:91
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::CBMAggregatorPostgreSQLWriter
CBMAggregatorPostgreSQLWriter(std::shared_ptr< flint::RecordAccumulatorWithMutex2< DateRow, DateRecord >> dateDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< PoolInfoRow, PoolInfoRecord >> poolInfoDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< ClassifierSetRow, ClassifierSetRecord >> classifierSetDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< LandClassRow, LandClassRecord >> landClassDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< TemporalLocationRow, TemporalLocationRecord >> locationDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< ModuleInfoRow, ModuleInfoRecord >> moduleInfoDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< DisturbanceTypeRow, DisturbanceTypeRecord >> disturbanceTypeDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< DisturbanceRow, DisturbanceRecord >> disturbanceDimension, std::shared_ptr< std::vector< std::string >> classifierNames, std::shared_ptr< flint::RecordAccumulatorWithMutex2< PoolRow, PoolRecord >> poolDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< FluxRow, FluxRecord >> fluxDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< AgeClassRow, AgeClassRecord >> ageClassDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< AgeAreaRow, AgeAreaRecord >> ageAreaDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< ErrorRow, ErrorRecord >> errorDimension, std::shared_ptr< flint::RecordAccumulatorWithMutex2< LocationErrorRow, LocationErrorRecord >> locationErrorDimension, bool isPrimary=false)
Definition: cbmaggregatorpostgresqlwriter.h:24
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_connectionString
std::string _connectionString
Definition: cbmaggregatorpostgresqlwriter.h:89
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_isPrimaryAggregator
bool _isPrimaryAggregator
Definition: cbmaggregatorpostgresqlwriter.h:93
moja::flint
Definition: cbmaggregatorcsvwriter.h:19
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_moduleInfoDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< ModuleInfoRow, ModuleInfoRecord > > _moduleInfoDimension
Definition: cbmaggregatorpostgresqlwriter.h:76
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_locationErrorDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< LocationErrorRow, LocationErrorRecord > > _locationErrorDimension
Definition: cbmaggregatorpostgresqlwriter.h:84
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_ageClassDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< AgeClassRow, AgeClassRecord > > _ageClassDimension
Definition: cbmaggregatorpostgresqlwriter.h:79
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_schema
std::string _schema
Definition: cbmaggregatorpostgresqlwriter.h:90
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_disturbanceTypeDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< DisturbanceTypeRow, DisturbanceTypeRecord > > _disturbanceTypeDimension
Definition: cbmaggregatorpostgresqlwriter.h:81
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_errorDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< ErrorRow, ErrorRecord > > _errorDimension
Definition: cbmaggregatorpostgresqlwriter.h:83
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_classifierNames
std::shared_ptr< std::vector< std::string > > _classifierNames
Definition: cbmaggregatorpostgresqlwriter.h:85
moja
Definition: ageclasshelper.cpp:10
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_dropSchema
bool _dropSchema
Definition: cbmaggregatorpostgresqlwriter.h:94
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_spatialLocationInfo
std::shared_ptr< const flint::SpatialLocationInfo > _spatialLocationInfo
Definition: cbmaggregatorpostgresqlwriter.h:87
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::moduleType
flint::ModuleTypes moduleType() override
Definition: cbmaggregatorpostgresqlwriter.h:65
cbmmodulebase.h
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_classifierSetDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< ClassifierSetRow, ClassifierSetRecord > > _classifierSetDimension
Definition: cbmaggregatorpostgresqlwriter.h:73
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_poolInfoDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< PoolInfoRow, PoolInfoRecord > > _poolInfoDimension
Definition: cbmaggregatorpostgresqlwriter.h:72
moja::modules::cbm::CBMAggregatorPostgreSQLWriter::_ageAreaDimension
std::shared_ptr< flint::RecordAccumulatorWithMutex2< AgeAreaRow, AgeAreaRecord > > _ageAreaDimension
Definition: cbmaggregatorpostgresqlwriter.h:80