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