TDbiRollbackDates.cxx

Go to the documentation of this file.
00001 ///////////////////////////////////////////////////////////////////////
00002 // $Id: TDbiRollbackDates.cxx,v 1.1 2011/01/18 05:49:20 finch Exp $
00003 //
00004 // TDbiRollbackDates
00005 
00006 #include <cstring>
00007 
00008 #include "TString.h"
00009 
00010 #include "TDbi.hxx"
00011 #include "TDbiRollbackDates.hxx"
00012 #include <TSK_DBI_Log.hxx>
00013 #include <MsgFormat.h>
00014 using std::endl;
00015 #include "TDbiRegistry.hxx"
00016 #include "UtilString.hxx"
00017 #include "TVldTimeStamp.hxx"
00018 
00019 ClassImp(TDbiRollbackDates)
00020 
00021 //   Definition of static data members
00022 //   *********************************
00023 
00024 
00025 // Definition of member functions (alphabetical order)
00026 // ***************************************************
00027 
00028 
00029 //.....................................................................
00030 
00031 TDbiRollbackDates::TDbiRollbackDates()
00032 {
00033 //
00034 //
00035 //  Purpose:  Default constructor
00036 //
00037 //  Contact:   N. West
00038 //
00039 //  Specification:-
00040 //  =============
00041 //
00042 //  o Create TDbiRollbackDates.
00043 
00044 
00045 //  Program Notes:-
00046 //  =============
00047 
00048 //  None.
00049 
00050 
00051     SK_DBI_Trace( "Creating TDbiRollbackDates" << "  ");
00052 }
00053 //.....................................................................
00054 
00055 TDbiRollbackDates::~TDbiRollbackDates() {
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 }
00070 //.....................................................................
00071 
00072 const std::string& TDbiRollbackDates::GetDate(const std::string& tableName) const {
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 }
00094 //.....................................................................
00095 
00096 const std::string& TDbiRollbackDates::GetType(const std::string& tableName) const {
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 }
00118 //.....................................................................
00119 
00120 void TDbiRollbackDates::Set(TDbiRegistry& reg) {
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(&reg);
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 }
00200 //.....................................................................
00201 
00202 void TDbiRollbackDates::Show() const {
00203 
00204 
00205 }
00206 
00207 
00208 /*    Template for New Member Function
00209 
00210 //.....................................................................
00211 
00212 TDbiRollbackDates:: {
00213 //
00214 //
00215 //  Purpose:
00216 //
00217 //  Arguments:
00218 //    xxxxxxxxx    in    yyyyyy
00219 //
00220 //  Return:
00221 //
00222 //  Contact:   N. West
00223 //
00224 //  Specification:-
00225 //  =============
00226 //
00227 //  o
00228 
00229 //  Program Notes:-
00230 //  =============
00231 
00232 //  None.
00233 
00234 
00235 }
00236 
00237 */
00238 
00239 

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1