00001 #include "ReadDBBase/ConnectionDBBase.h"
00002 #include "facilities/Util.h"
00003 #include "rdbModel/Management/Manager.h"
00004 #include "rdbModel/Management/XercesBuilder.h"
00005
00006 #include "rdbModel/Db/MysqlConnection.h"
00007 #include "rdbModel/Db/MysqlResults.h"
00008 #include "rdbModel/Rdb.h"
00009 #include "rdbModel/RdbException.h"
00010 #include "rdbModel/Tables/Assertion.h"
00011 #include "rdbModel/Tables/Table.h"
00012 #include "rdbModel/Tables/Column.h"
00013 #include <iostream>
00014 #include <cstdio>
00015
00016
00017
00018
00019
00020 ConnectionDBBase::ConnectionDBBase(const std::string& host, const std::string& table, const std::string& dbName)
00021 : m_readCxt(0), m_writeCxt(0),
00022 m_host(host), m_table(table), m_dbName(dbName), m_userName("maqm"), m_password("12345"), m_man(0), m_rdb(0),
00023 m_match(false) {
00024
00025
00026
00027 }
00028 ConnectionDBBase::ConnectionDBBase(const std::string& host, const std::string& dbName, const std::string& userName, const std::string& password)
00029 : m_readCxt(0), m_writeCxt(0),
00030 m_host(host), m_dbName(dbName), m_userName(userName), m_password(password),
00031 m_man(0), m_rdb(0), m_match(false) {
00032 }
00033
00034 ConnectionDBBase::~ConnectionDBBase() {
00035 disconnectRead();
00036 disconnectWrite();
00037 if (m_man) delete m_man;
00038 }
00039
00040
00041
00042
00043 bool ConnectionDBBase::connect(rdbModel::Connection* cxt, std::string& host,
00044 const std::string& user,
00045 const std::string& pw, eRet& err,
00046 const std::string& dbName) {
00047
00048
00049 bool connected = cxt->open(host, user, pw, dbName);
00050 if (connected) {
00051 err = RETOk;
00052 return true;
00053 }
00054 else {
00055 err = RETNoConnect;
00056 return false;
00057 }
00058 }
00059
00060 bool ConnectionDBBase::connectRead(eRet& err) {
00061 if (m_readCxt == 0) {
00062
00063 m_readCxt = new rdbModel::MysqlConnection();
00064 bool ok = connect(m_readCxt, m_host, m_userName,
00065 m_password, err, m_dbName);
00066 if (!ok) {
00067 delete m_readCxt;
00068 m_readCxt = 0;
00069 } else {
00070 }
00071 return ok;
00072 }
00073 else return true;
00074 }
00075
00076 bool ConnectionDBBase::connectWrite(eRet& err) {
00077 if (m_writeCxt == 0) {
00078 m_writeCxt = new rdbModel::MysqlConnection();
00079 bool ok;
00080
00081 ok = connect(m_writeCxt, m_host, m_userName,
00082 m_password, err, m_dbName);
00083
00084 if (!ok) {
00085 delete m_readCxt;
00086 m_readCxt = 0;
00087 } else {
00088
00089 }
00090
00091 return ok;
00092 }
00093 else return true;
00094 }
00095
00096 void ConnectionDBBase::disconnectRead() {
00097 if (m_readCxt) {
00098 m_readCxt->close();
00099 delete m_readCxt;
00100 m_readCxt = 0;
00101 }
00102 }
00103
00104 void ConnectionDBBase::disconnectWrite() {
00105 if (m_writeCxt) {
00106 m_writeCxt->close();
00107 delete m_writeCxt;
00108 m_writeCxt = 0;
00109 }
00110 }
00111