Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:08

0001 #include <string>
0002 #include "OnlineDB/Oracle/interface/Oracle.h"
0003 
0004 #include "OnlineDB/EcalCondDB/interface/MonRunOutcomeDef.h"
0005 
0006 using namespace std;
0007 using namespace oracle::occi;
0008 
0009 MonRunOutcomeDef::MonRunOutcomeDef() {
0010   m_env = nullptr;
0011   m_conn = nullptr;
0012   m_ID = 0;
0013   m_shortDesc = "";
0014   m_longDesc = "";
0015 }
0016 
0017 MonRunOutcomeDef::~MonRunOutcomeDef() {}
0018 
0019 string MonRunOutcomeDef::getShortDesc() const { return m_shortDesc; }
0020 
0021 void MonRunOutcomeDef::setShortDesc(string desc) {
0022   if (desc != m_shortDesc) {
0023     m_ID = 0;
0024     m_shortDesc = desc;
0025   }
0026 }
0027 
0028 string MonRunOutcomeDef::getLongDesc() const { return m_longDesc; }
0029 
0030 int MonRunOutcomeDef::fetchID() noexcept(false) {
0031   // Return def from memory if available
0032   if (m_ID) {
0033     return m_ID;
0034   }
0035 
0036   this->checkConnection();
0037 
0038   try {
0039     Statement* stmt = m_conn->createStatement();
0040     stmt->setSQL(
0041         "SELECT def_id FROM mon_run_outcome_def WHERE "
0042         "short_desc = :1");
0043     stmt->setString(1, m_shortDesc);
0044 
0045     ResultSet* rset = stmt->executeQuery();
0046 
0047     if (rset->next()) {
0048       m_ID = rset->getInt(1);
0049     } else {
0050       m_ID = 0;
0051     }
0052     m_conn->terminateStatement(stmt);
0053   } catch (SQLException& e) {
0054     throw(std::runtime_error("MonRunOutcomeDef::fetchID:  " + e.getMessage()));
0055   }
0056 
0057   return m_ID;
0058 }
0059 
0060 void MonRunOutcomeDef::setByID(int id) noexcept(false) {
0061   this->checkConnection();
0062 
0063   try {
0064     Statement* stmt = m_conn->createStatement();
0065 
0066     stmt->setSQL("SELECT short_desc, long_desc FROM mon_run_outcome_def WHERE def_id = :1");
0067     stmt->setInt(1, id);
0068 
0069     ResultSet* rset = stmt->executeQuery();
0070     if (rset->next()) {
0071       m_shortDesc = rset->getString(1);
0072       m_longDesc = rset->getString(2);
0073       m_ID = id;
0074     } else {
0075       throw(std::runtime_error("MonRunOutcomeDef::setByID:  Given def_id is not in the database"));
0076     }
0077 
0078     m_conn->terminateStatement(stmt);
0079   } catch (SQLException& e) {
0080     throw(std::runtime_error("MonRunOutcomeDef::setByID:  " + e.getMessage()));
0081   }
0082 }
0083 
0084 void MonRunOutcomeDef::fetchAllDefs(std::vector<MonRunOutcomeDef>* fillVec) noexcept(false) {
0085   this->checkConnection();
0086   try {
0087     Statement* stmt = m_conn->createStatement();
0088     stmt->setSQL("SELECT def_id FROM mon_run_outcome_def ORDER BY def_id");
0089     ResultSet* rset = stmt->executeQuery();
0090 
0091     MonRunOutcomeDef def;
0092     def.setConnection(m_env, m_conn);
0093 
0094     while (rset->next()) {
0095       def.setByID(rset->getInt(1));
0096       fillVec->push_back(def);
0097     }
0098   } catch (SQLException& e) {
0099     throw(std::runtime_error("MonRunOutcomeDef::fetchAllDefs:  " + e.getMessage()));
0100   }
0101 }