#include <ODTowersToByPassInfo.h>
Public Member Functions | |
int | fetchID () throw (std::runtime_error) |
int | fetchNextId () throw (std::runtime_error) |
int | getId () const |
std::string | getTable () |
int | getVersion () const |
ODTowersToByPassInfo () | |
void | setId (int id) |
void | setParameters (std::map< std::string, std::string > my_keys_map) |
void | setVersion (int id) |
~ODTowersToByPassInfo () | |
Private Member Functions | |
void | clear () |
void | fetchData (ODTowersToByPassInfo *result) throw (std::runtime_error) |
void | prepareWrite () throw (std::runtime_error) |
void | writeDB () throw (std::runtime_error) |
Private Attributes | |
int | m_ID |
int | m_version |
Friends | |
class | EcalCondDBInterface |
Definition at line 9 of file ODTowersToByPassInfo.h.
ODTowersToByPassInfo::ODTowersToByPassInfo | ( | ) |
Definition at line 11 of file ODTowersToByPassInfo.cc.
References NULL.
{ m_env = NULL; m_conn = NULL; m_writeStmt = NULL; m_readStmt = NULL; m_config_tag=""; m_ID=0; m_version=0; clear(); }
ODTowersToByPassInfo::~ODTowersToByPassInfo | ( | ) |
Definition at line 30 of file ODTowersToByPassInfo.cc.
{ }
void ODTowersToByPassInfo::clear | ( | void | ) | [private] |
Definition at line 24 of file ODTowersToByPassInfo.cc.
{ }
void ODTowersToByPassInfo::fetchData | ( | ODTowersToByPassInfo * | result | ) | throw (std::runtime_error) [private] |
Definition at line 130 of file ODTowersToByPassInfo.cc.
References query::result.
{ this->checkConnection(); result->clear(); if(result->getId()==0 && (result->getConfigTag()=="") ){ throw(std::runtime_error("ODTowersToByPassInfo::fetchData(): no Id defined for this ODTowersToByPassInfo ")); } try { if(result->getId()!=0) { m_readStmt->setSQL("SELECT * FROM " + getTable() + " where rec_id = :1 "); m_readStmt->setInt(1, result->getId()); } else if (result->getConfigTag()!="") { if(result->getVersion() !=0){ m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE tag = :tag " " and version = :version " ); m_readStmt->setString(1, result->getConfigTag()); m_readStmt->setInt(2, result->getVersion()); } else { // always select the last inserted one with a given tag m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE tag = :1 and version= (select max(version) from "+getTable() +" where tag=:2) " ); m_readStmt->setString(1, result->getConfigTag()); m_readStmt->setString(2, result->getConfigTag()); } } else { // we should never pass here throw(std::runtime_error("ODTowersToByPassInfo::fetchData(): no Id defined for this record ")); } ResultSet* rset = m_readStmt->executeQuery(); rset->next(); // 1 is the id and 2 is the config tag and 3 is the version result->setId(rset->getInt(1)); result->setConfigTag(rset->getString(2)); result->setVersion(rset->getInt(3)); } catch (SQLException &e) { throw(std::runtime_error("ODTowersToByPassInfo::fetchData(): "+e.getMessage())); } }
int ODTowersToByPassInfo::fetchID | ( | ) | throw (std::runtime_error) |
Definition at line 183 of file ODTowersToByPassInfo.cc.
{ // Return from memory if available if (m_ID!=0) { return m_ID; } this->checkConnection(); try { Statement* stmt = m_conn->createStatement(); stmt->setSQL("SELECT rec_id FROM "+ getTable()+ " WHERE tag=:1 and version=:2 " ); stmt->setString(1, getConfigTag() ); stmt->setInt(2, getVersion() ); ResultSet* rset = stmt->executeQuery(); if (rset->next()) { m_ID = rset->getInt(1); } else { m_ID = 0; } m_conn->terminateStatement(stmt); } catch (SQLException &e) { throw(std::runtime_error("ODTowersToByPassInfo::fetchID: "+e.getMessage())); } return m_ID; }
int ODTowersToByPassInfo::fetchNextId | ( | ) | throw (std::runtime_error) |
Definition at line 36 of file ODTowersToByPassInfo.cc.
References query::result.
{ int result=0; try { this->checkConnection(); m_readStmt = m_conn->createStatement(); m_readStmt->setSQL("select COND2CONF_INFO_SQ.NextVal from DUAL "); ResultSet* rset = m_readStmt->executeQuery(); while (rset->next ()){ result= rset->getInt(1); } result++; m_conn->terminateStatement(m_readStmt); return result; } catch (SQLException &e) { throw(std::runtime_error("ODTowersToByPassInfo::fetchNextId(): "+e.getMessage())); } }
int ODTowersToByPassInfo::getId | ( | ) | const [inline] |
std::string ODTowersToByPassInfo::getTable | ( | ) | [inline, virtual] |
Implements IODConfig.
Definition at line 16 of file ODTowersToByPassInfo.h.
{ return "TOWERS_TO_BYPASS_INFO"; }
int ODTowersToByPassInfo::getVersion | ( | ) | const [inline] |
void ODTowersToByPassInfo::prepareWrite | ( | ) | throw (std::runtime_error) [private, virtual] |
Implements IODConfig.
Definition at line 58 of file ODTowersToByPassInfo.cc.
References getId().
{ this->checkConnection(); int next_id=0; if(getId()==0){ next_id=fetchNextId(); } try { m_writeStmt = m_conn->createStatement(); m_writeStmt->setSQL("INSERT INTO "+getTable()+" ( rec_id, tag, version) " " VALUES ( :1, :2, :3 ) " ); m_writeStmt->setInt(1, next_id); m_ID=next_id; } catch (SQLException &e) { throw(std::runtime_error("ODTowersToByPassInfo::prepareWrite(): "+e.getMessage())); } }
void ODTowersToByPassInfo::setId | ( | int | id | ) | [inline] |
void ODTowersToByPassInfo::setParameters | ( | std::map< std::string, std::string > | my_keys_map | ) |
void ODTowersToByPassInfo::setVersion | ( | int | id | ) | [inline] |
void ODTowersToByPassInfo::writeDB | ( | ) | throw (std::runtime_error) [private] |
Definition at line 97 of file ODTowersToByPassInfo.cc.
References gather_cfg::cout.
{ this->checkConnection(); this->checkPrepare(); try { // number 1 is the id m_writeStmt->setString(2, this->getConfigTag()); m_writeStmt->setInt(3, this->getVersion()); m_writeStmt->executeUpdate(); } catch (SQLException &e) { throw(std::runtime_error("ODTowersToByPassInfo::writeDB(): "+e.getMessage())); } // Now get the ID if (!this->fetchID()) { throw(std::runtime_error("ODTowersToByPassInfo::writeDB: Failed to write")); } else { int old_version=this->getVersion(); m_readStmt = m_conn->createStatement(); this->fetchData (this); m_conn->terminateStatement(m_readStmt); if(this->getVersion()!=old_version) std::cout << "ODTowersToByPassInfo>>WARNING version is "<< getVersion()<< endl; } }
friend class EcalCondDBInterface [friend] |
Reimplemented from IDBObject.
Definition at line 11 of file ODTowersToByPassInfo.h.
int ODTowersToByPassInfo::m_ID [private] |
Definition at line 42 of file ODTowersToByPassInfo.h.
int ODTowersToByPassInfo::m_version [private] |
Definition at line 43 of file ODTowersToByPassInfo.h.
Referenced by getVersion(), and setVersion().