00001 #ifndef REALDBUTIL_CONNECTIONBASE_H
00002 #define REALDBUTIL_CONNECTIONBASE_H
00003
00004 #include "rdbModel/Db/Connection.h"
00005 #include "rdbModel/Tables/Assertion.h"
00006
00007 namespace rdbModel {
00008 class Rdb;
00009 class Manager;
00010 }
00011
00012
00013 class ConnectionDBBase {
00014 public:
00015 enum eRet {
00016 RETOk = 0,
00017 RETBadCnfFile = 1,
00018 RETBadHost = 2,
00019 RETNoConnect = 3,
00020 RETWrongState = 4,
00021 RETBadValue = 5,
00022 RETMySQLError = 6,
00023 RETNoSchemaMatch = 7
00024 };
00026 enum eLevel {
00027 LEVELProd = 1,
00028 LEVELDev = 2,
00029 LEVELTest = 4,
00030 LEVELSuperseded = 8
00031 };
00032
00033
00034
00035
00036
00037
00038
00040 ConnectionDBBase(const std::string& host, const std::string& table, const std::string& dbName);
00041
00042 ConnectionDBBase(const std::string& host, const std::string& dbName, const std::string& userName, const std::string& password);
00043
00044 ~ConnectionDBBase();
00045
00046 bool connectRead(eRet& err);
00047
00048 rdbModel::Connection* getReadConnection() {return m_readCxt;}
00049
00050
00051 rdbModel::Rdb* getRdb() {return m_rdb;}
00052 const std::string& getTable() {return m_table;}
00053
00054
00055 void disconnectRead();
00056 void disconnectWrite();
00057
00058 private:
00059
00060 rdbModel::Connection* m_readCxt;
00061 rdbModel::Connection* m_writeCxt;
00062
00063
00064 rdbModel::Assertion* m_findBest;
00065 rdbModel::Assertion* m_findSoonest;
00066
00067
00068
00069
00070 static bool connect(rdbModel::Connection* conn,
00071 std::string& host,
00072 const std::string& user,
00073 const std::string& pw, eRet& err,
00074 const std::string& dbName);
00075
00076 bool connectWrite(eRet& err);
00077
00078
00079 std::string m_host;
00080 std::string m_table;
00081 std::string m_dbName;
00082 std::string m_userName;
00083 std::string m_password;
00084
00085 rdbModel::Manager* m_man;
00086 rdbModel::Rdb* m_rdb;
00087 bool m_match;
00088 };
00089
00090 #endif