CMS 3D CMS Logo

ODBadTTDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
6 
7 using namespace std;
8 using namespace oracle::occi;
9 
11  m_env = nullptr;
12  m_conn = nullptr;
13  m_writeStmt = nullptr;
14  m_readStmt = nullptr;
15 
16  m_sm = 0;
17  m_fed = 0;
18  m_tt = 0;
19  m_t1 = 0;
20 }
21 
23 
24 void ODBadTTDat::prepareWrite() noexcept(false) {
25  this->checkConnection();
26 
27  try {
28  m_writeStmt = m_conn->createStatement();
29  m_writeStmt->setSQL("INSERT INTO " + getTable() +
30  " (rec_id, tr_id, fed_id, tt_id, status ) "
31  "VALUES (:1, :2, :3, :4, :5 )");
32  } catch (SQLException& e) {
33  throw(std::runtime_error("ODBadTTDat::prepareWrite(): " + e.getMessage()));
34  }
35 }
36 
37 void ODBadTTDat::writeDB(const ODBadTTDat* item, ODBadTTInfo* iov) noexcept(false) {
38  this->checkConnection();
39 
40  try {
41  m_writeStmt->setInt(1, item->getId());
42  m_writeStmt->setInt(2, item->getTRId());
43  m_writeStmt->setInt(3, item->getFedId());
44  m_writeStmt->setInt(4, item->getTTId());
45  m_writeStmt->setInt(5, item->getStatus());
46 
47  m_writeStmt->executeUpdate();
48  } catch (SQLException& e) {
49  throw(std::runtime_error("ODBadTTDat::writeDB(): " + e.getMessage()));
50  }
51 }
52 
53 void ODBadTTDat::fetchData(std::vector<ODBadTTDat>* p, ODBadTTInfo* iov) noexcept(false) {
54  this->checkConnection();
55 
56  iov->setConnection(m_env, m_conn);
57  int iovID = iov->fetchID();
58  if (!iovID) {
59  // throw(std::runtime_error("ODBadTTDat::writeDB: IOV not in DB"));
60  return;
61  }
62 
63  try {
64  m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :rec_id order by tr_id, fed_id, tt_id ");
65  m_readStmt->setInt(1, iovID);
66  ResultSet* rset = m_readStmt->executeQuery();
67 
68  // std::vector< ODBadTTDat > p;
69  ODBadTTDat dat;
70  while (rset->next()) {
71  // dat.setId( rset->getInt(1) );
72  dat.setTRId(rset->getInt(2));
73  dat.setFedId(rset->getInt(3));
74  dat.setTTId(rset->getInt(4));
75  dat.setStatus(rset->getInt(5));
76 
77  p->push_back(dat);
78  }
79  } catch (SQLException& e) {
80  throw(std::runtime_error("ODBadTTDat::fetchData(): " + e.getMessage()));
81  }
82 }
83 
84 // ************************************************************************ //
85 
86 void ODBadTTDat::writeArrayDB(const std::vector<ODBadTTDat>& data, ODBadTTInfo* iov) noexcept(false) {
87  this->checkConnection();
88 
89  int iovID = iov->fetchID();
90  if (!iovID) {
91  throw(std::runtime_error("ODDelays::writeArrayDB: ODBadTTInfo not in DB"));
92  }
93 
94  int nrows = data.size();
95  int* ids = new int[nrows];
96  int* xx = new int[nrows];
97  int* yy = new int[nrows];
98  int* zz = new int[nrows];
99  int* st = new int[nrows];
100 
101  ub2* ids_len = new ub2[nrows];
102  ub2* x_len = new ub2[nrows];
103  ub2* y_len = new ub2[nrows];
104  ub2* z_len = new ub2[nrows];
105  ub2* st_len = new ub2[nrows];
106 
107  ODBadTTDat dataitem;
108 
109  for (size_t count = 0; count != data.size(); count++) {
110  dataitem = data[count];
111  ids[count] = iovID;
112  xx[count] = dataitem.getTRId();
113  yy[count] = dataitem.getFedId();
114  zz[count] = dataitem.getTTId();
115  st[count] = dataitem.getStatus();
116 
117  ids_len[count] = sizeof(ids[count]);
118  x_len[count] = sizeof(xx[count]);
119  y_len[count] = sizeof(yy[count]);
120  z_len[count] = sizeof(zz[count]);
121  st_len[count] = sizeof(st[count]);
122  }
123 
124  try {
125  m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
126  m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
127  m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
128  m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
129  m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
130 
131  m_writeStmt->executeArrayUpdate(nrows);
132 
133  delete[] ids;
134  delete[] xx;
135  delete[] yy;
136  delete[] zz;
137  delete[] st;
138 
139  delete[] ids_len;
140  delete[] x_len;
141  delete[] y_len;
142  delete[] z_len;
143  delete[] st_len;
144 
145  } catch (SQLException& e) {
146  throw(std::runtime_error("ODBadTTDat::writeArrayDB(): " + e.getMessage()));
147  }
148 }
void setFedId(int dac)
Definition: ODBadTTDat.h:28
void setTRId(int dac)
Definition: ODBadTTDat.h:25
void setTTId(int dac)
Definition: ODBadTTDat.h:31
~ODBadTTDat() override
Definition: ODBadTTDat.cc:22
void writeArrayDB(const std::vector< ODBadTTDat > &data, ODBadTTInfo *iov) noexcept(false)
Definition: ODBadTTDat.cc:86
int getFedId() const
Definition: ODBadTTDat.h:29
int getTRId() const
Definition: ODBadTTDat.h:26
void fetchData(std::vector< ODBadTTDat > *fillMap, ODBadTTInfo *iov) noexcept(false)
Definition: ODBadTTDat.cc:53
void setStatus(int dac)
Definition: ODBadTTDat.h:34
void writeDB(const ODBadTTDat *item, ODBadTTInfo *iov) noexcept(false)
Definition: ODBadTTDat.cc:37
void prepareWrite() noexcept(false) override
Definition: ODBadTTDat.cc:24
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
int getStatus() const
Definition: ODBadTTDat.h:35
int getTTId() const
Definition: ODBadTTDat.h:32