10 using namespace oracle::occi;
38 if (iov != m_runIOV) {
52 if (subrun != m_subRunNum) {
69 if (start != m_subRunStart) {
71 m_subRunStart =
start;
86 if (end != m_subRunEnd) {
102 throw(std::runtime_error)
109 this->checkConnection();
113 this->fetchParentIDs(&runIOVID);
121 if (m_subRunEnd.isNull()) {
126 Statement* stmt = m_conn->createStatement();
127 stmt->setSQL(
"SELECT iov_id FROM OD_run_iov "
129 "run_iov_id = :1 AND "
130 "subrun_num = :2 AND "
131 "subrun_start = :3 AND "
134 stmt->setInt(1, runIOVID);
135 stmt->setInt(2, m_subRunNum);
136 stmt->setDate(3, dh.
tmToDate(m_subRunStart));
137 stmt->setDate(4, dh.
tmToDate(m_subRunEnd));
142 m_ID = rset->getInt(1);
146 m_conn->terminateStatement(stmt);
148 throw(std::runtime_error(
"MODRunIOV::fetchID: "+e.getMessage()));
157 throw(std::runtime_error)
159 this->checkConnection();
164 Statement* stmt = m_conn->createStatement();
166 stmt->setSQL(
"SELECT run_iov_id, subrun_num, subrun_start, subrun_end FROM OD_run_iov WHERE iov_id = :1");
171 int runIOVID = rset->getInt(1);
172 m_subRunNum = rset->getInt(2);
173 Date startDate = rset->getDate(3);
174 Date endDate = rset->getDate(4);
176 m_subRunStart = dh.
dateToTm( startDate );
177 m_subRunEnd = dh.
dateToTm( endDate );
179 m_runIOV.setConnection(m_env, m_conn);
180 m_runIOV.setByID(runIOVID);
184 throw(std::runtime_error(
"MODRunIOV::setByID: Given id is not in the database"));
187 m_conn->terminateStatement(stmt);
189 throw(std::runtime_error(
"MODRunIOV::setByID: "+e.getMessage()));
196 throw(std::runtime_error)
198 this->checkConnection();
201 if (this->fetchID()) {
207 this->fetchParentIDs(&runIOVID);
212 if (m_subRunStart.isNull()) {
213 throw(std::runtime_error(
"MODRunIOV::writeDB: Must setSubRunStart before writing"));
216 if (m_subRunEnd.isNull()) {
221 Statement* stmt = m_conn->createStatement();
223 stmt->setSQL(
"INSERT INTO od_run_iov (iov_id, run_iov_id, subrun_num, subrun_start, subrun_end) "
224 "VALUES (OD_run_iov_sq.NextVal, :1, :2, :3, :4)");
225 stmt->setInt(1, runIOVID);
226 stmt->setInt(2, m_subRunNum);
227 stmt->setDate(3, dh.
tmToDate(m_subRunStart));
228 stmt->setDate(4, dh.
tmToDate(m_subRunEnd));
230 stmt->executeUpdate();
232 m_conn->terminateStatement(stmt);
234 throw(std::runtime_error(
"MODRunIOV::writeDB: "+e.getMessage()));
238 if (!this->fetchID()) {
239 throw(std::runtime_error(
"MODRunIOV::writeDB: Failed to write"));
248 throw(std::runtime_error)
251 m_runIOV.setConnection(m_env, m_conn);
252 *runIOVID = m_runIOV.fetchID();
255 throw(std::runtime_error(
"MODRunIOV: Given RunIOV does not exist in DB"));
263 throw(std::runtime_error)
265 this->checkConnection();
267 runiov->setConnection(m_env, m_conn);
268 int runIOVID = runiov->fetchID();
271 throw(std::runtime_error(
"MODRunIOV::setByRun: Given RunIOV does not exist in DB"));
277 Statement* stmt = m_conn->createStatement();
279 stmt->setSQL(
"SELECT iov_id, subrun_start, subrun_end FROM OD_run_iov "
280 "WHERE run_iov_id = :1 AND subrun_num = :2");
281 stmt->setInt(1, runIOVID);
282 stmt->setInt(2, subrun);
287 m_subRunNum = subrun;
289 m_ID = rset->getInt(1);
290 Date startDate = rset->getDate(2);
291 Date endDate = rset->getDate(3);
293 m_subRunStart = dh.
dateToTm( startDate );
294 m_subRunEnd = dh.
dateToTm( endDate );
296 throw(std::runtime_error(
"MODRunIOV::setByRun: Given subrun is not in the database"));
299 m_conn->terminateStatement(stmt);
301 throw(std::runtime_error(
"MODRunIOV::setByRun: "+e.getMessage()));
Tm getSubRunStart() const
oracle::occi::SQLException SQLException
void setRunIOV(RunIOV iov)
run_t getSubRunNumber() const
void setByRun(RunIOV *runiov, subrun_t subrun)
void setSubRunEnd(Tm end)
oracle::occi::Date tmToDate(const Tm &inTm) const
void setSubRunStart(Tm start)
void setSubRunNumber(subrun_t subrun)
oracle::occi::ResultSet ResultSet
Tm dateToTm(oracle::occi::Date &date) const
void fetchParentIDs(int *runIOVID)