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 {
11  m_env = nullptr;
12  m_conn = nullptr;
13  m_ID = 0;
14  m_runMode = "";
15 
16 }
17 
18 
19 
21 {
22 }
23 
24 
25 
26 string RunModeDef::getRunMode() const
27 {
28  return m_runMode;
29 }
30 
31 
32 
33 void RunModeDef::setRunMode(string runmode)
34 {
35  if (runmode != m_runMode) {
36  m_ID = 0;
37  m_runMode = runmode;
38  }
39 }
40 
41 
42 
43 
44 
45 
48 {
49  // Return def from memory if available
50  if (m_ID) {
51  return m_ID;
52  }
53 
54  this->checkConnection();
55 
56  try {
57  Statement* stmt = m_conn->createStatement();
58  stmt->setSQL("SELECT def_id FROM ecal_run_mode_def WHERE "
59  "run_mode_string = :1"
60  );
61  stmt->setString(1, m_runMode);
62 
63  ResultSet* rset = stmt->executeQuery();
64 
65  if (rset->next()) {
66  m_ID = rset->getInt(1);
67  } else {
68  m_ID = 0;
69  }
70  m_conn->terminateStatement(stmt);
71  } catch (SQLException &e) {
72  throw(std::runtime_error("RunModeDef::fetchID: "+e.getMessage()));
73  }
74 
75  return m_ID;
76 }
77 
78 
79 
80 void RunModeDef::setByID(int id)
81  noexcept(false)
82 {
83  this->checkConnection();
84 
85  try {
86  Statement* stmt = m_conn->createStatement();
87 
88  stmt->setSQL("SELECT run_mode_string FROM ecal_run_mode_def WHERE def_id = :1");
89  stmt->setInt(1, id);
90 
91  ResultSet* rset = stmt->executeQuery();
92  if (rset->next()) {
93  m_runMode = rset->getString(1);
94  } else {
95  throw(std::runtime_error("RunModeDef::setByID: Given def_id is not in the database"));
96  }
97 
98  m_conn->terminateStatement(stmt);
99  } catch (SQLException &e) {
100  throw(std::runtime_error("RunModeDef::setByID: "+e.getMessage()));
101  }
102 }
103 
104 
105 
106 void RunModeDef::fetchAllDefs( std::vector<RunModeDef>* fillVec)
107  noexcept(false)
108 {
109  this->checkConnection();
110  try {
111  Statement* stmt = m_conn->createStatement();
112  stmt->setSQL("SELECT def_id FROM ecal_run_mode_def ORDER BY def_id");
113  ResultSet* rset = stmt->executeQuery();
114 
115  RunModeDef runModeDef;
116  runModeDef.setConnection(m_env, m_conn);
117 
118  while(rset->next()) {
119  runModeDef.setByID( rset->getInt(1) );
120  fillVec->push_back( runModeDef );
121  }
122  } catch (SQLException &e) {
123  throw(std::runtime_error("RunModeDef::fetchAllDefs: "+e.getMessage()));
124  }
125 }
#define noexcept
std::string getRunMode() const
Definition: RunModeDef.cc:26
~RunModeDef() override
Definition: RunModeDef.cc:20
void fetchAllDefs(std::vector< RunModeDef > *fillVec) noexcept(false)
Definition: RunModeDef.cc:106
int fetchID() noexcept(false) override
Definition: RunModeDef.cc:46
void setByID(int id) noexcept(false) override
Definition: RunModeDef.cc:80
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
void setRunMode(std::string runmode)
Definition: RunModeDef.cc:33