00001
00002 #ifndef RDBMODEL_COLUMN_H
00003 #define RDBMODEL_COLUMN_H
00004 #include <vector>
00005 #include <string>
00006 #include <utility>
00007 #include "rdbModel/Management/Visitor.h"
00008
00009
00010 namespace rdbModel {
00011
00012
00013 class Datatype;
00014 class Enum;
00015 class Table;
00016 class XercesBuilder;
00017
00018
00019
00023 class Column {
00024
00025
00026 public:
00030 enum FROM {
00031 FROMdefault = 1,
00032 FROMautoIncrement,
00033 FROMnow,
00034 FROMprogram,
00035 FROMendUser
00036 };
00037
00039 enum CONTENTS {
00040 CONTENTSunspecified = 0,
00041 CONTENTSserviceName = 1,
00042 CONTENTSusername = 2,
00043 CONTENTSinsertTime = 3,
00044 CONTENTSupdateTime = 4
00045
00046 };
00047
00048 Column(Table* myTable=0) : m_myTable(myTable), m_type(0),
00049 m_isPrimaryKey(false) {
00050 m_contents = CONTENTSunspecified;
00051 m_default = std::string("");};
00052
00053 ~Column();
00054
00055
00056 const std::string& getName() const {return m_name; };
00057 const std::string& getComment() const {return m_comment;};
00058
00059 const std::string& getDefault() const {return m_default;}
00060
00061 const std::string& getTableName() const;
00062
00063 Datatype* getDatatype() const {return m_type;};
00064
00067 Enum* getEnum() const;
00068
00074 bool okValue(const std::string& val, bool set=true) const;
00075
00077 bool isCompatible(const Column* otherCol) const;
00078
00080 bool nullAllowed() const { return m_null;}
00081
00082 bool stickyInsert() const { return m_stickyInsert;}
00083
00084 bool isPrimaryKey() const {return m_isPrimaryKey;}
00085
00086 bool isAutoIncrement() const;
00087
00088 FROM getSourceType() const {return m_from;}
00089 CONTENTS getContentsType() const {return m_contents;}
00090
00097 bool interpret(const std::string& interpType, std::string&val);
00098
00099 Visitor::VisitorState accept(Visitor* v);
00100
00101 private:
00102 friend class rdbModel::XercesBuilder;
00103
00104 Table* m_myTable;
00105
00106 std::string m_name;
00107 std::string m_comment;
00108 Datatype* m_type;
00109
00110 std::string m_default;
00111 FROM m_from;
00112 CONTENTS m_contents;
00113
00115 bool m_null;
00118 bool m_stickyInsert;
00119
00121 bool m_isPrimaryKey;
00122
00123 };
00124
00125
00126 class FieldVal {
00127
00128 public:
00129 FieldVal(std::string colname, std::string val, bool isNull=false) :
00130 m_colname(colname), m_val(val), m_null(isNull) { }
00131 std::string m_colname;
00132 std::string m_val;
00133 bool m_null;
00134 };
00135
00137 class FieldValCompare {
00138 public:
00139
00140 bool operator() (const FieldVal& a, const FieldVal& b) {
00141 return ((a.m_colname).compare(b.m_colname) < 0);
00142
00143 }
00144 };
00145
00150 class Row {
00151 public:
00152 Row() : m_sorted(false) {m_fields.clear();}
00153 Row(std::vector<FieldVal>& fields) : m_fields(fields), m_sorted(false) {}
00154
00155 ~Row() { m_fields.clear(); }
00156 void rowSort();
00157 void addField(const FieldVal& f) {m_fields.push_back(f); m_sorted = false;}
00158 void clear() {m_fields.clear();}
00159
00160 FieldVal* find(std::string colname);
00161
00163 void regroup(std::vector<std::string>& colNames,
00164 std::vector<std::string>& colVals,
00165 std::vector<std::string>& nullCols) const;
00166 private:
00167 std::vector<FieldVal> m_fields;
00168 bool m_sorted;
00169 };
00170 }
00171 #endif