38 if (genTag != m_genTag) {
55 if (locDef != m_locDef) {
72 if (runTypeDef != m_runTypeDef) {
74 m_runTypeDef = runTypeDef;
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);
110 ResultSet* rset = stmt->executeQuery();
113 m_ID = rset->getInt(1);
117 m_conn->terminateStatement(stmt);
118 }
catch (SQLException &
e) {
119 throw(std::runtime_error(
"RunTag::fetchID: "+e.getMessage()));
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");
138 ResultSet* rset = stmt->executeQuery();
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);
156 }
catch (SQLException &
e) {
157 throw(std::runtime_error(
"RunTag::setByID: "+e.getMessage()));
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);
190 }
catch (SQLException &
e) {
191 throw(std::runtime_error(
"RunTag::writeDB: "+e.getMessage()));
195 if (!this->fetchID()) {
196 throw(std::runtime_error(
"RunTag::writeDB: Failed to write"));
207 this->checkConnection();
209 Statement* stmt = m_conn->createStatement();
210 stmt->setSQL(
"SELECT tag_id FROM run_tag ORDER BY tag_id");
211 ResultSet* rset = stmt->executeQuery();
215 while(rset->next()) {
216 runtag.
setByID( rset->getInt(1) );
217 fillVec->push_back( runtag );
219 m_conn->terminateStatement(stmt);
220 }
catch (SQLException &
e) {
221 throw(std::runtime_error(
"RunTag::fetchAllTags: "+e.getMessage()));
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 setRunTypeDef(const RunTypeDef &runTypeDef)
void fetchAllTags(std::vector< RunTag > *fillVec) noexcept(false)
int writeDB() noexcept(false)
void fetchParentIDs(int *locId, int *runTypeID) noexcept(false)
void setByID(int id) noexcept(false) override
LocationDef getLocationDef() const
std::string getGeneralTag() const
void setLocationDef(const LocationDef &locDef)
RunTypeDef getRunTypeDef() const
int fetchID() noexcept(false) override
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
void setGeneralTag(std::string tag)