#include <OnlineDB/EcalCondDB/interface/RunSeqDef.h>
Public Member Functions | |
int | fetchID () throw (std::runtime_error) |
std::string | getRunSeq () const |
RunTypeDef | getRunTypeDef () const |
bool | operator!= (const RunSeqDef &t) const |
bool | operator== (const RunSeqDef &t) const |
RunSeqDef () | |
void | setByID (int id) throw (std::runtime_error) |
void | setRunSeq (std::string runseq) |
void | setRunTypeDef (const RunTypeDef runTypeDef) |
virtual | ~RunSeqDef () |
Protected Member Functions | |
void | fetchAllDefs (std::vector< RunSeqDef > *fillVec) throw (std::runtime_error) |
int | writeDB () throw (std::runtime_error) |
Protected Attributes | |
std::string | m_runSeq |
RunTypeDef | m_runType |
Friends | |
class | EcalCondDBInterface |
class | ODRunConfigSeqInfo |
Definition at line 13 of file RunSeqDef.h.
RunSeqDef::RunSeqDef | ( | ) |
Definition at line 9 of file RunSeqDef.cc.
References IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_runSeq, m_runType, and NULL.
00010 { 00011 m_env = NULL; 00012 m_conn = NULL; 00013 m_ID = 0; 00014 m_runSeq = ""; 00015 m_runType = RunTypeDef(); 00016 }
RunSeqDef::~RunSeqDef | ( | ) | [virtual] |
void RunSeqDef::fetchAllDefs | ( | std::vector< RunSeqDef > * | fillVec | ) | throw (std::runtime_error) [protected] |
Definition at line 118 of file RunSeqDef.cc.
References IDBObject::checkConnection(), e, IDBObject::m_conn, IDBObject::m_env, setByID(), and IDBObject::setConnection().
00120 { 00121 this->checkConnection(); 00122 try { 00123 Statement* stmt = m_conn->createStatement(); 00124 stmt->setSQL("SELECT def_id FROM ecal_sequence_type_def ORDER BY def_id"); 00125 ResultSet* rset = stmt->executeQuery(); 00126 00127 RunSeqDef runSeqDef; 00128 runSeqDef.setConnection(m_env, m_conn); 00129 00130 while(rset->next()) { 00131 runSeqDef.setByID( rset->getInt(1) ); 00132 fillVec->push_back( runSeqDef ); 00133 } 00134 } catch (SQLException &e) { 00135 throw(runtime_error("RunSeqDef::fetchAllDefs: "+e.getMessage())); 00136 } 00137 }
int RunSeqDef::fetchID | ( | ) | throw (std::runtime_error) [virtual] |
Implements IUniqueDBObject.
Definition at line 44 of file RunSeqDef.cc.
References IDBObject::checkConnection(), e, RunTypeDef::fetchID(), IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_runSeq, m_runType, and IDBObject::setConnection().
00046 { 00047 // Return def from memory if available 00048 if (m_ID) { 00049 return m_ID; 00050 } 00051 00052 this->checkConnection(); 00053 00054 00055 // get the run type 00056 m_runType.setConnection(m_env, m_conn); 00057 int run_type_id = m_runType.fetchID(); 00058 00059 00060 try { 00061 Statement* stmt = m_conn->createStatement(); 00062 stmt->setSQL("SELECT def_id FROM ecal_sequence_type_def WHERE " 00063 " run_type_def_id = :1 and sequence_type_string = :2 " 00064 ); 00065 00066 stmt->setInt(1, run_type_id); 00067 stmt->setString(2, m_runSeq); 00068 00069 ResultSet* rset = stmt->executeQuery(); 00070 00071 if (rset->next()) { 00072 m_ID = rset->getInt(1); 00073 } else { 00074 m_ID = 0; 00075 } 00076 m_conn->terminateStatement(stmt); 00077 } catch (SQLException &e) { 00078 throw(runtime_error("RunSeqDef::fetchID: "+e.getMessage())); 00079 } 00080 00081 return m_ID; 00082 }
string RunSeqDef::getRunSeq | ( | ) | const |
RunTypeDef RunSeqDef::getRunTypeDef | ( | ) | const |
Definition at line 32 of file RunSeqDef.cc.
References m_runType.
00033 { 00034 return m_runType; 00035 }
Implements IUniqueDBObject.
Definition at line 86 of file RunSeqDef.cc.
References IDBObject::checkConnection(), e, IDBObject::m_conn, IDBObject::m_env, m_runSeq, m_runType, RunTypeDef::setByID(), and IDBObject::setConnection().
Referenced by fetchAllDefs(), ODRunConfigSeqInfo::fetchData(), and ODRunConfigSeqInfo::setByID().
00088 { 00089 this->checkConnection(); 00090 00091 try { 00092 Statement* stmt = m_conn->createStatement(); 00093 00094 stmt->setSQL("SELECT run_type_def_id, sequence_type_string FROM ecal_sequence_type_def WHERE def_id = :1"); 00095 stmt->setInt(1, id); 00096 00097 int idruntype=0; 00098 ResultSet* rset = stmt->executeQuery(); 00099 if (rset->next()) { 00100 idruntype = rset->getInt(1); 00101 m_runSeq = rset->getString(2); 00102 } else { 00103 throw(runtime_error("RunSeqDef::setByID: Given def_id is not in the database")); 00104 } 00105 00106 m_conn->terminateStatement(stmt); 00107 00108 m_runType.setConnection(m_env, m_conn); 00109 m_runType.setByID(idruntype); 00110 00111 } catch (SQLException &e) { 00112 throw(runtime_error("RunSeqDef::setByID: "+e.getMessage())); 00113 } 00114 }
void RunSeqDef::setRunSeq | ( | std::string | runseq | ) |
void RunSeqDef::setRunTypeDef | ( | const RunTypeDef | runTypeDef | ) |
Definition at line 37 of file RunSeqDef.cc.
References m_runType.
00038 { 00039 m_runType = runTypeDef; 00040 }
int RunSeqDef::writeDB | ( | ) | throw (std::runtime_error) [protected] |
Definition at line 139 of file RunSeqDef.cc.
References IDBObject::checkConnection(), e, RunTypeDef::fetchID(), IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_runSeq, m_runType, and IDBObject::setConnection().
Referenced by ODRunConfigSeqInfo::writeDB().
00141 { 00142 // see if this data is already in the DB 00143 try { 00144 if (this->fetchID()) { 00145 return m_ID; 00146 } 00147 } catch (SQLException &e) { 00148 // it does not exist yet 00149 } 00150 00151 // check the connectioin 00152 this->checkConnection(); 00153 00154 // get the run type 00155 m_runType.setConnection(m_env, m_conn); 00156 int run_type_id = m_runType.fetchID(); 00157 00158 // write new seq def to the DB 00159 try { 00160 Statement* stmt = m_conn->createStatement(); 00161 00162 stmt->setSQL("insert into ecal_sequence_type_def(RUN_TYPE_DEF_ID, SEQUENCE_TYPE_STRING) values " 00163 " ( :1, :2 )"); 00164 stmt->setInt(1, run_type_id); 00165 stmt->setString(2, m_runSeq); 00166 00167 00168 stmt->executeUpdate(); 00169 00170 m_conn->terminateStatement(stmt); 00171 } catch (SQLException &e) { 00172 throw(runtime_error("RunSeqDef::writeDB: "+e.getMessage())); 00173 } 00174 00175 // now get the tag_id 00176 if (!this->fetchID()) { 00177 throw(runtime_error("RunSeqDef::writeDB: Failed to write")); 00178 } 00179 00180 return m_ID; 00181 }
friend class EcalCondDBInterface [friend] |
friend class ODRunConfigSeqInfo [friend] |
Definition at line 15 of file RunSeqDef.h.
std::string RunSeqDef::m_runSeq [protected] |
Definition at line 42 of file RunSeqDef.h.
Referenced by fetchID(), getRunSeq(), operator!=(), operator==(), RunSeqDef(), setByID(), and writeDB().
RunTypeDef RunSeqDef::m_runType [protected] |
Definition at line 43 of file RunSeqDef.h.
Referenced by fetchID(), getRunTypeDef(), RunSeqDef(), setByID(), setRunTypeDef(), and writeDB().