CMS 3D CMS Logo

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