CARMA C++
MonitorDataQueryManager.h
Go to the documentation of this file.
1 #ifndef CARMA_DBMS_MONITORDATAQUERYMANAGER_H
2 #define CARMA_DBMS_MONITORDATAQUERYMANAGER_H
3 
14 #include <set>
15 #include <vector>
16 #include "carma/util/Time.h"
18 #include "carma/dbms/ColumnNames.h"
20 
21 namespace carma {
22 namespace dbms {
23 
24  class DBConnection;
25  class Filter;
26  class OneComponentFilter;
27  class MonitorPointFilter;
28  //class MultiComponentFilter;
29  //class Selector;
30  class TimeRangeFilter;
31  class TagIDFilter;
32  class TagIDSetFilter;
33 
34 
109 
110 public:
122  /*
123  MonitorDataQueryManager
124  (const std::set<const carma::dbms::Selector*>& selectors,
125  const carma::dbms::TimeRangeFilter * const trFilter,
126  const carma::dbms::Filter * const otherFilter,
127  const carma::dbms::DBConnection * const dbc);
128  */
142  (const MPSelectorSet& selectors,
143  const carma::dbms::TimeRangeFilter * const trFilter,
144  const carma::dbms::DBConnection * const dbc);
145 
162  (const MPSelectorSet& selectors,
163  const carma::dbms::TimeRangeFilter * const trFilter,
164  const std::set<const carma::dbms::MonitorPointFilter * >& mpfilters,
165  const carma::dbms::DBConnection * const dbc);
166 
171  std::set<carma::dbms::MonitorAggregateType> getAggregateDataTypes() const;
172 
173 
174  //bool shouldCheckArchive() const;
175 
180 
186 
192  std::map<carma::dbms::MonitorAggregateType, std::vector<std::string> >
193  getTablesToQuery() const;
194 
202  std::vector<std::string> getSetUpQueries() const { return setUpQueries_; }
203 
212  std::vector<std::string> getWideSetUpQueries() const {
213  return wideSetUpQueries_;
214  }
215 
220  std::map<int,std::string> getNarrowRSQueries() const {
221  return narrowRSQueries_;
222  }
223 
228  std::string getWideRSQuery() const { return wideRSQuery_; }
229 
239  std::map<int,carma::dbms::Table> execNarrowQueries();
240 
250 
256  std::string mdqmGetColumnName(DBColumn column)const;
257 protected:
258  const carma::dbms::DBConnection *dbc_;
259  const carma::dbms::TimeRangeFilter *trFilter_;
260  //const carma::dbms::Filter *otherFilter_;
261  const std::set<const carma::dbms::MonitorPointFilter *> mpFilters_;
262  MPSelectorSet selectors_;
264  std::map<carma::dbms::MonitorAggregateType,std::string> tmpTableName_;
265 
266 
270  std::map<carma::dbms::MonitorAggregateType, carma::dbms::Table>
272 
274  std::vector<const carma::dbms::MonitorPointSelector * > >
275  aggType2MPSelectors_;
276 
278  std::vector<const carma::dbms::MonitorPointFilter * > >
279  aggType2MPFilters_;
280 
281  std::map<unsigned, const carma::dbms::MonitorPointFilter * > tagID2MPFilter_;
282 
286  std::map<carma::dbms::MonitorAggregateType, std::string>
288 
289 
293  std::set<MonitorAggregateType> aggTypes_;
294  const static std::string TAGID_TO_DATATYPE;
300 
306  std::vector<std::string> setUpQueries_;
307  bool haveRunSetUpQueries_;
308 
313  std::map<int,std::string> narrowRSQueries_;
314 
320  std::vector<std::string> wideSetUpQueries_;
321  bool haveRunWideSetUpQueries_;
322 
323  std::vector<std::string> tablesToDropUponDestruction_;
324 
325 
330  std::string wideRSQuery_;
331 
336  static int tCount_;
337 
338  std::string wideErrMsg_;
339 
344 
349  /*
350  void handleOneComponentFilter_
351  (const carma::dbms::OneComponentFilter * const ocf);
352  */
357  //void handleTagIDFilter_(const carma::dbms::TagIDFilter * const tif);
358 
363  //void handleTagIDSetFilter_(const carma::dbms::TagIDSetFilter * const tisf);
364 
365  /*
366  void handleMultiComponentFilter_
367  (const carma::dbms::MultiComponentFilter * const tcf);
368  */
369 
377 
382  void cacheTagIDToDataType_();
383 
387  void createQueries_();
388 
392  void doSanityChecks_();
393 
397  void execSetUpQueries_() const;
398 
403  void execWideSetUpQueries_() const;
404 
411  void createSetUpQueries_();
412 
417  void createNarrowRSQueries_();
418 
425  void createWideRSQuery_();
426 
427  void createJoinSetUpQueries_
428  (const std::vector
429  < std::vector<const carma::dbms::MonitorPointSelector * > >& mpssVec);
430 
431  void init_();
432 
433  void constructFilterClauses_();
434 };
435 }}
436 
437 #endif // CARMA_DBMS_MONITORDATAQUERYMANAGER_H
438 
static int tCount_
temporary table counter to better assure that created temp tables will have unique names ...
Class to mimic a db table The Table class is meant to mimic a database table.
Definition: Table.h:34
std::map< int, std::string > narrowRSQueries_
queries to execute to produce (generally) several &quot;narrow&quot; (as in tables, no joins are done) result s...
void execWideSetUpQueries_() const
execute the CREATE TABLE queries necessary to produce the tables which will be joined in the wide que...
std::string mdqmGetColumnName(DBColumn column) const
Return the column name string for the given column type.
std::set< MonitorPointSelector *, MPSelectorCompare > MPSelectorSet
A set of MonitorPointSelector points ordered by tagID.
void determineTablesToQuery_()
handle one component filters when determining which aggregate table types need to be queried ...
Common time functions.
MonitorAggregateType
aggregate data type of the monitor[point,data file, table]
carma::dbms::Table execWideQuery()
execute &quot;wide&quot; query.
MonitorDataQueryManager(const MPSelectorSet &selectors, const carma::dbms::TimeRangeFilter *const trFilter, const carma::dbms::DBConnection *const dbc)
constructor
MonitorPointSelector class.
std::vector< std::string > getSetUpQueries() const
get the queries which should be run to set up the tables that will be those on which the narrow SELEC...
std::vector< std::string > getWideSetUpQueries() const
get the queries which should be run to set up the tables that will be those on which the final wide r...
unsigned int frameType
Half second frames since Jan 1, 2000.
Definition: types.h:29
std::map< carma::dbms::MonitorAggregateType, std::string > aggType2FilterClause_
holds the filter clauses
carma::dbms::Table tagIDToDataTypeID_
this variable is only used if the ResultsCache singleton doesn&#39;t exist and cannot be created ...
void doSanityChecks_()
do some sanity checking on values passed to the constructor
void cacheTagIDToDataType_()
cache the tag id to data type mapping
void createQueries_()
create the queries to submit to the database
relationships between the monitor and dbms systems
std::vector< std::string > wideSetUpQueries_
the queries in the order they should be submitted to the database which create and populate temporary...
void createWideRSQuery_()
create the wide result set query, ie this is the query which will create a single, wide table containing n columns where n is the sum of all the columns specified in the monitor point selectors which were passed to the constructor
Class to compose and execute a query of the monitor database.
std::map< int, std::string > getNarrowRSQueries() const
get the SELECT queries which will produce (generally) multiple narrow (as in narrow table...
std::string wideRSQuery_
query to execute to produce a singe &quot;wide&quot; (generally using several joins) table
std::set< MonitorAggregateType > aggTypes_
the aggregate data types relevant to this query
std::map< carma::dbms::MonitorAggregateType, carma::dbms::Table > tablesToQuery_
holds the monitor data tables relevant to this query
void determineAggregateTableTypes_()
determine which aggregate table types will need to be used in the query
MonitorAverageType
average type of the monitor[point,data file,table]
access of column names in the database
represents an SQL query time range filter (part of a WHERE clause This class represents a (closed) ti...
void execSetUpQueries_() const
execute the set up queries
void createNarrowRSQueries_()
create the narrow result set queries, ie these are queries which will produce info on a single tagID ...
std::map< carma::dbms::MonitorAggregateType, std::vector< std::string > > getTablesToQuery() const
get the tables which this class will need to query to produce the result set
static carma::util::frameType getBeginningOfProduction()
get the frameCount that marks the beginning of production
std::set< carma::dbms::MonitorAggregateType > getAggregateDataTypes() const
get the aggregate data types used by this query
~MonitorDataQueryManager()
destructor deletes any &quot;temporary&quot; tables created for wide query
an abstract class from which database queries may be launched.
Definition: DBConnection.h:46
std::map< int, carma::dbms::Table > execNarrowQueries()
execute &quot;narrow&quot; queries.
std::vector< std::string > setUpQueries_
the queries in the order they should be submitted to the database which create and populate the table...
std::string getWideRSQuery() const
get the final wide result set query
void createSetUpQueries_()
create the set up queries, these are the queries which create the temporary tables which are ultimate...
DBColumn
database columns
Definition: ColumnNames.h:26