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

StDbManagerImpl.hh

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * 00003 * $Id: StDbManagerImpl.hh,v 1.4 2006/08/17 02:58:57 deph Exp $ 00004 * 00005 * Author: R. Jeff Porter 00006 *************************************************************************** 00007 * 00008 * Description: Manages access to Servers and passes Query-by-Table to db 00009 * --> Now the Implementation of the virtual StDbManager class 00010 * 00011 *************************************************************************** 00012 * 00013 * $Log: StDbManagerImpl.hh,v $ 00014 * Revision 1.4 2006/08/17 02:58:57 deph 00015 * updated load balancer - removing hard-coded nodes from API to xml 00016 * 00017 * Revision 1.3 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.2 2003/09/02 17:57:49 perev 00022 * gcc 3.2 updates + WarnOff 00023 * 00024 * Revision 1.1 2001/01/22 18:37:56 porter 00025 * Update of code needed in next year running. This update has little 00026 * effect on the interface (only 1 method has been changed in the interface). 00027 * Code also preserves backwards compatibility so that old versions of 00028 * StDbLib can read new table structures. 00029 * -Important features: 00030 * a. more efficient low-level table structure (see StDbSql.cc) 00031 * b. more flexible indexing for new systems (see StDbElememtIndex.cc) 00032 * c. environment variable override KEYS for each database 00033 * d. StMessage support & clock-time logging diagnostics 00034 * -Cosmetic features 00035 * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access 00036 * f. removed codes that have been obsolete for awhile (e.g. db factories) 00037 * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI 00038 * and mysqlAccessor became StDbSql) 00039 * 00040 **************************************************************************/ 00041 #ifndef STDBMANAGERIMPL_HH 00042 #define STDBMANAGERIMPL_HH 00043 00044 #include "StDbManager.hh" 00045 #include "parseXmlString.hh" 00046 #include "stdb_streams.h" 00047 #include "StDbTime.h" 00048 #include "StDataBaseI.hh" 00049 #include "StDbTableFactory.hh" 00050 #include "StDbMessService.hh" 00051 #include "StDbConfigNode.hh" 00052 #include "StDbTable.h" 00053 #include "StDbLogger.hh" 00054 00055 /********* helper classes (c-structs) *************/ 00056 class dbType{ 00057 public: 00058 StDbType type; 00059 char name[64]; 00060 dbType(StDbType atype,const char* aname): type(atype) { 00061 if(aname)strcpy(name,aname);}; 00062 }; 00063 class dbDomain{ 00064 public: 00065 StDbDomain domain; 00066 char name[64]; 00067 dbDomain(StDbDomain adom,const char* aname): domain(adom) { 00068 if(aname)strcpy(name,aname);}; 00069 }; 00070 00071 #define MAX_ENV_VARS 50 00072 class dbEnvList { 00073 public: 00074 dbEnvList(): num(0) {}; 00075 ~dbEnvList() { 00076 for(int i=0;i<num;i++){ 00077 delete [] envVar[i]; 00078 delete [] envDef[i]; 00079 } 00080 } 00081 int num; 00082 char* envVar[MAX_ENV_VARS]; 00083 char* envDef[MAX_ENV_VARS]; 00084 }; 00085 /*************** end helper class definitions ****************/ 00086 00087 #include <list> 00088 #ifdef ST_NO_TEMPLATE_DEF_ARGS 00089 typedef list<dbType*,allocator<dbType*> > dbTypes; 00090 typedef list<dbDomain*,allocator<dbDomain*> > dbDomains; 00091 typedef list<StDbServer*,allocator<StDbServer*> > ServerList; 00092 #else 00093 #if !defined(ST_NO_NAMESPACES) 00094 using std::list; 00095 #endif 00096 typedef list<dbType*> dbTypes; 00097 typedef list<dbDomain*> dbDomains; 00098 typedef list<StDbServer*> ServerList; 00099 #endif 00100 00101 class StDbManagerImpl : public StDbManager { 00102 00103 friend class StDbManager; 00104 00105 private: 00106 00107 dbTypes mTypes; 00108 dbDomains mDomains; 00109 StDbType dbTypeFree; 00110 StDbDomain dbDomainFree; 00111 ServerList mservers; 00112 parseXmlString mparser; 00113 00114 bool mhasServerList; 00115 bool mhasDefaultServer; 00116 StDbTime mcheckTime; 00117 StDbTime mstoreTime; 00118 StDbTableFactory* mfactory; 00119 StDbLogger mnodeLog; 00120 StDbLogger mdataLog; 00121 00122 protected: 00123 00124 // protected constructor 00125 StDbManagerImpl(); 00126 00127 public: 00128 00129 virtual ~StDbManagerImpl(); 00130 00131 virtual void turnOffTimeLogging(); 00132 // Factory class for Container of StDbTables.. 00133 virtual StDbConfigNode* initConfig(const char* databaseName); 00134 virtual StDbConfigNode* initConfig(const char* databaseName, 00135 const char* configName, int opt=0); 00136 virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain); 00137 virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain, 00138 const char* configName, int opt=0); 00139 virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain, 00140 unsigned int requestTime, int opt=0); 00141 virtual StDbConfigNode* initConfig(const char* databaseName, 00142 unsigned int requestTime, int opt=0); 00143 00144 virtual char* getConfigNodeName(StDbType type, StDbDomain domain); 00145 virtual char* getExternalVersion(StDbType type,StDbDomain domain); 00146 virtual dbEnvList* getEnvList(const char* name); 00147 00148 virtual StDbTable* newDbTable(const char* dbName,const char* tabName); 00149 virtual StDbTable* newDbTable(StDbNode* node); 00150 00151 // find databases & servers by various methods 00152 virtual StDataBaseI* findDb(StDbType type, StDbDomain domain); 00153 virtual StDataBaseI* findDb(const char* dbType, const char* dbDomain); 00154 virtual StDataBaseI* findDb(const char* databaseName); 00155 00156 virtual StDbServer* findServer(StDbType type, StDbDomain domain); 00157 virtual StDbServer* findServer(StDbNode* node); 00158 virtual StDbServer* findServer(const char* dbType, const char* dbDomain); 00159 virtual StDbServer* findServer(const char* databaseName); 00160 virtual StDbServer* findDefaultServer(); 00161 00162 // helper functions to map enumeration to type 00163 virtual char* getDbTypeName(StDbType type); 00164 virtual char* getDbDomainName(StDbDomain domain); 00165 virtual StDbType getDbType(const char* typeName); 00166 virtual StDbDomain getDbDomain(const char* domainName); 00167 virtual char* getDbName(const char* typeName, 00168 const char* domainName); 00169 virtual char* printDbName(StDbType type, StDbDomain domain); 00170 00171 // time stamp methods 00172 virtual void setRequestTime(unsigned int time); 00173 virtual void setRequestTime(const char* time); 00174 virtual unsigned int getUnixRequestTime(); 00175 virtual char* getDateRequestTime(); 00176 virtual unsigned int getUnixCheckTime(); 00177 virtual char* getDateCheckTime(); 00178 virtual void setStoreTime(unsigned int time); 00179 virtual void setStoreTime(const char* time); 00180 virtual unsigned int getUnixStoreTime(); 00181 virtual char* getDateStoreTime(); 00182 00183 // find the dbType & dbDomain for a database=>dbname 00184 virtual bool getDataBaseInfo(const char* dbname, 00185 char*& type, char*& domain); 00186 virtual bool getDataBaseInfo(const char* dbname, 00187 StDbType& type, StDbDomain& domain); 00188 00189 // fetch & store methods for data 00190 virtual bool IsValid(StDbTable* table); 00191 virtual bool fetchDbTable(StDbTable* table); 00192 virtual bool fetchDbTable(StDbTable* table, char* whereClause); 00193 virtual bool fetchAllTables(StDbConfigNode* node); 00194 virtual bool storeDbTable(StDbTable* table, bool commitWhenDone=true); 00195 virtual bool storeAllTables(StDbConfigNode* node, bool commitWhenDone=true); 00196 virtual int storeConfig(StDbConfigNode* node, int currentID, 00197 int& configID, bool commitWhenDone=true); 00198 00199 // transaction methods 00200 // nodes are node entries in the "Nodes" table 00201 // tables are real data entries in a data+dataIndex table 00202 virtual bool rollBackAllTables(StDbConfigNode* node); 00203 virtual bool rollBackAllNodes(StDbConfigNode* node); 00204 virtual bool rollBack(StDbNode* node); 00205 virtual bool rollBack(StDbTable* table); 00206 virtual bool commitAllTables(StDbConfigNode* node); 00207 virtual bool commitAllNodes(StDbConfigNode* node); 00208 00209 virtual void closeAllConnections(); 00210 virtual void closeAllConnections(StDbConfigNode* node); 00211 virtual void closeConnection(StDbNode* node); 00212 00213 virtual void printTimeStats(); 00214 00215 // MLK added for load balancing: 00216 00217 std::vector<std::string> xmlServerList; 00218 00219 short xmlInputSource; 00220 00221 protected: 00222 // initializers for standard types & domains 00223 virtual void initTypes(); 00224 virtual void initDomains(); 00225 virtual void addDbType(StDbType type, const char* typeName); 00226 virtual void addDbDomain(StDbDomain domain, const char* domainName); 00227 00228 // assigns an available user type or domain to a user supplied name 00229 virtual StDbType newDbType(const char* typeName); 00230 virtual StDbDomain newDbDomain(const char* domainName); 00231 00232 virtual void deleteServers(); 00233 virtual void deleteTypes(); 00234 virtual void deleteDomains(); 00235 00236 // These lookup up ServerInfo from XML files 00237 virtual void lookUpServers(); 00238 virtual void findServersXml(ifstream& is); 00239 virtual char* findServerString(ifstream& is); 00240 virtual char* getNextName(char*& name); 00241 00242 // ensure both unix & date timestamp are in-sinc. 00243 void updateDateTime(StDbTime& t); 00244 void updateUnixTime(StDbTime& t); 00245 }; 00246 00247 #endif 00248 00249 00250 00251 00252 00253 00254 00255 00256

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