Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

StDbNode.cc

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * 00003 * $Id: StDbNode.cc,v 1.10 2004/01/15 00:02:25 fisyak Exp $ 00004 * 00005 * Author: R. Jeff Porter 00006 *************************************************************************** 00007 * 00008 * Description: Base-class database entities 00009 * 00010 *************************************************************************** 00011 * 00012 * $Log: StDbNode.cc,v $ 00013 * Revision 1.10 2004/01/15 00:02:25 fisyak 00014 * Replace ostringstream => StString, add option for alpha 00015 * 00016 * Revision 1.9 2003/12/16 01:30:32 porter 00017 * additional fixes for change from ostrstream to StString that were not exposed until 00018 * running in online 00019 * 00020 * Revision 1.8 2003/09/16 22:44:17 porter 00021 * got rid of all ostrstream objects; replaced with StString+string. 00022 * modified rules.make and added file stdb_streams.h for standalone compilation 00023 * 00024 * Revision 1.7 2003/09/02 17:57:49 perev 00025 * gcc 3.2 updates + WarnOff 00026 * 00027 * Revision 1.6 2001/02/09 23:06:25 porter 00028 * replaced ostrstream into a buffer with ostrstream creating the 00029 * buffer. The former somehow clashed on Solaris with CC5 iostream (current .dev) 00030 * 00031 * Revision 1.5 2001/01/22 18:37:57 porter 00032 * Update of code needed in next year running. This update has little 00033 * effect on the interface (only 1 method has been changed in the interface). 00034 * Code also preserves backwards compatibility so that old versions of 00035 * StDbLib can read new table structures. 00036 * -Important features: 00037 * a. more efficient low-level table structure (see StDbSql.cc) 00038 * b. more flexible indexing for new systems (see StDbElememtIndex.cc) 00039 * c. environment variable override KEYS for each database 00040 * d. StMessage support & clock-time logging diagnostics 00041 * -Cosmetic features 00042 * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access 00043 * f. removed codes that have been obsolete for awhile (e.g. db factories) 00044 * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI 00045 * and mysqlAccessor became StDbSql) 00046 * 00047 * Revision 1.4 2000/04/25 18:26:03 porter 00048 * added flavor & production time as settable query fields in 00049 * table &/or node. Associated SQL updated in mysqlAccessor. 00050 * Flavor key supports "+" as an OR symbol. 00051 * 00052 * Revision 1.3 2000/01/19 20:20:06 porter 00053 * - finished transaction model needed by online 00054 * - fixed CC5 compile problem in StDbNodeInfo.cc 00055 * - replace TableIter class by StDbTableIter to prevent name problems 00056 * 00057 * Revision 1.2 2000/01/14 14:50:52 porter 00058 * expanded use of verbose mode & fixed inconsistency in 00059 * StDbNodeInfo::getElementID 00060 * 00061 * Revision 1.1 2000/01/10 20:37:54 porter 00062 * expanded functionality based on planned additions or feedback from Online work. 00063 * update includes: 00064 * 1. basis for real transaction model with roll-back 00065 * 2. limited SQL access via the manager for run-log & tagDb 00066 * 3. balance obtained between enumerated & string access to databases 00067 * 4. 3-levels of diagnostic output: Quiet, Normal, Verbose 00068 * 5. restructured Node model for better XML support 00069 * 00070 * 00071 ***************************************************************************/ 00072 00073 #include "StDbNode.hh" 00074 #include "StDbDefaults.hh" 00075 #include "stdb_streams.h" 00076 #include <stdlib.h> 00077 00078 #ifdef __ROOT__ 00079 ClassImp(StDbNode) 00080 #endif 00081 00083 00084 StDbNode::StDbNode(const char* name, const char* versionKey): mname(0), mversion(0), mdbName(0), mnodeID(0),mnodeType(0){ 00085 00086 setName(name); 00087 setVersion(versionKey); 00088 misConfigured = false; 00089 mcanRollBack = false; 00090 } 00091 00093 StDbNode::StDbNode(const char* name ): mname(0), mversion(0), mdbName(0), mnodeID(0) ,mnodeType(0){ 00094 setName(name); 00095 setVersion(StDbDefaults::Instance()->printVersion()); 00096 misConfigured = false; 00097 mcanRollBack = false; 00098 } 00099 00101 StDbNode::StDbNode(StDbNode& node){ 00102 00103 mname = node.getName(); 00104 mversion = node.getVersion(); 00105 mdbName = node.getDbName(); 00106 mdbType = node.getDbType(); 00107 mdbDomain = node.getDbDomain(); 00108 mnodeID = node.getNodeID(); 00109 mnodeType = node.getNodeType(); 00110 misConfigured = node.IsConfigured(); 00111 mcanRollBack = node.canRollBack(); 00112 } 00113 00115 StDbNode::~StDbNode(){ 00116 if(mname) delete [] mname; 00117 if(mversion) delete [] mversion; 00118 if(mdbName) delete [] mdbName; 00119 if(mnodeType) delete [] mnodeType; 00120 } 00121 00123 00124 char* StDbNode::getName() { return mstrDup((const char*)mname); }; 00125 char* StDbNode::getVersion() { return mstrDup((const char*)mversion); } 00126 char* StDbNode::getDbName() { return mstrDup((const char*)mdbName); } 00127 char* StDbNode::getNodeType() { return mstrDup(mnodeType); } 00128 00129 void StDbNode::setName(const char* nodeName) { 00130 if(mname) delete [] mname; 00131 mname=mstrDup(nodeName); 00132 } 00133 void StDbNode::setVersion(const char* version){ 00134 if(mversion) delete [] mversion; 00135 mversion=mstrDup(version); 00136 } 00137 void StDbNode::setDbName(const char* dbName) { 00138 if(mdbName)delete [] mdbName; 00139 mdbName=mstrDup(dbName); 00140 } 00141 void StDbNode::setNodeType(const char* type) { 00142 if(mnodeType) delete [] mnodeType; 00143 mnodeType=mstrDup(type); 00144 } 00145 00147 int* StDbNode::decodeElementID(const char* elemID, int& numRows) { 00148 00149 numRows=1; 00150 int * retVal = 0; 00151 char* id=strstr((char*)elemID,"None"); 00152 00153 if(id){ 00154 numRows=1; 00155 int* e = new int[1]; *e=0; 00156 return e; 00157 } 00158 00159 char* tmpName = new char[strlen(elemID)+1]; 00160 strcpy(tmpName,elemID); 00161 00162 int numElements = 1; 00163 id = strstr(tmpName,","); 00164 char* id1; 00165 char* id2; 00166 00167 id2 = strstr(tmpName,"-"); 00168 StString sl; 00169 00170 if(id2 && ( (id && id2<id) || !id)){ 00171 id=id2; 00172 id[0]=','; 00173 sl<<"r"; 00174 } else { 00175 sl<<"l"; 00176 } 00177 00178 int numEntries = 1; 00179 if(id)id++; 00180 while(id){ 00181 // cout << "id = " << id << endl; 00182 numEntries++; 00183 id1=strstr(id,","); 00184 id2=strstr(id,"-"); 00185 id = id1; 00186 if(id && id2 && id2<id){ 00187 id=id2; 00188 id[0]=','; 00189 sl<<"r"; 00190 } else { 00191 sl<<"l"; 00192 } 00193 if(id)id++; 00194 } 00195 char* islist=new char[strlen((sl.str()).c_str())+1]; 00196 strcpy(islist,(sl.str()).c_str()); 00197 00198 // cout << "My string list = " << islist << endl; 00199 00200 int* tmpElements = new int[100000]; 00201 char* p1=&tmpName[0]; 00202 char* anID=0; 00203 anID = getNextID(p1); 00204 tmpElements[0] = atoi(anID); 00205 if(anID)delete [] anID; 00206 numElements = 1; 00207 int iEnd, iStart, k; 00208 for(int ient=1;ient<numEntries;ient++){ 00209 anID = getNextID(p1); 00210 if(islist[ient-1]=='r'){ 00211 iEnd = atoi(anID); 00212 iStart = tmpElements[numElements-1]; 00213 int irange=iEnd-iStart; 00214 for(int ir=1;ir<=irange;ir++){ 00215 numElements++; 00216 tmpElements[numElements-1]=iStart+ir; 00217 } 00218 } else { 00219 numElements++; 00220 tmpElements[numElements-1]=atoi(anID); 00221 } 00222 if(anID) delete [] anID; 00223 } 00224 00225 retVal = new int[numElements]; 00226 for(k=0;k<numElements;k++)retVal[k]=tmpElements[k]; 00227 numRows = numElements; 00228 00229 delete [] islist; 00230 delete [] tmpElements; 00231 delete [] tmpName; 00232 00233 return retVal; 00234 } 00235 00237 char* 00238 StDbNode::getNextID(char*& currentElement) const { 00239 00240 char* nextID = 0; 00241 if(!currentElement)return nextID; 00242 00243 char* id = strstr(currentElement,","); 00244 00245 if(!id) { 00246 nextID = new char[strlen(currentElement)+1]; 00247 strcpy(nextID,currentElement); 00248 currentElement = 0; 00249 } else { 00250 int iloc = id-currentElement; 00251 nextID = new char[iloc+1]; 00252 strncpy(nextID,currentElement,iloc); 00253 nextID[iloc]='\0'; 00254 currentElement = id; currentElement++; 00255 } 00256 00257 return nextID; 00258 } 00259 00261 char* StDbNode::mstrDup(const char* s2) { 00262 00263 char* s1=0; 00264 if(!s2) return s1; 00265 s1 = new char[strlen(s2)+1]; 00266 strcpy(s1,s2); 00267 return s1; 00268 } 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281

Generated on Thu Aug 24 14:45:26 2006 for Doxygen by doxygen 1.3.7