22 if (
since != m_since) {
40 if (
tag != m_dcuTag) {
54 this->checkConnection();
56 m_dcuTag.setConnection(m_env, m_conn);
57 int tagID = m_dcuTag.fetchID();
64 if (m_till.isNull()) {
65 m_till =
dh.getPlusInfTm();
69 Statement* stmt = m_conn->createStatement();
71 "SELECT iov_id FROM dcu_iov " 72 "WHERE tag_id = :tag_id AND " 74 stmt->setInt(1, tagID);
75 stmt->setDate(2,
dh.tmToDate(m_since));
78 ResultSet* rset = stmt->executeQuery();
81 m_ID = rset->getInt(1);
85 m_conn->terminateStatement(stmt);
86 }
catch (SQLException&
e) {
87 throw(std::runtime_error(
"DCUIOV::fetchID: " +
e.getMessage()));
94 this->checkConnection();
99 Statement* stmt = m_conn->createStatement();
101 stmt->setSQL(
"SELECT tag_id, since, till FROM dcu_iov WHERE iov_id = :1");
104 ResultSet* rset = stmt->executeQuery();
106 int tagID = rset->getInt(1);
107 Date
since = rset->getDate(2);
108 Date
till = rset->getDate(3);
111 m_till =
dh.dateToTm(
till);
113 m_dcuTag.setConnection(m_env, m_conn);
114 m_dcuTag.setByID(tagID);
117 throw(std::runtime_error(
"DCUTag::setByID: Given tag_id is not in the database"));
120 m_conn->terminateStatement(stmt);
121 }
catch (SQLException&
e) {
122 throw(std::runtime_error(
"DCUTag::setByID: " +
e.getMessage()));
127 this->checkConnection();
130 if (this->fetchID()) {
134 m_dcuTag.setConnection(m_env, m_conn);
135 int tagID = m_dcuTag.writeDB();
140 if (m_since.isNull()) {
141 throw(std::runtime_error(
"DCUIOV::writeDB: Must setSince before writing"));
144 if (m_till.isNull()) {
145 m_till =
dh.getPlusInfTm();
149 Statement* stmt = m_conn->createStatement();
152 "INSERT INTO dcu_iov (iov_id, tag_id, since, till) " 153 "VALUES (dcu_iov_sq.NextVal, :1, :2, :3)");
154 stmt->setInt(1, tagID);
155 stmt->setDate(2,
dh.tmToDate(m_since));
156 stmt->setDate(3,
dh.tmToDate(m_till));
158 stmt->executeUpdate();
160 m_conn->terminateStatement(stmt);
161 }
catch (SQLException&
e) {
162 throw(std::runtime_error(
"DCUIOV::writeDB: " +
e.getMessage()));
166 if (!this->fetchID()) {
167 throw(std::runtime_error(
"DCUIOV::writeDB: Failed to write"));
174 this->checkConnection();
176 tag->setConnection(m_env, m_conn);
177 int tagID =
tag->fetchID();
180 throw(std::runtime_error(
"DCUIOV::setByTm: Given DCUTag does not exist in the DB"));
185 Date eventDate =
dh.tmToDate(eventTm);
188 Statement* stmt = m_conn->createStatement();
191 "SELECT iov_id, since, till FROM dcu_iov " 192 "WHERE tag_id = :1 AND since <= :2 AND till > :3");
193 stmt->setInt(1, tagID);
194 stmt->setDate(2, eventDate);
195 stmt->setDate(3, eventDate);
197 ResultSet* rset = stmt->executeQuery();
201 m_ID = rset->getInt(1);
202 Date sinceDate = rset->getDate(2);
203 Date tillDate = rset->getDate(3);
205 m_since =
dh.dateToTm(sinceDate);
206 m_till =
dh.dateToTm(tillDate);
208 throw(std::runtime_error(
"DCUIOV::setByTm: Given subrun is not in the database"));
211 m_conn->terminateStatement(stmt);
212 }
catch (SQLException&
e) {
213 throw(std::runtime_error(
"DCUIOV::setByTm: " +
e.getMessage()));
void setTill(const Tm &till)
int writeDB() noexcept(false)
void setByTm(DCUTag *tag, const Tm &time) noexcept(false)
int fetchID() noexcept(false) override
void setByID(int id) noexcept(false) override
void setSince(const Tm &since)
void setDCUTag(const DCUTag &tag)