CMS 3D CMS Logo

MonVersionDef.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_monVer = "";
14  m_desc = "";
15 }
16 
18 
19 string MonVersionDef::getMonitoringVersion() const { return m_monVer; }
20 
22  if (ver != m_monVer) {
23  m_ID = 0;
24  m_monVer = ver;
25  }
26 }
27 
28 string MonVersionDef::getDescription() const { return m_desc; }
29 
30 int MonVersionDef::fetchID() noexcept(false) {
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_version_def WHERE "
42  "mon_ver = :1");
43  stmt->setString(1, m_monVer);
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("MonVersionDef::fetchID: " + e.getMessage()));
55  }
56 
57  return m_ID;
58 }
59 
60 void MonVersionDef::setByID(int id) noexcept(false) {
61  this->checkConnection();
62 
63  try {
64  Statement* stmt = m_conn->createStatement();
65 
66  stmt->setSQL("SELECT mon_ver, description FROM mon_version_def WHERE def_id = :1");
67  stmt->setInt(1, id);
68 
69  ResultSet* rset = stmt->executeQuery();
70  if (rset->next()) {
71  m_monVer = rset->getString(1);
72  m_desc = rset->getString(2);
73  } else {
74  throw(std::runtime_error("MonVersionDef::setByID: Given def_id is not in the database"));
75  }
76 
77  m_conn->terminateStatement(stmt);
78  } catch (SQLException& e) {
79  throw(std::runtime_error("MonVersionDef::setByID: " + e.getMessage()));
80  }
81 }
82 
83 void MonVersionDef::fetchAllDefs(std::vector<MonVersionDef>* fillVec) noexcept(false) {
84  this->checkConnection();
85  try {
86  Statement* stmt = m_conn->createStatement();
87  stmt->setSQL("SELECT def_id FROM mon_version_def ORDER BY def_id");
88  ResultSet* rset = stmt->executeQuery();
89 
90  MonVersionDef monVersionDef;
91  monVersionDef.setConnection(m_env, m_conn);
92 
93  while (rset->next()) {
94  monVersionDef.setByID(rset->getInt(1));
95  fillVec->push_back(monVersionDef);
96  }
97  } catch (SQLException& e) {
98  throw(std::runtime_error("MonVersionDef::fetchAllDefs: " + e.getMessage()));
99  }
100 }
MonVersionDef::setMonitoringVersion
void setMonitoringVersion(std::string ver)
Definition: MonVersionDef.cc:21
funct::false
false
Definition: Factorize.h:29
MonVersionDef::fetchID
int fetchID() noexcept(false) override
Definition: MonVersionDef.cc:30
MonVersionDef::getMonitoringVersion
std::string getMonitoringVersion() const
Definition: MonVersionDef.cc:19
MonVersionDef::~MonVersionDef
~MonVersionDef() override
Definition: MonVersionDef.cc:17
MonVersionDef::fetchAllDefs
void fetchAllDefs(std::vector< MonVersionDef > *fillVec) noexcept(false)
Definition: MonVersionDef.cc:83
oracle::occi
Definition: ConnectionManager.h:7
MonVersionDef
Definition: MonVersionDef.h:12
MonVersionDef::MonVersionDef
MonVersionDef()
Definition: MonVersionDef.cc:9
MonVersionDef.h
std
Definition: JetResolutionObject.h:76
IDBObject::setConnection
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
MonVersionDef::getDescription
std::string getDescription() const
Definition: MonVersionDef.cc:28
Oracle.h
MonVersionDef::setByID
void setByID(int id) noexcept(false) override
Definition: MonVersionDef.cc:60
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37