40 #include "StDbServerImpl.hh"
42 #define __CLASS__ "StDbServerImpl"
46 StDbServerImpl::StDbServerImpl():
StDbServer(), mcurrentDb(0){}
48 StDbServerImpl::StDbServerImpl(
const char* name,
const char* host,
const char* sock,
int port):
StDbServer(name,host,sock,port), mcurrentDb(0) {};
52 StDbServerImpl::~StDbServerImpl() { deleteDataBases(); }
57 StDbServerImpl::addDataBase(StDbType type, StDbDomain domain) {
61 mcurrentDb =
new StDbSql(Db,buff,type,domain);
62 if(!Db.IsConnected())Db.Connect(mhostName,muserName,mpword,mcurrentDb->printDbName(),mportNumber);
64 mdataBases.push_back(mcurrentDb);
70 StDbServerImpl::addDataBase(
const char* type,
const char* domain) {
72 if(!useDb(type,domain)){
73 mcurrentDb =
new StDbSql(Db,buff,type,domain);
74 if(!Db.IsConnected())Db.Connect(mhostName,muserName,mpword,mcurrentDb->printDbName(),mportNumber);
76 mdataBases.push_back(mcurrentDb);
82 StDbServerImpl::useDb(StDbType type, StDbDomain domain) {
85 mcurrentDb->getDbType()==type &&
86 mcurrentDb->getDbDomain()==domain)
return mcurrentDb;
89 for(DbList::iterator itr = mdataBases.begin();
90 itr != mdataBases.end(); ++itr){
91 if(type==(*itr)->getDbType() && domain==(*itr)->getDbDomain()){
103 StDbServerImpl::useDb(
const char* type,
const char* domain) {
106 mcurrentDb->checkDbType(type) &&
107 mcurrentDb->checkDbDomain(domain))
return mcurrentDb;
110 for(DbList::iterator itr = mdataBases.begin();
111 itr != mdataBases.end(); ++itr){
112 if((*itr)->checkDbType(type) && (*itr)->checkDbDomain(domain)){
124 StDbServerImpl::useDb(){
127 mcurrentDb=
new StDbSql(Db,buff,dbServer,dbStar);
129 mdataBases.push_back(mcurrentDb);
132 if(Db.IsConnected() ||
133 Db.Connect(mhostName,muserName,mpword,mcurrentDb->printDbName(),mportNumber))
return mcurrentDb;
140 StDbServerImpl::deleteDataBases() {
142 for(
auto &it : mdataBases )
delete it;
148 bool StDbServerImpl::isConnected() {
return Db.IsConnected(); }
149 void StDbServerImpl::closeConnection(){ Db.Close(); }
151 void StDbServerImpl::setTimeLogging(
bool isTLog){ Db.mlogTime=isTLog; }
152 double StDbServerImpl::getQueryTimes() {
return Db.mqueryLog.getTotalTimes();};
153 double StDbServerImpl::getSocketTimes(){
return Db.msocketLog.getTotalTimes();};
154 double StDbServerImpl::getConnectTimes(){
return Db.mconnectLog.getTotalTimes();};