Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:58

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/FEConfigBadTTDat.h"
0006 
0007 using namespace std;
0008 using namespace oracle::occi;
0009 
0010 FEConfigBadTTDat::FEConfigBadTTDat() {
0011   m_env = nullptr;
0012   m_conn = nullptr;
0013   m_writeStmt = nullptr;
0014   m_readStmt = nullptr;
0015 
0016   m_tcc = 0;
0017   m_fed = 0;
0018   m_tt = 0;
0019   m_t1 = 0;
0020 }
0021 
0022 FEConfigBadTTDat::~FEConfigBadTTDat() {}
0023 
0024 void FEConfigBadTTDat::prepareWrite() noexcept(false) {
0025   this->checkConnection();
0026 
0027   try {
0028     m_writeStmt = m_conn->createStatement();
0029     m_writeStmt->setSQL("INSERT INTO " + getTable() +
0030                         " (rec_id, tcc_id, fed_id, tt_id, status ) "
0031                         "VALUES (:1, :2, :3, :4, :5 )");
0032   } catch (SQLException& e) {
0033     throw(std::runtime_error("FEConfigBadTTDat::prepareWrite():  " + e.getMessage()));
0034   }
0035 }
0036 
0037 void FEConfigBadTTDat::writeDB(const FEConfigBadTTDat* item, FEConfigBadTTInfo* iov) noexcept(false) {
0038   this->checkConnection();
0039 
0040   try {
0041     m_writeStmt->setInt(1, item->getId());
0042     m_writeStmt->setInt(2, item->getTCCId());
0043     m_writeStmt->setInt(3, item->getFedId());
0044     m_writeStmt->setInt(4, item->getTTId());
0045     m_writeStmt->setInt(5, item->getStatus());
0046 
0047     m_writeStmt->executeUpdate();
0048   } catch (SQLException& e) {
0049     throw(std::runtime_error("FEConfigBadTTDat::writeDB():  " + e.getMessage()));
0050   }
0051 }
0052 
0053 void FEConfigBadTTDat::fetchData(std::vector<FEConfigBadTTDat>* p, FEConfigBadTTInfo* iov) noexcept(false) {
0054   this->checkConnection();
0055 
0056   iov->setConnection(m_env, m_conn);
0057   int iovID = iov->fetchID();
0058   if (!iovID) {
0059     //  throw(std::runtime_error("FEConfigBadTTDat::writeDB:  IOV not in DB"));
0060     return;
0061   }
0062 
0063   try {
0064     m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :rec_id order by tcc_id, fed_id, tt_id ");
0065     m_readStmt->setInt(1, iovID);
0066     ResultSet* rset = m_readStmt->executeQuery();
0067 
0068     //    std::vector< FEConfigBadTTDat > p;
0069     FEConfigBadTTDat dat;
0070     while (rset->next()) {
0071       // dat.setId( rset->getInt(1) );
0072       dat.setTCCId(rset->getInt(2));
0073       dat.setFedId(rset->getInt(3));
0074       dat.setTTId(rset->getInt(4));
0075       dat.setStatus(rset->getInt(5));
0076 
0077       p->push_back(dat);
0078     }
0079   } catch (SQLException& e) {
0080     throw(std::runtime_error("FEConfigBadTTDat::fetchData():  " + e.getMessage()));
0081   }
0082 }
0083 
0084 //  ************************************************************************   //
0085 
0086 void FEConfigBadTTDat::writeArrayDB(const std::vector<FEConfigBadTTDat>& data, FEConfigBadTTInfo* iov) noexcept(false) {
0087   this->checkConnection();
0088 
0089   int iovID = iov->fetchID();
0090   if (!iovID) {
0091     throw(std::runtime_error("FEConfigDelays::writeArrayDB:  FEConfigBadTTInfo not in DB"));
0092   }
0093 
0094   int nrows = data.size();
0095   int* ids = new int[nrows];
0096   int* xx = new int[nrows];
0097   int* yy = new int[nrows];
0098   int* zz = new int[nrows];
0099   int* st = new int[nrows];
0100 
0101   ub2* ids_len = new ub2[nrows];
0102   ub2* x_len = new ub2[nrows];
0103   ub2* y_len = new ub2[nrows];
0104   ub2* z_len = new ub2[nrows];
0105   ub2* st_len = new ub2[nrows];
0106 
0107   FEConfigBadTTDat dataitem;
0108 
0109   for (size_t count = 0; count != data.size(); count++) {
0110     dataitem = data[count];
0111     ids[count] = iovID;
0112     xx[count] = dataitem.getTCCId();
0113     yy[count] = dataitem.getFedId();
0114     zz[count] = dataitem.getTTId();
0115     st[count] = dataitem.getStatus();
0116 
0117     ids_len[count] = sizeof(ids[count]);
0118     x_len[count] = sizeof(xx[count]);
0119     y_len[count] = sizeof(yy[count]);
0120     z_len[count] = sizeof(zz[count]);
0121     st_len[count] = sizeof(st[count]);
0122   }
0123 
0124   try {
0125     m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0126     m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
0127     m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
0128     m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
0129     m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
0130 
0131     m_writeStmt->executeArrayUpdate(nrows);
0132 
0133     delete[] ids;
0134     delete[] xx;
0135     delete[] yy;
0136     delete[] zz;
0137     delete[] st;
0138 
0139     delete[] ids_len;
0140     delete[] x_len;
0141     delete[] y_len;
0142     delete[] z_len;
0143     delete[] st_len;
0144 
0145   } catch (SQLException& e) {
0146     throw(std::runtime_error("FEConfigBadTTDat::writeArrayDB():  " + e.getMessage()));
0147   }
0148 }