#ifndef DBIWRITER_H #define DBIWRITER_H /** * * $Id: IDbiWriter.hxx,v 1.1 2011/01/18 05:49:20 finch Exp $ * * \class COMET::IDbiWriter * * * \brief * Concept Templated class COMET::of pointers to Writer objects. * Writer objects are lightweight and provide type safe write * access to a single validity set of a specific table. * A IDbiWriter knows about publishing protocols but uses a * IDbiSqlValPacket both to hold the data in a type- neutral * form and to do the actual I/O. * * \brief * Purpose Writers are the primary application output * interface to the IDbi. Users instantiate Writers with * the information necessary define a validity set and then * pass all the rows one at a time, to the writer. The user * is able to abort the process at any point before the final * commit. * * Contact: A.Finch@lancaster.ac.uk * * */ #include #include #include "IDbi.hxx" #include "IDbiLogEntry.hxx" #include "IDbiDatabaseManager.hxx" #include "IVldRange.hxx" #include "IVldTimeStamp.hxx" namespace COMET { class IDbiSqlValPacket; class IDbiTableProxy; class IDbiValidityRec; } namespace COMET { template class IDbiWriter { public: // Constructors and destructors. IDbiWriter(); IDbiWriter(const COMET::IVldRange& vr, Int_t aggNo, IDbi::Task task, COMET::IVldTimeStamp creationDate, const std::string& dbName, const std::string& logComment = "", const std::string& tableName = ""); IDbiWriter(const COMET::IVldRange& vr, Int_t aggNo, IDbi::Task task = 0, COMET::IVldTimeStamp creationDate = COMET::IVldTimeStamp(0,0), UInt_t dbNo = 0, const std::string& logComment = "", const std::string& tableName = ""); IDbiWriter(const IDbiValidityRec& vrec, const std::string& dbName, const std::string& logComment = ""); IDbiWriter(const IDbiValidityRec& vrec, UInt_t dbNo = 0, const std::string& logComment = ""); virtual ~IDbiWriter(); // State testing member functions UInt_t GetEpoch() const; IDbiTableProxy& TableProxy() const; /// Open and ready to receive data. Bool_t IsOpen(Bool_t reportErrors = kTRUE) const; /// Open and ready to receive/output data. Bool_t CanOutput(Bool_t reportErrors = kTRUE) const; // State changing member functions void SetDbNo(UInt_t dbNo) { fDbNo = dbNo;} void SetDbName(const string& dbName); void SetEpoch(UInt_t epoch); void SetLogComment(const std::string& reason); // For setting of requireGlobal see IDbiCascader::AllocateSeqNo void SetRequireGlobalSeqno(Int_t requireGlobal) {fRequireGlobalSeqno = requireGlobal;} void SetOverlayCreationDate() {fUseOverlayCreationDate = kTRUE;} // I/O functions void Abort() { Reset(); } Bool_t Close(const char* fileSpec=0); Bool_t Open(const COMET::IVldRange& vr, Int_t aggNo, IDbi::Task task, COMET::IVldTimeStamp creationDate, const string& dbName, const std::string& logComment = ""); Bool_t Open(const COMET::IVldRange& vr, Int_t aggNo, IDbi::Task task = 0, COMET::IVldTimeStamp creationDate = COMET::IVldTimeStamp(), UInt_t dbNo = 0, const std::string& logComment = ""); Bool_t Open(const IDbiValidityRec& vrec, const string& dbName, const std::string& logComment = ""); Bool_t Open(const IDbiValidityRec& vrec, UInt_t dbNo = 0, const std::string& logComment = ""); COMET::IDbiWriter& operator<<(const T& row); private: // State testing member functions Bool_t NeedsLogEntry() const; Bool_t WritingToMaster() const; // State changing member functions IDbiWriter(const IDbiWriter&); // Forbidden IDbiWriter& operator=(const IDbiWriter&); // Forbidden void CompleteOpen(UInt_t dbNo = 0, const std::string& logComment = ""); void Reset(); static IDbiTableProxy& GetTableProxy(); static IDbiTableProxy& GetTableProxy(const std::string& tableName); // Data members /// Aggregate noumber for set. Int_t fAggregateNo; ///Database number in cascade UInt_t fDbNo; /// The assembled record to be output. Never null. IDbiSqlValPacket* fPacket; /// Controls SEQNO type (see IDbiCascader::AllocateSeqNo) Int_t fRequireGlobalSeqno; /// Proxy to associated table. IDbiTableProxy* fTableProxy; /// Associated table name. std::string fTableName; /// Use overlay creation date if true. Bool_t fUseOverlayCreationDate; /// Validity record. May be =0 if closed. IDbiValidityRec* fValidRec; /// Associated log entry (if any) for update IDbiLogEntry fLogEntry; ClassDefT(IDbiWriter,0) // Writer for specific database table. }; }; ClassDefT2(IDbiWriter,T) #endif // DBIWRITER_H