#ifndef DBICACHE_H #define DBICACHE_H /** * * * \class COMET::IDbiCache * * * \brief * Concept Cache holding IDbiResultSet s for a specific database table. * * \brief * Purpose A IDbiCache is an object that minimises database I/O * by caching query results. Queries are always first sent to the * cache and only if not present are they sent down to the database. * * Contact: A.Finch@lancaster.ac.uk * * */ #include #include #include using std::string; #include "IDbi.hxx" namespace COMET { class IVldContext; }; namespace COMET { class IDbiResultSet; class IDbiDatabaseManager; class IDbiTableProxy; class IDbiValidityRec; } //class ostream; namespace COMET { class IDbiCache { friend class TDbiValidate; // To allow access to purge. public: // Typedefs typedef std::list ResultList_t; // Constructors and destructors. IDbiCache(IDbiTableProxy& qp, const string& tableName); virtual ~IDbiCache(); // State testing member functions UInt_t GetMaxSize() const { return fMaxSize; } UInt_t GetCurSize() const { return fCurSize; } UInt_t GetNumAdopted() const { return fNumAdopted; } UInt_t GetNumReused() const { return fNumReused; } // Primary searches. const IDbiResultSet* Search(const COMET::IVldContext& vc, const IDbi::Task& task) const; const IDbiResultSet* Search(const string& sqlQualifiers) const; /// Secondary search. const IDbiResultSet* Search(const IDbiValidityRec& vr, const string& sqlQualifiers = "") const; std::ostream& ShowStatistics(std::ostream& msg) const; // State changing member functions void Adopt(IDbiResultSet* res,bool generateKey = true); void Purge(); void SetStale(); protected: // State testing member functions // State changing member functions private: // Disabled (not implemented) copy constructor and asignment. IDbiCache(const IDbiCache&); COMET::IDbiCache& operator=(const COMET::IDbiCache&); const ResultList_t* GetSubCache(Int_t aggNo) const; void Purge(ResultList_t& subCache, const IDbiResultSet* res=0); // Data members /// TableProxy owning cache. IDbiTableProxy& fTableProxy; /// Name of associated table. const string& fTableName; /// Map of sub-caches indexed by aggregate number. /// Each sub-cache is a list of owned results for /// that aggregate. std::map fCache; /// Current size mutable UInt_t fCurSize; /// Max (high water) size mutable UInt_t fMaxSize; /// Total number adopted mutable UInt_t fNumAdopted; /// Number reused i.e. found. mutable UInt_t fNumReused; ClassDef(IDbiCache,0) //Query result cache for specific database table. }; }; #endif // DBICACHE_H