52 std::string parentNodeId, childNodeId, parentTagId;
56 m_msgStream << MSG::ERROR <<
"VersionAccessor: No connection to database!" <<
endmsg;
67 coral::ITable& tableTag2Node =
m_session->nominalSchema().tableHandle(
"HVS_TAG2NODE");
68 coral::ITable& tableNode =
m_session->nominalSchema().tableHandle(
"HVS_NODE");
69 coral::ITable& tableLtag2Ltag =
m_session->nominalSchema().tableHandle(
"HVS_LTAG2LTAG");
76 coral::IQuery *queryTag2Node = tableTag2Node.newQuery();
77 queryTag2Node->addToOutputList(
"TAG_ID");
78 queryTag2Node->setMemoryCacheSize(1);
80 bindsTag2Node.extend<std::string>(
"tagN");
81 queryTag2Node->setCondition(
"TAG_NAME=:tagN", bindsTag2Node);
84 coral::ICursor& cursorTag2Node = queryTag2Node->execute();
86 while(cursorTag2Node.next()) {
89 throw std::runtime_error(
"The tag " +
m_parentTag +
" is not unique in HVS_TAG2NODE table!");
92 const coral::AttributeList& row = cursorTag2Node.currentRow();
98 throw std::runtime_error(
"The tag " +
m_parentTag +
" not found in HVS_TAG2NODE table!");
101 delete queryTag2Node;
103 m_msgStream << MSG::VERBOSE <<
"VersionAccessor: Parent Tag Id = " << parentTagId <<
endmsg;
113 coral::IQuery* queryNodeIDs = tableNode.newQuery();
115 queryNodeIDs->addToOutputList(
"NODE_NAME");
116 queryNodeIDs->addToOutputList(
"NODE_ID");
117 queryNodeIDs->addToOutputList(
"BRANCH_FLAG");
118 queryNodeIDs->setMemoryCacheSize(2);
121 bindsNodeIDs.extend<std::string>(
"parentN");
122 bindsNodeIDs.extend<std::string>(
"childN");
124 queryNodeIDs->setCondition(
"NODE_NAME=:parentN OR NODE_NAME=:childN", bindsNodeIDs);
129 coral::ICursor& cursorNodeIDs = queryNodeIDs->execute();
132 while(cursorNodeIDs.next()) {
136 const coral::AttributeList& row = cursorNodeIDs.currentRow();
148 throw std::runtime_error(
"Error processing HVS_NODE, Number of fetched records !=2");
152 m_msgStream << MSG::VERBOSE <<
"VersionAccessor: Child Node Id = " << childNodeId <<
endmsg;
153 m_msgStream << MSG::VERBOSE <<
"VersionAccessor: Parent Node Id = " << parentNodeId <<
endmsg;
160 m_tagID = std::move(parentTagId);
176 std::vector<std::string> path;
177 path.push_back(childNodeId);
178 std::string currentParrent = childNodeId;
179 std::string currentChild = std::move(childNodeId);
182 bindsNode.extend<std::string>(
"nodeId");
183 const std::string parentIdStr{
"PARENT_ID"};
184 const std::string conditionStr{
"NODE_ID=:nodeId"};
185 while(currentParrent != parentNodeId) {
189 coral::IQuery* queryNode(tableNode.newQuery());
191 queryNode->addToOutputList(parentIdStr);
192 queryNode->setMemoryCacheSize(1);
194 queryNode->setCondition(conditionStr, bindsNode);
195 bindsNode[0].data<std::string>()=currentChild;
197 coral::ICursor& cursorNode = queryNode->execute();
202 while(cursorNode.next()) {
205 throw std::runtime_error(
"The node " + currentChild +
" has more than one parent!");
208 const coral::AttributeList& row = cursorNode.currentRow();
210 if(row[0].isNull()) {
212 throw std::runtime_error(
"The requested child and parent nodes are not on the same branch!");
216 currentChild = currentParrent;
217 path.push_back(currentParrent);
221 throw std::runtime_error(
"The node " + currentChild +
" has no parent!");
226 m_msgStream << MSG::VERBOSE <<
"VersionAccessor: Current Child = " << currentChild <<
endmsg;
227 m_msgStream << MSG::VERBOSE <<
"VersionAccessor: Current Parrent = " << currentParrent <<
endmsg;
232 bindsLtag2Ltag.extend<std::string>(
"childN");
233 bindsLtag2Ltag.extend<std::string>(
"parentT");
234 bindsLtag2Ltag.extend<std::string>(
"parentN");
236 const std::string childTagString{
"CHILD_TAG"};
237 const std::string childConditionStr =
"CHILD_NODE =:childN AND PARENT_TAG =:parentT AND PARENT_NODE =:parentN";
238 for(
unsigned int ind=1; ind<path.size(); ind++) {
243 coral::IQuery* queryLtag2Ltag(tableLtag2Ltag.newQuery());
245 queryLtag2Ltag->addToOutputList(childTagString);
246 queryLtag2Ltag->setMemoryCacheSize(1);
248 queryLtag2Ltag->setCondition(childConditionStr, bindsLtag2Ltag);
250 bindsLtag2Ltag[0].data<std::string>() = path[path.size()-ind-1];
251 bindsLtag2Ltag[1].data<std::string>() = parentTagId;
252 bindsLtag2Ltag[2].data<std::string>() = path[path.size()-ind];
254 coral::ICursor& cursorLtag2Ltag = queryLtag2Ltag->execute();
258 while(cursorLtag2Ltag.next()) {
260 delete queryLtag2Ltag;
261 throw std::runtime_error(
"Version " + parentTagId +
262 " has more than one child of type " + path[path.size()-ind-1] +
"!");
265 const coral::AttributeList& row = cursorLtag2Ltag.currentRow();
269 delete queryLtag2Ltag;
270 throw std::runtime_error(
"Version " + parentTagId +
" has no child of type " + path[path.size()-ind-1] +
"!");
273 delete queryLtag2Ltag;
276 m_msgStream << MSG::VERBOSE <<
"VersionAccessor: Parent Tag Id = " << parentTagId <<
endmsg;
285 coral::IQuery* queryTagName(tableTag2Node.newQuery());
286 const std::string tagNameStr{
"TAG_NAME"};
287 queryTagName->addToOutputList(tagNameStr);
288 queryTagName->setMemoryCacheSize(1);
291 bindsTagName.extend<std::string>(
"tagId");
293 queryTagName->setCondition(
"TAG_ID=:tagId", bindsTagName);
294 bindsTagName[0].data<std::string>() = parentTagId;
296 coral::ICursor& cursorTagName = queryTagName->execute();
299 while(cursorTagName.next()) {
302 throw std::runtime_error(
"More than one record retrieved when getting tag name for given ID");
305 const coral::AttributeList& row = cursorTagName.currentRow();
317 catch(coral::SchemaException& se)
319 m_msgStream << MSG::ERROR <<
"VersionAccessor: Schema Exception : " << se.what() <<
endmsg;
321 catch(std::exception& e)