File indexing completed on 2024-04-06 12:23:12
0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004
0005 #include "OnlineDB/EcalCondDB/interface/RunCommentDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0007
0008 #include "OnlineDB/EcalCondDB/interface/Tm.h"
0009 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
0010
0011 using namespace std;
0012 using namespace oracle::occi;
0013
0014 RunCommentDat::RunCommentDat() {
0015 m_env = nullptr;
0016 m_conn = nullptr;
0017 m_writeStmt = nullptr;
0018 m_source = "";
0019 m_comment = "";
0020 m_time = Tm();
0021 }
0022
0023 RunCommentDat::~RunCommentDat() {}
0024
0025 void RunCommentDat::prepareWrite() noexcept(false) {
0026 this->checkConnection();
0027
0028 try {
0029 m_writeStmt = m_conn->createStatement();
0030 m_writeStmt->setSQL(
0031 "INSERT INTO run_comment_dat (iov_id, "
0032 "source, user_comment) "
0033 "VALUES (:iov_id, "
0034 ":source, :user_comment)");
0035 } catch (SQLException& e) {
0036 throw(std::runtime_error("RunCommentDat::prepareWrite(): " + e.getMessage()));
0037 }
0038 }
0039
0040 void RunCommentDat::writeDB(const EcalLogicID* ecid, const RunCommentDat* item, RunIOV* iov) noexcept(false) {
0041 this->checkConnection();
0042 this->checkPrepare();
0043
0044 int iovID = iov->fetchID();
0045 if (!iovID) {
0046 throw(std::runtime_error("RunCommentDat::writeDB: IOV not in DB"));
0047 }
0048
0049 try {
0050 m_writeStmt->setInt(1, iovID);
0051 m_writeStmt->setString(2, item->getSource());
0052 m_writeStmt->setString(3, item->getComment());
0053
0054 m_writeStmt->executeUpdate();
0055 } catch (SQLException& e) {
0056 throw(std::runtime_error("RunCommentDat::writeDB(): " + e.getMessage()));
0057 }
0058 }
0059
0060 void RunCommentDat::fetchData(map<EcalLogicID, RunCommentDat>* fillMap, RunIOV* iov) noexcept(false) {
0061 this->checkConnection();
0062 fillMap->clear();
0063
0064 DateHandler dh(m_env, m_conn);
0065
0066 iov->setConnection(m_env, m_conn);
0067 int iovID = iov->fetchID();
0068 if (!iovID) {
0069
0070 return;
0071 }
0072
0073 try {
0074 Statement* stmt = m_conn->createStatement();
0075 stmt->setSQL(
0076 "SELECT d.comment_id, "
0077 "d.source, d.user_comment, d.db_timestamp "
0078 "FROM run_comment_dat d "
0079 "WHERE d.iov_id = :iov_id order by d.logic_id ");
0080 stmt->setInt(1, iovID);
0081 ResultSet* rset = stmt->executeQuery();
0082
0083 std::pair<EcalLogicID, RunCommentDat> p;
0084 RunCommentDat dat;
0085 while (rset->next()) {
0086 p.first = EcalLogicID("Comment_order",
0087 rset->getInt(1),
0088 rset->getInt(1),
0089 EcalLogicID::NULLID,
0090 EcalLogicID::NULLID,
0091 "Comment_order");
0092
0093 dat.setSource(rset->getString(2));
0094 dat.setComment(rset->getString(3));
0095
0096 Date startDate = rset->getDate(4);
0097 m_time = dh.dateToTm(startDate);
0098
0099 p.second = dat;
0100 fillMap->insert(p);
0101 }
0102 m_conn->terminateStatement(stmt);
0103 } catch (SQLException& e) {
0104 throw(std::runtime_error("RunCommentDat::fetchData(): " + e.getMessage()));
0105 }
0106 }