10 using namespace oracle::occi;
30 if (since != m_since) {
64 if (tag != m_caliTag) {
80 throw(std::runtime_error)
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));
114 m_ID = rset->getInt(1);
118 m_conn->terminateStatement(stmt);
120 throw(std::runtime_error(
"CaliIOV::fetchID: "+e.getMessage()));
129 throw(std::runtime_error)
131 this->checkConnection();
136 Statement* stmt = m_conn->createStatement();
138 stmt->setSQL(
"SELECT tag_id, since, till FROM cali_iov WHERE iov_id = :1");
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);
159 throw(std::runtime_error(
"CaliTag::setByID: "+e.getMessage()));
166 throw(std::runtime_error)
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);
202 throw(std::runtime_error(
"CaliIOV::writeDB: "+e.getMessage()));
206 if (!this->fetchID()) {
207 throw(std::runtime_error(
"CaliIOV::writeDB: Failed to write"));
216 throw(std::runtime_error)
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);
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);
257 throw(std::runtime_error(
"CaliIOV::setByTm: "+e.getMessage()));
void setByTm(CaliTag *tag, const Tm &time)
void setSince(const Tm &since)
oracle::occi::SQLException SQLException
CaliTag getCaliTag() const
oracle::occi::Date tmToDate(const Tm &inTm) const
void setCaliTag(const CaliTag &tag)
oracle::occi::ResultSet ResultSet
Tm dateToTm(oracle::occi::Date &date) const
void setTill(const Tm &till)