#include <OnlineDB/EcalCondDB/interface/ODDCUConfig.h>
Public Member Functions | |
int | getId () const |
std::string | getTable () |
ODDCUConfig () | |
void | setId (int id) |
void | setParameters (std::map< string, string > my_keys_map) |
~ODDCUConfig () | |
Private Member Functions | |
void | clear () |
void | fetchData (ODDCUConfig *result) throw (std::runtime_error) |
int | fetchID () throw (std::runtime_error) |
int | fetchNextId () throw (std::runtime_error) |
void | prepareWrite () throw (std::runtime_error) |
void | writeDB () throw (std::runtime_error) |
Private Attributes | |
int | m_ID |
Friends | |
class | EcalCondDBInterface |
Definition at line 15 of file ODDCUConfig.h.
ODDCUConfig::ODDCUConfig | ( | ) |
Definition at line 10 of file ODDCUConfig.cc.
References clear(), IODConfig::m_config_tag, IDBObject::m_conn, IDBObject::m_env, m_ID, IODConfig::m_readStmt, IODConfig::m_writeStmt, and NULL.
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 }
ODDCUConfig::~ODDCUConfig | ( | ) |
void ODDCUConfig::fetchData | ( | ODDCUConfig * | result | ) | throw (std::runtime_error) [private] |
Definition at line 113 of file ODDCUConfig.cc.
References IDBObject::checkConnection(), e, IODConfig::m_readStmt, and HLT_VtxMuL3::result.
00115 { 00116 this->checkConnection(); 00117 result->clear(); 00118 if(result->getId()==0 && (result->getConfigTag()=="") ){ 00119 throw(runtime_error("ODDCUConfig::fetchData(): no Id defined for this ODDCUConfig ")); 00120 } 00121 00122 try { 00123 00124 m_readStmt->setSQL("SELECT * " 00125 "FROM ECAL_DCU_CONFIGURATION " 00126 " where ( dcu_configuration_id = :1 or dcu_tag=:2 ) " ); 00127 m_readStmt->setInt(1, result->getId()); 00128 m_readStmt->setString(2, result->getConfigTag()); 00129 ResultSet* rset = m_readStmt->executeQuery(); 00130 00131 rset->next(); 00132 // 1 is the id and 2 is the config tag 00133 result->setId(rset->getInt(1)); 00134 result->setConfigTag(rset->getString(2)); 00135 00136 00137 } catch (SQLException &e) { 00138 throw(runtime_error("ODDCUConfig::fetchData(): "+e.getMessage())); 00139 } 00140 }
int ODDCUConfig::fetchID | ( | ) | throw (std::runtime_error) [private] |
Definition at line 142 of file ODDCUConfig.cc.
References IDBObject::checkConnection(), e, IODConfig::getConfigTag(), IDBObject::m_conn, and m_ID.
00143 { 00144 // Return from memory if available 00145 if (m_ID!=0) { 00146 return m_ID; 00147 } 00148 00149 this->checkConnection(); 00150 00151 try { 00152 Statement* stmt = m_conn->createStatement(); 00153 stmt->setSQL("SELECT dcu_configuration_id FROM ecal_dcu_configuration " 00154 "WHERE dcu_tag=:dcu_tag " ); 00155 00156 stmt->setString(1, getConfigTag()); 00157 00158 ResultSet* rset = stmt->executeQuery(); 00159 00160 if (rset->next()) { 00161 m_ID = rset->getInt(1); 00162 } else { 00163 m_ID = 0; 00164 } 00165 m_conn->terminateStatement(stmt); 00166 } catch (SQLException &e) { 00167 throw(runtime_error("ODDCUConfig::fetchID: "+e.getMessage())); 00168 } 00169 00170 return m_ID; 00171 }
int ODDCUConfig::fetchNextId | ( | ) | throw (std::runtime_error) [private] |
Definition at line 44 of file ODDCUConfig.cc.
References IDBObject::checkConnection(), e, IDBObject::m_conn, IODConfig::m_readStmt, and HLT_VtxMuL3::result.
Referenced by prepareWrite().
00044 { 00045 00046 int result=0; 00047 try { 00048 this->checkConnection(); 00049 00050 m_readStmt = m_conn->createStatement(); 00051 m_readStmt->setSQL("select ecal_dcu_config_sq.NextVal from dual"); 00052 ResultSet* rset = m_readStmt->executeQuery(); 00053 while (rset->next ()){ 00054 result= rset->getInt(1); 00055 } 00056 m_conn->terminateStatement(m_readStmt); 00057 return result; 00058 00059 } catch (SQLException &e) { 00060 throw(runtime_error("ODDCUConfig::fetchNextId(): "+e.getMessage())); 00061 } 00062 00063 }
int ODDCUConfig::getId | ( | ) | const [inline] |
std::string ODDCUConfig::getTable | ( | ) | [inline, virtual] |
void ODDCUConfig::prepareWrite | ( | ) | throw (std::runtime_error) [private, virtual] |
Implements IODConfig.
Definition at line 66 of file ODDCUConfig.cc.
References IDBObject::checkConnection(), e, fetchNextId(), IDBObject::m_conn, m_ID, and IODConfig::m_writeStmt.
00068 { 00069 this->checkConnection(); 00070 int next_id=fetchNextId(); 00071 00072 try { 00073 m_writeStmt = m_conn->createStatement(); 00074 m_writeStmt->setSQL("INSERT INTO ECAL_DCU_CONFIGURATION ( dcu_configuration_id, dcu_tag ) " 00075 "VALUES ( " 00076 ":1, :2 )"); 00077 m_writeStmt->setInt(1, next_id); 00078 m_ID=next_id; 00079 00080 } catch (SQLException &e) { 00081 throw(runtime_error("ODDCUConfig::prepareWrite(): "+e.getMessage())); 00082 } 00083 }
void ODDCUConfig::setParameters | ( | std::map< string, string > | my_keys_map | ) |
Definition at line 31 of file ODDCUConfig.cc.
References IODConfig::setConfigTag().
00031 { 00032 00033 // parses the result of the XML parser that is a map of 00034 // string string with variable name variable value 00035 00036 for( std::map<std::string, std::string >::iterator ci= 00037 my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) { 00038 00039 if(ci->first== "DCU_CONFIGURATION_ID") setConfigTag(ci->second); 00040 } 00041 00042 }
void ODDCUConfig::writeDB | ( | ) | throw (std::runtime_error) [private] |
Definition at line 87 of file ODDCUConfig.cc.
References IDBObject::checkConnection(), IODConfig::checkPrepare(), e, and IODConfig::m_writeStmt.
00089 { 00090 this->checkConnection(); 00091 this->checkPrepare(); 00092 00093 try { 00094 00095 m_writeStmt->setString(2, this->getConfigTag()); 00096 00097 m_writeStmt->executeUpdate(); 00098 00099 00100 } catch (SQLException &e) { 00101 throw(runtime_error("ODDCUConfig::writeDB(): "+e.getMessage())); 00102 } 00103 // Now get the ID 00104 if (!this->fetchID()) { 00105 throw(runtime_error("ODDCUConfig::writeDB: Failed to write")); 00106 } 00107 00108 00109 }
friend class EcalCondDBInterface [friend] |
int ODDCUConfig::m_ID [private] |
Definition at line 40 of file ODDCUConfig.h.
Referenced by fetchID(), getId(), ODDCUConfig(), prepareWrite(), and setId().