Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:57:36

0001 #include <string>
0002 #include "OnlineDB/Oracle/interface/Oracle.h"
0003 
0004 #include "OnlineDB/EcalCondDB/interface/RunTypeDef.h"
0005 
0006 using namespace std;
0007 using namespace oracle::occi;
0008 
0009 RunTypeDef::RunTypeDef() {
0010   m_env = nullptr;
0011   m_conn = nullptr;
0012   m_ID = 0;
0013   m_runType = "";
0014   m_desc = "";
0015 }
0016 
0017 RunTypeDef::~RunTypeDef() {}
0018 
0019 string RunTypeDef::getRunType() const { return m_runType; }
0020 
0021 void RunTypeDef::setRunType(string runtype) {
0022   if (runtype != m_runType) {
0023     m_ID = 0;
0024     m_runType = runtype;
0025   }
0026 }
0027 
0028 string RunTypeDef::getDescription() const { return m_desc; }
0029 
0030 int RunTypeDef::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 run_type_def WHERE "
0042         "run_type   = :1");
0043     stmt->setString(1, m_runType);
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("RunTypeDef::fetchID:  " + e.getMessage()));
0055   }
0056 
0057   return m_ID;
0058 }
0059 
0060 void RunTypeDef::setByID(int id) noexcept(false) {
0061   this->checkConnection();
0062 
0063   try {
0064     Statement* stmt = m_conn->createStatement();
0065 
0066     stmt->setSQL("SELECT run_type, description FROM run_type_def WHERE def_id = :1");
0067     stmt->setInt(1, id);
0068 
0069     ResultSet* rset = stmt->executeQuery();
0070     if (rset->next()) {
0071       m_runType = rset->getString(1);
0072       m_desc = rset->getString(2);
0073     } else {
0074       throw(std::runtime_error("RunTypeDef::setByID:  Given def_id is not in the database"));
0075     }
0076 
0077     m_conn->terminateStatement(stmt);
0078   } catch (SQLException& e) {
0079     throw(std::runtime_error("RunTypeDef::setByID:  " + e.getMessage()));
0080   }
0081 }
0082 
0083 void RunTypeDef::fetchAllDefs(std::vector<RunTypeDef>* fillVec) noexcept(false) {
0084   this->checkConnection();
0085   try {
0086     Statement* stmt = m_conn->createStatement();
0087     stmt->setSQL("SELECT def_id FROM run_type_def ORDER BY def_id");
0088     ResultSet* rset = stmt->executeQuery();
0089 
0090     RunTypeDef runTypeDef;
0091     runTypeDef.setConnection(m_env, m_conn);
0092 
0093     while (rset->next()) {
0094       runTypeDef.setByID(rset->getInt(1));
0095       fillVec->push_back(runTypeDef);
0096     }
0097   } catch (SQLException& e) {
0098     throw(std::runtime_error("RunTypeDef::fetchAllDefs:  " + e.getMessage()));
0099   }
0100 }