9 #include "RelationalAccess/ISchema.h"
10 #include "RelationalAccess/ITable.h"
11 #include "RelationalAccess/IQuery.h"
12 #include "RelationalAccess/ICursor.h"
13 #include "CoralBase/AttributeList.h"
14 #include "CoralBase/Attribute.h"
15 #include "RelationalAccess/SchemaException.h"
26 m_coraldb(coraldb), pfnEditor(prefix,postfix)
39 if(!existsTagDatabase()){
42 std::pair<std::string,std::string> treenodepair=parseglobaltag(globaltag);
46 if( !treename.empty() ){
47 for(
unsigned int i=0;
i<treename.size(); ++
i){
48 treename[
i]=std::toupper(treename[
i]);
51 treetablename+=treename;
53 return m_coraldb.nominalSchema().existsTable(treetablename);
58 std::set<cond::TagMetadata >&
result){
59 if(!selectTagCollection( globaltag, result ) )
65 std::set<cond::TagMetadata >&
result){
69 std::pair<std::string,std::string> treenodepair=parseglobaltag(globaltag);
75 if( !treename.empty() ){
76 for(
unsigned int i=0;
i<treename.size(); ++
i){
77 treename[
i]=std::toupper(treename[
i]);
80 treetablename+=treename;
82 if( !m_coraldb.nominalSchema().existsTable(treetablename) )
return false;
84 coral::IQuery*
query=m_coraldb.nominalSchema().newQuery();
86 query->addToTableList( treetablename,
"p1" );
87 query->addToTableList( treetablename,
"p2" );
88 query->addToOutputList(
"p1.tagid" );
89 query->setRowCacheSize( 100 );
90 coral::AttributeList bindData;
92 bindData.extend(
"tagid",
typeid(
unsigned int) );
93 bindData[
"tagid"].data<
unsigned int>()=0;
95 query->setCondition(
"p1.lft BETWEEN p2.lft AND p2.rgt AND p2.nodelabel = :nodelabel AND p1.tagid <> :tagid", bindData );
96 coral::AttributeList qresult;
97 qresult.extend(
"tagid",
typeid(
unsigned int));
98 query->defineOutput(qresult);
99 std::vector<unsigned int> leaftagids;
100 leaftagids.reserve(100);
101 coral::ICursor& cursor = query->execute();
102 while( cursor.next() ) {
103 const coral::AttributeList& row = cursor.currentRow();
104 leaftagids.push_back(row[
"tagid"].data<unsigned int>());
108 std::vector<unsigned int>::iterator it;
109 std::vector<unsigned int>::iterator itBeg=leaftagids.begin();
110 std::vector<unsigned int>::iterator itEnd=leaftagids.end();
112 for( it=itBeg; it!=itEnd; ++it ){
113 coral::IQuery* leaftagquery=tagInventorytable.newQuery();
114 leaftagquery->addToOutputList(
"tagname" );
115 leaftagquery->addToOutputList(
"pfn" );
116 leaftagquery->addToOutputList(
"recordname" );
117 leaftagquery->addToOutputList(
"objectname" );
118 leaftagquery->addToOutputList(
"labelname" );
119 coral::AttributeList myresult;
125 leaftagquery->defineOutput( myresult );
126 coral::AttributeList bindVariableList;
127 bindVariableList.extend(
"tagid",
typeid(
unsigned int));
128 leaftagquery->setCondition(
"tagid = :tagid",bindVariableList );
129 leaftagquery->limitReturnedRows(1,0);
130 bindVariableList[
"tagid"].data<
unsigned int>()=*it;
131 coral::ICursor& cursor2 =leaftagquery->execute();
132 if( cursor2.next() ){
133 const coral::AttributeList& row = cursor2.currentRow();
137 tagmetadata.
pfn=pfnEditor(row[
"pfn"].data<std::string>());
141 if(! result.insert(tagmetadata).second ){
142 throw cond::Exception(
"cond::TagCollectionRetriever::getTagCollection tag "+tagname+
" from "+tagmetadata.
pfn+
" already exist, cannot insert in the tag collection ");
151 std::pair<std::string,std::string>
153 std::pair<std::string,std::string>
result;
154 std::size_t pos=globaltag.find(
"::");
155 if(pos==std::string::npos){
159 result.first=globaltag.substr(0,pos);
160 result.second=globaltag.substr(pos+2);
bool selectTagCollection(const std::string &globaltag, std::set< cond::TagMetadata > &result)
void getTagCollection(const std::string &globaltag, std::set< cond::TagMetadata > &result)
const std::string tagTreeTablePrefix
std::pair< std::string, std::string > parseglobaltag(const std::string &globaltag)
parse global tag string returns result in pair <treename,nodename>
const std::string tagInventoryTable
bool existsTagCollection(const std::string &globaltag)
TagCollectionRetriever(cond::DbSession &coraldb)
constructor
~TagCollectionRetriever()
destructor