CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RunCommentDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
7 
10 
11 using namespace std;
12 using namespace oracle::occi;
13 
15  m_env = nullptr;
16  m_conn = nullptr;
17  m_writeStmt = nullptr;
18  m_source = "";
19  m_comment = "";
20  m_time = Tm();
21 }
22 
24 
26  this->checkConnection();
27 
28  try {
29  m_writeStmt = m_conn->createStatement();
30  m_writeStmt->setSQL(
31  "INSERT INTO run_comment_dat (iov_id, "
32  "source, user_comment) "
33  "VALUES (:iov_id, "
34  ":source, :user_comment)");
35  } catch (SQLException& e) {
36  throw(std::runtime_error("RunCommentDat::prepareWrite(): " + e.getMessage()));
37  }
38 }
39 
40 void RunCommentDat::writeDB(const EcalLogicID* ecid, const RunCommentDat* item, RunIOV* iov) noexcept(false) {
41  this->checkConnection();
42  this->checkPrepare();
43 
44  int iovID = iov->fetchID();
45  if (!iovID) {
46  throw(std::runtime_error("RunCommentDat::writeDB: IOV not in DB"));
47  }
48 
49  try {
50  m_writeStmt->setInt(1, iovID);
51  m_writeStmt->setString(2, item->getSource());
52  m_writeStmt->setString(3, item->getComment());
53 
54  m_writeStmt->executeUpdate();
55  } catch (SQLException& e) {
56  throw(std::runtime_error("RunCommentDat::writeDB(): " + e.getMessage()));
57  }
58 }
59 
60 void RunCommentDat::fetchData(map<EcalLogicID, RunCommentDat>* fillMap, RunIOV* iov) noexcept(false) {
61  this->checkConnection();
62  fillMap->clear();
63 
64  DateHandler dh(m_env, m_conn);
65 
66  iov->setConnection(m_env, m_conn);
67  int iovID = iov->fetchID();
68  if (!iovID) {
69  // throw(std::runtime_error("RunCommentDat::writeDB: IOV not in DB"));
70  return;
71  }
72 
73  try {
74  Statement* stmt = m_conn->createStatement();
75  stmt->setSQL(
76  "SELECT d.comment_id, "
77  "d.source, d.user_comment, d.db_timestamp "
78  "FROM run_comment_dat d "
79  "WHERE d.iov_id = :iov_id order by d.logic_id ");
80  stmt->setInt(1, iovID);
81  ResultSet* rset = stmt->executeQuery();
82 
83  std::pair<EcalLogicID, RunCommentDat> p;
84  RunCommentDat dat;
85  while (rset->next()) {
86  p.first = EcalLogicID("Comment_order",
87  rset->getInt(1),
88  rset->getInt(1),
90  EcalLogicID::NULLID, // comment number
91  "Comment_order");
92 
93  dat.setSource(rset->getString(2));
94  dat.setComment(rset->getString(3));
95 
96  Date startDate = rset->getDate(4);
97  m_time = dh.dateToTm(startDate);
98 
99  p.second = dat;
100  fillMap->insert(p);
101  }
102  m_conn->terminateStatement(stmt);
103  } catch (SQLException& e) {
104  throw(std::runtime_error("RunCommentDat::fetchData(): " + e.getMessage()));
105  }
106 }
void setSource(std::string x)
Definition: RunCommentDat.h:20
void fetchData(std::map< EcalLogicID, RunCommentDat > *fillMap, RunIOV *iov) noexcept(false)
void prepareWrite() noexcept(false) override
~RunCommentDat() override
static const int NULLID
Definition: EcalLogicID.h:35
void writeDB(const EcalLogicID *ecid, const RunCommentDat *item, RunIOV *iov) noexcept(false)
dh
Definition: cuy.py:354
Definition: RunIOV.h:13
void setComment(std::string x)
Definition: RunCommentDat.h:22
Definition: Tm.h:13