CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/OnlineDB/EcalCondDB/interface/LMFUnique.h

Go to the documentation of this file.
00001 #ifndef LMFUNIQUE_H
00002 #define LMFUNIQUE_H
00003 
00004 /*
00005  Copyright (c) Giovanni.Organtini@roma1.infn.it 2010
00006  */
00007 
00008 #include <stdexcept>
00009 #include <iostream>
00010 #include <map>
00011 #include <boost/ptr_container/ptr_list.hpp>
00012 #include "OnlineDB/EcalCondDB/interface/Tm.h"
00013 #include "OnlineDB/EcalCondDB/interface/IUniqueDBObject.h"
00014 #include "OnlineDB/Oracle/interface/Oracle.h"
00015 #include "OnlineDB/EcalCondDB/interface/EcalDBConnection.h"
00016 
00017 class LMFUnique: public IUniqueDBObject {
00018  public:
00019   typedef oracle::occi::ResultSet ResultSet;
00020   typedef oracle::occi::Statement Statement;
00021   friend class EcalCondDBInterface;
00022 
00023   LMFUnique() { 
00024     _profiling = false;
00025     m_env = NULL;
00026     m_conn = NULL;
00027     m_ID = 0;
00028     setClassName("LMFUnique"); nodebug(); 
00029   }
00030   LMFUnique(oracle::occi::Environment* env,
00031             oracle::occi::Connection* conn) {
00032     _profiling = false;
00033     m_ID = 0;
00034     setClassName("LMFUnique"); nodebug(); 
00035     setConnection(env, conn);
00036   }
00037   LMFUnique(EcalDBConnection *c) {
00038     _profiling = false;
00039     m_ID = 0;
00040     setClassName("LMFUnique"); nodebug(); 
00041     setConnection(c->getEnv(), c->getConn());
00042   }
00043 
00044   virtual ~LMFUnique();
00045 
00046   virtual bool isValid() const { return true; }
00047   virtual bool isValid() { return true; }
00048   virtual bool exists();
00049 
00050   //  int getID()       { return m_ID; } 
00051   std::string sequencePostfix(Tm t);
00052   int getID() const { return m_ID; } 
00053   int getInt(std::string fieldname) const;
00054   std::string getClassName() { return m_className; }
00055   std::string getClassName() const { return m_className; }
00056   std::string getString(std::string fieldname) const;
00057 
00058   int fetchID() throw(std::runtime_error); 
00059 
00060   LMFUnique& setString(std::string key, std::string value);
00061   LMFUnique& setInt(std::string key, int value);
00062   void attach(std::string name, LMFUnique *u);
00063   void setByID(int id) throw(std::runtime_error);
00064 
00065   virtual void dump() const ;
00066   virtual void dump(int n) const ;
00067 
00068   inline void debug() { m_debug = 1; }
00069   inline void nodebug() { m_debug = 0; }
00070 
00071   virtual boost::ptr_list<LMFUnique> fetchAll() const 
00072     throw (std::runtime_error);
00073 
00074   virtual bool operator<(const LMFUnique &r) {
00075     return (m_ID < r.m_ID);
00076   }
00077   virtual bool operator<=(const LMFUnique &r) {
00078     return (m_ID <= r.m_ID);
00079   }
00080   void startProfiling() { _profiling = true; }
00081   void stopProfiling() { _profiling = false; }
00082 
00083  private:
00084   virtual std::string writeDBSql(Statement *stmt) { return ""; } 
00085   virtual std::string fetchIdSql(Statement *stmt) { return ""; }
00086   virtual std::string fetchAllSql(Statement *stmt) const;
00087   virtual std::string setByIDSql(Statement *stmt, 
00088                                  int id) { return ""; }
00089 
00090   virtual void getParameters(ResultSet *rset) {}
00091   virtual void fetchParentIDs() {}
00092   virtual LMFUnique * createObject() const;
00093 
00094  protected:
00095   virtual int writeDB() throw(std::runtime_error);
00096   virtual int writeForeignKeys() throw(std::runtime_error);
00097   virtual void setClassName(std::string s) { m_className = s; }
00098 
00099   std::string m_className;
00100   char m_debug;
00101   // this is a map of string fields and their values
00102   std::map<std::string, std::string> m_stringFields;   
00103   // this is a map of int fields and their values
00104   std::map<std::string, int> m_intFields;
00105   // this is a map of objects related to this by a foreign key
00106   std::map<std::string, LMFUnique*> m_foreignKeys;
00107   bool _profiling;
00108 };
00109 
00110 #endif