CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/OnlineDB/EcalCondDB/src/MonRunOutcomeDef.cc

Go to the documentation of this file.
00001 #include <string>
00002 #include "OnlineDB/Oracle/interface/Oracle.h"
00003 
00004 #include "OnlineDB/EcalCondDB/interface/MonRunOutcomeDef.h"
00005 
00006 
00007 using namespace std;
00008 using namespace oracle::occi;
00009 
00010 MonRunOutcomeDef::MonRunOutcomeDef()
00011 {
00012   m_env = NULL;
00013   m_conn = NULL;
00014   m_ID = 0;
00015   m_shortDesc = "";
00016   m_longDesc = "";
00017 
00018 }
00019 
00020 
00021 
00022 MonRunOutcomeDef::~MonRunOutcomeDef()
00023 {
00024 }
00025 
00026 
00027 
00028 string MonRunOutcomeDef::getShortDesc() const
00029 {
00030   return m_shortDesc;
00031 }
00032 
00033 
00034 
00035 void MonRunOutcomeDef::setShortDesc(string desc)
00036 {
00037   if (desc != m_shortDesc) {
00038     m_ID = 0;
00039     m_shortDesc = desc;
00040   }
00041 }
00042 
00043 
00044 
00045 string MonRunOutcomeDef::getLongDesc() const
00046 {
00047   return m_longDesc;
00048 }
00049 
00050 
00051   
00052 int MonRunOutcomeDef::fetchID()
00053   throw(std::runtime_error)
00054 {
00055   // Return def from memory if available
00056   if (m_ID) {
00057     return m_ID;
00058   }
00059 
00060   this->checkConnection();
00061   
00062   try {
00063     Statement* stmt = m_conn->createStatement();
00064     stmt->setSQL("SELECT def_id FROM mon_run_outcome_def WHERE "
00065                  "short_desc = :1");
00066     stmt->setString(1, m_shortDesc);
00067 
00068     ResultSet* rset = stmt->executeQuery();
00069     
00070     if (rset->next()) {
00071       m_ID = rset->getInt(1);
00072     } else {
00073       m_ID = 0;
00074     }
00075     m_conn->terminateStatement(stmt);
00076   } catch (SQLException &e) {
00077     throw(std::runtime_error("MonRunOutcomeDef::fetchID:  "+e.getMessage()));
00078   }
00079 
00080   return m_ID;
00081 }
00082 
00083 
00084 
00085 void MonRunOutcomeDef::setByID(int id) 
00086   throw(std::runtime_error)
00087 {
00088   this->checkConnection();
00089 
00090   try {
00091     Statement* stmt = m_conn->createStatement();
00092 
00093     stmt->setSQL("SELECT short_desc, long_desc FROM mon_run_outcome_def WHERE def_id = :1");
00094     stmt->setInt(1, id);
00095 
00096     ResultSet* rset = stmt->executeQuery();
00097     if (rset->next()) {
00098       m_shortDesc = rset->getString(1);
00099       m_longDesc = rset->getString(2);
00100       m_ID = id;
00101     } else {
00102       throw(std::runtime_error("MonRunOutcomeDef::setByID:  Given def_id is not in the database"));
00103     }
00104     
00105     m_conn->terminateStatement(stmt);
00106   } catch (SQLException &e) {
00107    throw(std::runtime_error("MonRunOutcomeDef::setByID:  "+e.getMessage()));
00108   }
00109 }
00110 
00111 
00112 
00113 void MonRunOutcomeDef::fetchAllDefs( std::vector<MonRunOutcomeDef>* fillVec) 
00114   throw(std::runtime_error)
00115 {
00116   this->checkConnection();
00117   try {
00118     Statement* stmt = m_conn->createStatement();
00119     stmt->setSQL("SELECT def_id FROM mon_run_outcome_def ORDER BY def_id");
00120     ResultSet* rset = stmt->executeQuery();
00121     
00122     MonRunOutcomeDef def;
00123     def.setConnection(m_env, m_conn);
00124 
00125     while(rset->next()) {
00126       def.setByID( rset->getInt(1) );
00127       fillVec->push_back( def );
00128     }
00129   } catch (SQLException &e) {
00130     throw(std::runtime_error("MonRunOutcomeDef::fetchAllDefs:  "+e.getMessage()));
00131   }
00132 }