31 if (runTypeDef != m_runTypeDef) {
33 m_runTypeDef = runTypeDef;
39 if (runModeDef != m_runModeDef) {
41 m_runModeDef = runModeDef;
49 this->checkConnection();
51 m_readStmt = m_conn->createStatement();
52 m_readStmt->setSQL(
"select ecal_run_sq.NextVal from dual");
53 ResultSet* rset = m_readStmt->executeQuery();
54 while (rset->next()) {
55 result = rset->getInt(1);
57 m_conn->terminateStatement(m_readStmt);
61 throw(std::runtime_error(
"ODDCCConfig::fetchNextId(): " + e.getMessage()));
71 this->checkConnection();
76 Statement* stmt = m_conn->createStatement();
78 "SELECT config_id from ECAL_RUN_CONFIGURATION_DAT " 80 " and version = :version ");
81 stmt->setString(1, m_tag);
82 stmt->setInt(2, m_version);
84 ResultSet* rset = stmt->executeQuery();
86 m_ID = rset->getInt(1);
90 m_conn->terminateStatement(stmt);
92 throw(std::runtime_error(
"ODRunConfigInfo::fetchID: " + e.getMessage()));
99 this->checkConnection();
104 Statement* stmt = m_conn->createStatement();
105 stmt->setSQL(
"SELECT max(config_id) FROM ecal_run_configuration_dat ");
106 ResultSet* rset = stmt->executeQuery();
109 m_ID = rset->getInt(1);
113 m_conn->terminateStatement(stmt);
115 throw(std::runtime_error(
"ODRunConfigInfo::fetchIDLast: " + e.getMessage()));
129 this->checkConnection();
134 Statement* stmt = m_conn->createStatement();
137 "SELECT tag, version, run_type_def_id, run_mode_def_id, num_of_sequences, description, defaults," 138 " trg_mode,num_of_events, db_timestamp, usage_status" 139 " FROM ECAL_RUN_CONFIGURATION_DAT WHERE config_id = :1");
142 ResultSet* rset = stmt->executeQuery();
144 m_tag = rset->getString(1);
145 m_version = rset->getInt(2);
146 int run_type_id = rset->getInt(3);
147 int run_mode_id = rset->getInt(4);
148 m_num_seq = rset->getInt(5);
149 m_description = rset->getString(6);
150 m_defaults = rset->getInt(7);
151 m_trigger_mode = rset->getString(8);
152 m_num_events = rset->getInt(9);
153 Date dbdate = rset->getDate(10);
156 m_runModeDef.setConnection(m_env, m_conn);
157 m_runModeDef.setByID(run_mode_id);
158 m_runTypeDef.setConnection(m_env, m_conn);
159 m_runTypeDef.setByID(run_type_id);
160 m_usage_status = rset->getString(11);
162 throw(std::runtime_error(
"ODRunConfigInfo::setByID: Given config_id is not in the database"));
164 m_conn->terminateStatement(stmt);
166 throw(std::runtime_error(
"ODRunConfigInfo::setByID: " + e.getMessage()));
171 this->checkConnection();
173 int next_id = fetchNextId();
176 m_writeStmt = m_conn->createStatement();
178 "INSERT INTO ECAL_RUN_CONFIGURATION_DAT (CONFIG_ID, tag, version, run_type_def_id, " 179 " run_mode_def_id, num_of_sequences, defaults, trg_mode, num_of_events, description, usage_status ) " 180 " VALUES (:1, :2, :3 , :4, :5, :6 ,:7, :8, :9, :10 , :11)");
182 m_writeStmt->setInt(1, next_id);
186 throw(std::runtime_error(
"ODRunConfigInfo::prepareWrite(): " + e.getMessage()));
191 this->checkConnection();
192 this->checkPrepare();
199 m_runModeDef.setConnection(m_env, m_conn);
200 int run_mode_id = m_runModeDef.fetchID();
203 m_runTypeDef.setConnection(m_env, m_conn);
204 int run_type_id = m_runTypeDef.fetchID();
208 m_writeStmt->setString(2, this->getTag());
209 m_writeStmt->setInt(3, this->getVersion());
210 m_writeStmt->setInt(4, run_type_id);
211 m_writeStmt->setInt(5, run_mode_id);
212 m_writeStmt->setInt(6, this->getNumberOfSequences());
213 m_writeStmt->setInt(7, this->getDefaults());
214 m_writeStmt->setString(8, this->getTriggerMode());
215 m_writeStmt->setInt(9, this->getNumberOfEvents());
216 m_writeStmt->setString(10, this->getDescription());
217 m_writeStmt->setString(11, this->getUsageStatus());
219 m_writeStmt->executeUpdate();
222 throw(std::runtime_error(
"ODRunConfigInfo::writeDB: " + e.getMessage()));
225 if (!this->fetchID()) {
226 throw(std::runtime_error(
"ODRunConfigInfo::writeDB Failed to write"));
231 cout <<
"ODRunConfigInfo::writeDB>> done inserting ODRunConfigInfo with id=" << m_ID << endl;
235 this->checkConnection();
238 if (!this->fetchID()) {
243 Statement* stmt = m_conn->createStatement();
245 stmt->setSQL(
"UPDATE ecal_run_configuration_dat set defaults=:1 where config_id=:2 ");
247 stmt->setInt(1, m_defaults);
248 stmt->setInt(2, m_ID);
250 stmt->executeUpdate();
252 m_conn->terminateStatement(stmt);
254 throw(std::runtime_error(
"ODRunConfigInfo::writeDB: " + e.getMessage()));
270 this->checkConnection();
274 if (
result->getId() == 0) {
280 "SELECT config_id, tag, version, run_type_def_id, run_mode_def_id, \ 281 num_of_sequences, description, defaults, trg_mode, num_of_events, db_timestamp, usage_status \ 282 FROM ECAL_RUN_CONFIGURATION_DAT WHERE config_id = :1 ");
283 m_readStmt->setInt(1,
result->getId());
285 ResultSet* rset = m_readStmt->executeQuery();
288 result->setId(rset->getInt(1));
289 result->setTag(rset->getString(2));
290 result->setVersion(rset->getInt(3));
295 result->setNumberOfSequences(rset->getInt(6));
296 result->setDescription(rset->getString(7));
297 result->setDefaults(rset->getInt(8));
298 result->setTriggerMode(rset->getString(9));
299 result->setNumberOfEvents(rset->getInt(10));
300 Date dbdate = rset->getDate(11);
302 result->setUsageStatus(rset->getString(12));
305 cout <<
" ODRunConfigInfo::fetchData(): " << e.getMessage() << endl;
306 throw(std::runtime_error(
"ODRunConfigInfo::fetchData(): " + e.getMessage()));
int fetchIDLast() noexcept(false)
RunModeDef getRunModeDef() const
int fetchIDFromTagAndVersion() noexcept(false)
void writeDB() noexcept(false)
int fetchID() noexcept(false)
void setRunModeDef(const RunModeDef &runModeDef)
void setRunTypeDef(const RunTypeDef &runTypeDef)
int fetchNextId() noexcept(false)
~ODRunConfigInfo() override
int updateDefaultCycle() noexcept(false)
void setByID(int id) noexcept(false)
oracle::occi::Statement Statement
RunTypeDef getRunTypeDef() const
void fetchData(ODRunConfigInfo *result) noexcept(false)
oracle::occi::SQLException SQLException
void prepareWrite() noexcept(false) override
Tm dateToTm(oracle::occi::Date &date) const