CMS 3D CMS Logo

RunModeDef.cc
Go to the documentation of this file.
1 #include <string>
3 
5 
6 using namespace std;
7 using namespace oracle::occi;
8 
10  m_env = nullptr;
11  m_conn = nullptr;
12  m_ID = 0;
13  m_runMode = "";
14 }
15 
17 
18 string RunModeDef::getRunMode() const { return m_runMode; }
19 
21  if (runmode != m_runMode) {
22  m_ID = 0;
23  m_runMode = runmode;
24  }
25 }
26 
27 int RunModeDef::fetchID() noexcept(false) {
28  // Return def from memory if available
29  if (m_ID) {
30  return m_ID;
31  }
32 
33  this->checkConnection();
34 
35  try {
36  Statement* stmt = m_conn->createStatement();
37  stmt->setSQL(
38  "SELECT def_id FROM ecal_run_mode_def WHERE "
39  "run_mode_string = :1");
40  stmt->setString(1, m_runMode);
41 
42  ResultSet* rset = stmt->executeQuery();
43 
44  if (rset->next()) {
45  m_ID = rset->getInt(1);
46  } else {
47  m_ID = 0;
48  }
49  m_conn->terminateStatement(stmt);
50  } catch (SQLException& e) {
51  throw(std::runtime_error("RunModeDef::fetchID: " + e.getMessage()));
52  }
53 
54  return m_ID;
55 }
56 
57 void RunModeDef::setByID(int id) noexcept(false) {
58  this->checkConnection();
59 
60  try {
61  Statement* stmt = m_conn->createStatement();
62 
63  stmt->setSQL("SELECT run_mode_string FROM ecal_run_mode_def WHERE def_id = :1");
64  stmt->setInt(1, id);
65 
66  ResultSet* rset = stmt->executeQuery();
67  if (rset->next()) {
68  m_runMode = rset->getString(1);
69  } else {
70  throw(std::runtime_error("RunModeDef::setByID: Given def_id is not in the database"));
71  }
72 
73  m_conn->terminateStatement(stmt);
74  } catch (SQLException& e) {
75  throw(std::runtime_error("RunModeDef::setByID: " + e.getMessage()));
76  }
77 }
78 
79 void RunModeDef::fetchAllDefs(std::vector<RunModeDef>* fillVec) noexcept(false) {
80  this->checkConnection();
81  try {
82  Statement* stmt = m_conn->createStatement();
83  stmt->setSQL("SELECT def_id FROM ecal_run_mode_def ORDER BY def_id");
84  ResultSet* rset = stmt->executeQuery();
85 
86  RunModeDef runModeDef;
87  runModeDef.setConnection(m_env, m_conn);
88 
89  while (rset->next()) {
90  runModeDef.setByID(rset->getInt(1));
91  fillVec->push_back(runModeDef);
92  }
93  } catch (SQLException& e) {
94  throw(std::runtime_error("RunModeDef::fetchAllDefs: " + e.getMessage()));
95  }
96 }
std::string getRunMode() const
Definition: RunModeDef.cc:18
~RunModeDef() override
Definition: RunModeDef.cc:16
void fetchAllDefs(std::vector< RunModeDef > *fillVec) noexcept(false)
Definition: RunModeDef.cc:79
int fetchID() noexcept(false) override
Definition: RunModeDef.cc:27
void setByID(int id) noexcept(false) override
Definition: RunModeDef.cc:57
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
void setRunMode(std::string runmode)
Definition: RunModeDef.cc:20