290 #include "StDbManagerImpl.hh"
291 #include "StDbDefaults.hh"
292 #include "StDbTableFactory.hh"
293 #include "StDbConfigNodeImpl.hh"
294 #include "StDbServerImpl.hh"
295 #include "StDbTable.h"
296 #include "StDbTime.h"
297 #include "StDbTableIter.hh"
298 #include "dbCollection.h"
299 #include "StDbMessenger.hh"
303 #ifndef __STDB_STANDALONE__
304 #include "StMessMgr.h"
306 #define LOG_DEBUG cout
307 #define LOG_INFO cout
308 #define LOG_WARN cout
309 #define LOG_ERROR cerr
310 #define LOG_FATAL cerr
315 #include "stdb_streams.h"
319 #ifndef NoXmlTreeReader
330 #define freeze(i) str()
335 extern char** environ;
337 #define __CLASS__ "StDbManagerImpl"
339 StDbManagerImpl::StDbManagerImpl():
StDbManager(), dbTypeFree(dbTUser1), dbDomainFree(dbDUser1), mhasServerList(false), mhasDefaultServer(false) {
344 #ifndef NoXmlTreeReader
351 StDbManagerImpl::~StDbManagerImpl(){
356 #ifndef __STDB_STANDALONE__
357 SafeDelete(mfactory);
371 #ifndef NoXmlTreeReader
373 #ifndef __STDB_STANDALONE__
374 SafeDelete(myServiceBroker);
376 if (myServiceBroker) {
377 delete myServiceBroker;
394 StDbManagerImpl::initTypes(){
396 addDbType(dbStDb,
"StarDb");
397 addDbType(dbRunLog,
"RunLog");
398 addDbType(dbServer,
" ");
399 addDbType(dbConditions,
"Conditions");
400 addDbType(dbCalibrations,
"Calibrations");
401 addDbType(dbGeometry,
"Geometry");
402 addDbType(dbRunCatalog,
"RunCatalog");
403 addDbType(dbConfigurations,
"Configurations");
404 addDbType(dbRunParams,
"RunParams");
405 addDbType(dbScalers,
"Scalers");
406 addDbType(dbTestScheme,
"TestScheme");
413 StDbManagerImpl::initDomains(){
415 addDbDomain(dbStar,
"Star");
416 addDbDomain(dbTpc,
"tpc");
417 addDbDomain(dbFtpc,
"ftpc");
418 addDbDomain(dbEmc,
"emc");
419 addDbDomain(dbSvt,
"svt");
420 addDbDomain(dbCtb,
"ctb");
421 addDbDomain(dbTrg,
"trg");
422 addDbDomain(dbDaq,
"daq");
423 addDbDomain(dbScaler,
"scaler");
424 addDbDomain(dbGlobal,
"global");
425 addDbDomain(dbL3,
"l3");
426 addDbDomain(dbOnl,
"onl");
427 addDbDomain(dbRich,
"rich");
428 addDbDomain(dbMwc,
"mwc");
429 addDbDomain(dbRhic,
"rhic");
430 addDbDomain(dbSsd,
"ssd");
431 addDbDomain(dbRts,
"rts");
432 addDbDomain(dbTof,
"tof");
433 addDbDomain(dbFpd,
"fpd");
434 addDbDomain(dbEemc,
"eemc");
435 addDbDomain(dbPmd,
"pmd");
436 addDbDomain(dbBbc,
"bbc");
437 addDbDomain(dbTracker,
"tracker");
438 addDbDomain(dbZdc,
"zdc");
439 addDbDomain(dbFms,
"fms");
440 addDbDomain(dbpp2pp,
"pp2pp");
441 addDbDomain(dbFgt,
"fgt");
442 addDbDomain(dbPxl,
"pxl");
443 addDbDomain(dbMtd,
"mtd");
444 addDbDomain(dbIst,
"ist");
445 addDbDomain(dbFps,
"fps");
446 addDbDomain(dbSst,
"sst");
447 addDbDomain(dbEpd,
"epd");
448 addDbDomain(dbRhicf,
"rhicf");
449 addDbDomain(dbEtof,
"etof");
450 addDbDomain(dbFcs,
"fcs");
451 addDbDomain(dbFst,
"fst");
452 addDbDomain(dbFtt,
"ftt");
458 StDbManagerImpl::addDbType(StDbType type,
const char* typeName){
459 mTypes.push_back(
new dbType(type,typeName));
465 StDbManagerImpl::addDbDomain(StDbDomain domain,
const char* domainName){
466 mDomains.push_back(
new dbDomain(domain,domainName));
472 StDbManagerImpl::newDbType(
const char* typeName){
474 StDbType retVal=dbTypeFree;
478 addDbType(dbTUser1,typeName);
479 dbTypeFree = dbTUser2;
484 addDbType(dbTUser2,typeName);
485 dbTypeFree = dbTUser3;
490 addDbType(dbTUser3,typeName);
506 StDbManagerImpl::newDbDomain(
const char* domainName){
508 StDbDomain retVal=dbDomainFree;
509 switch(dbDomainFree) {
512 addDbDomain(dbDUser1,domainName);
513 dbDomainFree = dbDUser2;
518 addDbDomain(dbDUser2,domainName);
519 dbDomainFree = dbDUser3;
524 addDbDomain(dbDUser3,domainName);
525 dbDomainFree = dbDEnd;
540 StDbManagerImpl::deleteServers() {
542 if ( !mhasServerList )
return;
544 for(
auto &it : mservers )
delete it;
552 StDbManagerImpl::deleteDomains(){
554 for(
auto &it : mDomains )
delete it;
562 StDbManagerImpl::deleteTypes(){
564 for(
auto &it : mTypes )
delete it;
572 #define __METHOD__ "lookUpServer()"
579 #ifndef NoXmlTreeReader
581 string dbLoadBalancerLocalConfig =
"dbLoadBalancerLocalConfig.xml";
582 string dbLoadBalancerGlobalConfig =
"dbLoadBalancerGlobalConfig.xml";
584 vector<string> configFileNames;
585 const char* fLocalConfig = getenv(
"DB_SERVER_LOCAL_CONFIG");
590 LOG_ERROR <<
"StDbManagerImpl::lookUpServers(): DB_SERVER_LOCAL_CONFIG is undefined! "<<endm;
594 configFileNames.push_back(fLocalConfig);
614 const char* STAR = getenv(
"STAR");
618 LOG_ERROR <<
"StDbManagerImpl::lookUpServers(): STAR is undefined! "<<endm;
625 const char* fGlobalConfig = getenv(
"DB_SERVER_GLOBAL_CONFIG");
633 configFileNames.push_back(fGlobalConfig);
638 configFileNames.push_back((
string)STAR+
"/StDb/servers/"+dbLoadBalancerGlobalConfig);
644 string dbLoadBalancerConfig =
"";
646 vector<string>::iterator I= configFileNames.begin();
647 while (I!=configFileNames.end())
650 dbLbIn.open((*I).c_str(),ios::in);
653 dbLoadBalancerConfig = (*I);
659 LOG_ERROR <<
"StDbManagerImpl::lookUpServers(): could not open "<<(*I)<<endm;
664 LOG_INFO <<
"StDbManagerImpl::lookUpServers(): config file name is "<<dbLoadBalancerConfig<<endm;
669 short SBStatus = myServiceBroker->GetStatus();
670 if (SBStatus == st_db_service_broker::NO_ERROR)
672 mhasServerList =
true;
676 delete myServiceBroker;
678 LOG_ERROR <<
"StDbManagerImpl::lookUpServers() StDbServiceBroker error "<<SBStatus<<
" disable XML loadbalancing "<<endm;
685 char* xmlFile[3]={NULL,NULL,NULL};
687 dbFindServerMode mode[3]={serverEnvVar,userHome,starDefault};
690 costr<<stendl<<
"******** Order of Files searched for dbServers ********* "<<stendl;
692 for(
int i=0;i<3; i++){
693 xmlFile[i]=StDbDefaults::Instance()->getServerFileName(mode[i]);
695 ifstream is(xmlFile[i]);
698 cout <<
" looking at "<<i <<
" " << xmlFile[i]<< endl;
699 costr<<
" "<<i+1<<
". "<< xmlFile[i] <<stendl;
703 xmlInputSource = mode[i];
706 cout <<
"There is no "<< i <<
" " << xmlFile[i] << endl;
708 delete [] xmlFile[i];
712 costr <<
"********************************************************" << stendl;
713 printInfo((costr.str()).c_str(),dbMConnect,__LINE__,__CLASS__,__METHOD__);
716 mhasServerList =
true;
722 void StDbManagerImpl::findServersXml(ifstream& is){
724 char* stardatabase=NULL;
734 stardatabase = findServerString(is);
736 if(!stardatabase)
continue;
739 char bserver[32]=
"<server>";
char eserver[32]=
"</server>";
740 char bhost[32]=
"<host>";
char ehost[32]=
"</host>";
741 char bsock[32]=
"<socket>";
char esock[32]=
"</socket>";
742 char bport[32]=
"<port>";
char eport[32]=
"</port>";
743 char bdb[32]=
"<databases>";
char edb[32]=
"</databases>";
747 char* servName = mparser.getString(stardatabase,(
char*)bserver,(
char*)eserver);
748 char* hostName = mparser.getString(stardatabase,(
char*)bhost,(
char*)ehost);
749 char* uSocket = mparser.getString(stardatabase,(
char*)bsock,(
char*)esock);
750 char* portNumber = mparser.getString(stardatabase,(
char*)bport,(
char*)eport);
752 if(portNumber)portNum = atoi(portNumber);
753 #ifndef NoXmlTreeReader
755 myserver->PointMysqlDb(
this);
761 if(muserName) server->setUser(muserName,mpWord);
765 if(portNumber)
delete [] portNumber;
766 mservers.push_back(server);
767 server->setTimeLogging(misTimeLogged);
769 char* dbNames = mparser.getString(stardatabase,(
char*)bdb,(
char*)edb);
772 if( !dbNames && !mhasDefaultServer ){
775 server->setIsDefaultServer();
776 mhasDefaultServer =
true;
783 StDbType type; StDbDomain domain;
784 while(p1 && (aname=getNextName(p1))){
785 if(getDataBaseInfo(aname,type,domain))server->addDataBase(type,domain);
788 if(dbNames)
delete [] dbNames;
791 delete [] stardatabase;
798 char* StDbManagerImpl::findServerString(ifstream& is){
802 bool started =
false;
814 is.getline(tmpline,255);
816 if((
id=strstr(tmpline,
"//")))
continue;
819 id= strstr(tmpline,
"<StDbServer>");
826 id=strstr(tmpline,
"</StDbServer>");
833 string osstr=os.str();
834 line=
new char[osstr.length()+1];
835 strcpy(line,osstr.c_str());
841 char* StDbManagerImpl::getNextName(
char*& names){
844 if(!names)
return nextName;
846 char*
id = strstr(names,
",");
849 nextName = mparser.removeBlankEnds(names);
853 char* saveName =
new char[iloc+1];
854 strncpy(saveName,names,iloc);
856 nextName=mparser.removeBlankEnds(saveName);
868 void StDbManagerImpl::turnOffTimeLogging(){
869 StDbManager::turnOffTimeLogging();
871 for(ServerList::iterator itr = mservers.begin();
872 itr != mservers.end(); ++itr)
873 (*itr)->setTimeLogging(misTimeLogged);
877 StDataBaseI* StDbManagerImpl::findDb(StDbType type, StDbDomain domain){
878 return findServer(type,domain)->useDb();
882 return findServer(dbType,dbDomain)->useDb();
885 StDataBaseI* StDbManagerImpl::findDb(
const char* databaseName){
886 return findServer(databaseName)->useDb();
889 StDbServer* StDbManagerImpl::findServer(StDbType type, StDbDomain domain){
896 for(ServerList::iterator itr = mservers.begin();
897 itr != mservers.end(); ++itr){
898 if((*itr)->useDb(type,domain)){
906 server=findDefaultServer();
907 server->addDataBase(type,domain);
916 return findServer(node->getDbType(),node->getDbDomain());
921 StDbServer* StDbManagerImpl::findServer(
const char* typeName,
const char* domainName){
922 return findServer(getDbType(typeName),getDbDomain(domainName));
927 StDbServer* StDbManagerImpl::findServer(
const char* databaseName){
932 char* typeName =
new char[strlen(databaseName)+1];
933 strcpy(typeName,databaseName);
936 char*
id=strstr(typeName,
"_");
940 domainName=
new char[strlen(
id)+1];
941 strcpy(domainName,
id);
943 domainName=
new char[strlen(
"Star")+1];
944 strcpy(domainName,
"Star");
947 StDbServer* server=findServer(typeName,(
const char*) domainName);
948 delete [] domainName;
957 StDbServer* StDbManagerImpl::findDefaultServer(){
969 for(ServerList::iterator itr = mservers.begin(); itr != mservers.end(); ++itr){
970 if((*itr)->isDefault()){
981 char* StDbManagerImpl::getDbTypeName(StDbType type){
982 #define __METHOD__ "getDbTypeName(StDbType)"
985 for(dbTypes::iterator itr=mTypes.begin();
986 itr != mTypes.end(); ++itr){
987 if((*itr)->type == type){
993 if(name)
return mstringDup(name);
994 printInfo(
" No dbType name found ",dbMErr,__LINE__,__CLASS__,__METHOD__);
1002 char* StDbManagerImpl::getDbDomainName(StDbDomain domain){
1003 #define __METHOD__ "getDbDomainName(StDbDomain)"
1005 if(domain==dbDomainUnknown)
return mstringDup(
"Star");
1008 for(dbDomains::iterator itr=mDomains.begin();
1009 itr != mDomains.end(); ++itr){
1010 if((*itr)->domain == domain){
1011 name = (*itr)->name;
1016 if(name)
return mstringDup(name);
1017 printInfo(
" Domain Name not found",dbMErr,__LINE__,__CLASS__,__METHOD__);
1025 StDbType StDbManagerImpl::getDbType(
const char* typeName){
1026 #define __METHOD__ "getDbType(typeName)"
1027 StDbType retType=dbStDb;
1029 for(dbTypes::iterator itr=mTypes.begin();
1030 itr != mTypes.end(); ++itr){
1031 if(strcmp((*itr)->name,typeName)==0){
1032 retType = (*itr)->type;
1038 if(found)
return retType;
1039 printInfo(
"Adding New User dbType=",typeName,dbMDebug,__LINE__,__CLASS__,__METHOD__);
1041 return newDbType(typeName);
1048 StDbDomain StDbManagerImpl::getDbDomain(
const char* domainName){
1049 #define __METHOD__ "getDbDomain(domainName)"
1050 StDbDomain retType=dbDomainUnknown;
1053 for(dbDomains::iterator itr=mDomains.begin();
1054 itr != mDomains.end(); ++itr){
1055 if(strcmp((*itr)->name,domainName) ==0){
1056 retType = (*itr)->domain;
1062 if(found)
return retType;
1063 printInfo(
"Adding New dbDomain=",domainName,dbMWarn,__LINE__,__CLASS__,__METHOD__);
1064 return newDbDomain(domainName);
1068 void StDbManagerImpl::blacklistDbDomain(
const char* domainName) {
1069 std::string domain(domainName);
1070 std::transform(domain.begin(), domain.end(), domain.begin(), ::tolower);
1071 if (mBlacklist.find(domain) == mBlacklist.end()) {
1072 mBlacklist.insert(domain);
1077 char* StDbManagerImpl::printDbName(StDbType type, StDbDomain domain){
1079 if(db)
return db->printDbName();
1080 return (
char*)
"Unknown DataBase";
1085 StDbType type; StDbDomain domain;
1086 getDataBaseInfo(dbName,type,domain);
1087 return initConfig(type,domain);
1091 StDbConfigNode* StDbManagerImpl::initConfig(
const char* dbName,
const char* configName,
int opt){
1092 #define __METHOD__ "initConfig(dbName,configName,opt)"
1093 StDbType type; StDbDomain domain;
1094 getDataBaseInfo(dbName,type,domain);
1095 return initConfig(type,domain,configName,opt);
1100 StDbConfigNode* StDbManagerImpl::initConfig(StDbType type, StDbDomain domain){
1103 name = getConfigNodeName(type,domain);
1105 configNode->setIsDbNode(
true);
1111 StDbConfigNode* StDbManagerImpl::initConfig(StDbType type, StDbDomain domain,
const char* configName,
int opt){
1113 if(misTimeLogged)mnodeLog.start();
1115 configNode->setVersion(configName);
1116 configNode->buildTree(opt);
1117 if(misTimeLogged)mnodeLog.end();
1123 StDbConfigNode* StDbManagerImpl::initConfig(StDbType type, StDbDomain domain,
unsigned int requestTime,
int opt){
1124 #define __METHOD__ "initConfig(type,domain,time)"
1128 StDataBaseI* db = findServer(type,domain)->useDb();
1130 printInfo(
"DataBase Not Found",dbMErr,__LINE__,__CLASS__,__METHOD__);
1134 if(!db->QueryDb(table,requestTime)){
1135 printInfo(
"Timestamped collection Not found",dbMErr,__LINE__,__CLASS__,__METHOD__);
1139 configNode=initConfig(type,domain,collection->name,opt);
1146 StDbConfigNode* StDbManagerImpl::initConfig(
const char* dbName,
unsigned int requestTime,
int opt){
1147 StDbType type; StDbDomain domain;
1148 getDataBaseInfo(dbName,type,domain);
1149 return initConfig(type,domain,requestTime,opt);
1153 char* StDbManagerImpl::getConfigNodeName(StDbType type, StDbDomain domain){
1156 if(domain == dbStar)
return getDbTypeName(type);
1157 return getDbDomainName(domain);
1161 char* StDbManagerImpl::getExternalVersion(StDbType type, StDbDomain domain){
1162 if (!type || !domain)
return 0;
1163 char* dbname = printDbName(type,domain);
1164 if (!dbname)
return 0;
1165 return getenv(dbname);
1169 dbEnvList* StDbManagerImpl::getEnvList(
const char* name){
1174 if(!environ[i])
break;
1175 if(strstr(environ[i],name)){
1176 char* tmpName=mstringDup(environ[i]);
1177 char*
id=strstr(tmpName,
"=");
1180 if(strstr(tmpName,name)){
1181 retVal->envVar[retVal->num]=mstringDup(tmpName);
1182 retVal->envDef[retVal->num]=mstringDup(
id);
1200 StDbTable* StDbManagerImpl::newDbTable(
const char* dbName,
const char* tabName){
1201 return mfactory->newDbTable(dbName,tabName);
1206 StDbTable* table=mfactory->newDbTable(node->printDbName(),node->printName());
1207 if(table)table->setNodeInfo(node);
1212 void StDbManagerImpl::setRequestTime(
unsigned int time){
1213 mcheckTime.munixTime = time;
1214 updateDateTime(mcheckTime);
1218 void StDbManagerImpl::setRequestTime(
const char* time){
1219 mcheckTime.setDateTime(time);
1220 updateUnixTime(mcheckTime);
1224 void StDbManagerImpl::setStoreTime(
unsigned int time){
1225 mstoreTime.munixTime = time;
1226 updateDateTime(mstoreTime);
1230 void StDbManagerImpl::setStoreTime(
const char* time){
1231 mstoreTime.setDateTime(time);
1232 updateUnixTime(mstoreTime);
1236 void StDbManagerImpl::updateDateTime(
StDbTime& t){
1237 #define __METHOD__ "updateDateTime(StDbTime)"
1241 if(db && (dt=db->getDateTime(t.munixTime))){
1249 void StDbManagerImpl::updateUnixTime(
StDbTime& t){
1252 if(db)t.setUnixTime(db->getUnixTime(t.mdateTime));
1256 unsigned int StDbManagerImpl::getUnixCheckTime(){
return mcheckTime.munixTime;}
1257 unsigned int StDbManagerImpl::getUnixRequestTime(){
return mcheckTime.munixTime;}
1258 char* StDbManagerImpl::getDateCheckTime() {
return mcheckTime.mdateTime; }
1259 char* StDbManagerImpl::getDateRequestTime(){
return mcheckTime.mdateTime; }
1262 unsigned int StDbManagerImpl::getUnixStoreTime(){
return mstoreTime.munixTime; }
1263 char* StDbManagerImpl::getDateStoreTime(){
return mstoreTime.mdateTime; }
1266 bool StDbManagerImpl::IsValid(
StDbTable* table){
1267 bool retVal =
false;
1269 unsigned int time = mcheckTime.munixTime;
1270 if(time >= table->getBeginTime() && time < table->getEndTime())retVal=
true;
1276 bool StDbManagerImpl::fetchDbTable(
StDbTable* table){
1278 bool retVal =
false;
1279 if(!table)
return false;
1280 StDataBaseI* db=findDb(table->getDbType(),table->getDbDomain());
1281 if(!db)
return false;
1283 if(misTimeLogged)mdataLog.start();
1284 if(db->QueryDb(table,mcheckTime.munixTime))retVal=
true;
1285 if(misTimeLogged)mdataLog.end();
1290 bool StDbManagerImpl::fetchDbTable(
StDbTable* table,
char* whereClause){
1292 if(!table)
return false;
1293 StDataBaseI* db=findDb(table->getDbType(),table->getDbDomain());
1294 if(!db)
return false;
1295 if(misTimeLogged)mdataLog.start();
1296 bool retVal=(bool) db->QueryDb(table,whereClause);
1297 if(misTimeLogged)mdataLog.end();
1305 bool children =
true;
1306 bool siblings =
true;
1308 if(node->hasData()){
1310 while(!itr->done()) {
1312 tables = (tables && fetchDbTable(tab));
1317 if(node->hasChildren())children = fetchAllTables(node->getFirstChildNode());
1319 if((nextNode=node->getNextNode()))siblings = fetchAllTables(nextNode);
1321 return (tables && children && siblings);
1325 bool StDbManagerImpl::storeDbTable(
StDbTable* table,
bool commitWhenDone){
1326 #define __METHOD__ "storeDbTable(StDbTable*)"
1328 if(!table)
return (
bool) printInfo(
"Cannot store Null Table",dbMErr,__LINE__,__CLASS__,__METHOD__);
1329 if(mstoreTime.munixTime==0)
return (
bool) printInfo(
"Cannot store withou timestamp",dbMErr,__LINE__,__CLASS__,__METHOD__);
1331 StDataBaseI* db = findDb(table->getDbType(),table->getDbDomain());
1332 if(!db)
return false;
1333 bool retVal = (bool)db->WriteDb(table,mstoreTime.munixTime);
1334 if(commitWhenDone)table->commitData();
1341 bool StDbManagerImpl::storeAllTables(
StDbConfigNode* node,
bool commitWhenDone){
1342 #define __METHOD__ "storeAllTable(StDbConfigNode*)"
1344 if(!node)
return (
bool) printInfo(
"Cannot store Null Node",dbMErr,__LINE__,__CLASS__,__METHOD__);
1345 if(mstoreTime.munixTime==0)
return (
bool) printInfo(
"Cannot store withno timestamp",dbMErr,__LINE__,__CLASS__,__METHOD__);
1348 if(node->hasData()){
1350 while(!itr->done()){
1352 tables = (tables && storeDbTable(itr->next(),
false));
1354 (itr->next())->commitData();
1362 rollBackAllTables(node);
1367 bool children =
true;
1368 bool siblings =
true;
1370 if(node->hasChildren()) children = storeAllTables(node->getFirstChildNode(),
false);
1373 rollBackAllTables(node);
1378 if((nextNode=node->getNextNode())) siblings = storeAllTables(nextNode,
false);
1381 rollBackAllTables(node);
1391 StDbManagerImpl::storeConfig(
StDbConfigNode* node,
int currentID,
int& configID,
bool commitWhenDone){
1392 #define __METHOD__ "storeConfig(node,ID,configID,commitFlag)"
1394 StDataBaseI* db = findDb(node->getDbType(),node->getDbDomain());
1396 int nodeID, childID, sibID;
1398 if(!(nodeID=db->WriteDb(node,currentID,configID)))
return printInfo(
" Write Failed ",dbMErr,__LINE__,__CLASS__,__METHOD__);
1400 node->addWrittenNode(nodeID);
1402 if(node->hasChildren())
1403 if(!(childID=storeConfig(node->getFirstChildNode(),nodeID,configID,
false))){
1405 return printInfo(
" Write Failed in Child Node",dbMErr,__LINE__,__CLASS__,__METHOD__);
1408 if(node->getNextNode())
1409 if(!(sibID=storeConfig(node->getNextNode(),currentID,configID,
false))) {
1412 return printInfo(
" Write Failed in Sibling Node",dbMErr,__LINE__,__CLASS__,__METHOD__);
1424 bool tables, children, siblings;
1425 tables=children=siblings=
true;
1427 if(node->hasData()){
1429 while(!itr->done()){
1431 if(table && table->canRollBack())tables = (tables &&
rollBack(table));
1436 if(node->hasChildren())
1437 children = rollBackAllTables(node->getFirstChildNode());
1439 if((nextNode=node->getNextNode()))
1440 siblings = rollBackAllTables(nextNode);
1442 return (tables && children && siblings);
1449 bool tables, children, siblings, thisNode;
1450 tables=children=siblings=
true;
1452 if(node->hasData()){
1454 while(!itr->done()){
1461 if(node->hasChildren())
1464 if((nextNode=node->getNextNode()))
1469 return (tables && children && siblings && thisNode);
1475 #define __METHOD__ "rollBack(node)"
1477 if(!node->canRollBack())
1478 return (
bool)printInfo(
" Cannot rollback Store of Node ",dbMErr,__LINE__,__CLASS__,__METHOD__);
1480 StDataBaseI* db=findDb(node->getDbType(),node->getDbDomain());
1481 if(!db)
return false;
1482 return db->rollBack(node);
1491 int* dataRows=table->getWrittenRows(numRows);
1492 if(!dataRows)
return true;
1493 StDataBaseI* db=findDb(table->getDbType(),table->getDbDomain());
1494 if(!db)
return false;
1495 return db->rollBack(table);
1504 if(node->hasData()){
1506 while(!itr->done()){
1513 bool children =
true;
1514 bool siblings =
true;
1516 if(node->hasChildren())children =
commitAllTables(node->getFirstChildNode());
1518 if((nextNode=node->getNextNode()))siblings =
commitAllTables(nextNode);
1520 return (retVal && children && siblings);
1527 if(node->hasData()){
1529 while(!itr->done()){
1535 if(node->hasChildren())
commitAllNodes(node->getFirstChildNode());
1547 for(ServerList::iterator itr = mservers.begin();
1548 itr != mservers.end(); ++itr)
1549 (*itr)->closeConnection();
1558 closeConnection(node);
1567 StDbManagerImpl::closeConnection(
StDbNode* node){
1570 StDbServer* server=findServer(node->getDbType(),node->getDbDomain());
1571 if(server && (server->isConnected())) server->closeConnection();
1577 StDbManagerImpl::printTimeStats(){
1578 #define __METHOD__ "printTimeStats()"
1580 if(!misTimeLogged){ cout<<
"Timing Not Logged"<<stendl;
return; }
1581 double queryTimes=0;
1582 double socketTimes=0;
1583 double connectTimes[10];
1586 for(ServerList::iterator itr = mservers.begin();
1587 itr != mservers.end(); ++itr){
1588 queryTimes+=(*itr)->getQueryTimes();
1589 socketTimes+=(*itr)->getSocketTimes();
1590 connectTimes[j]=(*itr)->getConnectTimes();
1591 serverID[j]=(*itr)->printServerName();
1594 double dbTotalConnect=0.;
1596 for(i=0;i<j;i++)dbTotalConnect+=connectTimes[i];
1598 double dbTotalTimes=mnodeLog.getTotalTimes() + mdataLog.getTotalTimes();
1599 double dbNodeTotal=mnodeLog.getTotalTimes();
1600 double dbNF=100.0*(dbNodeTotal/dbTotalTimes);
1601 double dbDF=100.0*(mdataLog.getTotalTimes()/dbTotalTimes);
1602 double dbQF=100.0*(queryTimes/dbTotalTimes);
1603 double dbSF=100.0*(socketTimes/dbTotalTimes);
1605 double dbCF=100.0*(dbTotalConnect/dbTotalTimes);
1608 cos<<stendl<<
"*************************** DataBase ClockTime Stats *************************** "<<stendl;
1610 cos<<
"Total Time in DB-API = "<<dbTotalTimes<<
"\t sec"<<stendl;
1611 cos<<
" --------------------- In aggregate ------------------"<<stendl;
1612 cos<<
" - Prepare Nodes & Servers = "<<dbNodeTotal<<
"\t sec --> "<<dbNF<<
"% of total"<<stendl;
1613 cos<<
" - Select & Retrieve data = "<<mdataLog.getTotalTimes()<<
"\t sec --> "<<dbDF<<
"% of total"<<stendl;
1614 cos<<
" --------------- In MySQL C-API (approximate) ---------"<<stendl;
1615 cos<<
" - Connecting to Servers = "<<dbTotalConnect<<
"\t sec --> "<<dbCF<<
"% of total"<<stendl;
1617 cos<<
" [ Connections per Server; ";
1618 for(i=0;i<j;i++)cos<<serverID[i]<<
"="<<connectTimes[i]<<
" sec ";
1621 cos<<
" - SQL Query Times = "<<queryTimes<<
"\t sec --> "<<dbQF<<
"% of total"<<stendl;
1622 cos<<
" - socket transfer Times = "<<socketTimes<<
"\t sec --> "<<dbSF<<
"% of total"<<stendl;
1624 cos<<
"********************************************************************************"<<stendl;
1626 printInfo((cos.str()).c_str(),dbMConnect,__LINE__,__CLASS__,__METHOD__);
1633 StDbManagerImpl::getDataBaseInfo(
const char* dbName,
char*& type,
char*& domain){
1634 #define __METHOD__ "getDataBaseInfo(dbName,type,domain)"
1635 char* tmpName=mstringDup(dbName);
1636 if(!tmpName)
return false;
1638 if( !(
id=strstr(tmpName,
"_"))){
1640 domain = mstringDup(
"Star");
1643 type=mstringDup(tmpName);
1644 domain=mstringDup(
id);
1649 ni<<
" Found dbType="<<type<<
" & dbDomain="<<domain;
1650 ni<<
" from DataBase Name="<<dbName;
1652 printInfo((ni.str()).c_str(),dbMDebug,__LINE__,__CLASS__,__METHOD__);
1659 StDbManagerImpl::getDataBaseInfo(
const char* dbName, StDbType& type, StDbDomain& domain){
1660 char* typeName=0;
char* domainName=0;
1661 if(!dbName || !(getDataBaseInfo(dbName,typeName,domainName)))
return false;
1662 type=getDbType(typeName);
1663 domain=getDbDomain(domainName);
1664 if(typeName)
delete [] typeName;
1665 if(domainName)
delete [] domainName;
1671 StDbManagerImpl::getDbName(
const char* typeName,
const char* domainName){
1672 if (!typeName || !domainName)
return 0;
1673 std::string tpName(typeName);
1674 std::string dmName(domainName);
1675 std::string mergedName = tpName +
"_" + dmName;
1676 std::string completeName;
1677 std::string blacklisted_domain;
1679 for (std::set<std::string>::iterator it = mBlacklist.begin(); it != mBlacklist.end(); ++it) {
1680 blacklisted_domain = *it;
1681 completeName =
"Calibrations_" + blacklisted_domain;
1682 if (mergedName == completeName) {
1683 mergedName =
"blacklist_" + mergedName;
1684 return mstringDup(mergedName.c_str());
1690 if(strcmp(domainName,
"Star")!=0)dbname<<
"_"<<domainName;
1691 char* retName = mstringDup((dbname.str()).c_str());
virtual void closeAllConnections()
node commits
virtual bool commitAllNodes(StDbConfigNode *node)
table commits
virtual bool rollBack(StDbNode *node)
for node data
virtual bool commitAllTables(StDbConfigNode *node)
for table data
virtual void lookUpServers()
virtual bool rollBackAllNodes(StDbConfigNode *node)
for table data
StDbMessService * Messenger
where normal=!misVerbose && !misQuiet