CMS 3D CMS Logo

FEConfigBadTTDat.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_t1 = 0;
20 }
21 
23 
25  this->checkConnection();
26 
27  try {
28  m_writeStmt = m_conn->createStatement();
29  m_writeStmt->setSQL("INSERT INTO " + getTable() +
30  " (rec_id, tcc_id, fed_id, tt_id, status ) "
31  "VALUES (:1, :2, :3, :4, :5 )");
32  } catch (SQLException& e) {
33  throw(std::runtime_error("FEConfigBadTTDat::prepareWrite(): " + e.getMessage()));
34  }
35 }
36 
38  this->checkConnection();
39 
40  try {
41  m_writeStmt->setInt(1, item->getId());
42  m_writeStmt->setInt(2, item->getTCCId());
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("FEConfigBadTTDat::writeDB(): " + e.getMessage()));
50  }
51 }
52 
53 void FEConfigBadTTDat::fetchData(std::vector<FEConfigBadTTDat>* p, FEConfigBadTTInfo* 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("FEConfigBadTTDat::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 tcc_id, fed_id, tt_id ");
65  m_readStmt->setInt(1, iovID);
66  ResultSet* rset = m_readStmt->executeQuery();
67 
68  // std::vector< FEConfigBadTTDat > p;
69  FEConfigBadTTDat dat;
70  while (rset->next()) {
71  // dat.setId( rset->getInt(1) );
72  dat.setTCCId(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("FEConfigBadTTDat::fetchData(): " + e.getMessage()));
81  }
82 }
83 
84 // ************************************************************************ //
85 
86 void FEConfigBadTTDat::writeArrayDB(const std::vector<FEConfigBadTTDat>& data, FEConfigBadTTInfo* iov) noexcept(false) {
87  this->checkConnection();
88 
89  int iovID = iov->fetchID();
90  if (!iovID) {
91  throw(std::runtime_error("FEConfigDelays::writeArrayDB: FEConfigBadTTInfo 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  FEConfigBadTTDat dataitem;
108 
109  for (size_t count = 0; count != data.size(); count++) {
110  dataitem = data[count];
111  ids[count] = iovID;
112  xx[count] = dataitem.getTCCId();
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("FEConfigBadTTDat::writeArrayDB(): " + e.getMessage()));
147  }
148 }
void prepareWrite() noexcept(false) override
void setTCCId(int dac)
void setFedId(int x)
void setStatus(int dac)
void fetchData(std::vector< FEConfigBadTTDat > *fillMap, FEConfigBadTTInfo *iov) noexcept(false)
~FEConfigBadTTDat() override
void writeDB(const FEConfigBadTTDat *item, FEConfigBadTTInfo *iov) noexcept(false)
int getTTId() const
void setTTId(int dac)
#define noexcept
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
int getFedId() const
int getStatus() const
void writeArrayDB(const std::vector< FEConfigBadTTDat > &data, FEConfigBadTTInfo *iov) noexcept(false)
int getTCCId() const