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

StDbManager.hh

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * 00003 * $Id: StDbManager.hh,v 1.23 2004/01/15 00:02:25 fisyak Exp $ 00004 * 00005 * Author: R. Jeff Porter 00006 *************************************************************************** 00007 * 00008 * Description: Manages access to Servers and passes Query-by-Table to db 00009 * --> Now a pure virtual interface 00010 * 00011 *************************************************************************** 00012 * 00013 * $Log: StDbManager.hh,v $ 00014 * Revision 1.23 2004/01/15 00:02:25 fisyak 00015 * Replace ostringstream => StString, add option for alpha 00016 * 00017 * Revision 1.22 2003/09/16 22:44:17 porter 00018 * got rid of all ostrstream objects; replaced with ostringstream+string. 00019 * modified rules.make and added file stdb_streams.h for standalone compilation 00020 * 00021 * Revision 1.21 2003/09/02 17:57:49 perev 00022 * gcc 3.2 updates + WarnOff 00023 * 00024 * Revision 1.20 2001/02/09 23:06:24 porter 00025 * replaced ostrstream into a buffer with ostrstream creating the 00026 * buffer. The former somehow clashed on Solaris with CC5 iostream (current .dev) 00027 * 00028 * Revision 1.19 2001/01/22 18:37:55 porter 00029 * Update of code needed in next year running. This update has little 00030 * effect on the interface (only 1 method has been changed in the interface). 00031 * Code also preserves backwards compatibility so that old versions of 00032 * StDbLib can read new table structures. 00033 * -Important features: 00034 * a. more efficient low-level table structure (see StDbSql.cc) 00035 * b. more flexible indexing for new systems (see StDbElememtIndex.cc) 00036 * c. environment variable override KEYS for each database 00037 * d. StMessage support & clock-time logging diagnostics 00038 * -Cosmetic features 00039 * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access 00040 * f. removed codes that have been obsolete for awhile (e.g. db factories) 00041 * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI 00042 * and mysqlAccessor became StDbSql) 00043 * 00044 * Revision 1.18 2000/06/02 13:37:37 porter 00045 * built up list of minor changes: 00046 * - made buffer more robust for certain null inputs 00047 * - fixed small leak in StDbTables & restructure call to createMemory 00048 * - added dbRhic as a database domain in StDbDefs 00049 * - added setUser() in StDbManager 00050 * - added more diagnostic printouts in mysqlAccessor.cc 00051 * 00052 * Revision 1.17 2000/03/28 17:03:19 porter 00053 * Several upgrades: 00054 * 1. configuration by timestamp for Conditions 00055 * 2. query by whereClause made more systematic 00056 * 3. conflict between db-stored comments & number lists resolved 00057 * 4. ensure endtime is correct for certain query falures 00058 * 5. dbstl.h->handles ObjectSpace & RogueWave difference (Online vs Offline) 00059 * 00060 * Revision 1.16 2000/03/01 20:56:16 porter 00061 * 3 items: 00062 * 1. activated reConnect for server timeouts 00063 * 2. activated connection sharing; better resource utilization but poorer 00064 * logging 00065 * 3. made rollback method in mysqlAccessor more robust (affects writes only) 00066 * 00067 * Revision 1.15 2000/02/24 20:30:46 porter 00068 * fixed padding for uchar; beginTime in mysqlAccessor; 00069 * added rollback safety checkes in StDbManger 00070 * 00071 * Revision 1.14 2000/02/18 16:58:09 porter 00072 * optimization of table-query, + whereClause gets timeStamp if indexed 00073 * + fix to write multiple rows algorithm 00074 * 00075 * Revision 1.13 2000/02/15 20:27:44 porter 00076 * Some updates to writing to the database(s) via an ensemble (should 00077 * not affect read methods & haven't in my tests. 00078 * - closeAllConnections(node) & closeConnection(table) method to mgr. 00079 * - 'NullEntry' version to write, with setStoreMode in table; 00080 * - updated both StDbTable's & StDbTableDescriptor's copy-constructor 00081 * 00082 * Revision 1.12 2000/01/27 05:54:34 porter 00083 * Updated for compiling on CC5 + HPUX-aCC + KCC (when flags are reset) 00084 * Fixed reConnect()+transaction model mismatch 00085 * added some in-code comments 00086 * 00087 * Revision 1.11 2000/01/19 20:20:05 porter 00088 * - finished transaction model needed by online 00089 * - fixed CC5 compile problem in StDbNodeInfo.cc 00090 * - replace TableIter class by StDbTableIter to prevent name problems 00091 * 00092 * Revision 1.10 2000/01/10 20:37:54 porter 00093 * expanded functionality based on planned additions or feedback from Online work. 00094 * update includes: 00095 * 1. basis for real transaction model with roll-back 00096 * 2. limited SQL access via the manager for run-log & tagDb 00097 * 3. balance obtained between enumerated & string access to databases 00098 * 4. 3-levels of diagnostic output: Quiet, Normal, Verbose 00099 * 5. restructured Node model for better XML support 00100 * 00101 * Revision 1.9 1999/12/28 21:31:42 porter 00102 * added 'using std::vector' and 'using std::list' for Solaris CC5 compilation. 00103 * Also fixed some warnings arising from the CC5 compiles 00104 * 00105 * Revision 1.8 1999/12/03 22:24:01 porter 00106 * expanded functionality used by online, fixed bug in 00107 * mysqlAccessor::getElementID(char*), & update StDbDataSet to 00108 * conform to changes in Xml reader & writer 00109 * 00110 * Revision 1.7 1999/10/19 14:30:39 porter 00111 * modifications relevant to use with StDbBroker and future merging with 00112 * "params" database structure + some docs + suppressing diagnostics messages 00113 * 00114 * Revision 1.6 1999/09/30 02:06:07 porter 00115 * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor) 00116 * allow multiple rows (StDbTable), & Added the comment sections at top of 00117 * each header and src file 00118 * 00119 **************************************************************************/ 00120 #ifndef STDBMANAGER_HH 00121 #define STDBMANAGER_HH 00122 00123 #include <string.h> 00124 #include "StString.h" 00125 00126 #include "stdb_streams.h" 00127 00128 // real basic definitions 00129 #include "StDbDefs.hh" 00130 // pure virtual classes 00131 #include "StDbMessService.hh" 00132 00133 // other classes 00134 class StDbServer; 00135 class StDataBaseI; 00136 class dbEnvList; 00137 class StDbNode; 00138 class StDbConfigNode; 00139 class StDbTable; 00140 00141 #ifdef __ROOT__ 00142 #include "TROOT.h" 00143 #endif 00144 00145 class StDbManager { 00146 00147 protected: 00148 00149 bool misVerbose; 00150 bool misQuiet; 00151 StDbMessService* Messenger; 00152 char* muserName; 00153 char* mpWord; 00154 00155 bool misTimeLogged; 00156 00157 StDbManager(); 00158 static StDbManager* mInstance; 00159 00160 char* mstringDup(const char* str); 00161 00162 public: 00163 00164 // access to this singleton object 00165 static StDbManager* Instance(); 00166 virtual ~StDbManager(); 00167 00168 // Act as Factory object for StDbConfigNodess 00169 // --> get dbHandle & Container of StDbTables.. 00170 virtual StDbConfigNode* initConfig(const char* dbName) =0; 00171 virtual StDbConfigNode* initConfig(const char* dbName, 00172 const char* configName, int opt=0) =0; 00173 virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain) =0; 00174 virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain, 00175 const char* configName, int opt=0) =0; 00176 virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain, 00177 unsigned int requestTime, int opt=0) =0; 00178 virtual StDbConfigNode* initConfig(const char* dbName, 00179 unsigned int requestTime, int opt=0) =0; 00180 00181 virtual char* getConfigNodeName(StDbType t, StDbDomain d) =0; 00182 virtual char* getExternalVersion(StDbType t,StDbDomain d) =0; 00183 virtual dbEnvList* getEnvList(const char* name) =0; 00184 00185 // act as a Factory object for StDbTables 00186 virtual StDbTable* newDbTable(const char* dbName,const char* tName)=0; 00187 virtual StDbTable* newDbTable(StDbNode* node) =0; 00188 00189 // Retreive DbLib owned database & server poointers by various methods 00190 virtual StDataBaseI* findDb(StDbType type, StDbDomain domain) =0; 00191 virtual StDataBaseI* findDb(const char* dbType, const char* dbDomain) =0; 00192 virtual StDataBaseI* findDb(const char* databaseName) =0; 00193 virtual StDbServer* findServer(StDbType type, StDbDomain domain) =0; 00194 virtual StDbServer* findServer(StDbNode* node) =0; 00195 virtual StDbServer* findServer(const char* type, const char* domain) =0; 00196 virtual StDbServer* findServer(const char* databaseName) =0; 00197 virtual StDbServer* findDefaultServer() =0; 00198 00199 // helper functions using mapped enumeration to dbType & dbDomain 00200 virtual char* getDbTypeName(StDbType type) =0; 00201 virtual char* getDbDomainName(StDbDomain domain) =0; 00202 virtual StDbType getDbType(const char* typeName) =0; 00203 virtual StDbDomain getDbDomain(const char* domainName) =0; 00204 virtual char* getDbName(const char* typeName, const char* domName)=0; 00205 virtual char* printDbName(StDbType type, StDbDomain domain) =0; 00206 00207 // time stamp methods 00208 virtual void setRequestTime(unsigned int time) =0; 00209 virtual void setRequestTime(const char* time) =0; 00210 virtual unsigned int getUnixRequestTime() =0; 00211 virtual char* getDateRequestTime() =0; 00212 virtual unsigned int getUnixCheckTime() =0; 00213 virtual char* getDateCheckTime() =0; 00214 virtual void setStoreTime(unsigned int time) =0; 00215 virtual void setStoreTime(const char* time) =0; 00216 virtual unsigned int getUnixStoreTime() =0; 00217 virtual char* getDateStoreTime() =0; 00218 00219 // find the dbType & dbDomain for a database=>dbname 00220 virtual bool getDataBaseInfo(const char* dbname, 00221 char*& type, char*& domain) =0; 00222 virtual bool getDataBaseInfo(const char* dbname, 00223 StDbType& type, StDbDomain& domain) =0; 00224 00225 // fetch & store methods for data 00226 virtual bool IsValid(StDbTable* table) =0; 00227 virtual bool fetchDbTable(StDbTable* table) =0; 00228 virtual bool fetchDbTable(StDbTable* table, char* whereClause) =0; 00229 virtual bool fetchAllTables(StDbConfigNode* node) =0; 00230 virtual bool storeDbTable(StDbTable* table, bool commitWhenDone=true) =0; 00231 virtual bool storeAllTables(StDbConfigNode* node, 00232 bool commitWhenDone=true) =0; 00233 virtual int storeConfig(StDbConfigNode* node, int currentID, 00234 int& configID, bool commitWhenDone=true) =0; 00235 00236 // transaction methods 00237 virtual bool rollBackAllTables(StDbConfigNode* node) =0; 00238 virtual bool rollBackAllNodes(StDbConfigNode* node) =0; 00239 virtual bool rollBack(StDbNode* node) =0; 00240 virtual bool rollBack(StDbTable* table) =0; 00241 virtual bool commitAllTables(StDbConfigNode* node) =0; 00242 virtual bool commitAllNodes(StDbConfigNode* node) =0; 00243 00244 // close connection methods 00245 virtual void closeAllConnections() =0; 00246 virtual void closeAllConnections(StDbConfigNode* node) =0; 00247 virtual void closeConnection(StDbNode* node) =0; 00248 00249 virtual void printTimeStats() =0; 00250 00251 // messaging service directions *** These are real functions *** 00252 virtual bool IsVerbose() const; 00253 virtual void setVerbose(bool isVerbose); 00254 virtual bool IsQuiet() const ; 00255 virtual void setQuiet(bool isQuiet); 00256 virtual void turnOffTimeLogging(); 00257 virtual void updateMessLevel(); 00258 virtual void setMessenger(StDbMessService* service); 00259 virtual StDbMessService* getMessenger(); 00260 virtual int printInfo(const char* m1, StDbMessLevel ml, 00261 int lineNumber=0, const char* className=" ", 00262 const char* methodName=" ") ; 00263 virtual int printInfo(const char* m1, const char* m2, 00264 StDbMessLevel ml, int lineNumber=0, 00265 const char* className=" ", 00266 const char* methodName=" "); 00267 00268 virtual char* userName(); 00269 virtual char* pWord(); 00270 virtual void setUser(const char* userName, const char* pWord); 00271 00272 // make ROOT-CLI via star-ofl "makefiles" 00273 #ifdef __ROOT__ 00274 ClassDef(StDbManager,0) 00275 #endif 00276 00277 }; 00278 00279 inline bool StDbManager::IsVerbose() const { return misVerbose;}; 00280 inline void StDbManager::setVerbose(bool isVerbose){ 00281 misVerbose=isVerbose; 00282 if(isVerbose)misQuiet=false; 00283 updateMessLevel(); 00284 }; 00285 inline bool StDbManager::IsQuiet() const { return misQuiet;}; 00286 inline void StDbManager::setQuiet(bool isQuiet){ 00287 misQuiet=isQuiet; 00288 if(isQuiet) misVerbose=false; 00289 updateMessLevel(); 00290 } 00291 inline void StDbManager::updateMessLevel(){ 00292 Messenger->setMessLevel(dbMWarn); 00293 if(misQuiet)Messenger->setMessLevel(dbMErr); 00294 if(misVerbose)Messenger->setMessLevel(dbMDebug); 00295 } 00296 inline void StDbManager::setMessenger(StDbMessService* service){ 00297 delete Messenger; 00298 Messenger=service; 00299 updateMessLevel(); 00300 } 00301 inline StDbMessService* StDbManager::getMessenger(){ return Messenger; } 00302 inline char* StDbManager::userName() { return muserName; } 00303 inline char* StDbManager::pWord() { return mpWord; } 00304 00305 #endif 00306 00307 00308 00309 00310 00311 00312 00313 00314

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