test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
11  m_env = NULL;
12  m_conn = NULL;
13  m_ID = 0;
14  m_monVer = "";
15  m_desc = "";
16 }
17 
18 
19 
21 {
22 }
23 
24 
25 
27 {
28  return m_monVer;
29 }
30 
31 
32 
34 {
35  if (ver != m_monVer) {
36  m_ID = 0;
37  m_monVer = ver;
38  }
39 }
40 
41 
43 {
44  return m_desc;
45 }
46 
47 
48 
50  throw(std::runtime_error)
51 {
52  // Return def from memory if available
53  if (m_ID) {
54  return m_ID;
55  }
56 
57  this->checkConnection();
58 
59  try {
60  Statement* stmt = m_conn->createStatement();
61  stmt->setSQL("SELECT def_id FROM mon_version_def WHERE "
62  "mon_ver = :1"
63  );
64  stmt->setString(1, m_monVer);
65 
66  ResultSet* rset = stmt->executeQuery();
67 
68  if (rset->next()) {
69  m_ID = rset->getInt(1);
70  } else {
71  m_ID = 0;
72  }
73  m_conn->terminateStatement(stmt);
74  } catch (SQLException &e) {
75  throw(std::runtime_error("MonVersionDef::fetchID: "+e.getMessage()));
76  }
77 
78  return m_ID;
79 }
80 
81 
82 
84  throw(std::runtime_error)
85 {
86  this->checkConnection();
87 
88  try {
89  Statement* stmt = m_conn->createStatement();
90 
91  stmt->setSQL("SELECT mon_ver, description FROM mon_version_def WHERE def_id = :1");
92  stmt->setInt(1, id);
93 
94  ResultSet* rset = stmt->executeQuery();
95  if (rset->next()) {
96  m_monVer = rset->getString(1);
97  m_desc = rset->getString(2);
98  } else {
99  throw(std::runtime_error("MonVersionDef::setByID: Given def_id is not in the database"));
100  }
101 
102  m_conn->terminateStatement(stmt);
103  } catch (SQLException &e) {
104  throw(std::runtime_error("MonVersionDef::setByID: "+e.getMessage()));
105  }
106 }
107 
108 
109 
110 void MonVersionDef::fetchAllDefs( std::vector<MonVersionDef>* fillVec)
111  throw(std::runtime_error)
112 {
113  this->checkConnection();
114  try {
115  Statement* stmt = m_conn->createStatement();
116  stmt->setSQL("SELECT def_id FROM mon_version_def ORDER BY def_id");
117  ResultSet* rset = stmt->executeQuery();
118 
119  MonVersionDef monVersionDef;
120  monVersionDef.setConnection(m_env, m_conn);
121 
122  while(rset->next()) {
123  monVersionDef.setByID( rset->getInt(1) );
124  fillVec->push_back( monVersionDef );
125  }
126  } catch (SQLException &e) {
127  throw(std::runtime_error("MonVersionDef::fetchAllDefs: "+e.getMessage()));
128  }
129 }
std::string getDescription() const
#define NULL
Definition: scimark2.h:8
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
void setByID(int id)
virtual ~MonVersionDef()
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void setMonitoringVersion(std::string ver)
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
std::string getMonitoringVersion() const
void fetchAllDefs(std::vector< MonVersionDef > *fillVec)