CMS 3D CMS Logo

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