7 using namespace oracle::occi;
38 if (genTag != m_genTag) {
55 if (locDef != m_locDef) {
72 if (runTypeDef != m_runTypeDef) {
74 m_runTypeDef = runTypeDef;
81 throw(std::runtime_error)
92 this->checkConnection();
97 this->fetchParentIDs(&locID, &runTypeID);
101 Statement* stmt = m_conn->createStatement();
102 stmt->setSQL(
"SELECT tag_id FROM run_tag WHERE "
104 "location_id = :2 AND "
106 stmt->setString(1, m_genTag);
107 stmt->setInt(2, locID);
108 stmt->setInt(3, runTypeID);
113 m_ID = rset->getInt(1);
117 m_conn->terminateStatement(stmt);
119 throw(std::runtime_error(
"RunTag::fetchID: "+e.getMessage()));
128 throw(std::runtime_error)
130 this->checkConnection();
133 Statement* stmt = m_conn->createStatement();
135 stmt->setSQL(
"SELECT gen_tag, location_id, run_type_id FROM run_tag WHERE tag_id = :1");
140 m_genTag = rset->getString(1);
141 int locID = rset->getInt(2);
142 int runTypeID = rset->getInt(3);
144 m_locDef.setConnection(m_env, m_conn);
145 m_locDef.setByID(locID);
147 m_runTypeDef.setConnection(m_env, m_conn);
148 m_runTypeDef.setByID(runTypeID);
152 throw(std::runtime_error(
"RunTag::setByID: Given tag_id is not in the database"));
155 m_conn->terminateStatement(stmt);
157 throw(std::runtime_error(
"RunTag::setByID: "+e.getMessage()));
163 throw(std::runtime_error)
166 if (this->fetchID()) {
171 this->checkConnection();
174 int locID, runTypeID;
175 this->fetchParentIDs(&locID, &runTypeID);
179 Statement* stmt = m_conn->createStatement();
181 stmt->setSQL(
"INSERT INTO run_tag (tag_id, gen_tag, location_id, run_type_id) "
182 "VALUES (run_tag_sq.NextVal, :1, :2, :3)");
183 stmt->setString(1, m_genTag);
184 stmt->setInt(2, locID);
185 stmt->setInt(3, runTypeID);
187 stmt->executeUpdate();
189 m_conn->terminateStatement(stmt);
191 throw(std::runtime_error(
"RunTag::writeDB: "+e.getMessage()));
195 if (!this->fetchID()) {
196 throw(std::runtime_error(
"RunTag::writeDB: Failed to write"));
205 throw(std::runtime_error)
207 this->checkConnection();
209 Statement* stmt = m_conn->createStatement();
210 stmt->setSQL(
"SELECT tag_id FROM run_tag ORDER BY tag_id");
215 while(rset->next()) {
216 runtag.
setByID( rset->getInt(1) );
217 fillVec->push_back( runtag );
219 m_conn->terminateStatement(stmt);
221 throw(std::runtime_error(
"RunTag::fetchAllTags: "+e.getMessage()));
228 throw(std::runtime_error)
231 m_locDef.setConnection(m_env, m_conn);
232 *locID = m_locDef.fetchID();
235 m_runTypeDef.setConnection(m_env, m_conn);
236 *runTypeID = m_runTypeDef.fetchID();
241 throw(std::runtime_error(
"RunTag::fetchparentids: Given location does not exist in DB"));
245 throw(std::runtime_error(
"RunTag::fetchParentIDs: Given run type does not exist in DB"));
void setLocationDef(const LocationDef locDef)
LocationDef getLocationDef() const
std::string getGeneralTag() const
oracle::occi::SQLException SQLException
void fetchAllTags(std::vector< RunTag > *fillVec)
void setRunTypeDef(const RunTypeDef runTypeDef)
void fetchParentIDs(int *locId, int *runTypeID)
RunTypeDef getRunTypeDef() const
oracle::occi::ResultSet ResultSet
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
void setGeneralTag(std::string tag)