CMS 3D CMS Logo

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