CARMA C++
TableManager.h
Go to the documentation of this file.
1 #ifndef CARMA_DBMS_TABLEMANAGER_H
2 #define CARMA_DBMS_TABLEMANAGER_H
3 
15 //#include "carma/util/Trace.h"
16 #include <vector>
17 
18 namespace carma {
19 namespace dbms {
20 
21 
34 class TableManager {
35 
36 
37 public:
38  struct Partition {
39  std::string name;
40  unsigned minFreeSpace;
41  };
42 
54  TableManager(const bool& persistentConnection=true, DBConfigurator
55  *dbconf = NULL);
56 
57  virtual ~TableManager();
58 
66 
81  virtual int createMonitorDataTable(
82  const carma::dbms::MonitorAverageType& averageType,
83  const carma::dbms::MonitorAggregateType& aggType,
84  const unsigned& requiredSpace,
85  std::string& tableName, const std::string& tag);
86 
87 
88 
96  void updateMonitorIndexTable(const std::string& tableName,
97  const MonitorAverageType& averageType);
98 
99 
100 protected:
101  bool persistentConnection_;
102  bool useProductionDB_;
103  std::string rdbms_;
105  std::map<int,Partition> partitions_;
106  DBConfigurator *dbconf_;
107 
108  static int minimumFrameRetentionFrames_;
109  static int minimumCorrelRetentionFrames_;
110  static int minimumMinuteRetentionFrames_;
111 
112  //carma::util::Trace *trace_;
113 
119 
125 
129  void closeDBConnection();
130 
144  virtual int getAvailablePartition(const int& requiredSpace,
145  const bool& connectionIsOpen);
146 
158  std::map<int, Partition> getEmptyPartitions(const bool& connectionIsOpen);
159 
166  unsigned getFreeMB(const std::string& partition) const;
167 
173  unsigned getTotalMB(const std::string& partition) const;
174 
175 
183  void dropTable(const std::string& tableName) const;
184 
185 
186 };
187 
188 class TableManagerException : public carma::util::ErrorException {
189 public:
190  TableManagerException (const char* msg, const char* fileName = __FILE__,
191  const int lineNum = __LINE__)
192  : carma::util::ErrorException (msg, fileName, lineNum) {};
193 
194  TableManagerException (const std::string msg,
195  const char* fileName = __FILE__,
196  const int lineNum = __LINE__)
197  : carma::util::ErrorException (msg.c_str(), fileName, lineNum) {};
198 
199 };
200 
201 
202 
203 
204 }}
205 #endif
void openDBConnectionIfNecessary()
open a connection to the database if one is not currently established
Class used for configuring a DBConnection.
void closeDBConnectionIfNecessary()
close the db connection and delete the db connection object if !persistentConnection_ ...
MonitorAggregateType
aggregate data type of the monitor[point,data file, table]
TableManager(const bool &persistentConnection=true, DBConfigurator *dbconf=NULL)
constructor
std::map< int, Partition > getEmptyPartitions(const bool &connectionIsOpen)
get the partitions which do not have any volatile tables on them This method queries the database to ...
virtual int createMonitorDataTable(const carma::dbms::MonitorAverageType &averageType, const carma::dbms::MonitorAggregateType &aggType, const unsigned &requiredSpace, std::string &tableName, const std::string &tag)
create a monitor data table table
This class is responsible for managing the large, short lived tables produced by CARMA.
Definition: TableManager.h:34
DBConnection and DBConnectionFactory classes.
virtual int getAvailablePartition(const int &requiredSpace, const bool &connectionIsOpen)
find a partition on which a new table can be created.
void updateMonitorIndexTable(const std::string &tableName, const MonitorAverageType &averageType)
insert the max and min frame counts into the specified row in the volatile tables table...
MonitorAverageType
average type of the monitor[point,data file,table]
Exception class for errors The exception comes with a text string that can be printed or logged...
unsigned getFreeMB(const std::string &partition) const
get the available space (for normal users) in MB of the specified partition
void loadConfigurationInformation()
(re)load config info regarding partitions from the db this is called by the constructor and can be ca...
void closeDBConnection()
close the DBConnection
an abstract class from which database queries may be launched.
Definition: DBConnection.h:46
void dropTable(const std::string &tableName) const
removes a table from the db and removes its entry in MONITOR_INDEX_TABLE Callers from this class must...
unsigned getTotalMB(const std::string &partition) const
get the total (used+free) size, in megabytes, of the specified partition