CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/OnlineDB/EcalCondDB/src/ODJBH4Config.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/ODJBH4Config.h"
00006 
00007 using namespace std;
00008 using namespace oracle::occi;
00009 
00010 ODJBH4Config::ODJBH4Config()
00011 {
00012   m_env = NULL;
00013   m_conn = NULL;
00014   m_writeStmt = NULL;
00015   m_readStmt = NULL;
00016   m_config_tag="";
00017   m_ID=0;
00018   clear();
00019 }
00020 
00021 
00022 
00023 ODJBH4Config::~ODJBH4Config()
00024 {
00025 }
00026 
00027 void ODJBH4Config::clear(){
00028 
00029   m_use_buffer=0;
00030   m_hal_mod_file="";
00031   m_hal_add_file="";
00032   m_hal_tab_file="";
00033   m_serial="";
00034   m_caen1="";
00035   m_caen2=0;
00036   m_caen3=0;
00037 
00038 }
00039 
00040 
00041 int ODJBH4Config::fetchNextId()  throw(std::runtime_error) {
00042 
00043   int result=0;
00044   try {
00045     this->checkConnection();
00046 
00047     m_readStmt = m_conn->createStatement(); 
00048     m_readStmt->setSQL("select ecal_JBH4_config_sq.NextVal from dual");
00049     ResultSet* rset = m_readStmt->executeQuery();
00050     while (rset->next ()){
00051       result= rset->getInt(1);
00052     }
00053     m_conn->terminateStatement(m_readStmt);
00054     return result; 
00055 
00056   } catch (SQLException &e) {
00057     throw(std::runtime_error("ODJBH4Config::fetchNextId():  "+e.getMessage()));
00058   }
00059 
00060 }
00061 
00062 void ODJBH4Config::prepareWrite()
00063   throw(std::runtime_error)
00064 {
00065   this->checkConnection();
00066   int next_id=fetchNextId();
00067 
00068   try {
00069     m_writeStmt = m_conn->createStatement();
00070     m_writeStmt->setSQL("INSERT INTO ECAL_Jbh4_CONFIGURATION ( jbh4_configuration_id, jbh4_tag, "
00071                         " useBuffer, halModuleFile, halAddressTableFile, halStaticTableFile, halcbd8210serialnumber, "
00072                         " caenbridgetype, caenlinknumber, caenboardnumber) "
00073                         " VALUES ( :1, :2, :3, :4, :5, :6, :7, :8 , :9, :10 )");
00074 
00075     m_writeStmt->setInt(1, next_id);
00076     m_ID=next_id;
00077   } catch (SQLException &e) {
00078     throw(std::runtime_error("ODJBH4Config::prepareWrite():  "+e.getMessage()));
00079   }
00080 }
00081 
00082 
00083 
00084 void ODJBH4Config::writeDB()
00085   throw(std::runtime_error)
00086 {
00087   this->checkConnection();
00088   this->checkPrepare();
00089 
00090   try {
00091 
00092     // number 1 is the id number 2 is the tag
00093     m_writeStmt->setString(2, this->getConfigTag());
00094 
00095     m_writeStmt->setInt(3, this->getUseBuffer());
00096     m_writeStmt->setString(4,  this->getHalModuleFile() );
00097     m_writeStmt->setString(5, this->getHalAddressTableFile() );
00098     m_writeStmt->setString(6, this->getHalStaticTableFile() );
00099     m_writeStmt->setString(7, this->getCbd8210SerialNumber() );
00100     m_writeStmt->setString(8, this->getCaenBridgeType() );
00101     m_writeStmt->setInt(9, this->getCaenLinkNumber() );
00102     m_writeStmt->setInt(10, this->getCaenBoardNumber() );
00103  
00104     m_writeStmt->executeUpdate();
00105 
00106 
00107   } catch (SQLException &e) {
00108     throw(std::runtime_error("ODJBH4Config::writeDB():  "+e.getMessage()));
00109   }
00110   // Now get the ID
00111   if (!this->fetchID()) {
00112     throw(std::runtime_error("ODJBH4Config::writeDB:  Failed to write"));
00113   }
00114 
00115 }
00116 
00117 
00118 void ODJBH4Config::fetchData(ODJBH4Config * result)
00119   throw(std::runtime_error)
00120 {
00121   this->checkConnection();
00122   result->clear();
00123   if(result->getId()==0){
00124     throw(std::runtime_error("ODJBH4Config::fetchData(): no Id defined for this ODJBH4Config "));
00125   }
00126 
00127   try {
00128 
00129     m_readStmt->setSQL("SELECT * FROM ECAL_Jbh4_CONFIGURATION  "
00130                        " where ( jbh4_configuration_id = :1 or jbh4_tag=:2 )");
00131     m_readStmt->setInt(1, result->getId());
00132     m_readStmt->setString(2, result->getConfigTag());
00133     ResultSet* rset = m_readStmt->executeQuery();
00134 
00135     rset->next();
00136 
00137     result->setId(rset->getInt(1));
00138     result->setConfigTag(rset->getString(2));
00139 
00140     result->setUseBuffer(           rset->getInt(3) );
00141     result->setHalModuleFile(        rset->getString(4) );
00142     result->setHalAddressTableFile(         rset->getString(5) );
00143     result->setHalStaticTableFile(    rset->getString(6) );
00144     result->setCbd8210SerialNumber(        rset->getString(7) );
00145     result->setCaenBridgeType(           rset->getString(8) );
00146     result->setCaenLinkNumber(            rset->getInt(9) );
00147     result->setCaenBoardNumber(              rset->getInt(10) );
00148 
00149   } catch (SQLException &e) {
00150     throw(std::runtime_error("ODJBH4Config::fetchData():  "+e.getMessage()));
00151   }
00152 }
00153 
00154 int ODJBH4Config::fetchID()    throw(std::runtime_error)
00155 {
00156   // Return from memory if available
00157   if (m_ID!=0) {
00158     return m_ID;
00159   }
00160 
00161   this->checkConnection();
00162 
00163   try {
00164     Statement* stmt = m_conn->createStatement();
00165     stmt->setSQL("SELECT jbh4_configuration_id FROM ecal_jbh4_configuration "
00166                  "WHERE  jbh4_tag=:jbh4_tag ");
00167     
00168 
00169     stmt->setString(1, getConfigTag());
00170 
00171     ResultSet* rset = stmt->executeQuery();
00172 
00173     if (rset->next()) {
00174       m_ID = rset->getInt(1);
00175     } else {
00176       m_ID = 0;
00177     }
00178     m_conn->terminateStatement(stmt);
00179   } catch (SQLException &e) {
00180     throw(std::runtime_error("ODJBH4Config::fetchID:  "+e.getMessage()));
00181   }
00182 
00183   return m_ID;
00184 }