CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/OnlineDB/EcalCondDB/src/MonVersionDef.cc

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