00001 // $Header: /bes/bes/BossCvs/Calibration/rdbModel/rdbModel/Tables/Table.h,v 1.1.1.1 2005/10/17 06:10:53 maqm Exp $ 00002 #ifndef RDBMODEL_TABLE_H 00003 #define RDBMODEL_TABLE_H 00004 #include <vector> 00005 #include <string> 00006 #include <iostream> 00007 #include "rdbModel/Management/Visitor.h" 00008 #include "rdbModel/Tables/Column.h" 00009 00010 namespace rdbModel { 00011 00012 // class Column; 00013 class Index; 00014 class Assertion; 00015 00016 class XercesBuilder; 00017 class Connection; 00018 00019 class InsertNew; 00020 class Supersede; 00021 00023 class ColCompare { 00024 public: 00025 bool operator() (const Column* a, const Column* b) { 00026 return (a->getName().compare(b->getName()) < 0); 00027 } 00028 }; 00029 00033 class Table { 00034 public: 00035 Table(); 00036 ~Table(); 00037 00038 void setConnection(Connection* connect); 00039 00040 const std::string& getName() const { return m_name;} 00041 Column* getColumnByName(const std::string& name) const; 00042 Index* getIndexByName(const std::string& name) const; 00043 Assertion* getAssertionByName(const std::string& name) const; 00044 00061 int insertLatest(Row& row, int* serial=0) const; 00062 00069 int insertRow(Row& row, int* serial=0) const; 00070 00078 int supersedeRow(Row& row, int oldKey, int* newKey=0) const; 00079 00084 int updateRows(Row &row, Assertion* where) const; 00085 00086 // Do we need these for anything? 00087 InsertNew* getInsertNew() const {return m_iNew;} 00088 Supersede* getSupersede() const {return m_sup;} 00089 00090 Visitor::VisitorState accept(Visitor* v); 00091 // Visitor::VisitorState acceptNotRec(Visitor* v); 00092 00093 void sortColumns(); 00094 00095 private: 00096 friend class rdbModel::XercesBuilder; // needs access to add.. methods 00097 friend class rdbModel::Rdb; // to set connection 00098 void setValidRow(Assertion* v) {m_validRow = v;} 00099 std::vector<Column* > m_cols; 00100 std::vector<Column* > m_sortedCols; 00101 std::vector<Assertion* > m_asserts; 00102 std::vector<Index* > m_indices; 00103 00105 std::vector<Column* > m_programCols; 00106 00108 std::vector<Column* > m_userCols; 00109 00111 std::vector<Column*> m_mayDefault; 00112 00113 std::string m_name; 00114 std::string m_version; 00115 std::string m_comment; 00116 00117 std::string m_primaryKeyCol; // cache this for use in supersedeRow 00118 00119 bool m_sorted; // set to true once columns have been sorted by name 00120 unsigned m_nEndUser; // #columns whose value must be supplied by user 00121 00122 Assertion* m_validRow; 00123 InsertNew* m_iNew; 00124 Supersede* m_sup; 00125 00126 Connection* m_connect; 00127 std::ostream* m_out; 00128 std::ostream* m_err; 00129 00131 void addColumn(Column* c); 00132 00134 void addAssert(Assertion* a) {m_asserts.push_back(a);} 00136 void addIndex(Index* i) {m_indices.push_back(i); } 00137 00139 bool doInterUpdate(const std::vector<Set>& sets, Assertion* subsAssert, 00140 Row& toBe) const; 00141 00147 bool fillProgramCols(Row& row, bool newRow) const; 00148 00150 void fillDefaults(Row& row) const; 00151 00153 bool isSupersedable(std::string oldKeyStr) const; 00154 00156 const std::string& setPrimaryKeyCol(); 00157 00158 00159 }; 00160 00161 } 00162 #endif