00001 #ifndef DBISQLVALPACKET
00002 #define DBISQLVALPACKET
00003
00027 #include <fstream>
00028 #include <list>
00029 #include <vector>
00030 #include <string>
00031 using std::string;
00032
00033 #if !defined(__CINT__) || defined(__MAKECINT__)
00034 #include "Rtypes.h"
00035 #endif
00036
00037 #include "DatabaseInterface/Dbi.h"
00038 #include "DatabaseInterface/DbiTableProxy.h"
00039 #include "Validity/VldTimeStamp.h"
00040
00041 class DbiTableRow;
00042 class DbiValidityRec;
00043 class VldRange;
00044
00045 class DbiSqlValPacket
00046 {
00047
00048 public:
00049
00050
00051
00052 typedef enum ECompResult {
00053 kIdentical,
00054 kUpdate,
00055 kOutOfDate,
00056 kConflict
00057 } CompResult_t;
00058
00059
00060 DbiSqlValPacket();
00061 DbiSqlValPacket(std::ifstream& is);
00062 DbiSqlValPacket(const DbiValidityRec& vrec);
00063 virtual ~DbiSqlValPacket();
00064
00065
00066 Bool_t CanBeStored() const {
00067 return (fSeqNo > 0 && fNumErrors == 0 && this->GetNumSqlStmts()> 0)
00068 ? kTRUE : kFALSE; };
00069 CompResult_t Compare(const DbiSqlValPacket& that,
00070 Bool_t log = kFALSE,
00071 const Char_t* thisName = "this",
00072 const Char_t* thatName = "that" ) const;
00073 Bool_t CreateTable(UInt_t dbNo) const;
00074 UInt_t GetNumErrors() const { return fNumErrors; }
00075 UInt_t GetNumSqlStmts() const { return fNumStmts; }
00076 UInt_t GetSeqNo() const { return fSeqNo; }
00077 VldTimeStamp GetCreationDate() const { return fCreationDate; }
00078 string GetStmt(UInt_t stmtNo) const;
00079 std::vector<string> GetStmtValues(UInt_t stmtNo) const;
00080 const string& GetTableName() const{ return fTableName; }
00081 Bool_t IsEqual(const DbiSqlValPacket& that,
00082 Bool_t log = kFALSE,
00083 const Char_t* thisName = "this",
00084 const Char_t* thatName = "that" ) const;
00085
00086
00087 Bool_t Fill(std::ifstream& is);
00088 Bool_t Store(UInt_t dbNo, Bool_t replace = kFALSE) const;
00089 Bool_t Write(std::ofstream& ios,
00090 Bool_t addMetadata = kFALSE) const;
00091
00092
00093 void Recreate(const string& tableName,
00094 const VldRange& vr,
00095 Int_t aggNo,
00096 Dbi::Task task = 0,
00097 VldTimeStamp creationDate = VldTimeStamp());
00098 Bool_t AddDataRow(const DbiTableProxy& tblProxy,
00099 const DbiValidityRec* vrec,
00100 const DbiTableRow& row);
00101
00102
00103 void Clear() { this->Reset(); fNumErrors = 0; }
00104 void SetCreationDate(VldTimeStamp ts);
00105 void SetSeqNo(UInt_t seqno);
00106 void Reset();
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 DbiTableProxy& tblProxy,
00115 const DbiValidityRec* vrec,
00116 const DbiTableRow& 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 static Bool_t fgLastMetaHadRowCounter;
00124 DbiSqlValPacket(const DbiSqlValPacket& );
00125
00126
00127
00128
00130 UInt_t fNumErrors;
00131
00133 UInt_t fSeqNo;
00134
00136 mutable string fSqlMySqlMetaMain;
00137
00139 mutable string fSqlMySqlMetaVld;
00140
00142 std::list<string> fSqlStmts;
00143
00145 UInt_t fNumStmts;
00146
00148 string fTableName;
00149
00151 VldTimeStamp fCreationDate;
00152
00153 ClassDef(DbiSqlValPacket,0)
00154
00155 };
00156 #endif // DBISQLVALPACKET