CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/OnlineDB/EcalCondDB/src/RunModeDef.cc

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