00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef STDBMANAGERIMPL_HH
00054 #define STDBMANAGERIMPL_HH
00055
00056 #include "StDbManager.hh"
00057 #include "parseXmlString.hh"
00058 #include "stdb_streams.h"
00059 #include "StDbTime.h"
00060 #include "StDataBaseI.hh"
00061 #include "StDbTableFactory.hh"
00062 #include "StDbMessService.hh"
00063 #include "StDbConfigNode.hh"
00064 #include "StDbTable.h"
00065 #include "StDbLogger.hh"
00066 #include "StDbServiceBroker.h"
00067
00068
00069 class dbType{
00070 public:
00071 StDbType type;
00072 char name[64];
00073 dbType(StDbType atype,const char* aname): type(atype) {
00074 if(aname)strcpy(name,aname);};
00075 };
00076 class dbDomain{
00077 public:
00078 StDbDomain domain;
00079 char name[64];
00080 dbDomain(StDbDomain adom,const char* aname): domain(adom) {
00081 if(aname)strcpy(name,aname);};
00082 };
00083
00084 #define MAX_ENV_VARS 50
00085 class dbEnvList {
00086 public:
00087 dbEnvList(): num(0) {};
00088 ~dbEnvList() {
00089 for(int i=0;i<num;i++){
00090 delete [] envVar[i];
00091 delete [] envDef[i];
00092 }
00093 }
00094 int num;
00095 char* envVar[MAX_ENV_VARS];
00096 char* envDef[MAX_ENV_VARS];
00097 };
00098
00099
00100 #include <list>
00101 #include <set>
00102 #ifdef ST_NO_TEMPLATE_DEF_ARGS
00103 typedef list<dbType*,allocator<dbType*> > dbTypes;
00104 typedef list<dbDomain*,allocator<dbDomain*> > dbDomains;
00105 typedef list<StDbServer*,allocator<StDbServer*> > ServerList;
00106 typedef set<std::string,allocator<std::string> > dbDomainBlacklist;
00107 #else
00108 #if !defined(ST_NO_NAMESPACES)
00109 using std::list;
00110 #endif
00111 typedef list<dbType*> dbTypes;
00112 typedef list<dbDomain*> dbDomains;
00113 typedef list<StDbServer*> ServerList;
00114 typedef set<std::string> dbDomainBlacklist;
00115 #endif
00116
00117
00118
00119 class StDbManagerImpl : public StDbManager {
00120
00121 friend class StDbManager;
00122
00123 private:
00124
00125 dbTypes mTypes;
00126 dbDomains mDomains;
00127 StDbType dbTypeFree;
00128 StDbDomain dbDomainFree;
00129 ServerList mservers;
00130 dbDomainBlacklist mBlacklist;
00131 parseXmlString mparser;
00132
00133 bool mhasServerList;
00134 bool mhasDefaultServer;
00135 StDbTime mcheckTime;
00136 StDbTime mstoreTime;
00137 StDbTableFactory* mfactory;
00138 StDbLogger mnodeLog;
00139 StDbLogger mdataLog;
00140
00141 protected:
00142
00143
00144 StDbManagerImpl();
00145
00146 public:
00147
00148 virtual ~StDbManagerImpl();
00149
00150 virtual void turnOffTimeLogging();
00151
00152 virtual StDbConfigNode* initConfig(const char* databaseName);
00153 virtual StDbConfigNode* initConfig(const char* databaseName,
00154 const char* configName, int opt=0);
00155 virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain);
00156 virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain,
00157 const char* configName, int opt=0);
00158 virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain,
00159 unsigned int requestTime, int opt=0);
00160 virtual StDbConfigNode* initConfig(const char* databaseName,
00161 unsigned int requestTime, int opt=0);
00162
00163 virtual char* getConfigNodeName(StDbType type, StDbDomain domain);
00164 virtual char* getExternalVersion(StDbType type,StDbDomain domain);
00165 virtual dbEnvList* getEnvList(const char* name);
00166
00167 virtual StDbTable* newDbTable(const char* dbName,const char* tabName);
00168 virtual StDbTable* newDbTable(StDbNode* node);
00169
00170
00171 virtual StDataBaseI* findDb(StDbType type, StDbDomain domain);
00172 virtual StDataBaseI* findDb(const char* dbType, const char* dbDomain);
00173 virtual StDataBaseI* findDb(const char* databaseName);
00174
00175 virtual StDbServer* findServer(StDbType type, StDbDomain domain);
00176 virtual StDbServer* findServer(StDbNode* node);
00177 virtual StDbServer* findServer(const char* dbType, const char* dbDomain);
00178 virtual StDbServer* findServer(const char* databaseName);
00179 virtual StDbServer* findDefaultServer();
00180
00181
00182 virtual char* getDbTypeName(StDbType type);
00183 virtual char* getDbDomainName(StDbDomain domain);
00184 virtual StDbType getDbType(const char* typeName);
00185 virtual StDbDomain getDbDomain(const char* domainName);
00186 virtual char* getDbName(const char* typeName,
00187 const char* domainName);
00188 virtual char* printDbName(StDbType type, StDbDomain domain);
00189
00190 virtual void blacklistDbDomain(const char* domainName);
00191
00192
00193 virtual void setRequestTime(unsigned int time);
00194 virtual void setRequestTime(const char* time);
00195 virtual unsigned int getUnixRequestTime();
00196 virtual char* getDateRequestTime();
00197 virtual unsigned int getUnixCheckTime();
00198 virtual char* getDateCheckTime();
00199 virtual void setStoreTime(unsigned int time);
00200 virtual void setStoreTime(const char* time);
00201 virtual unsigned int getUnixStoreTime();
00202 virtual char* getDateStoreTime();
00203
00204
00205 virtual bool getDataBaseInfo(const char* dbname,
00206 char*& type, char*& domain);
00207 virtual bool getDataBaseInfo(const char* dbname,
00208 StDbType& type, StDbDomain& domain);
00209
00210
00211 virtual bool IsValid(StDbTable* table);
00212 virtual bool fetchDbTable(StDbTable* table);
00213 virtual bool fetchDbTable(StDbTable* table, char* whereClause);
00214 virtual bool fetchAllTables(StDbConfigNode* node);
00215 virtual bool storeDbTable(StDbTable* table, bool commitWhenDone=true);
00216 virtual bool storeAllTables(StDbConfigNode* node, bool commitWhenDone=true);
00217 virtual int storeConfig(StDbConfigNode* node, int currentID,
00218 int& configID, bool commitWhenDone=true);
00219
00220
00221
00222
00223 virtual bool rollBackAllTables(StDbConfigNode* node);
00224 virtual bool rollBackAllNodes(StDbConfigNode* node);
00225 virtual bool rollBack(StDbNode* node);
00226 virtual bool rollBack(StDbTable* table);
00227 virtual bool commitAllTables(StDbConfigNode* node);
00228 virtual bool commitAllNodes(StDbConfigNode* node);
00229
00230 virtual void closeAllConnections();
00231 virtual void closeAllConnections(StDbConfigNode* node);
00232 virtual void closeConnection(StDbNode* node);
00233
00234 virtual void printTimeStats();
00235
00236
00237 short xmlInputSource;
00238
00239
00240 #ifndef NoXmlTreeReader
00241 StDbServiceBroker* myServiceBroker;
00242
00243 #endif
00244
00245 protected:
00246
00247 virtual void initTypes();
00248 virtual void initDomains();
00249 virtual void addDbType(StDbType type, const char* typeName);
00250 virtual void addDbDomain(StDbDomain domain, const char* domainName);
00251
00252
00253 virtual StDbType newDbType(const char* typeName);
00254 virtual StDbDomain newDbDomain(const char* domainName);
00255
00256 virtual void deleteServers();
00257 virtual void deleteTypes();
00258 virtual void deleteDomains();
00259
00260
00261 virtual void lookUpServers();
00262 virtual void findServersXml(ifstream& is);
00263 virtual char* findServerString(ifstream& is);
00264 virtual char* getNextName(char*& name);
00265
00266
00267 void updateDateTime(StDbTime& t);
00268 void updateUnixTime(StDbTime& t);
00269
00270
00271 };
00272
00273 #endif
00274
00275
00276
00277
00278
00279
00280
00281
00282