TDbiSqlValPacket.hxx

Go to the documentation of this file.
00001 #ifndef DBISQLVALPACKET
00002 #define DBISQLVALPACKET
00003 
00004 /**
00005  *
00006  *
00007  * \class TDbiSqlValPacket
00008  *
00009  *
00010  * \brief
00011  * <b>Concept</b>  The SQL statements to generate a Validity Packet
00012  *   i.e a single TDbiValidityRec row and its associated main table
00013  *   data rows.
00014  *
00015  * \brief
00016  * <b>Purpose</b> Used as part of database maintenance as the unit of
00017  *   transfer between databases.
00018  *
00019  * Contact: A.Finch@lancaster.ac.uk
00020  *
00021  *
00022  */
00023 
00024 
00025 #include <fstream>
00026 #include <list>
00027 #include <vector>
00028 #include <string>
00029 using std::string;
00030 
00031 #if !defined(__CINT__) || defined(__MAKECINT__)
00032 #include "Rtypes.h"
00033 #endif
00034 
00035 #include "TDbi.hxx"
00036 #include "TDbiTableProxy.hxx"
00037 #include "TVldTimeStamp.hxx"
00038 
00039 class TDbiTableRow;
00040 class TDbiValidityRec;
00041 
00042 class TVldRange;
00043 
00044 class TDbiSqlValPacket
00045 {
00046 
00047 public:
00048 
00049 // Types and enum
00050 
00051   typedef enum ECompResult {
00052     kIdentical,
00053     kUpdate,
00054     kOutOfDate,
00055     kConflict
00056   } CompResult_t;
00057 
00058 // Constructors and destructors.
00059            TDbiSqlValPacket();
00060            TDbiSqlValPacket(std::ifstream& is);
00061            TDbiSqlValPacket(const TDbiValidityRec& vrec);
00062   virtual ~TDbiSqlValPacket();
00063 
00064 // State testing member functions
00065         Bool_t CanBeStored() const {
00066              return (fSeqNo > 0 && fNumErrors == 0 && this->GetNumSqlStmts()> 0)
00067             ? kTRUE : kFALSE; };
00068   CompResult_t Compare(const TDbiSqlValPacket& that,
00069                        Bool_t log = kFALSE,
00070                        const Char_t* thisName = "this",
00071                        const Char_t* thatName = "that" ) const;
00072         Bool_t CreateTable(UInt_t dbNo) const;
00073         UInt_t GetNumErrors() const { return fNumErrors; }
00074         UInt_t GetNumSqlStmts() const { return fNumStmts; }
00075         UInt_t GetSeqNo() const { return fSeqNo; }
00076   TVldTimeStamp GetCreationDate() const { return fCreationDate; }
00077         string GetStmt(UInt_t stmtNo) const;
00078         std::vector<string> GetStmtValues(UInt_t stmtNo) const;
00079  const string& GetTableName() const{ return fTableName; }
00080         Bool_t IsEqual(const TDbiSqlValPacket& that,
00081                        Bool_t log = kFALSE,
00082                        const Char_t* thisName = "this",
00083                        const Char_t* thatName = "that" ) const;
00084 
00085 //  I/O
00086         Bool_t Fill(std::ifstream& is);
00087         Bool_t Store(UInt_t dbNo, Bool_t replace = kFALSE) const;
00088         Bool_t Write(std::ofstream& ios,
00089                      Bool_t addMetadata = kFALSE) const;
00090 
00091 //  Reconstruct.        
00092           void Recreate(const string& tableName,
00093                         const TVldRange& vr,
00094                         Int_t aggNo,
00095                         TDbi::Task task = 0,
00096                         TVldTimeStamp creationDate = TVldTimeStamp());
00097         Bool_t AddDataRow(const TDbiTableProxy& tblProxy,
00098                           const TDbiValidityRec* vrec,
00099                           const TDbiTableRow& row);
00100 
00101 //  State changing member functions
00102           void Clear() { this->Reset(); fNumErrors = 0; }
00103           void SetEpoch(UInt_t epoch);
00104           void SetCreationDate(TVldTimeStamp ts);
00105           void SetSeqNo(UInt_t seqno);
00106           void Reset();  //Doesn't clear fNumErrors.
00107 
00108   virtual void Print(Option_t *option="") const;
00109 
00110 protected:
00111 
00112 private:
00113           void AddRow(const string & row);
00114         Bool_t AddRow(const TDbiTableProxy& tblProxy,
00115                       const TDbiValidityRec* vrec,
00116                       const TDbiTableRow& row);
00117           void Report(const char* msg,
00118                       UInt_t line_num,
00119                       const string& line);
00120           void SetMetaData() const;
00121           void SetSeqNoOnRow(string& row,const string& seqno);
00122 
00123   TDbiSqlValPacket(const TDbiSqlValPacket& );  // Not allowed.
00124 
00125 
00126 // Data members
00127 
00128 /// Number of error encountered while filling.
00129   UInt_t fNumErrors;
00130 
00131 /// Sequence number or 0 if not filled.
00132   UInt_t fSeqNo;
00133 
00134 /// MySQL SQL to create main table. May be empty until needed.
00135   mutable string fSqlMySqlMetaMain;
00136 
00137 /// As fSqlMySqlMetaMain but for aux. table.
00138   mutable string fSqlMySqlMetaVld;
00139 
00140 /// Set of SQL statements to generate packet.
00141   std::list<string>  fSqlStmts;
00142 
00143 /// Number of statements
00144   UInt_t fNumStmts;
00145 
00146 /// Table name or null if not filled.
00147   string fTableName;
00148 
00149 /// Creation date, or object creation date if unfilled.
00150   TVldTimeStamp fCreationDate;
00151 
00152  ClassDef(TDbiSqlValPacket,0)           // SQL to generate Validity Packet.
00153 
00154 };
00155 #endif  // DBISQLVALPACKET
00156 

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1