CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/OnlineDB/EcalCondDB/src/RunCommentDat.cc

Go to the documentation of this file.
00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004 
00005 #include "OnlineDB/EcalCondDB/interface/RunCommentDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00007 
00008 #include "OnlineDB/EcalCondDB/interface/Tm.h"
00009 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
00010 
00011 using namespace std;
00012 using namespace oracle::occi;
00013 
00014 
00015 
00016 RunCommentDat::RunCommentDat()
00017 {
00018   m_env = NULL;
00019   m_conn = NULL;
00020   m_writeStmt = NULL;
00021   m_source = "";
00022   m_comment = "";
00023   m_time = Tm();
00024 }
00025 
00026 
00027 
00028 RunCommentDat::~RunCommentDat()
00029 {
00030 }
00031 
00032 
00033 
00034 void RunCommentDat::prepareWrite()
00035   throw(std::runtime_error)
00036 {
00037   this->checkConnection();
00038 
00039   try {
00040     m_writeStmt = m_conn->createStatement();
00041     m_writeStmt->setSQL("INSERT INTO run_comment_dat (iov_id,  "
00042                         "source, user_comment) "
00043                         "VALUES (:iov_id,  "
00044                         ":source, :user_comment)");
00045   } catch (SQLException &e) {
00046     throw(std::runtime_error("RunCommentDat::prepareWrite():  "+e.getMessage()));
00047   }
00048 }
00049 
00050 
00051 
00052 void RunCommentDat::writeDB(const EcalLogicID* ecid, const RunCommentDat* item, RunIOV* iov)
00053   throw(std::runtime_error)
00054 {
00055   this->checkConnection();
00056   this->checkPrepare();
00057 
00058   int iovID = iov->fetchID();
00059   if (!iovID) { throw(std::runtime_error("RunCommentDat::writeDB:  IOV not in DB")); }
00060   
00061   try {
00062     m_writeStmt->setInt(1, iovID);
00063     m_writeStmt->setString(2, item->getSource());
00064     m_writeStmt->setString(3, item->getComment());
00065     
00066     m_writeStmt->executeUpdate();
00067   } catch (SQLException &e) {
00068     throw(std::runtime_error("RunCommentDat::writeDB():  "+e.getMessage()));
00069   }
00070 }
00071 
00072 
00073 
00074 void RunCommentDat::fetchData(map< EcalLogicID, RunCommentDat >* fillMap, RunIOV* iov)
00075   throw(std::runtime_error)
00076 {
00077   this->checkConnection();
00078   fillMap->clear();
00079 
00080   DateHandler dh(m_env, m_conn);
00081 
00082   iov->setConnection(m_env, m_conn);
00083   int iovID = iov->fetchID();
00084   if (!iovID) { 
00085     //  throw(std::runtime_error("RunCommentDat::writeDB:  IOV not in DB")); 
00086     return;
00087   }
00088 
00089   try {
00090     Statement* stmt = m_conn->createStatement();
00091     stmt->setSQL("SELECT d.comment_id, "
00092                  "d.source, d.user_comment, d.db_timestamp "
00093                  "FROM run_comment_dat d "
00094                  "WHERE d.iov_id = :iov_id order by d.logic_id ");
00095     stmt->setInt(1, iovID);
00096     ResultSet* rset = stmt->executeQuery();
00097     
00098     std::pair< EcalLogicID, RunCommentDat > p;
00099     RunCommentDat dat;
00100     while(rset->next()) {
00101       p.first = EcalLogicID( "Comment_order",
00102                              rset->getInt(1),  rset->getInt(1), 
00103                              EcalLogicID::NULLID, EcalLogicID::NULLID,        // comment number
00104                             "Comment_order");    
00105 
00106       dat.setSource( rset->getString(2) );
00107       dat.setComment( rset->getString(3) );
00108 
00109       Date startDate = rset->getDate(4);
00110       m_time = dh.dateToTm( startDate );
00111 
00112       p.second = dat;
00113       fillMap->insert(p);
00114     }
00115     m_conn->terminateStatement(stmt);
00116   } catch (SQLException &e) {
00117     throw(std::runtime_error("RunCommentDat::fetchData():  "+e.getMessage()));
00118   }
00119 }