00001 #ifndef DBIWRITER_H
00002 #define DBIWRITER_H
00003
00032 #include <list>
00033 #include <string>
00034
00035 #include "DatabaseInterface/Dbi.h"
00036 #include "DatabaseInterface/DbiLogEntry.h"
00037 #include "DatabaseInterface/DbiTableProxyRegistry.h"
00038 #include "Context/ContextRange.h"
00039 #include "Context/TimeStamp.h"
00040
00041 class DbiSqlValPacket;
00042 class DbiTableProxy;
00043 class DbiValidityRec;
00044
00045 template <class T> class DbiWriter
00046 {
00047
00048 public:
00049
00050
00051 DbiWriter();
00052 DbiWriter(const ContextRange& vr,
00053 Int_t aggNo,
00054 Dbi::SubSite subsite,
00055 Dbi::Task task,
00056 TimeStamp versionDate,
00057 const std::string& dbName,
00058 const std::string& logComment = "",
00059 const std::string& tableName = "");
00060 DbiWriter(const ContextRange& vr,
00061 Int_t aggNo,
00062 Dbi::SubSite subsite = 0,
00063 Dbi::Task task = 0,
00064 TimeStamp versionDate = TimeStamp(0,0),
00065 UInt_t dbNo = 0,
00066 const std::string& logComment = "",
00067 const std::string& tableName = "");
00068 DbiWriter(const DbiValidityRec& vrec,
00069 const std::string& dbName,
00070 const std::string& logComment = "");
00071 DbiWriter(const DbiValidityRec& vrec,
00072 UInt_t dbNo = 0,
00073 const std::string& logComment = "");
00074
00075 virtual ~DbiWriter();
00076
00077
00078
00079 DbiTableProxy& TableProxy() const;
00080
00082 Bool_t IsOpen(Bool_t reportErrors = kTRUE) const;
00084 Bool_t CanOutput(Bool_t reportErrors = kTRUE) const;
00085
00086
00087
00088 void SetDbNo(UInt_t dbNo) { fDbNo = dbNo;}
00089 void SetDbName(const string& dbName);
00090 void SetLogComment(const std::string& reason);
00091
00092 void SetRequireGlobalSeqno(Int_t requireGlobal) {fRequireGlobalSeqno = requireGlobal;}
00093 void SetOverlayVersionDate() {fUseOverlayVersionDate = kTRUE;}
00094
00095
00096 void Abort() { Reset(); }
00097 Bool_t Close(const char* fileSpec=0);
00098 Bool_t Open(const ContextRange& vr,
00099 Int_t aggNo,
00100 Dbi::SubSite subsite,
00101 Dbi::Task task,
00102 TimeStamp versionDate,
00103 const string& dbName,
00104 const std::string& logComment = "");
00105 Bool_t Open(const ContextRange& vr,
00106 Int_t aggNo,
00107 Dbi::SubSite subsite = 0,
00108 Dbi::Task task = 0,
00109 TimeStamp versionDate = TimeStamp(),
00110 UInt_t dbNo = 0,
00111 const std::string& logComment = "");
00112 Bool_t Open(const DbiValidityRec& vrec,
00113 const string& dbName,
00114 const std::string& logComment = "");
00115 Bool_t Open(const DbiValidityRec& vrec,
00116 UInt_t dbNo = 0,
00117 const std::string& logComment = "");
00118
00119 DbiWriter<T>& operator<<(const T& row);
00120
00121 private:
00122
00123
00124
00125 Bool_t NeedsLogEntry() const;
00126 Bool_t WritingToMaster() const;
00127
00128
00129
00130 DbiWriter(const DbiWriter&);
00131 DbiWriter& operator=(const DbiWriter&);
00132
00133 void CompleteOpen(UInt_t dbNo = 0,
00134 const std::string& logComment = "");
00135 void Reset();
00136
00137 static DbiTableProxy& GetTableProxy();
00138 static DbiTableProxy& GetTableProxy(const std::string& tableName);
00139
00140
00141
00143 Int_t fAggregateNo;
00144
00146 UInt_t fDbNo;
00147
00149 DbiSqlValPacket* fPacket;
00150
00152 Int_t fRequireGlobalSeqno;
00153
00155 DbiTableProxy* fTableProxy;
00156
00158 std::string fTableName;
00159
00161 Bool_t fUseOverlayVersionDate;
00162
00164 DbiValidityRec* fValidRec;
00165
00167 DbiLogEntry fLogEntry;
00168
00169
00170
00171 };
00172
00173
00174 #endif // DBIWRITER_H