Go to the documentation of this file.00001 #include <string>
00002 #include "OnlineDB/Oracle/interface/Oracle.h"
00003
00004 #include "OnlineDB/EcalCondDB/interface/RunSeqDef.h"
00005
00006 using namespace std;
00007 using namespace oracle::occi;
00008
00009 RunSeqDef::RunSeqDef()
00010 {
00011 m_env = NULL;
00012 m_conn = NULL;
00013 m_ID = 0;
00014 m_runSeq = "";
00015 m_runType = RunTypeDef();
00016 }
00017
00018
00019
00020 RunSeqDef::~RunSeqDef()
00021 {
00022 }
00023
00024
00025
00026 string RunSeqDef::getRunSeq() const { return m_runSeq;}
00027
00028
00029
00030 void RunSeqDef::setRunSeq(string runseq){ m_runSeq = runseq;}
00031
00032 RunTypeDef RunSeqDef::getRunTypeDef() const
00033 {
00034 return m_runType;
00035 }
00036
00037 void RunSeqDef::setRunTypeDef(const RunTypeDef runTypeDef)
00038 {
00039 m_runType = runTypeDef;
00040 }
00041
00042
00043
00044 int RunSeqDef::fetchID()
00045 throw(std::runtime_error)
00046 {
00047
00048 if (m_ID) {
00049 return m_ID;
00050 }
00051
00052 this->checkConnection();
00053
00054
00055
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(std::runtime_error("RunSeqDef::fetchID: "+e.getMessage()));
00079 }
00080
00081 return m_ID;
00082 }
00083
00084
00085
00086 void RunSeqDef::setByID(int id)
00087 throw(std::runtime_error)
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(std::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(std::runtime_error("RunSeqDef::setByID: "+e.getMessage()));
00113 }
00114 }
00115
00116
00117
00118 void RunSeqDef::fetchAllDefs( std::vector<RunSeqDef>* fillVec)
00119 throw(std::runtime_error)
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(std::runtime_error("RunSeqDef::fetchAllDefs: "+e.getMessage()));
00136 }
00137 }
00138
00139 int RunSeqDef::writeDB()
00140 throw(std::runtime_error)
00141 {
00142
00143 try {
00144 if (this->fetchID()) {
00145 return m_ID;
00146 }
00147 } catch (SQLException &e) {
00148
00149 }
00150
00151
00152 this->checkConnection();
00153
00154
00155 m_runType.setConnection(m_env, m_conn);
00156 int run_type_id = m_runType.fetchID();
00157
00158
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(std::runtime_error("RunSeqDef::writeDB: "+e.getMessage()));
00173 }
00174
00175
00176 if (!this->fetchID()) {
00177 throw(std::runtime_error("RunSeqDef::writeDB: Failed to write"));
00178 }
00179
00180 return m_ID;
00181 }
00182