10 using namespace oracle::occi;
30 if (since != m_since) {
64 if (tag != m_dcuTag) {
80 throw(std::runtime_error)
87 this->checkConnection();
89 m_dcuTag.setConnection(m_env, m_conn);
90 int tagID = m_dcuTag.fetchID();
97 if (m_till.isNull()) {
102 Statement* stmt = m_conn->createStatement();
103 stmt->setSQL(
"SELECT iov_id FROM dcu_iov "
104 "WHERE tag_id = :tag_id AND "
106 stmt->setInt(1, tagID);
107 stmt->setDate(2, dh.
tmToDate(m_since));
113 m_ID = rset->getInt(1);
117 m_conn->terminateStatement(stmt);
119 throw(std::runtime_error(
"DCUIOV::fetchID: "+e.getMessage()));
128 throw(std::runtime_error)
130 this->checkConnection();
135 Statement* stmt = m_conn->createStatement();
137 stmt->setSQL(
"SELECT tag_id, since, till FROM dcu_iov WHERE iov_id = :1");
142 int tagID = rset->getInt(1);
143 Date since = rset->getDate(2);
144 Date till = rset->getDate(3);
149 m_dcuTag.setConnection(m_env, m_conn);
150 m_dcuTag.setByID(tagID);
153 throw(std::runtime_error(
"DCUTag::setByID: Given tag_id is not in the database"));
156 m_conn->terminateStatement(stmt);
158 throw(std::runtime_error(
"DCUTag::setByID: "+e.getMessage()));
165 throw(std::runtime_error)
167 this->checkConnection();
170 if (this->fetchID()) {
174 m_dcuTag.setConnection(m_env, m_conn);
175 int tagID = m_dcuTag.writeDB();
180 if (m_since.isNull()) {
181 throw(std::runtime_error(
"DCUIOV::writeDB: Must setSince before writing"));
184 if (m_till.isNull()) {
189 Statement* stmt = m_conn->createStatement();
191 stmt->setSQL(
"INSERT INTO dcu_iov (iov_id, tag_id, since, till) "
192 "VALUES (dcu_iov_sq.NextVal, :1, :2, :3)");
193 stmt->setInt(1, tagID);
194 stmt->setDate(2, dh.
tmToDate(m_since));
195 stmt->setDate(3, dh.
tmToDate(m_till));
197 stmt->executeUpdate();
199 m_conn->terminateStatement(stmt);
201 throw(std::runtime_error(
"DCUIOV::writeDB: "+e.getMessage()));
205 if (!this->fetchID()) {
206 throw(std::runtime_error(
"DCUIOV::writeDB: Failed to write"));
215 throw(std::runtime_error)
217 this->checkConnection();
219 tag->setConnection(m_env, m_conn);
220 int tagID =
tag->fetchID();
223 throw(std::runtime_error(
"DCUIOV::setByTm: Given DCUTag does not exist in the DB"));
228 Date eventDate = dh.
tmToDate(eventTm);
231 Statement* stmt = m_conn->createStatement();
234 stmt->setSQL(
"SELECT iov_id, since, till FROM dcu_iov "
235 "WHERE tag_id = :1 AND since <= :2 AND till > :3");
236 stmt->setInt(1, tagID);
237 stmt->setDate(2, eventDate);
238 stmt->setDate(3, eventDate);
244 m_ID = rset->getInt(1);
245 Date sinceDate = rset->getDate(2);
246 Date tillDate = rset->getDate(3);
251 throw(std::runtime_error(
"DCUIOV::setByTm: Given subrun is not in the database"));
254 m_conn->terminateStatement(stmt);
256 throw(std::runtime_error(
"DCUIOV::setByTm: "+e.getMessage()));
void setByTm(DCUTag *tag, Tm time)
oracle::occi::SQLException SQLException
void setDCUTag(DCUTag tag)
oracle::occi::Date tmToDate(const Tm &inTm) const
oracle::occi::ResultSet ResultSet
Tm dateToTm(oracle::occi::Date &date) const