Concept A register of rollback dates organised by table name More...
#include <TDbiRollbackDates.hxx>
Public Types | |
typedef std::map< std::string, std::string > | name_map_t |
Public Member Functions | |
TDbiRollbackDates () | |
virtual | ~TDbiRollbackDates () |
const std::string & | GetDate (const std::string &tableName) const |
const std::string & | GetType (const std::string &tableName) const |
void | Show () const |
void | Clear () |
void | Set (TDbiRegistry ®) |
Private Attributes | |
name_map_t | fTableToDate |
Look-up table name -> date string. | |
name_map_t | fTableToType |
Look-up table name -> time type (either "INSERTDATE" [default] or "CREATIONDATE"). |
Concept A register of rollback dates organised by table name
Purpose Simplify rollback date management by extracting info. from DBI registry and serving by table name Contact: A.Finch@lancaster.ac.uk
Definition at line 34 of file TDbiRollbackDates.hxx.
typedef std::map<std::string,std::string> TDbiRollbackDates::name_map_t |
Definition at line 39 of file TDbiRollbackDates.hxx.
TDbiRollbackDates::TDbiRollbackDates | ( | ) |
TDbiRollbackDates::~TDbiRollbackDates | ( | ) | [virtual] |
Definition at line 55 of file TDbiRollbackDates.cxx.
References SK_DBI_Trace.
00055 { 00056 // 00057 // 00058 // Contact: N. West 00059 // 00060 // Specification:- 00061 // ============= 00062 // 00063 // o Destroy TDbiRollbackDates. 00064 00065 00066 00067 SK_DBI_Trace( "Destroying TDbiRollbackDates" << " "); 00068 00069 }
void TDbiRollbackDates::Clear | ( | ) | [inline] |
Definition at line 53 of file TDbiRollbackDates.hxx.
References fTableToDate, and fTableToType.
Referenced by TDbiDatabaseManager::ClearRollbacks().
00053 {fTableToDate.clear(); fTableToType.clear();}
const std::string & TDbiRollbackDates::GetDate | ( | const std::string & | tableName | ) | const |
Definition at line 72 of file TDbiRollbackDates.cxx.
References UtilString::cmp_wildcard(), and fTableToDate.
Referenced by TDbiDatabaseManager::ApplySqlCondition().
00072 { 00073 // 00074 // 00075 // Purpose: Return rollback date associated with named table. 00076 // 00077 // Contact: N. West 00078 00079 // Program Notes:- 00080 // ============= 00081 00082 // Search in reverse order so that specific entries are processed 00083 // before generic (i.e. ones that end in wildcard *). 00084 00085 static std::string date; 00086 00087 name_map_t::const_reverse_iterator itr = fTableToDate.rbegin(); 00088 name_map_t::const_reverse_iterator itrEnd = fTableToDate.rend(); 00089 for (; itr != itrEnd; ++itr) 00090 if ( ! UtilString::cmp_wildcard(tableName,itr->first) 00091 ) return itr->second; 00092 return date; 00093 }
const std::string & TDbiRollbackDates::GetType | ( | const std::string & | tableName | ) | const |
Definition at line 96 of file TDbiRollbackDates.cxx.
References UtilString::cmp_wildcard(), and fTableToType.
Referenced by TDbiDatabaseManager::ApplySqlCondition().
00096 { 00097 // 00098 // 00099 // Purpose: Return rollback time type associated with named table. 00100 // 00101 // Contact: N. West 00102 00103 // Program Notes:- 00104 // ============= 00105 00106 // Search in reverse order so that specific entries are processed 00107 // before generic (i.e. ones that end in wildcard *). 00108 00109 static std::string type("INSERTDATE"); // The default type 00110 00111 name_map_t::const_reverse_iterator itr = fTableToType.rbegin(); 00112 name_map_t::const_reverse_iterator itrEnd = fTableToType.rend(); 00113 for (; itr != itrEnd; ++itr) 00114 if ( ! UtilString::cmp_wildcard(tableName,itr->first) 00115 ) return itr->second; 00116 return type; 00117 }
void TDbiRollbackDates::Set | ( | TDbiRegistry & | reg | ) |
Definition at line 120 of file TDbiRollbackDates.cxx.
References fTableToDate, fTableToType, TDbiRegistry::Get(), TDbi::MakeDateTimeString(), TDbi::MakeTimeStamp(), TDbiRegistry::RemoveKey(), Show(), and SK_DBI_Warn.
Referenced by TDbiDatabaseManager::Config().
00120 { 00121 // 00122 // 00123 // Purpose: Extract Rollback dates from TDbiRegistry. 00124 // 00125 // Arguments: 00126 // reg in TDbiRegistry containing "Rollback:" and "RollbackType:" keys. 00127 // out Updated TDbiRegistry with these keys removed. 00128 // 00129 // Contact: N. West 00130 // 00131 // Specification:- 00132 // ============= 00133 // 00134 // o Extract Rollback dates from TDbiRegistry. 00135 00136 TDbiRegistry::TDbiRegistryKey keyItr(®); 00137 00138 Bool_t hasChanged = kFALSE; 00139 00140 const char* key = keyItr(); 00141 while ( key ) { 00142 00143 const char* nextKey = keyItr(); 00144 00145 // Process Rollback keys 00146 00147 if ( ! strncmp("Rollback:",key,9) ) { 00148 std::string tableName = key+9; 00149 std::string date; 00150 const char* dateChars = 0; 00151 bool ok = reg.Get(key,dateChars); 00152 if ( ok ) { 00153 date = dateChars; 00154 TVldTimeStamp ts(TDbi::MakeTimeStamp(date,&ok)); 00155 date = TDbi::MakeDateTimeString(ts); 00156 } 00157 if ( ok ) { 00158 00159 // Prune away any trailing spaces - they cause SQL 00160 // to fail expressions involving the date. 00161 int loc = date.size()-1; 00162 while ( loc && date[loc] == ' ' ) date.erase(loc--); 00163 00164 fTableToDate[tableName] = date; 00165 hasChanged = kTRUE; 00166 00167 } 00168 else SK_DBI_Warn( "Illegal Rollback registry item: " << key 00169 << " = " << dateChars << " "); 00170 reg.RemoveKey(key); 00171 } 00172 00173 // Process RollbackType keys 00174 00175 else if ( ! strncmp("RollbackType:",key,13) ) { 00176 std::string tableName = key+13; 00177 TString type; 00178 const char* typeChars = 0; 00179 bool ok = reg.Get(key,typeChars); 00180 if ( ok ) { 00181 // Convert to upper case and remove any leading or trailing spaces 00182 type = typeChars; 00183 type.ToUpper(); 00184 type = type.Strip(TString::kBoth); 00185 ok = ! type.CompareTo("INSERTDATE") || ! type.CompareTo("CREATIONDATE"); 00186 } 00187 if ( ok ) { 00188 fTableToType[tableName] = type.Data(); 00189 hasChanged = kTRUE; 00190 } 00191 else SK_DBI_Warn( "Illegal RollbackType registry item: " << key 00192 << " = " << typeChars << " "); 00193 reg.RemoveKey(key); 00194 } 00195 key = nextKey; 00196 } 00197 00198 if ( hasChanged ) this->Show(); 00199 }
void TDbiRollbackDates::Show | ( | ) | const |
Definition at line 202 of file TDbiRollbackDates.cxx.
Referenced by Set().
name_map_t TDbiRollbackDates::fTableToDate [private] |
Look-up table name -> date string.
Definition at line 61 of file TDbiRollbackDates.hxx.
name_map_t TDbiRollbackDates::fTableToType [private] |
Look-up table name -> time type (either "INSERTDATE" [default] or "CREATIONDATE").
Definition at line 63 of file TDbiRollbackDates.hxx.