30 if (since != m_since) {
64 if (tag != m_caliTag) {
87 this->checkConnection();
89 m_caliTag.setConnection(m_env, m_conn);
90 int tagID = m_caliTag.fetchID();
97 if (m_till.isNull()) {
102 Statement* stmt = m_conn->createStatement();
103 stmt->setSQL(
"SELECT iov_id FROM cali_iov " 104 "WHERE tag_id = :tag_id AND " 105 "since = :since AND " 107 stmt->setInt(1, tagID);
108 stmt->setDate(2, dh.
tmToDate(m_since));
109 stmt->setDate(3, dh.
tmToDate(m_till));
111 ResultSet* rset = stmt->executeQuery();
114 m_ID = rset->getInt(1);
118 m_conn->terminateStatement(stmt);
119 }
catch (SQLException &
e) {
120 throw(std::runtime_error(
std::string(
"CaliIOV::fetchID: ")+e.getMessage()));
131 this->checkConnection();
136 Statement* stmt = m_conn->createStatement();
138 stmt->setSQL(
"SELECT tag_id, since, till FROM cali_iov WHERE iov_id = :1");
141 ResultSet* rset = stmt->executeQuery();
143 int tagID = rset->getInt(1);
144 Date
since = rset->getDate(2);
145 Date
till = rset->getDate(3);
150 m_caliTag.setConnection(m_env, m_conn);
151 m_caliTag.setByID(tagID);
154 throw(std::runtime_error(
"CaliTag::setByID: Given tag_id is not in the database"));
157 m_conn->terminateStatement(stmt);
158 }
catch (SQLException &
e) {
159 throw(std::runtime_error(
std::string(
"CaliTag::setByID: ")+e.getMessage()));
168 this->checkConnection();
171 if (this->fetchID()) {
175 m_caliTag.setConnection(m_env, m_conn);
176 int tagID = m_caliTag.writeDB();
181 if (m_since.isNull()) {
182 throw(std::runtime_error(
"CaliIOV::writeDB: Must setSince before writing"));
185 if (m_till.isNull()) {
190 Statement* stmt = m_conn->createStatement();
192 stmt->setSQL(
"INSERT INTO cali_iov (iov_id, tag_id, since, till) " 193 "VALUES (cali_iov_sq.NextVal, :1, :2, :3)");
194 stmt->setInt(1, tagID);
195 stmt->setDate(2, dh.
tmToDate(m_since));
196 stmt->setDate(3, dh.
tmToDate(m_till));
198 stmt->executeUpdate();
200 m_conn->terminateStatement(stmt);
201 }
catch (SQLException &
e) {
202 throw(std::runtime_error(
std::string(
"CaliIOV::writeDB: ")+e.getMessage()));
206 if (!this->fetchID()) {
207 throw(std::runtime_error(
"CaliIOV::writeDB: Failed to write"));
218 this->checkConnection();
220 tag->setConnection(m_env, m_conn);
221 int tagID =
tag->fetchID();
224 throw(std::runtime_error(
"CaliIOV::setByTm: Given CaliTag does not exist in the DB"));
229 Date eventDate = dh.
tmToDate(eventTm);
232 Statement* stmt = m_conn->createStatement();
235 stmt->setSQL(
"SELECT iov_id, since, till FROM cali_iov " 236 "WHERE tag_id = :1 AND since <= :2 AND till > :3");
237 stmt->setInt(1, tagID);
238 stmt->setDate(2, eventDate);
239 stmt->setDate(3, eventDate);
241 ResultSet* rset = stmt->executeQuery();
245 m_ID = rset->getInt(1);
246 Date sinceDate = rset->getDate(2);
247 Date tillDate = rset->getDate(3);
252 throw(std::runtime_error(
"CaliIOV::setByTm: Given subrun is not in the database"));
255 m_conn->terminateStatement(stmt);
256 }
catch (SQLException &
e) {
257 throw(std::runtime_error(
std::string(
"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)