30 if (since != m_since) {
64 if (tag != m_dcuTag) {
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));
110 ResultSet* rset = stmt->executeQuery();
113 m_ID = rset->getInt(1);
117 m_conn->terminateStatement(stmt);
118 }
catch (SQLException &
e) {
119 throw(std::runtime_error(
std::string(
"DCUIOV::fetchID: ")+getOraMessage(&e)));
130 this->checkConnection();
135 Statement* stmt = m_conn->createStatement();
137 stmt->setSQL(
"SELECT tag_id, since, till FROM dcu_iov WHERE iov_id = :1");
140 ResultSet* rset = stmt->executeQuery();
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);
157 }
catch (SQLException &
e) {
158 throw(std::runtime_error(
std::string(
"DCUTag::setByID: ")+getOraMessage(&e)));
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);
200 }
catch (SQLException &
e) {
201 throw(std::runtime_error(
std::string(
"DCUIOV::writeDB: ")+getOraMessage(&e)));
205 if (!this->fetchID()) {
206 throw(std::runtime_error(
"DCUIOV::writeDB: Failed to write"));
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);
240 ResultSet* rset = stmt->executeQuery();
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);
255 }
catch (SQLException &
e) {
256 throw(std::runtime_error(
std::string(
"DCUIOV::setByTm: ")+getOraMessage(&e)));
void setTill(const Tm &till)
int writeDB() noexcept(false)
oracle::occi::Date tmToDate(const Tm &inTm) const
void setByTm(DCUTag *tag, const Tm &time) noexcept(false)
int fetchID() noexcept(false) override
void setByID(int id) noexcept(false) override
Tm dateToTm(oracle::occi::Date &date) const
void setSince(const Tm &since)
void setDCUTag(const DCUTag &tag)