00001 00002 // 00003 // Implementation of class AlephDbManager 00004 // 00005 // Author : G. Dissertori , 02.11.98 00006 // 00008 00009 00010 #include <stdlib.h> 00011 #include <iostream> 00012 #include <fstream> 00013 #include <string> 00014 #include "AlephIoManager.h" 00015 #include "AlephDbManager.h" 00016 #include "AlephROOTDbManager.h" 00017 00018 extern ofstream fout; 00019 00020 // 00021 // set the global instance variable 00022 // 00023 AlephManager* AlephDbManager::_theAlephDbManager=0; 00024 00025 // 00026 // the instance function of the Singleton 00027 // 00028 AlephManager* AlephDbManager::TheAlephDbManager() 00029 { 00030 if (_theAlephDbManager == 0) 00031 { 00032 // check which type of database we want 00033 string databaseType; 00034 // first check is the IoManager is there and has a card DBTY 00035 AlephManager* ioManager = (AlephSession::TheAlephSession())->aAlephManager("IoManager"); 00036 if (ioManager != NULL) 00037 { 00038 AlephStatus ioManStatus = ioManager->status(); 00039 if (ioManStatus == INITIALIZED) 00040 { 00041 AlephIoManager* IoManager = (AlephIoManager*)ioManager; 00042 // get the cards reader 00043 AlephCardsReader& cardsReader = IoManager->theCardsReader(); 00044 // get the DBTY card 00045 databaseType = cardsReader.getDbType(); 00046 } 00047 } 00048 // else look for an environment variable 00049 else 00050 { 00051 databaseType = getenv("DATABASETYPE"); 00052 } 00053 00054 if (databaseType == "") 00055 { 00056 fout << "AlephDbManager Warning : env variable DATABASETYPE not set" 00057 << endl; 00058 fout << "Therefore creating a default database manager..." << endl; 00059 _theAlephDbManager = new AlephDbManager; 00060 } 00061 else 00062 { 00063 if (databaseType == "epio") 00064 { 00065 _theAlephDbManager = new AlephDbManager; 00066 } 00067 else 00068 if ((databaseType == "root") || 00069 (databaseType == "epio/root")) 00070 { 00071 _theAlephDbManager = new AlephROOTDbManager; 00072 } 00073 else // else just create a default database manager 00074 { 00075 fout << "AlephDbManager Warning : env variable DATABASETYPE " 00076 << databaseType << " is not a valid db type " << endl; 00077 fout << "Therefore creating a default database manager..." << endl; 00078 _theAlephDbManager = new AlephDbManager; 00079 } 00080 } 00081 } 00082 return _theAlephDbManager; 00083 } 00084 00085 // 00086 // the constructor 00087 // 00088 AlephDbManager::AlephDbManager() 00089 { 00090 // call the constructor of the base class 00091 AlephManagerSetup("DbManager"); 00092 // set the dbname to an empty string 00093 string _dbName = " "; 00094 } 00095 00096 // 00097 // the destructor 00098 // 00099 AlephDbManager::~AlephDbManager() 00100 { 00101 AlephManagerShutDown(); 00102 delete [] _theAlephDbManager; 00103 } 00104 00105 // 00106 // the initialization step 00107 // 00108 AlephRC AlephDbManager::initialize() 00109 { 00110 // say something 00111 fout << " AlephDbManager : initializing .... " << endl; 00112 // start reading transaction as default 00113 startTransaction(READING); 00114 // set the status 00115 setStatus(INITIALIZED); 00116 return AlephOK; 00117 } 00118 00119 // 00120 // the termination step 00121 // 00122 AlephRC AlephDbManager::terminate() 00123 { 00124 // say something 00125 fout << " AlephDbManager : terminating .... " << endl; 00126 // stop any transaction 00127 stopTransaction(); 00128 // set the status 00129 setStatus(TERMINATED); 00130 return AlephOK; 00131 } 00132 00133 // 00134 // get the transaction type 00135 // 00136 AlephTransaction AlephDbManager::transactionType() const 00137 { 00138 return _theTransactionType; 00139 } 00140 00141 // 00142 // set the transaction type 00143 // 00144 void AlephDbManager::setTransactionType(const AlephTransaction& transType) 00145 { 00146 _theTransactionType = transType; 00147 } 00148 00149 // 00150 // start a transaction, transType = READING or UPDATE 00151 // 00152 AlephRC AlephDbManager::startTransaction(const AlephTransaction& transType) 00153 { 00154 // set the transaction type 00155 setTransactionType(transType); 00156 // but to nothing else.... 00157 return AlephOK; 00158 } 00159 00160 // 00161 // stop the current transaction, sets transType to HALTED 00162 // 00163 AlephRC AlephDbManager::stopTransaction() 00164 { 00165 // set the transaction type to HALTED 00166 setTransactionType(HALTED); 00167 // but to nothing else.... 00168 return AlephOK; 00169 } 00170 00171 // 00172 // do commit and hold 00173 // 00174 AlephRC AlephDbManager::commitAndHoldTransaction() 00175 { 00176 // do nothing 00177 return AlephOK; 00178 } 00179 00180 // 00181 // open an existing database 00182 // 00183 AlephRC AlephDbManager::openExistingDb(const vector<string>& aDbName, 00184 const string& mode = "TRANSTY") 00185 { 00186 // do nothing 00187 return AlephOK; 00188 } 00189 00190 // 00191 // open a new database 00192 // 00193 AlephRC AlephDbManager::openNewDb(const string& aDbName) 00194 { 00195 // do nothing 00196 return AlephOK; 00197 } 00198 00199 // 00200 // return the name of the current database 00201 // 00202 string AlephDbManager::dbName() const 00203 { 00204 //return an empty string 00205 return _dbName; 00206 } 00207 00208 // 00209 // set the name of the current database 00210 // 00211 void AlephDbManager::setDbName(const string& aDbName) 00212 { 00213 _dbName = aDbName; 00214 } 00215 00217 AlephRC AlephDbManager::StoreEvent(AlphaBanks* event) 00218 { 00219 return AlephOK; 00220 } 00221 00223 AlephRC AlephDbManager::GetEvent(AlphaBanks*) 00224 { 00225 return AlephOK; 00226 } 00227