CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ODRunConfigCycleInfo.cc
Go to the documentation of this file.
1 #include <stdexcept>
3 
7 
8 using namespace std;
9 using namespace oracle::occi;
10 
11 
13 {
14  m_env = NULL;
15  m_conn = NULL;
16  m_writeStmt = NULL;
17  m_readStmt = NULL;
18 
19  m_ID=0;
20 
21  m_sequence_id =0;
22  m_cycle_num =0;
23  m_tag = "";
24  m_description="";
25 }
26 
27 
28 
30 
31 
33  m_sequence_id =0;
34  m_cycle_num =0;
35  m_tag = "";
36  m_description="";
37 
38 }
39 
41  throw(std::runtime_error)
42 {
43  this->checkConnection();
44 
45  try {
46  m_writeStmt = m_conn->createStatement();
47  m_writeStmt->setSQL("INSERT INTO ECAL_CYCLE_DAT ( sequence_id , cycle_num, tag, description ) "
48  "VALUES (:1, :2, :3 , :4 )");
49 
50  } catch (SQLException &e) {
51  throw(std::runtime_error("ODRunConfigCycleInfo::prepareWrite(): "+e.getMessage()));
52  }
53 }
54 
55 
57  throw(std::runtime_error)
58 {
59  this->checkConnection();
60  this->checkPrepare();
61 
62  // Validate the data, use infinity-till convention
63  DateHandler dh(m_env, m_conn);
64 
65  try {
66 
67  m_writeStmt->setInt(1, this->getSequenceID());
68  m_writeStmt->setInt(2, this->getCycleNumber());
69  m_writeStmt->setString(3, this->getTag());
70  m_writeStmt->setString(4, this->getDescription());
71  m_writeStmt->executeUpdate();
72 
73 
74 
75  } catch (SQLException &e) {
76  throw(std::runtime_error("ODRunConfigCycleInfo::writeDB: "+e.getMessage()));
77  }
78  // Now get the ID
79  if (!this->fetchID()) {
80  throw(std::runtime_error("ODRunConfigCycleInfo::writeDB: Failed to write"));
81  }
82 
83  cout<< "ODRunConfigCycleInfo::writeDB>> done inserting ODRunConfigCycleInfo with id="<<m_ID<<endl;
84 
85 }
86 
87 
88 
89 
90 
91 
93  throw(std::runtime_error)
94 {
95  // Return from memory if available
96  if (m_ID>0) {
97  return m_ID;
98  }
99 
100  this->checkConnection();
101 
102 
103  DateHandler dh(m_env, m_conn);
104 
105  try {
106  Statement* stmt = m_conn->createStatement();
107  stmt->setSQL("SELECT cycle_id from ECAL_cycle_DAT "
108  "WHERE sequence_id = :id1 "
109  " and cycle_num = :id2 " );
110  stmt->setInt(1, m_sequence_id);
111  stmt->setInt(2, m_cycle_num);
112 
113  ResultSet* rset = stmt->executeQuery();
114 
115  if (rset->next()) {
116  m_ID = rset->getInt(1);
117  } else {
118  m_ID = 0;
119  }
120  m_conn->terminateStatement(stmt);
121  } catch (SQLException &e) {
122  throw(std::runtime_error("ODRunConfigCycleInfo::fetchID: "+e.getMessage()));
123  }
124  setByID(m_ID);
125 
126  return m_ID;
127 }
128 
129 
130 
132  throw(std::runtime_error)
133 {
134 
135  this->checkConnection();
136 
137  DateHandler dh(m_env, m_conn);
138 
139  try {
140  Statement* stmt = m_conn->createStatement();
141  stmt->setSQL("SELECT max(cycle_id) FROM ecal_cycle_dat " );
142  ResultSet* rset = stmt->executeQuery();
143 
144  if (rset->next()) {
145  m_ID = rset->getInt(1);
146  } else {
147  m_ID = 0;
148  }
149  m_conn->terminateStatement(stmt);
150  } catch (SQLException &e) {
151  throw(std::runtime_error("ODRunConfigCycleInfo::fetchIDLast: "+e.getMessage()));
152  }
153 
154  setByID(m_ID);
155  return m_ID;
156 }
157 
158 
160  throw(std::runtime_error)
161 {
162  this->checkConnection();
163 
164  DateHandler dh(m_env, m_conn);
165 
166  cout<< "ODRunConfigCycleInfo::setByID called for id "<<id<<endl;
167 
168  try {
169  Statement* stmt = m_conn->createStatement();
170 
171  stmt->setSQL("SELECT sequence_id , cycle_num , tag , description FROM ECAL_cycle_DAT WHERE cycle_id = :1 ");
172  stmt->setInt(1, id);
173 
174  ResultSet* rset = stmt->executeQuery();
175  if (rset->next()) {
176  m_sequence_id=rset->getInt(1);
177  m_cycle_num=rset->getInt(2);
178  m_tag = rset->getString(3);
179  m_description= rset->getString(4);
180  m_ID = id;
181  } else {
182  throw(std::runtime_error("ODRunConfigCycleInfo::setByID: Given cycle_id is not in the database"));
183  }
184  m_conn->terminateStatement(stmt);
185  } catch (SQLException &e) {
186  throw(std::runtime_error("ODRunConfigCycleInfo::setByID: "+e.getMessage()));
187  }
188 }
189 
190 
192  throw(std::runtime_error)
193 {
194  this->checkConnection();
195  result->clear();
196  if(result->getId()==0){
197  throw(std::runtime_error("ODRunConfigCycleInfo::fetchData(): no Id defined for this ODRunConfigCycleInfo "));
198  }
199 
200  try {
201  m_readStmt->setSQL("SELECT sequence_id , cycle_num , tag , description FROM ECAL_cycle_DAT WHERE cycle_id = :1 ");
202 
203  m_readStmt->setInt(1, result->getId());
204  ResultSet* rset = m_readStmt->executeQuery();
205 
206  rset->next();
207 
208  result->setSequenceID( rset->getInt(1) );
209  result->setCycleNumber( rset->getInt(2) );
210  result->setTag( rset->getString(3) );
211  result->setDescription( rset->getString(4) );
212 
213  } catch (SQLException &e) {
214  throw(std::runtime_error("ODRunConfigCycleInfo::fetchData(): "+e.getMessage()));
215  }
216 }
217 
219  throw(std::runtime_error)
220 {
221  try {
222 
223  prepareWrite();
224  writeDB();
225  m_conn->commit();
226  terminateWriteStatement();
227  } catch (std::runtime_error &e) {
228  m_conn->rollback();
229  throw(e);
230  } catch (...) {
231  m_conn->rollback();
232  throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
233  }
234 }
235 
void fetchData(ODRunConfigCycleInfo *result)
#define NULL
Definition: scimark2.h:8
tuple result
Definition: query.py:137
oracle::occi::Statement Statement
Definition: IODConfig.h:23
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
tuple cout
Definition: gather_cfg.py:121
tuple dh
Definition: cuy.py:353