CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RunSeqDef.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_runSeq = "";
15  m_runType = RunTypeDef();
16 }
17 
18 
19 
21 {
22 }
23 
24 
25 
26 string RunSeqDef::getRunSeq() const { return m_runSeq;}
27 
28 
29 
30 void RunSeqDef::setRunSeq(string runseq){ m_runSeq = runseq;}
31 
33 {
34  return m_runType;
35 }
36 
37 void RunSeqDef::setRunTypeDef(const RunTypeDef& runTypeDef)
38 {
39  m_runType = runTypeDef;
40 }
41 
42 
43 
45  throw(std::runtime_error)
46 {
47  // Return def from memory if available
48  if (m_ID) {
49  return m_ID;
50  }
51 
52  this->checkConnection();
53 
54 
55  // get the run type
56  m_runType.setConnection(m_env, m_conn);
57  int run_type_id = m_runType.fetchID();
58 
59 
60  try {
61  Statement* stmt = m_conn->createStatement();
62  stmt->setSQL("SELECT def_id FROM ecal_sequence_type_def WHERE "
63  " run_type_def_id = :1 and sequence_type_string = :2 "
64  );
65 
66  stmt->setInt(1, run_type_id);
67  stmt->setString(2, m_runSeq);
68 
69  ResultSet* rset = stmt->executeQuery();
70 
71  if (rset->next()) {
72  m_ID = rset->getInt(1);
73  } else {
74  m_ID = 0;
75  }
76  m_conn->terminateStatement(stmt);
77  } catch (SQLException &e) {
78  throw(std::runtime_error("RunSeqDef::fetchID: "+e.getMessage()));
79  }
80 
81  return m_ID;
82 }
83 
84 
85 
86 void RunSeqDef::setByID(int id)
87  throw(std::runtime_error)
88 {
89  this->checkConnection();
90 
91  try {
92  Statement* stmt = m_conn->createStatement();
93 
94  stmt->setSQL("SELECT run_type_def_id, sequence_type_string FROM ecal_sequence_type_def WHERE def_id = :1");
95  stmt->setInt(1, id);
96 
97  int idruntype=0;
98  ResultSet* rset = stmt->executeQuery();
99  if (rset->next()) {
100  idruntype = rset->getInt(1);
101  m_runSeq = rset->getString(2);
102  } else {
103  throw(std::runtime_error("RunSeqDef::setByID: Given def_id is not in the database"));
104  }
105 
106  m_conn->terminateStatement(stmt);
107 
108  m_runType.setConnection(m_env, m_conn);
109  m_runType.setByID(idruntype);
110 
111  } catch (SQLException &e) {
112  throw(std::runtime_error("RunSeqDef::setByID: "+e.getMessage()));
113  }
114 }
115 
116 
117 
118 void RunSeqDef::fetchAllDefs( std::vector<RunSeqDef>* fillVec)
119  throw(std::runtime_error)
120 {
121  this->checkConnection();
122  try {
123  Statement* stmt = m_conn->createStatement();
124  stmt->setSQL("SELECT def_id FROM ecal_sequence_type_def ORDER BY def_id");
125  ResultSet* rset = stmt->executeQuery();
126 
127  RunSeqDef runSeqDef;
128  runSeqDef.setConnection(m_env, m_conn);
129 
130  while(rset->next()) {
131  runSeqDef.setByID( rset->getInt(1) );
132  fillVec->push_back( runSeqDef );
133  }
134  } catch (SQLException &e) {
135  throw(std::runtime_error("RunSeqDef::fetchAllDefs: "+e.getMessage()));
136  }
137 }
138 
140  throw(std::runtime_error)
141 {
142  // see if this data is already in the DB
143  try {
144  if (this->fetchID()) {
145  return m_ID;
146  }
147  } catch (SQLException &e) {
148  // it does not exist yet
149  }
150 
151  // check the connectioin
152  this->checkConnection();
153 
154  // get the run type
155  m_runType.setConnection(m_env, m_conn);
156  int run_type_id = m_runType.fetchID();
157 
158  // write new seq def to the DB
159  try {
160  Statement* stmt = m_conn->createStatement();
161 
162  stmt->setSQL("insert into ecal_sequence_type_def(RUN_TYPE_DEF_ID, SEQUENCE_TYPE_STRING) values "
163  " ( :1, :2 )");
164  stmt->setInt(1, run_type_id);
165  stmt->setString(2, m_runSeq);
166 
167 
168  stmt->executeUpdate();
169 
170  m_conn->terminateStatement(stmt);
171  } catch (SQLException &e) {
172  throw(std::runtime_error("RunSeqDef::writeDB: "+e.getMessage()));
173  }
174 
175  // now get the tag_id
176  if (!this->fetchID()) {
177  throw(std::runtime_error("RunSeqDef::writeDB: Failed to write"));
178  }
179 
180  return m_ID;
181 }
182 
#define NULL
Definition: scimark2.h:8
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
std::string getRunSeq() const
Definition: RunSeqDef.cc:26
int writeDB()
Definition: RunSeqDef.cc:139
RunSeqDef()
Definition: RunSeqDef.cc:9
RunTypeDef getRunTypeDef() const
Definition: RunSeqDef.cc:32
void setRunSeq(std::string runseq)
Definition: RunSeqDef.cc:30
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunSeqDef.cc:37
int fetchID()
Definition: RunSeqDef.cc:44
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
virtual ~RunSeqDef()
Definition: RunSeqDef.cc:20
void setByID(int id)
Definition: RunSeqDef.cc:86
void fetchAllDefs(std::vector< RunSeqDef > *fillVec)
Definition: RunSeqDef.cc:118