#include <cstdlib>
#include <memory>
#include <sstream>
#include "TList.h"
#include "TROOT.h"
#include "TSQLStatement.h"
#include "TSystem.h"
#include "TDbi.hxx"
#include "TDbiCascader.hxx"
#include "TDbiString.hxx"
#include <TSK_DBI_Log.hxx>
#include <MsgFormat.h>
#include "UtilString.hxx"
Go to the source code of this file.
Functions | |
ClassImp (TDbiCascader) TDbiCascader | |
ostream & | operator<< (ostream &os, const TDbiCascader &cascader) |
ClassImp | ( | TDbiCascader | ) |
Purpose: Default constructor Arguments: beQuiet - If true, fail quietly. If not be more verbose. Return: n/a Throws: ENoEnvironment(); if there is no environment defined throw EBadDatabase(); if any other error occured Contact: N. West Specification:- ============= o Create Cascader. Program Notes:- ============= Current cascader configuration comes from 3 environmental variables:- SK_TSQL_URL a semi-colon separated list of URLs SK_TSQL_USER user name (one or a semi-colon separated list) SK_TSQL_PSWD password (one or a semi-colon separated list) or the _UPDATE alternatives e.g. SK_TSQL_UPDATE_USER The _UPDATE versions take priority.
Definition at line 26 of file TDbiCascader.cxx.
References TDbiConnection::Open(), SK_DBI_Info, SK_DBI_Severe, SK_DBI_Trace, and UtilString::StringTok().
00035 : ctors, dtor, operators then in alphabetical order. 00036 00037 //..................................................................... 00038 ///\verbatim 00039 /// 00040 /// Purpose: Default constructor 00041 /// 00042 /// Arguments: beQuiet - If true, fail quietly. If not be more verbose. 00043 /// 00044 /// Return: n/a 00045 /// 00046 /// Throws: ENoEnvironment(); if there is no environment defined 00047 /// throw EBadDatabase(); if any other error occured 00048 /// Contact: N. West 00049 /// 00050 /// Specification:- 00051 /// ============= 00052 /// 00053 /// o Create Cascader. 00054 /// 00055 /// 00056 /// Program Notes:- 00057 /// ============= 00058 /// 00059 /// Current cascader configuration comes from 3 environmental 00060 /// variables:- 00061 /// 00062 /// SK_TSQL_URL a semi-colon separated list of URLs 00063 /// SK_TSQL_USER user name (one or a semi-colon separated list) 00064 /// SK_TSQL_PSWD password (one or a semi-colon separated list) 00065 /// 00066 /// or the _UPDATE alternatives e.g. SK_TSQL_UPDATE_USER 00067 /// 00068 /// The _UPDATE versions take priority. 00069 ///\endverbatim 00070 TDbiCascader::TDbiCascader(bool beQuiet): 00071 fGlobalSeqNoDbNo(-1) 00072 { 00073 00074 00075 SK_DBI_Trace( "Creating TDbiCascader" << " "); 00076 00077 // Extract args from SK_TSQL environmental variables 00078 const char* strUser = gSystem->Getenv("SK_TSQL_UPDATE_USER"); 00079 if ( ! strUser ) strUser = gSystem->Getenv("SK_TSQL_USER"); 00080 const char* strPswd = gSystem->Getenv("SK_TSQL_UPDATE_PSWD"); 00081 if ( ! strPswd ) strPswd = gSystem->Getenv("SK_TSQL_PSWD"); 00082 const char* strUrl = gSystem->Getenv("SK_TSQL_UPDATE_URL"); 00083 if ( !strUrl ) strUrl = gSystem->Getenv("SK_TSQL_URL"); 00084 string userList = ( strUser ) ? strUser : ""; 00085 string pswdList = ( strPswd ) ? strPswd : ""; 00086 string urlList = ( strUrl ) ? strUrl : ""; 00087 00088 00089 if ( urlList == "" || userList == "" || pswdList == "" ) { 00090 /* 00091 If beQuiet is true be mute about why we are failing, leave it to the caller to deal with. 00092 */ 00093 if(!beQuiet) 00094 { 00095 std::cout<<"error!"<<std::endl; 00096 SK_DBI_Severe("Cannnot open a Database cascade;\n" 00097 << " the environmental variables SK_TSQL_*:-" << endl 00098 << "USER: \"" << userList << "\" PSWD:\"" << pswdList 00099 << "\" URL:\"" << urlList << endl 00100 << " are either not defined or empty.\n" 00101 << " Please check your settings of SK_TSQL_USER," 00102 << " SK_TSQL_PSWD and SK_TSQL_URL\n" ); 00103 00104 throw ENoEnvironment(); 00105 } 00106 } 00107 00108 std::vector<std::string> users, pswds, urls; 00109 UtilString::StringTok(users, userList, ";"); 00110 UtilString::StringTok(pswds, pswdList, ";"); 00111 UtilString::StringTok(urls, urlList, ";"); 00112 00113 bool fail = false; 00114 00115 for (unsigned entry = 0; entry < urls.size(); ++entry ) { 00116 string url = urls[entry]; 00117 string user = ( entry >= users.size() ) ? users[0] : users[entry]; 00118 string pswd = ( entry >= pswds.size() ) ? pswds[0] : pswds[entry]; 00119 00120 // Handle empty password designated as '\0' (an empty null terminated character string) 00121 if ( pswd == "\\0" ) pswd = ""; 00122 00123 std::cout << "Make connection " << url << " " << user << " " << pswd << std::endl; 00124 TDbiConnection* con; 00125 // If we are testing the cascade for validity, just try connecting once, otherwise use defaults. 00126 if(!beQuiet) 00127 con = new TDbiConnection(url,user,pswd,1); 00128 else 00129 con = new TDbiConnection(url,user,pswd); 00130 00131 00132 fConnections.push_back(con); 00133 if ( ! con->Open() ) { 00134 00135 fail = true; 00136 continue; 00137 } 00138 00139 // Attempt to locate first GlobalSeqNo/GLOBALSEQNO table. 00140 if ( fGlobalSeqNoDbNo != -1 ) continue; 00141 auto_ptr<TDbiStatement> stmtDb(new TDbiStatement(*con)); 00142 if ( ! stmtDb.get() ) continue; 00143 TSQLStatement* stmt = stmtDb->ExecuteQuery("Select * from GLOBALSEQNO where 1=0"); 00144 if ( stmt ) { 00145 fGlobalSeqNoDbNo = fConnections.size()-1; 00146 delete stmt; 00147 stmt = 0; 00148 } 00149 00150 // Check for presence of a DBI_STATE_FLAG table 00151 00152 if ( this->GetTableDbNo("DBI_STATE_FLAGS",entry) != -1 ) { 00153 if(!beQuiet) SK_DBI_Severe(" POSSIBLE VERSION SHEAR DETECTED !!!\n" 00154 << " The DBI_STATE_FLAGS table is present on cascade entry " << entry << ". This table will\n" 00155 << " only be introduced to manage backward incompatible changes that could lead\n" 00156 << " to version shear between the code and the database. This version of the\n" 00157 << " code does not support the change the presence of that table indicates\n" 00158 << " so has to shut down. \n"); 00159 fail = true; 00160 } 00161 } 00162 00163 SK_DBI_Info( *this); 00164 00165 // Abort, if there have been any failures. 00166 if ( fail ) { 00167 throw EBadDatabase(); 00168 } 00169 00170 }
ostream& operator<< | ( | ostream & | os, | |
const TDbiCascader & | cascader | |||
) |
Purpose: Output TDbiCascader status to message stream. Arguments: os in ostream to output on cascader in Cascader to be output Return: ostream Contact: N. West Specification:- ============= o Output TDbiCascader status to ostream. Program Notes:- ============= None.
Definition at line 210 of file TDbiCascader.cxx.
References TDbiCascader::fGlobalSeqNoDbNo, TDbiCascader::GetNumDb(), TDbiCascader::GetStatusAsString(), and TDbiCascader::GetURL().
00210 { 00211 00212 00213 os << "TDbiCascader Status:- " << endl 00214 << "Status URL" << endl << endl; 00215 00216 int maxDb = cascader.GetNumDb(); 00217 for (Int_t dbNo = 0; dbNo < maxDb; ++dbNo) 00218 os << cascader.GetStatusAsString(dbNo) << " " 00219 << ( ( dbNo == cascader.fGlobalSeqNoDbNo ) ? "(auth) " : " ") 00220 << cascader.GetURL(dbNo) << endl; 00221 os << endl; 00222 return os; 00223 00224 }