TDbiDatabaseManager.hxx

Go to the documentation of this file.
00001 #ifndef TDBITABLEPROXYREGISTRY_H
00002 #define TDBITABLEPROXYREGISTRY_H
00003 
00004 /**
00005  *
00006  * $Id: TDbiDatabaseManager.hxx,v 1.1 2011/01/18 05:49:19 finch Exp $
00007  *
00008  * \class TDbiDatabaseManager
00009  *
00010  *
00011  * \brief
00012  * <b>Concept</b>  Factory creating TDbiTableProxy objects.
00013  *
00014  * \brief
00015  * <b>Purpose</b> A TDbiDatabaseManager is a factory that creates
00016  *   and owns, TDbiTableProxys for all database tables.
00017  *
00018  * Contact: A.Finch@lancaster.ac.uk
00019  *
00020  *
00021  */
00022 
00023 #if !defined(__CINT__) || defined(__MAKECINT__)
00024 #include "Rtypes.h"
00025 #endif
00026 #include <map>
00027 #include <string>
00028 #include "TDbiCfgConfigurable.hxx"
00029 #include "TDbiSimFlagAssociation.hxx"
00030 #include "TDbiRollbackDates.hxx"
00031 #include "TDbiEpochRollback.hxx"
00032 
00033 
00034 
00035 class TDbiCascader;
00036 class TDbiTableProxy;
00037 class TDbiTableRow;
00038 class TDbiValidate;
00039 
00040 class TDbiDatabaseManager :public TDbiCfgConfigurable
00041 {
00042 
00043   friend class TDbiValidate;      //Allow TDbiValidate access to dtor and
00044                                  // fCascader
00045 public:
00046 
00047 // State testing member functions
00048       void ShowStatistics() const;
00049 
00050 // State changing member functions
00051 static TDbiDatabaseManager& Instance();
00052 static       Bool_t IsActive() { return fgInstance ? kTRUE: kFALSE; }
00053 
00054                void Config();
00055                void ClearRollbacks();
00056                void ClearSimFlagAssociation();
00057        TDbiCascader& GetCascader() { return *fCascader; }
00058      TDbiTableProxy& GetTableProxy(const std::string& tableName,
00059                                   const TDbiTableRow* tableRow) ;
00060                void PurgeCaches();
00061                void RefreshMetaData(const std::string& tableName);
00062                void SetSqlCondition(const std::string& sql="");
00063 
00064 protected:
00065 
00066 // Constructors (protected because singleton).
00067            TDbiDatabaseManager();
00068   virtual ~TDbiDatabaseManager();
00069 
00070 private:
00071 
00072 // State changing member functions
00073 
00074                void SetConfigFromEnvironment();
00075 
00076 public:
00077 
00078 /// Helper class to handle deletion of singleton TDbiDatabaseManager
00079  struct Cleaner {
00080    static int fgCount; // counts #includes
00081    Cleaner() { this->Increment(); }
00082    ~Cleaner() {
00083      if (--fgCount==0 && TDbiDatabaseManager::fgInstance!=0) {
00084        delete TDbiDatabaseManager::fgInstance;
00085        TDbiDatabaseManager::fgInstance = 0;
00086      }
00087    }
00088    void Increment() { ++fgCount; };
00089  };
00090  friend class Cleaner;
00091 
00092 private:
00093 
00094 // Disabled (not implemented) copy constructor and asignment.
00095 
00096  TDbiDatabaseManager(const TDbiDatabaseManager&);
00097  TDbiDatabaseManager& operator=(const TDbiDatabaseManager&);
00098 
00099 // State testing member functions
00100                void ApplySqlCondition() const;
00101                void ApplySqlCondition(TDbiTableProxy* proxy) const;
00102 
00103 // Data members
00104 
00105 /// Cascader
00106   TDbiCascader* fCascader;
00107 
00108 /// Default optional condition.
00109   std::string fSqlCondition;
00110 
00111 #ifndef __CINT__  // Hide map from CINT; complains: missing Streamer() etc.
00112 /// TableName::RowName -> TableProxy
00113   std::map<std::string,TDbiTableProxy*> fTPmap;
00114 #endif  // __CINT__
00115 
00116 /// Epoch Rollback  for each table.
00117   TDbiEpochRollback fEpochRollback;
00118 
00119 /// Rollback dates for each table.
00120   TDbiRollbackDates fRollbackDates;
00121 
00122 /// Lists of SimFlag associations.
00123   TDbiSimFlagAssociation fSimFlagAss;
00124 
00125 
00126 /// Holds only instance
00127   static TDbiDatabaseManager* fgInstance;
00128 
00129 ClassDef(TDbiDatabaseManager,0)   // Singleton register TDbiTableProxys.
00130 
00131 };
00132 
00133 
00134 #ifndef __CINT__
00135 /// Count the number of #includes for this class
00136 static struct TDbiDatabaseManager::Cleaner __dbi_cleaner;
00137 #endif
00138 
00139 #endif  // TDBITABLEPROXYREGISTRY_H
00140 

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1