#ifndef TDBIRESULT_H #define TDBIRESULT_H /** * * * \class COMET::IDbiResultSet * * * \brief * Concept Abstract base class representing the Result of a single * database query. If query suceeded the Result will hold (own) a vector * of table row objects that correspond to result of the query. It will * also own a IDbiValidityRec that gives the range over which the result * is valid. * * \brief * Purpose To provide suitable objects to cache. TDbiResultSets can * be checked to see if they satisfy new queries. * * Contact: A.Finch@lancaster.ac.uk * * */ #include #include using std::string; #include "IDbi.hxx" #include "IDbiExceptionLog.hxx" #include "IDbiValidityRec.hxx" typedef std::map IndexToRow_t; namespace COMET { class IDbiBinaryFile; class IDbiResultKey; class IDbiResultSet; class IDbiInRowStream; class IDbiTableRow; } namespace COMET { class IVldContext; }; COMET::IDbiBinaryFile& operator<<(COMET::IDbiBinaryFile& bf, const COMET::IDbiResultSet& res); COMET::IDbiBinaryFile& operator>>(COMET::IDbiBinaryFile& bf, COMET::IDbiResultSet& res); namespace COMET { class IDbiResultSet { public: // Constructors and destructors. IDbiResultSet(IDbiInRowStream* resultSet = 0, const IDbiValidityRec* vrec = 0, const string& sqlQualifiers = ""); virtual ~IDbiResultSet(); // State testing member functions virtual Bool_t CanReuse() const { return fCanReuse; } virtual Bool_t CanSave() const { return kTRUE; } virtual void Connect() const { ++fNumClients; } virtual IDbiResultKey* CreateKey() const = 0; virtual void Disconnect() const { --fNumClients; } const IDbiExceptionLog& GetExceptionLog() const { return fExceptionLog; } Int_t GetID() const { return fID; } virtual const IDbiResultKey* GetKey() const; virtual UInt_t GetNumAggregates() const =0; virtual UInt_t GetNumClients() const { return fNumClients; } virtual UInt_t GetNumRows() const =0; const string& GetSqlQualifiers() const { return fSqlQualifiers; } virtual const IDbiTableRow* GetTableRow(UInt_t rowNum) const =0; virtual const IDbiTableRow* GetTableRowByIndex(UInt_t index) const; virtual const IDbiValidityRec& GetValidityRec( const IDbiTableRow* /* row */ = 0) const { return GetValidityRecGlobal(); } virtual const IDbiValidityRec& GetValidityRecGlobal() const { return fEffVRec; } Bool_t IsExtendedContext() const { return this->GetSqlQualifiers() != ""; } virtual Bool_t Owns(const IDbiTableRow* /* row */) const { return kFALSE; } Bool_t ResultsFromDb() const { return fResultsFromDb; } virtual const string& TableName() const { return fTableName; } // State changing member functions void CaptureExceptionLog(UInt_t startFrom); /// Return true if no clients and unlikely to be reused. virtual Bool_t CanDelete(const IDbiResultSet* res = 0); /// All IDbiResultSet classes can satisfy this type of primary /// query so impliment here. virtual Bool_t Satisfies(const COMET::IVldContext& vc, const IDbi::Task& task); /// Not all IDbiResultSet classes can satisfy these types of /// query so those that do must override. virtual Bool_t Satisfies(const string&) {return kFALSE;} virtual Bool_t Satisfies(const IDbiValidityRec&, const string& = "") {return kFALSE;} /// Key handling virtual void GenerateKey(); virtual void Streamer(IDbiBinaryFile& file); virtual void SetCanReuse(Bool_t reuse) { fCanReuse = reuse ; } protected: void SetResultsFromDb() { fResultsFromDb = kTRUE; } // State testing member functions void BuildLookUpTable() const; Bool_t LookUpBuilt() const { return fIndexKeys.size() > 0; } // State changing member functions. virtual void SetTableName(const string& tableName) { fTableName = tableName; } virtual void SetValidityRec(const IDbiValidityRec& vRec) { fEffVRec = vRec; } private: // Data members /// Unique ID within the current job Int_t fID; //// Set kTRUE if can be reused Bool_t fCanReuse; //// Effective validity record IDbiValidityRec fEffVRec; //// Look-up: Index -> TableRow mutable IndexToRow_t fIndexKeys; //// Only non-zero for top-level result const IDbiResultKey* fKey; /// True is at least part didn't come from cache. Bool_t fResultsFromDb; //// Number of clients mutable Int_t fNumClients; //// Table name string fTableName; /// Null unless Extended Context query in which case it contains:- /// context-sql;data-sql;fill-options string fSqlQualifiers; /// Exception log produced when query was executed. IDbiExceptionLog fExceptionLog; /// Used to allocate unique ID within the current job static Int_t fgLastID; ClassDef(IDbiResultSet,0) //Abstract base representing query result }; }; #endif // TDBIRESULT_H