00001
00002
00003
00004
00005
00006 #include <cstring>
00007
00008 #include "TString.h"
00009
00010 #include "DatabaseInterface/Dbi.h"
00011 #include "DatabaseInterface/DbiRollbackDates.h"
00012 #include "LeakChecker/Lea.h"
00013 #include "MessageService/MsgService.h"
00014 #include "Registry/Registry.h"
00015 #include "Util/UtilString.h"
00016 #include "Validity/VldTimeStamp.h"
00017
00018 ClassImp(DbiRollbackDates)
00019
00020
00021
00022
00023 CVSID("$Id: DbiRollbackDates.cxx,v 1.4 2008/01/30 16:42:35 nwest Exp $");
00024
00025
00026
00027
00028
00029
00030
00031 DbiRollbackDates::DbiRollbackDates()
00032 {
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 LEA_CTOR
00051
00052 MSG("Dbi", Msg::kVerbose) << "Creating DbiRollbackDates" << endl;
00053 }
00054
00055
00056 DbiRollbackDates::~DbiRollbackDates() {
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 LEA_DTOR
00068
00069 MSG("Dbi", Msg::kVerbose) << "Destroying DbiRollbackDates" << endl;
00070
00071 }
00072
00073
00074 const std::string& DbiRollbackDates::GetDate(const std::string& tableName) const {
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 static std::string date;
00088
00089 name_map_t::const_reverse_iterator itr = fTableToDate.rbegin();
00090 name_map_t::const_reverse_iterator itrEnd = fTableToDate.rend();
00091 for (; itr != itrEnd; ++itr)
00092 if ( ! UtilString::cmp_wildcard(tableName,itr->first)
00093 ) return itr->second;
00094 return date;
00095 }
00096
00097
00098 const std::string& DbiRollbackDates::GetType(const std::string& tableName) const {
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 static std::string type("INSERTDATE");
00112
00113 name_map_t::const_reverse_iterator itr = fTableToType.rbegin();
00114 name_map_t::const_reverse_iterator itrEnd = fTableToType.rend();
00115 for (; itr != itrEnd; ++itr)
00116 if ( ! UtilString::cmp_wildcard(tableName,itr->first)
00117 ) return itr->second;
00118 return type;
00119 }
00120
00121
00122 void DbiRollbackDates::Set(Registry& reg) {
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 Registry::RegistryKey keyItr(®);
00139
00140 Bool_t hasChanged = kFALSE;
00141
00142 const char* key = keyItr();
00143 while ( key ) {
00144
00145 const char* nextKey = keyItr();
00146
00147
00148
00149 if ( ! strncmp("Rollback:",key,9) ) {
00150 std::string tableName = key+9;
00151 std::string date;
00152 const char* dateChars = 0;
00153 bool ok = reg.Get(key,dateChars);
00154 if ( ok ) {
00155 date = dateChars;
00156 VldTimeStamp ts(Dbi::MakeTimeStamp(date,&ok));
00157 date = Dbi::MakeDateTimeString(ts);
00158 }
00159 if ( ok ) {
00160
00161
00162
00163 int loc = date.size()-1;
00164 while ( loc && date[loc] == ' ' ) date.erase(loc--);
00165
00166 fTableToDate[tableName] = date;
00167 hasChanged = kTRUE;
00168
00169 }
00170 else MSG("Dbi",Msg::kWarning)
00171 << "Illegal Rollback registry item: " << key
00172 << " = " << dateChars << endl;
00173 reg.RemoveKey(key);
00174 }
00175
00176
00177
00178 else if ( ! strncmp("RollbackType:",key,13) ) {
00179 std::string tableName = key+13;
00180 TString type;
00181 const char* typeChars = 0;
00182 bool ok = reg.Get(key,typeChars);
00183 if ( ok ) {
00184
00185 type = typeChars;
00186 type.ToUpper();
00187 type = type.Strip(TString::kBoth);
00188 ok = ! type.CompareTo("INSERTDATE") || ! type.CompareTo("CREATIONDATE");
00189 }
00190 if ( ok ) {
00191 fTableToType[tableName] = type.Data();
00192 hasChanged = kTRUE;
00193 }
00194 else MSG("Dbi",Msg::kWarning)
00195 << "Illegal RollbackType registry item: " << key
00196 << " = " << typeChars << endl;
00197 reg.RemoveKey(key);
00198 }
00199 key = nextKey;
00200 }
00201
00202 if ( hasChanged ) this->Show();
00203 }
00204
00205
00206 void DbiRollbackDates::Show() const {
00207
00208
00209
00210
00211
00212
00213
00214
00215 MsgStream msg = MSGSTREAM("Dbi",Msg::kInfo);
00216 msg << "\n\nRollback Status: ";
00217 if ( fTableToDate.size() == 0 ) msg <<"Not enabled" << endl;
00218 else {
00219 msg << "\n\n Dates:- " << endl;
00220 name_map_t::const_reverse_iterator itr = fTableToDate.rbegin();
00221 name_map_t::const_reverse_iterator itrEnd = fTableToDate.rend();
00222 for (; itr != itrEnd; ++itr) {
00223 std::string name = itr->first;
00224 if ( name.size() < 30 ) name.append(30-name.size(),' ');
00225 msg <<" " << name << " " << itr->second << endl;
00226 }
00227 msg << "\n Rollback Type is 'INSERTDATE'";
00228 if ( fTableToType.size() ) {
00229 msg << " except as follows:- " << endl;
00230 itr = fTableToType.rbegin();
00231 itrEnd = fTableToType.rend();
00232 for (; itr != itrEnd; ++itr) {
00233 std::string name = itr->first;
00234 if ( name.size() < 30 ) name.append(30-name.size(),' ');
00235 msg <<" " << name << " " << itr->second << endl;
00236 }
00237 }
00238 msg << endl;
00239 }
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273