CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MonRunOutcomeDef.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_shortDesc = "";
14  m_longDesc = "";
15 }
16 
18 
19 string MonRunOutcomeDef::getShortDesc() const { return m_shortDesc; }
20 
22  if (desc != m_shortDesc) {
23  m_ID = 0;
24  m_shortDesc = desc;
25  }
26 }
27 
28 string MonRunOutcomeDef::getLongDesc() const { return m_longDesc; }
29 
31  // Return def from memory if available
32  if (m_ID) {
33  return m_ID;
34  }
35 
36  this->checkConnection();
37 
38  try {
39  Statement* stmt = m_conn->createStatement();
40  stmt->setSQL(
41  "SELECT def_id FROM mon_run_outcome_def WHERE "
42  "short_desc = :1");
43  stmt->setString(1, m_shortDesc);
44 
45  ResultSet* rset = stmt->executeQuery();
46 
47  if (rset->next()) {
48  m_ID = rset->getInt(1);
49  } else {
50  m_ID = 0;
51  }
52  m_conn->terminateStatement(stmt);
53  } catch (SQLException& e) {
54  throw(std::runtime_error("MonRunOutcomeDef::fetchID: " + e.getMessage()));
55  }
56 
57  return m_ID;
58 }
59 
60 void MonRunOutcomeDef::setByID(int id) noexcept(false) {
61  this->checkConnection();
62 
63  try {
64  Statement* stmt = m_conn->createStatement();
65 
66  stmt->setSQL("SELECT short_desc, long_desc FROM mon_run_outcome_def WHERE def_id = :1");
67  stmt->setInt(1, id);
68 
69  ResultSet* rset = stmt->executeQuery();
70  if (rset->next()) {
71  m_shortDesc = rset->getString(1);
72  m_longDesc = rset->getString(2);
73  m_ID = id;
74  } else {
75  throw(std::runtime_error("MonRunOutcomeDef::setByID: Given def_id is not in the database"));
76  }
77 
78  m_conn->terminateStatement(stmt);
79  } catch (SQLException& e) {
80  throw(std::runtime_error("MonRunOutcomeDef::setByID: " + e.getMessage()));
81  }
82 }
83 
84 void MonRunOutcomeDef::fetchAllDefs(std::vector<MonRunOutcomeDef>* fillVec) noexcept(false) {
85  this->checkConnection();
86  try {
87  Statement* stmt = m_conn->createStatement();
88  stmt->setSQL("SELECT def_id FROM mon_run_outcome_def ORDER BY def_id");
89  ResultSet* rset = stmt->executeQuery();
90 
92  def.setConnection(m_env, m_conn);
93 
94  while (rset->next()) {
95  def.setByID(rset->getInt(1));
96  fillVec->push_back(def);
97  }
98  } catch (SQLException& e) {
99  throw(std::runtime_error("MonRunOutcomeDef::fetchAllDefs: " + e.getMessage()));
100  }
101 }
int def(FILE *, FILE *, int)
uint16_t *__restrict__ id
std::string getShortDesc() const
void setByID(int id) noexcept(false) override
void fetchAllDefs(std::vector< MonRunOutcomeDef > *fillVec) noexcept(false)
void setShortDesc(std::string desc)
std::string getLongDesc() const
int fetchID() noexcept(false) override
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
~MonRunOutcomeDef() override