37 if (genTag != m_genTag) {
54 if (locDef != m_locDef) {
70 this->checkConnection();
74 this->fetchParentIDs(&locID);
78 Statement* stmt = m_conn->createStatement();
79 stmt->setSQL(
"SELECT tag_id FROM dcu_tag WHERE " 82 stmt->setString(1, m_genTag);
83 stmt->setInt(2, locID);
85 ResultSet* rset = stmt->executeQuery();
88 m_ID = rset->getInt(1);
92 m_conn->terminateStatement(stmt);
93 }
catch (SQLException &
e) {
94 throw(std::runtime_error(
"DCUTag::fetchID: "+e.getMessage()));
105 this->checkConnection();
108 Statement* stmt = m_conn->createStatement();
110 stmt->setSQL(
"SELECT gen_tag, location_id FROM dcu_tag WHERE tag_id = :1");
113 ResultSet* rset = stmt->executeQuery();
115 m_genTag = rset->getString(1);
116 int locID = rset->getInt(2);
118 m_locDef.setConnection(m_env, m_conn);
119 m_locDef.setByID(locID);
123 throw(std::runtime_error(
"DCUTag::setByID: Given tag_id is not in the database"));
126 m_conn->terminateStatement(stmt);
127 }
catch (SQLException &
e) {
128 throw(std::runtime_error(
"DCUTag::setByID: "+e.getMessage()));
137 if (this->fetchID()) {
142 this->checkConnection();
146 this->fetchParentIDs(&locID);
150 Statement* stmt = m_conn->createStatement();
152 stmt->setSQL(
"INSERT INTO dcu_tag (tag_id, gen_tag, location_id) " 153 "VALUES (dcu_tag_sq.NextVal, :1, :2)");
154 stmt->setString(1, m_genTag);
155 stmt->setInt(2, locID);
157 stmt->executeUpdate();
159 m_conn->terminateStatement(stmt);
160 }
catch (SQLException &
e) {
161 throw(std::runtime_error(
"DCUTag::writeDB: "+e.getMessage()));
165 if (!this->fetchID()) {
166 throw(std::runtime_error(
"DCUTag::writeDB: Failed to write"));
177 this->checkConnection();
179 Statement* stmt = m_conn->createStatement();
180 stmt->setSQL(
"SELECT tag_id FROM dcu_tag ORDER BY tag_id");
181 ResultSet* rset = stmt->executeQuery();
185 while(rset->next()) {
186 dcutag.
setByID( rset->getInt(1) );
187 fillVec->push_back( dcutag );
189 m_conn->terminateStatement(stmt);
190 }
catch (SQLException &
e) {
191 throw(std::runtime_error(
"DCUTag::fetchAllTags: "+e.getMessage()));
201 m_locDef.setConnection(m_env, m_conn);
202 *locID = m_locDef.fetchID();
205 throw(std::runtime_error(
"DCUTag::writeDB: Given location does not exist in DB"));
void setLocationDef(const LocationDef &locDef)
LocationDef getLocationDef() const
void fetchParentIDs(int *locId) noexcept(false)
void setGeneralTag(std::string tag)
int writeDB() noexcept(false)
void fetchAllTags(std::vector< DCUTag > *fillVec) noexcept(false)
int fetchID() noexcept(false) override
void setByID(int id) noexcept(false) override
std::string getGeneralTag() const
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)