22 if (since != m_since) {
40 if (tag != m_caliTag) {
54 this->checkConnection();
56 m_caliTag.setConnection(m_env, m_conn);
57 int tagID = m_caliTag.fetchID();
64 if (m_till.isNull()) {
69 Statement* stmt = m_conn->createStatement();
71 "SELECT iov_id FROM cali_iov " 72 "WHERE tag_id = :tag_id AND " 75 stmt->setInt(1, tagID);
76 stmt->setDate(2, dh.
tmToDate(m_since));
77 stmt->setDate(3, dh.
tmToDate(m_till));
79 ResultSet* rset = stmt->executeQuery();
82 m_ID = rset->getInt(1);
86 m_conn->terminateStatement(stmt);
87 }
catch (SQLException&
e) {
88 throw(std::runtime_error(
"CaliIOV::fetchID: " + e.getMessage()));
95 this->checkConnection();
100 Statement* stmt = m_conn->createStatement();
102 stmt->setSQL(
"SELECT tag_id, since, till FROM cali_iov WHERE iov_id = :1");
105 ResultSet* rset = stmt->executeQuery();
107 int tagID = rset->getInt(1);
108 Date
since = rset->getDate(2);
109 Date
till = rset->getDate(3);
114 m_caliTag.setConnection(m_env, m_conn);
115 m_caliTag.setByID(tagID);
118 throw(std::runtime_error(
"CaliTag::setByID: Given tag_id is not in the database"));
121 m_conn->terminateStatement(stmt);
122 }
catch (SQLException&
e) {
123 throw(std::runtime_error(
"CaliTag::setByID: " + e.getMessage()));
128 this->checkConnection();
131 if (this->fetchID()) {
135 m_caliTag.setConnection(m_env, m_conn);
136 int tagID = m_caliTag.writeDB();
141 if (m_since.isNull()) {
142 throw(std::runtime_error(
"CaliIOV::writeDB: Must setSince before writing"));
145 if (m_till.isNull()) {
150 Statement* stmt = m_conn->createStatement();
153 "INSERT INTO cali_iov (iov_id, tag_id, since, till) " 154 "VALUES (cali_iov_sq.NextVal, :1, :2, :3)");
155 stmt->setInt(1, tagID);
156 stmt->setDate(2, dh.
tmToDate(m_since));
157 stmt->setDate(3, dh.
tmToDate(m_till));
159 stmt->executeUpdate();
161 m_conn->terminateStatement(stmt);
162 }
catch (SQLException&
e) {
163 throw(std::runtime_error(
"CaliIOV::writeDB: " + e.getMessage()));
167 if (!this->fetchID()) {
168 throw(std::runtime_error(
"CaliIOV::writeDB: Failed to write"));
175 this->checkConnection();
177 tag->setConnection(m_env, m_conn);
178 int tagID =
tag->fetchID();
181 throw(std::runtime_error(
"CaliIOV::setByTm: Given CaliTag does not exist in the DB"));
186 Date eventDate = dh.
tmToDate(eventTm);
189 Statement* stmt = m_conn->createStatement();
192 "SELECT iov_id, since, till FROM cali_iov " 193 "WHERE tag_id = :1 AND since <= :2 AND till > :3");
194 stmt->setInt(1, tagID);
195 stmt->setDate(2, eventDate);
196 stmt->setDate(3, eventDate);
198 ResultSet* rset = stmt->executeQuery();
202 m_ID = rset->getInt(1);
203 Date sinceDate = rset->getDate(2);
204 Date tillDate = rset->getDate(3);
209 throw(std::runtime_error(
"CaliIOV::setByTm: Given subrun is not in the database"));
212 m_conn->terminateStatement(stmt);
213 }
catch (SQLException&
e) {
214 throw(std::runtime_error(
"CaliIOV::setByTm: " + e.getMessage()));
int writeDB() noexcept(false)
void setSince(const Tm &since)
void setByID(int id) noexcept(false) override
CaliTag getCaliTag() const
oracle::occi::Date tmToDate(const Tm &inTm) const
void setCaliTag(const CaliTag &tag)
void setByTm(CaliTag *tag, const Tm &time) noexcept(false)
int fetchID() noexcept(false) override
Tm dateToTm(oracle::occi::Date &date) const
void setTill(const Tm &till)