|
solarpowerlog trunk
|
00001 /* 00002 * IPersistanceStorage.h 00003 * 00004 * Created on: Jan 18, 2010 00005 * Author: tobi 00006 */ 00007 00008 #ifndef IPERSISTANCESTORAGE_H_ 00009 #define IPERSISTANCESTORAGE_H_ 00010 00011 #include <dbixx/dbixx.h> 00012 00013 #include <map> 00014 #include <vector> 00015 #include <boost/any.hpp> 00016 00017 enum dbtypes 00018 { 00019 db_integer, 00020 db_unsignedinteger, 00021 db_longlong, 00022 db_unsignedlonglong, 00023 db_string, 00024 db_decimal, 00025 db_tm 00026 }; 00027 00028 class IPersistanceStorage 00029 { 00030 public: 00031 IPersistanceStorage(std::string &configname, std::string &table); 00032 virtual ~IPersistanceStorage(); 00033 00034 // Let the persitance model know what you are expecting as a type for a 00035 // given field. Note: By default, it is a std::string.... 00036 // the tablespec can be submitted to the queryhelper. 00037 virtual void SetColumnTypes(std::map<std::string, dbtypes> type) 00038 { 00039 table_spec = type; 00040 } 00041 ; 00042 00043 const std::map<std::string, dbtypes> *GetColumnTypes(void) const { 00044 00045 return &table_spec; 00046 } 00047 00048 // Check if table exists and if necessary create it. 00049 // If the table exists, check if all columns are there 00050 // and one is missing alter the table to add the columns. 00051 virtual void CheckAndCreateTable(void); 00052 00053 private: 00054 std::string config; 00055 std::string table; 00056 00057 dbixx::session session; 00058 00059 // map for the table spec to assign the values the right types- 00060 std::map<std::string /*identifier*/, dbtypes /*type*/> table_spec; 00061 00062 // Has the session been opened? 00063 bool session_ready; 00064 std::string dbname; 00065 00066 }; 00067 00068 #endif /* IPERSISTANCESTORAGE_H_ */