Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DbmLogFile.cxx

Go to the documentation of this file.
00001 
00002 // DbmLogFile                                                         //
00003 //                                                                    //
00004 // Package: Dbm (Database Maintenance).                               //
00005 //                                                                    //
00006 // N. West 12/2001                                                    //
00007 //                                                                    //
00008 // Concept: Archive of import/export transactions.                    //
00009 //                                                                    //
00010 // Purpose: To record transactions and provide context for successive //
00011 //          exports.                                                  //
00012 //                                                                    //
00014 
00015 #include <algorithm>
00016 #include <cctype>
00017 #include <iomanip>
00018 #include <sstream>
00019 
00020 #include "DatabaseMaintenance/DbmCmdOptions.h"
00021 #include "DatabaseInterface/Dbi.h"
00022 #include "DatabaseInterface/DbiLogEntry.h"
00023 #include "DatabaseInterface/DbiResultPtr.h"
00024 #include "DatabaseInterface/DbiTableProxy.h"
00025 #include "DatabaseInterface/DbiValidityRec.h"
00026 #include "DatabaseMaintenance/DbmLogFile.h"
00027 #include "LeakChecker/Lea.h"
00028 #include "MessageService/MsgService.h"
00029 #include "Validity/VldTimeStamp.h"
00030 
00031 ClassImp(DbmLogFile)
00032 
00033 
00034 //   Definition of static data members
00035 //   *********************************
00036 
00037 CVSID("$Id: DbmLogFile.cxx,v 1.15 2008/06/13 12:40:30 nwest Exp $");
00038 
00039 // Definition of member functions (alphabetical order)
00040 // ***************************************************
00041 
00042 
00043 //.....................................................................
00044 
00045 DbmLogFile::DbmLogFile(const string& fileName,UInt_t dbNo) :
00046 fDbNo(dbNo),
00047 fLogFile(0)
00048 {
00049 //
00050 //  Purpose:  Default constructor
00051 //
00052 //  Arguments:
00053 //     fileName  in  File name.  Default = "". 
00054 //     dbNo      in  Database no.
00055 //
00056 //  Return:    n/a
00057 //
00058 //  Contact:   N. West
00059 //
00060 //  Specification:-
00061 //  =============
00062 //
00063 //  o  Create a DbmLogFile.
00064 
00065 
00066 //  Program Notes:-
00067 //  =============
00068 
00069 //  None.
00070 
00071   LEA_CTOR    //Leak Checker
00072   MSG("Dbm", Msg::kVerbose) << "Creating DbmLogFile" << endl;
00073 
00074   if ( fileName == "") return;
00075   
00076   fLogFile = new ofstream(fileName.c_str(),ios::app);
00077   if ( ! fLogFile->is_open() ) {
00078     MSG("Dbm",Msg::kError) << "Cannot open " << fileName << endl;
00079     return;
00080   }    
00081 }
00082 
00083 //.....................................................................
00084 
00085 DbmLogFile::~DbmLogFile() {
00086 //
00087 //
00088 //  Purpose: Destructor
00089 //
00090 //  Arguments: 
00091 //    None.
00092 //
00093 //  Return:    n/a
00094 //
00095 //  Contact:   N. West
00096 //
00097 //  Specification:-
00098 //  =============
00099 //
00100 //  o  Complete last LogRec (if any) and Destroy DbmLogFile.
00101 
00102 
00103 //  Program Notes:-
00104 //  =============
00105 
00106 //  None.
00107 
00108   LEA_DTOR    //Leak Checker
00109 
00110   MSG("Dbm", Msg::kVerbose) << "Destroying DbmLogFile" << endl;
00111 
00112   LogRec(0);
00113   delete fLogFile;
00114   fLogFile = 0;
00115 
00116 }
00117 
00118 //.....................................................................
00119 
00120 void DbmLogFile::LogCmd(const string& cmd,
00121                         const DbmCmdOptions& opts)  {
00122 //
00123 //
00124 //  Purpose:  Record command plus options into the log.
00125 //
00126 //  Arguments: 
00127 //    cmd          in    The command to be executed.
00128 //    opts          in   The options for the current command.
00129 //
00130 //  Return:    n/a.
00131 //
00132 //  Contact:   N. West
00133 //
00134 //  Specification:-
00135 //  =============
00136 //
00137 //  o Record command plus options into the log.
00138 
00139 //  Program Notes:-
00140 //  =============
00141 
00142 //  None.
00143 
00144   if ( ! IsValid() ) return;
00145   //Skip a line.
00146   this->LogMsg("",kFALSE);
00147   string msg(cmd);
00148   msg += " ";
00149   msg += opts.GetOpts();
00150 
00151   // Tidy up command by placing each option on a new line.
00152   string insert("+\n      ");
00153   UInt_t locOpt = 0;
00154   while (  (locOpt = msg.find("--",locOpt)) != string::npos ) {
00155     msg.insert(locOpt,insert);
00156     locOpt += insert.size() + 2;
00157   }
00158   this->LogMsg(msg);
00159   return;
00160   
00161   
00162 }
00163 //.....................................................................
00164 
00165 void DbmLogFile::LogMsg(const string& msg,
00166                         Bool_t addDateStamp)  {
00167 //
00168 //
00169 //  Purpose:  Record date-stamped message  into the log.
00170 //
00171 //  Arguments: 
00172 //    msg          in    The message to be recorded.
00173 //    addDateStamp in    If true (default) prefix date stamp.
00174 //
00175 //  Contact:   N. West
00176 
00177   if ( ! IsValid() ) return;
00178   if ( addDateStamp ) {
00179     VldTimeStamp now;
00180     (*fLogFile) << Dbi::MakeDateTimeString( now )
00181               << " ";
00182   }
00183   (*fLogFile) << msg <<  endl;
00184 
00185   return;
00186   
00187   
00188 }
00189 //.....................................................................
00190 
00191 void DbmLogFile::LogRec(const DbiValidityRec* vrec ) {
00192 //
00193 //
00194 //  Purpose:  Record DbiValidityRec I/O into the log.
00195 //
00196 //  Arguments: 
00197 //    vrec         in    The DbiValidityRec to be recorded.
00198 //                       May be zero (just to flush out last log 
00199 //                       summary).
00200 //
00201 //  Return:    None.
00202 //
00203 //  Contact:   N. West
00204 //
00205 //  Specification:-
00206 //  =============
00207 //
00208 //  o Record summary of DbiValidityRec I/O into the log.
00209 
00210 //  Program Notes:-
00211 //  =============
00212 
00213 //  None.
00214 
00215   if ( ! IsValid() ) return;
00216   string tableName =  vrec ? vrec->GetTableProxy()->GetTableName() : "";
00217   UInt_t seqNo =  vrec ? vrec->GetSeqNo() : 0;  
00218   LogRec(tableName,seqNo);
00219 
00220 }
00221 //.....................................................................
00222 
00223 void DbmLogFile::LogRec(const string tableName, UInt_t seqNo) {
00224 //
00225 //
00226 //  Purpose:  Record DbiValidityRec I/O into the log.
00227 //
00228 //  Arguments: 
00229 //    tableName    in    Table name to be logged.. May be null (just to 
00230 //                         Flush out last log summary).
00231 //    seqNo        in    SeqNo to be logged.
00232 //
00233 //  Return:    None.
00234 //
00235 //  Contact:   N. West
00236 //
00237 //  Specification:-
00238 //  =============
00239 //
00240 //  o Record summary of DbiValidityRec I/O into the log.
00241 
00242 //  Program Notes:-
00243 //  =============
00244 
00245 //  None.
00246 
00247   if ( ! IsValid() ) return;
00248   
00249 //  If there is a change of table name output any buffered log info.
00250   if ( tableName != fLogTableName ) {
00251     if ( fLogDBSrcNos.size() ) {
00252       list<UInt_t>::const_iterator itr    = fLogDBSrcNos.begin();
00253       list<UInt_t>::const_iterator itrEnd = fLogDBSrcNos.end();
00254       while ( itr != itrEnd ) {
00255         UInt_t dbSrcNo = *itr;
00256         (*fLogFile) << "      "
00257                     << fLogTableName << " "
00258                     << fLogNumSeqNo[dbSrcNo] << " recs: "
00259                     << fLogSeqNoMin[dbSrcNo];
00260         if ( fLogSeqNoMin[dbSrcNo] != fLogSeqNoMax[dbSrcNo]
00261            ) (*fLogFile) << ".." << fLogSeqNoMax[dbSrcNo];
00262         (*fLogFile) << endl;
00263         ++itr;
00264       }
00265     }
00266     if ( tableName == "DBILOGENTRY" 
00267          ) (*fLogFile) << "Start of update log entries..." << endl;
00268     else if ( fLogTableName == "DBILOGENTRY" 
00269          ) (*fLogFile) << "End of update log entries..." << endl;
00270 
00271     fLogTableName =  tableName;
00272     fLogDBSrcNos.clear();
00273     fLogNumSeqNo.clear();
00274     fLogSeqNoMin.clear();
00275     fLogSeqNoMax.clear();
00276 
00277   }
00278     
00279 // Buffer info for next summary.
00280   if ( tableName != "" ) {
00281     UInt_t dbSrcNo = seqNo/(Dbi::kMAXLOCALSEQNO+1);
00282     if (     find(fLogDBSrcNos.begin(), fLogDBSrcNos.end(), dbSrcNo)
00283           == fLogDBSrcNos.end() ) {
00284       fLogDBSrcNos.push_back(dbSrcNo);
00285       fLogSeqNoMin[dbSrcNo] = seqNo;
00286       fLogSeqNoMax[dbSrcNo] = seqNo;
00287       fLogNumSeqNo[dbSrcNo] = 1;
00288     }
00289     else {
00290       if ( fLogSeqNoMin[dbSrcNo] > seqNo ) fLogSeqNoMin[dbSrcNo] = seqNo;
00291       if ( fLogSeqNoMax[dbSrcNo] < seqNo ) fLogSeqNoMax[dbSrcNo] = seqNo;
00292       ++fLogNumSeqNo[dbSrcNo];
00293     }
00294   }
00295 
00296 // Record DbiLogEntrys directly into the file.
00297 
00298   if ( tableName == "DBILOGENTRY" ) {
00299     DbiResultPtr<DbiLogEntry> rp("DBILOGENTRY",seqNo,fDbNo);
00300     const DbiLogEntry* le = rp.GetRow(0);
00301     if ( le ) (*fLogFile) << *le << endl;
00302   }
00303 
00304 }
00305 
00306 /*    Template for New Member Function
00307 
00308 //.....................................................................
00309 
00310 DbmLogFile:: {
00311 //
00312 //
00313 //  Purpose:  
00314 //
00315 //  Arguments: 
00316 //    xxxxxxxxx    in    yyyyyy
00317 //
00318 //  Return:    
00319 //
00320 //  Cotact:   N. West
00321 //
00322 //  Specification:-
00323 //  =============
00324 //
00325 //  o 
00326 
00327 //  Program Notes:-
00328 //  =============
00329 
00330 //  None.
00331 
00332 
00333 }
00334 
00335 */
00336 

Generated on Mon Feb 15 11:06:35 2010 for loon by  doxygen 1.3.9.1