TDbiWriter.hxx

Go to the documentation of this file.
00001 #ifndef DBIWRITER_H
00002 #define DBIWRITER_H
00003 
00004 /**
00005  *
00006  * $Id: TDbiWriter.hxx,v 1.1 2011/01/18 05:49:20 finch Exp $
00007  *
00008  * \class TDbiWriter
00009  *
00010  *
00011  * \brief
00012  * <b>Concept</b>  Templated class of pointers to Writer objects.
00013  *   Writer objects are lightweight and provide type safe write
00014  *   access to a single validity set of a specific table.
00015  *   A TDbiWriter knows about publishing protocols but uses a
00016  *   TDbiSqlValPacket both to hold the data in a type- neutral
00017  *   form and to do the actual I/O.
00018  *
00019  * \brief
00020  * <b>Purpose</b> Writers are the primary application output
00021  *   interface to the TDbi.  Users instantiate Writers with
00022  *   the information necessary define a validity set and then
00023  *   pass all the rows one at a time, to the writer.  The user
00024  *   is able to abort the process at any point before the final
00025  *   commit.
00026  *
00027  * Contact: A.Finch@lancaster.ac.uk
00028  *
00029  *
00030  */
00031 #include <list>
00032 #include <string>
00033 
00034 #include "TDbi.hxx"
00035 #include "TDbiLogEntry.hxx"
00036 #include "TDbiDatabaseManager.hxx"
00037 #include "TVldRange.hxx"
00038 #include "TVldTimeStamp.hxx"
00039 
00040 
00041 class TDbiSqlValPacket;
00042 class TDbiTableProxy;
00043 class TDbiValidityRec;
00044 
00045 template <class T> class TDbiWriter
00046 {
00047 
00048 public:
00049 
00050 // Constructors and destructors.
00051            TDbiWriter();
00052            TDbiWriter(const TVldRange& vr,
00053                      Int_t aggNo,
00054                      TDbi::Task task,
00055                      TVldTimeStamp creationDate,
00056                      const std::string& dbName,
00057                      const std::string& logComment = "",
00058                      const std::string& tableName = "");
00059            TDbiWriter(const TVldRange& vr,
00060                      Int_t aggNo,
00061                      TDbi::Task task = 0,
00062                      TVldTimeStamp creationDate = TVldTimeStamp(0,0),
00063                      UInt_t dbNo = 0,
00064                      const std::string& logComment = "",
00065                      const std::string& tableName = "");
00066            TDbiWriter(const TDbiValidityRec& vrec,
00067                      const std::string& dbName,
00068                      const std::string& logComment = "");
00069            TDbiWriter(const TDbiValidityRec& vrec,
00070                      UInt_t dbNo = 0,
00071                      const std::string& logComment = "");
00072 
00073   virtual ~TDbiWriter();
00074 
00075 // State testing member functions
00076 
00077        UInt_t GetEpoch() const;
00078        TDbiTableProxy& TableProxy() const;
00079 
00080 ///    Open and ready to receive data.
00081           Bool_t IsOpen(Bool_t reportErrors = kTRUE) const;
00082 ///    Open and ready to receive/output data.
00083           Bool_t CanOutput(Bool_t reportErrors = kTRUE) const;
00084 
00085 // State changing member functions
00086 
00087     void SetDbNo(UInt_t dbNo) { fDbNo = dbNo;}
00088     void SetDbName(const string& dbName);
00089     void SetEpoch(UInt_t epoch);
00090     void SetLogComment(const std::string& reason);
00091     // For setting of requireGlobal see TDbiCascader::AllocateSeqNo
00092     void SetRequireGlobalSeqno(Int_t requireGlobal) {fRequireGlobalSeqno = requireGlobal;}
00093     void SetOverlayCreationDate() {fUseOverlayCreationDate = kTRUE;}
00094 
00095 //  I/O functions
00096   void Abort() { Reset(); }
00097   Bool_t Close(const char* fileSpec=0);
00098   Bool_t Open(const TVldRange& vr,
00099             Int_t aggNo,
00100             TDbi::Task task,
00101             TVldTimeStamp creationDate,
00102             const string& dbName,
00103             const std::string& logComment = "");
00104    Bool_t Open(const TVldRange& vr,
00105             Int_t aggNo,
00106             TDbi::Task task = 0,
00107             TVldTimeStamp creationDate = TVldTimeStamp(),
00108             UInt_t dbNo = 0,
00109             const std::string& logComment = "");
00110  Bool_t Open(const TDbiValidityRec& vrec,
00111              const string& dbName,
00112              const std::string& logComment = "");
00113  Bool_t Open(const TDbiValidityRec& vrec,
00114               UInt_t dbNo = 0,
00115               const std::string& logComment = "");
00116 
00117   TDbiWriter<T>& operator<<(const T& row);
00118 
00119 private:
00120 
00121 // State testing member functions
00122 
00123   Bool_t NeedsLogEntry() const;
00124   Bool_t WritingToMaster() const;
00125 
00126 // State changing member functions
00127 
00128 TDbiWriter(const TDbiWriter&); // Forbidden
00129 TDbiWriter& operator=(const TDbiWriter&); // Forbidden
00130 
00131     void CompleteOpen(UInt_t dbNo = 0,
00132                       const std::string& logComment = "");
00133     void Reset();
00134 
00135 static TDbiTableProxy& GetTableProxy();
00136 static TDbiTableProxy& GetTableProxy(const std::string& tableName);
00137 
00138 // Data members
00139 
00140 /// Aggregate noumber for set.
00141   Int_t fAggregateNo;
00142 
00143 ///Database number in cascade
00144   UInt_t fDbNo;
00145 
00146 /// The assembled record to be output. Never null.
00147   TDbiSqlValPacket* fPacket;
00148 
00149 /// Controls SEQNO type (see TDbiCascader::AllocateSeqNo)
00150   Int_t fRequireGlobalSeqno;
00151 
00152 /// Proxy to associated table.
00153   TDbiTableProxy* fTableProxy;
00154 
00155 /// Associated table name.
00156   std::string fTableName;
00157 
00158 /// Use overlay creation date if true.
00159   Bool_t fUseOverlayCreationDate;
00160 
00161 /// Validity record. May be =0 if closed.
00162   TDbiValidityRec* fValidRec;
00163 
00164 /// Associated log entry (if any) for update
00165   TDbiLogEntry fLogEntry;
00166 
00167 ClassDefT(TDbiWriter<T>,0)          // Writer for specific database table.
00168 
00169 };
00170 
00171 ClassDefT2(TDbiWriter,T)
00172 
00173 #endif  // DBIWRITER_H
00174 

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1