Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:54

0001 #ifndef LMFUNIQUE_H
0002 #define LMFUNIQUE_H
0003 
0004 /*
0005  Giovanni.Organtini@roma1.infn.it 2010
0006  */
0007 
0008 #include <algorithm>
0009 #include <cstring>
0010 #include <iostream>
0011 #include <list>
0012 #include <map>
0013 #include <memory>
0014 #include <stdexcept>
0015 
0016 #include "OnlineDB/EcalCondDB/interface/Tm.h"
0017 #include "OnlineDB/EcalCondDB/interface/IUniqueDBObject.h"
0018 #include "OnlineDB/Oracle/interface/Oracle.h"
0019 #include "OnlineDB/EcalCondDB/interface/EcalDBConnection.h"
0020 
0021 class LMFUnique : public IUniqueDBObject {
0022 public:
0023   typedef oracle::occi::ResultSet ResultSet;
0024   typedef oracle::occi::Statement Statement;
0025   friend class EcalCondDBInterface;
0026 
0027   LMFUnique() {
0028     _profiling = false;
0029     m_env = nullptr;
0030     m_conn = nullptr;
0031     m_ID = 0;
0032     setClassName("LMFUnique");
0033     nodebug();
0034   }
0035   LMFUnique(oracle::occi::Environment *env, oracle::occi::Connection *conn) {
0036     _profiling = false;
0037     m_ID = 0;
0038     setClassName("LMFUnique");
0039     nodebug();
0040     setConnection(env, conn);
0041   }
0042   LMFUnique(EcalDBConnection *c) {
0043     _profiling = false;
0044     m_ID = 0;
0045     setClassName("LMFUnique");
0046     nodebug();
0047     setConnection(c->getEnv(), c->getConn());
0048   }
0049 
0050   ~LMFUnique() override;
0051 
0052   virtual bool isValid() const { return true; }
0053   virtual bool isValid() { return true; }
0054   virtual bool exists();
0055 
0056   //  int getID()       { return m_ID; }
0057   std::string sequencePostfix(const Tm &t);
0058   int getID() const { return m_ID; }
0059   int getInt(std::string fieldname) const;
0060   std::string getClassName() { return m_className; }
0061   std::string getClassName() const { return m_className; }
0062   std::string getString(std::string fieldname) const;
0063 
0064   int fetchID() noexcept(false) override;
0065 
0066   LMFUnique &setString(std::string key, std::string value);
0067   LMFUnique &setInt(std::string key, int value);
0068   void attach(std::string name, LMFUnique *u);
0069   void setByID(int id) noexcept(false) override;
0070 
0071   virtual void dump() const;
0072   virtual void dump(int n) const;
0073 
0074   inline void debug() { m_debug = 1; }
0075   inline void nodebug() { m_debug = 0; }
0076 
0077   virtual std::list<std::unique_ptr<LMFUnique>> fetchAll() const noexcept(false);
0078 
0079   virtual bool operator<(const LMFUnique &r) { return (m_ID < r.m_ID); }
0080   virtual bool operator<=(const LMFUnique &r) { return (m_ID <= r.m_ID); }
0081   void startProfiling() { _profiling = true; }
0082   void stopProfiling() { _profiling = false; }
0083 
0084 private:
0085   virtual std::string writeDBSql(Statement *stmt) { return ""; }
0086   virtual std::string fetchIdSql(Statement *stmt) { return ""; }
0087   virtual std::string fetchAllSql(Statement *stmt) const;
0088   virtual std::string setByIDSql(Statement *stmt, int id) { return ""; }
0089 
0090   virtual void fetchParentIDs() {}
0091   virtual LMFUnique *createObject() const;
0092 
0093 protected:
0094   virtual void getParameters(ResultSet *rset) {}
0095   virtual int writeDB() noexcept(false);
0096   virtual int writeForeignKeys() noexcept(false);
0097   virtual void setClassName(std::string s) { m_className = s; }
0098 
0099   std::string m_className;
0100   char m_debug;
0101   // this is a map of string fields and their values
0102   std::map<std::string, std::string> m_stringFields;
0103   // this is a map of int fields and their values
0104   std::map<std::string, int> m_intFields;
0105   // this is a map of objects related to this by a foreign key
0106   std::map<std::string, LMFUnique *> m_foreignKeys;
0107   bool _profiling;
0108 };
0109 
0110 #endif