15ElogConnection::ElogConnection(TSQLServer* pSQLServer)
17 elog_db_server = pSQLServer;
20ElogConnection* ElogConnection::OpenConnection(
const TString& connect_string,
23 const char* db_password)
28 TSQLServer* pSQLServer =
nullptr;
31 pSQLServer = it->second;
34 for (
int i = 0;
i < 4;
i++) {
35 pSQLServer = TSQLServer::Connect(connect_string, db_user, db_password);
39 cout <<
"ERROR: database connection was not established (" << db_host <<
") for '" << db_user
43 unsigned int random_integer = pow(10,
i) + gRandom->Integer(pow(10,
i) * 2 + 1);
44 this_thread::sleep_for(chrono::seconds(random_integer));
61 const char *db_username = gSystem->Getenv(
"ELOG_USERNAME"), *db_password = gSystem->Getenv(
"ELOG_PASSWORD");
63 if ((db_username ==
nullptr) || (db_password ==
nullptr)) {
68 return OpenConnection(conString,
ELOG_DB_HOST, db_username, db_password);
73 const char* strDBHost,
74 const char* strDBName,
76 const char* strPassword)
79 switch (database_type) {
81 db_type = (
char*)
"mysql";
84 db_type = (
char*)
"pgsql";
87 cout <<
"ERROR: incorrect database type!" << endl;
91 TString conString = TString::Format(
"%s://%s/%s", db_type, strDBHost, strDBName);
92 return OpenConnection(conString, strDBHost, strUID, strPassword);
static ElogConnection * Open()
virtual ~ElogConnection()
static mapSQLServer * mapConnection
map< string, TSQLServer * > mapSQLServer
map< string, TSQLServer * >::iterator itSQLServer
const char *const ELOG_DB_PASSWORD
const char *const ELOG_DB_USERNAME
const char *const ELOG_DB_HOST
const char *const ELOG_DB_NAME
map< string, TSQLServer * > mapSQLServer
pair< string, TSQLServer * > pairSQLServer