9 using namespace oracle::occi;
38 if (runTypeDef != m_runTypeDef) {
40 m_runTypeDef = runTypeDef;
47 if (runModeDef != m_runModeDef) {
49 m_runModeDef = runModeDef;
58 this->checkConnection();
60 m_readStmt = m_conn->createStatement();
61 m_readStmt->setSQL(
"select ecal_run_sq.NextVal from dual");
62 ResultSet* rset = m_readStmt->executeQuery();
63 while (rset->next ()){
64 result= rset->getInt(1);
66 m_conn->terminateStatement(m_readStmt);
70 throw(std::runtime_error(
"ODDCCConfig::fetchNextId(): "+e.getMessage()));
76 throw(std::runtime_error)
83 this->checkConnection();
89 Statement* stmt = m_conn->createStatement();
90 stmt->setSQL(
"SELECT config_id from ECAL_RUN_CONFIGURATION_DAT "
92 " and version = :version " );
93 stmt->setString(1, m_tag);
94 stmt->setInt(2, m_version);
98 m_ID = rset->getInt(1);
102 m_conn->terminateStatement(stmt);
104 throw(std::runtime_error(
"ODRunConfigInfo::fetchID: "+e.getMessage()));
113 throw(std::runtime_error)
116 this->checkConnection();
121 Statement* stmt = m_conn->createStatement();
122 stmt->setSQL(
"SELECT max(config_id) FROM ecal_run_configuration_dat " );
126 m_ID = rset->getInt(1);
130 m_conn->terminateStatement(stmt);
132 throw(std::runtime_error(
"ODRunConfigInfo::fetchIDLast: "+e.getMessage()));
141 throw(std::runtime_error)
150 throw(std::runtime_error)
152 this->checkConnection();
157 Statement* stmt = m_conn->createStatement();
159 stmt->setSQL(
"SELECT tag, version, run_type_def_id, run_mode_def_id, num_of_sequences, description, defaults,"
160 " trg_mode,num_of_events, db_timestamp, usage_status"
161 " FROM ECAL_RUN_CONFIGURATION_DAT WHERE config_id = :1");
166 m_tag= rset->getString(1);
167 m_version= rset->getInt(2);
168 int run_type_id=rset->getInt(3);
169 int run_mode_id=rset->getInt(4);
170 m_num_seq=rset->getInt(5);
171 m_description= rset->getString(6);
172 m_defaults= rset->getInt(7);
173 m_trigger_mode= rset->getString(8);
174 m_num_events= rset->getInt(9);
175 Date dbdate = rset->getDate(10);
178 m_runModeDef.setConnection(m_env, m_conn);
179 m_runModeDef.setByID(run_mode_id);
180 m_runTypeDef.setConnection(m_env, m_conn);
181 m_runTypeDef.setByID(run_type_id);
182 m_usage_status=rset->getString(11);
184 throw(std::runtime_error(
"ODRunConfigInfo::setByID: Given config_id is not in the database"));
186 m_conn->terminateStatement(stmt);
188 throw(std::runtime_error(
"ODRunConfigInfo::setByID: "+e.getMessage()));
193 throw(std::runtime_error)
195 this->checkConnection();
197 int next_id=fetchNextId();
203 m_writeStmt = m_conn->createStatement();
204 m_writeStmt->setSQL(
"INSERT INTO ECAL_RUN_CONFIGURATION_DAT (CONFIG_ID, tag, version, run_type_def_id, "
205 " run_mode_def_id, num_of_sequences, defaults, trg_mode, num_of_events, description, usage_status ) "
206 " VALUES (:1, :2, :3 , :4, :5, :6 ,:7, :8, :9, :10 , :11)");
208 m_writeStmt->setInt(1, next_id);
212 throw(std::runtime_error(
"ODRunConfigInfo::prepareWrite(): "+e.getMessage()));
218 throw(std::runtime_error)
220 this->checkConnection();
221 this->checkPrepare();
229 m_runModeDef.setConnection(m_env, m_conn);
230 int run_mode_id = m_runModeDef.fetchID();
233 m_runTypeDef.setConnection(m_env, m_conn);
234 int run_type_id = m_runTypeDef.fetchID();
238 m_writeStmt->setString(2, this->getTag());
239 m_writeStmt->setInt(3, this->getVersion());
240 m_writeStmt->setInt(4, run_type_id);
241 m_writeStmt->setInt(5, run_mode_id);
242 m_writeStmt->setInt(6, this->getNumberOfSequences());
243 m_writeStmt->setInt(7, this->getDefaults());
244 m_writeStmt->setString(8, this->getTriggerMode());
245 m_writeStmt->setInt(9, this->getNumberOfEvents());
246 m_writeStmt->setString(10, this->getDescription());
247 m_writeStmt->setString(11, this->getUsageStatus());
249 m_writeStmt->executeUpdate();
252 throw(std::runtime_error(
"ODRunConfigInfo::writeDB: "+e.getMessage()));
255 if (!this->fetchID()) {
256 throw(std::runtime_error(
"ODRunConfigInfo::writeDB Failed to write"));
261 cout<<
"ODRunConfigInfo::writeDB>> done inserting ODRunConfigInfo with id="<<m_ID<<endl;
266 throw(std::runtime_error)
268 this->checkConnection();
271 if(!this->fetchID()){
277 Statement* stmt = m_conn->createStatement();
279 stmt->setSQL(
"UPDATE ecal_run_configuration_dat set defaults=:1 where config_id=:2 " );
281 stmt->setInt(1, m_defaults);
282 stmt->setInt(2, m_ID);
284 stmt->executeUpdate();
286 m_conn->terminateStatement(stmt);
288 throw(std::runtime_error(
"ODRunConfigInfo::writeDB: "+e.getMessage()));
304 throw(std::runtime_error)
306 this->checkConnection();
315 m_readStmt->setSQL(
"SELECT config_id, tag, version, run_type_def_id, run_mode_def_id, \
316 num_of_sequences, description, defaults, trg_mode, num_of_events, db_timestamp, usage_status \
317 FROM ECAL_RUN_CONFIGURATION_DAT WHERE config_id = :1 ");
318 m_readStmt->setInt(1,
result->getId());
320 ResultSet* rset = m_readStmt->executeQuery();
323 result->setId( rset->getInt(1) );
324 result->setTag( rset->getString(2) );
325 result->setVersion( rset->getInt(3) );
330 result->setNumberOfSequences(rset->getInt(6) );
331 result->setDescription( rset->getString(7) );
332 result->setDefaults( rset->getInt(8) );
333 result->setTriggerMode( rset->getString(9) );
334 result->setNumberOfEvents( rset->getInt(10) );
335 Date dbdate = rset->getDate(11);
337 result->setUsageStatus( rset->getString(12) );
340 cout <<
" ODRunConfigInfo::fetchData(): " << e.getMessage() << endl;
341 throw(std::runtime_error(
"ODRunConfigInfo::fetchData(): "+e.getMessage()));
RunModeDef getRunModeDef() const
void fetchData(ODRunConfigInfo *result)
void setRunModeDef(const RunModeDef &runModeDef)
void setRunTypeDef(const RunTypeDef &runTypeDef)
int fetchIDFromTagAndVersion()
oracle::occi::Statement Statement
RunTypeDef getRunTypeDef() const
oracle::occi::ResultSet ResultSet
oracle::occi::SQLException SQLException
Tm dateToTm(oracle::occi::Date &date) const