#ifndef TDBITABLEPROXYREGISTRY_H #define TDBITABLEPROXYREGISTRY_H /** * * $Id: IDbiDatabaseManager.hxx,v 1.1 2011/01/18 05:49:19 finch Exp $ * * \class COMET::IDbiDatabaseManager * * * \brief * Concept Factory creating IDbiTableProxy objects. * * \brief * Purpose A IDbiDatabaseManager is a factory that creates * and owns, TDbiTableProxys for all database tables. * * Contact: A.Finch@lancaster.ac.uk * * */ #if !defined(__CINT__) || defined(__MAKECINT__) #include "Rtypes.h" #endif #include #include #include "IDbiCfgConfigurable.hxx" #include "IDbiSimFlagAssociation.hxx" #include "IDbiRollbackDates.hxx" #include "IDbiEpochRollback.hxx" namespace COMET { class IDbiCascader; class IDbiTableProxy; class IDbiTableRow; class TDbiValidate; } namespace COMET { class IDbiDatabaseManager :public COMET::IDbiCfgConfigurable { friend class TDbiValidate; //Allow TDbiValidate access to dtor and // fCascader public: // State testing member functions void ShowStatistics() const; // State changing member functions static IDbiDatabaseManager& Instance(); static Bool_t IsActive() { return fgInstance ? kTRUE: kFALSE; } void Config(); void ClearRollbacks(); void ClearSimFlagAssociation(); IDbiCascader& GetCascader() { return *fCascader; } IDbiTableProxy& GetTableProxy(const std::string& tableName, const IDbiTableRow* tableRow) ; void PurgeCaches(); void RefreshMetaData(const std::string& tableName); void SetSqlCondition(const std::string& sql=""); protected: // Constructors (protected because singleton). IDbiDatabaseManager(); virtual ~IDbiDatabaseManager(); private: // State changing member functions void SetConfigFromEnvironment(); public: /// Helper class to handle deletion of singleton IDbiDatabaseManager struct Cleaner { static int fgCount; // counts #includes Cleaner() { this->Increment(); } ~Cleaner() { if (--fgCount==0 && IDbiDatabaseManager::fgInstance!=0) { delete IDbiDatabaseManager::fgInstance; IDbiDatabaseManager::fgInstance = 0; } } void Increment() { ++fgCount; }; }; friend class Cleaner; private: // Disabled (not implemented) copy constructor and asignment. IDbiDatabaseManager(const IDbiDatabaseManager&); COMET::IDbiDatabaseManager& operator=(const COMET::IDbiDatabaseManager&); // State testing member functions void ApplySqlCondition() const; void ApplySqlCondition(IDbiTableProxy* proxy) const; // Data members /// Cascader IDbiCascader* fCascader; /// Default optional condition. std::string fSqlCondition; #ifndef __CINT__ // Hide map from CINT; complains: missing Streamer() etc. /// TableName::RowName -> TableProxy std::map fTPmap; #endif // __CINT__ /// Epoch Rollback for each table. IDbiEpochRollback fEpochRollback; /// Rollback dates for each table. IDbiRollbackDates fRollbackDates; /// Lists of SimFlag associations. IDbiSimFlagAssociation fSimFlagAss; /// Holds only instance static IDbiDatabaseManager* fgInstance; ClassDef(IDbiDatabaseManager,0) // Singleton register TDbiTableProxys. }; }; #ifndef __CINT__ /// Count the number of #includes for this class static struct COMET::IDbiDatabaseManager::Cleaner __dbi_cleaner; #endif #endif // TDBITABLEPROXYREGISTRY_H