CMS 3D CMS Logo

MonRunOutcomeDef.cc
Go to the documentation of this file.
1 #include <string>
3 
5 
6 
7 using namespace std;
8 using namespace oracle::occi;
9 
11 {
12  m_env = NULL;
13  m_conn = NULL;
14  m_ID = 0;
15  m_shortDesc = "";
16  m_longDesc = "";
17 
18 }
19 
20 
21 
23 {
24 }
25 
26 
27 
29 {
30  return m_shortDesc;
31 }
32 
33 
34 
36 {
37  if (desc != m_shortDesc) {
38  m_ID = 0;
39  m_shortDesc = desc;
40  }
41 }
42 
43 
44 
46 {
47  return m_longDesc;
48 }
49 
50 
51 
54 {
55  // Return def from memory if available
56  if (m_ID) {
57  return m_ID;
58  }
59 
60  this->checkConnection();
61 
62  try {
63  Statement* stmt = m_conn->createStatement();
64  stmt->setSQL("SELECT def_id FROM mon_run_outcome_def WHERE "
65  "short_desc = :1");
66  stmt->setString(1, m_shortDesc);
67 
68  ResultSet* rset = stmt->executeQuery();
69 
70  if (rset->next()) {
71  m_ID = rset->getInt(1);
72  } else {
73  m_ID = 0;
74  }
75  m_conn->terminateStatement(stmt);
76  } catch (SQLException &e) {
77  throw(std::runtime_error("MonRunOutcomeDef::fetchID: "+e.getMessage()));
78  }
79 
80  return m_ID;
81 }
82 
83 
84 
86  noexcept(false)
87 {
88  this->checkConnection();
89 
90  try {
91  Statement* stmt = m_conn->createStatement();
92 
93  stmt->setSQL("SELECT short_desc, long_desc FROM mon_run_outcome_def WHERE def_id = :1");
94  stmt->setInt(1, id);
95 
96  ResultSet* rset = stmt->executeQuery();
97  if (rset->next()) {
98  m_shortDesc = rset->getString(1);
99  m_longDesc = rset->getString(2);
100  m_ID = id;
101  } else {
102  throw(std::runtime_error("MonRunOutcomeDef::setByID: Given def_id is not in the database"));
103  }
104 
105  m_conn->terminateStatement(stmt);
106  } catch (SQLException &e) {
107  throw(std::runtime_error("MonRunOutcomeDef::setByID: "+e.getMessage()));
108  }
109 }
110 
111 
112 
113 void MonRunOutcomeDef::fetchAllDefs( std::vector<MonRunOutcomeDef>* fillVec)
114  noexcept(false)
115 {
116  this->checkConnection();
117  try {
118  Statement* stmt = m_conn->createStatement();
119  stmt->setSQL("SELECT def_id FROM mon_run_outcome_def ORDER BY def_id");
120  ResultSet* rset = stmt->executeQuery();
121 
123  def.setConnection(m_env, m_conn);
124 
125  while(rset->next()) {
126  def.setByID( rset->getInt(1) );
127  fillVec->push_back( def );
128  }
129  } catch (SQLException &e) {
130  throw(std::runtime_error("MonRunOutcomeDef::fetchAllDefs: "+e.getMessage()));
131  }
132 }
std::string getShortDesc() const
#define noexcept
void fetchAllDefs(std::vector< MonRunOutcomeDef > *fillVec) noexcept(false)
#define NULL
Definition: scimark2.h:8
void setShortDesc(std::string desc)
std::string getLongDesc() const
void setByID(int id) noexcept(false)
int fetchID() noexcept(false)
virtual ~MonRunOutcomeDef()
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
JetCorrectorParameters::Definitions def
Definition: classes.h:6