test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MappingTree.cc
Go to the documentation of this file.
1 #include "MappingTree.h"
3 // externals
4 #include "CoralBase/AttributeSpecification.h"
5 #include "CoralBase/Blob.h"
6 
8  m_version( "" ),
9  m_element(),
10  m_parentTable(){
11 }
12 
14  m_version( version ),
15  m_element(),
16  m_parentTable(){
17 }
18 
20  m_version( rhs.m_version ),
21  m_element( rhs.m_element ),
22  m_parentTable(){
23  if( rhs.m_parentTable.get()) m_parentTable.reset( new TableInfo( *rhs.m_parentTable ) );
24 }
25 
27 }
28 
30  if( this != &rhs ){
31  m_version = rhs.m_version;
32  m_element = rhs.m_element;
33  m_parentTable.reset();
34  if( rhs.m_parentTable.get()) m_parentTable.reset( new TableInfo( *rhs.m_parentTable ) );
35  }
36  return *this;
37 }
38 
41  const std::string& tableName,
42  bool isDependency ){
44  if( isDependency ) elementType = ora::MappingElement::dependencyMappingElementType();
45  m_element = ora::MappingElement( elementType,
46  className,
47  className,
48  tableName );
49  return m_element;
50 }
51 
52 void ora::MappingTree::setDependency( const MappingTree& parentTree ){
53  m_parentTable.reset( new TableInfo() );
54  m_parentTable->m_tableName = parentTree.m_element.tableName();
55  m_parentTable->m_idColumns = parentTree.m_element.columnNames();
56 }
57 
59 {
60  if( className() == source.className() ) m_element.override( source.m_element );
61 }
62 
63 namespace ora {
64  void scanElement( const MappingElement& element,
65  const TableInfo& currentTable,
66  bool isDependency,
67  std::vector<std::string>& tableHierarchy,
68  std::map<std::string,TableInfo>& tableMap ){
69  const std::string& tName = element.tableName();
70  std::map<std::string,TableInfo>::iterator iT = tableMap.find( tName );
71  if( iT == tableMap.end() ){
72  tableHierarchy.push_back( tName );
73  iT = tableMap.insert( std::make_pair( tName, TableInfo() ) ).first;
74  iT->second.m_dependency = isDependency;
75  iT->second.m_tableName = tName;
76  iT->second.m_idColumns = element.columnNames();
77  iT->second.m_parentTableName = currentTable.m_tableName;
78  iT->second.m_refColumns = currentTable.m_idColumns;
79  } else {
80  const std::vector<std::string>& dataCols = element.columnNames();
81  MappingElement::ElementType elementType = element.elementType();
82  switch ( elementType ) {
84  iT->second.m_dataColumns.insert( std::make_pair( dataCols[0],
85  element.variableType() ));
86  break;
88  iT->second.m_dataColumns.insert( std::make_pair( dataCols[0],
89  coral::AttributeSpecification::typeNameForId( typeid(coral::Blob) ) ));
90  iT->second.m_dataColumns.insert( std::make_pair( dataCols[1],
91  coral::AttributeSpecification::typeNameForId( typeid(std::string) ) ));
92  iT->second.m_nullableColumns.insert( dataCols[1] );
93  break;
95  iT->second.m_dataColumns.insert( std::make_pair( dataCols[0],
96  coral::AttributeSpecification::typeNameForId( typeid(int) ) ));
97  iT->second.m_dataColumns.insert( std::make_pair( dataCols[1],
98  coral::AttributeSpecification::typeNameForId( typeid(int) ) ));
99  break;
101  iT->second.m_dataColumns.insert( std::make_pair( dataCols[0],
102  coral::AttributeSpecification::typeNameForId( typeid(std::string) ) ));
103  break;
105  iT->second.m_dataColumns.insert( std::make_pair( dataCols[0],
106  coral::AttributeSpecification::typeNameForId( typeid(std::string) ) ));
107  iT->second.m_dataColumns.insert( std::make_pair( dataCols[1],
108  coral::AttributeSpecification::typeNameForId( typeid(int) ) ));
109  break;
110  default:
111  break;
112  }
113  }
114  TableInfo currT = iT->second;
115  for( MappingElement::const_iterator iM = element.begin();
116  iM != element.end(); ++iM ){
117  scanElement( iM->second, currT, isDependency, tableHierarchy, tableMap );
118  }
119  }
120 
121 }
122 
123 std::vector<ora::TableInfo> ora::MappingTree::tables() const {
124  std::vector<std::string> tableHierarchy;
125  std::map<std::string,TableInfo> tableMap;
126  TableInfo mainTable;
127  bool isDependency = false;
128  if( m_parentTable.get() ){
129  isDependency = true;
130  mainTable = *m_parentTable;
131  }
132  scanElement( m_element, mainTable, isDependency, tableHierarchy, tableMap );
133  std::vector<TableInfo> ret;
134  for( std::vector<std::string>::const_iterator iT = tableHierarchy.begin();
135  iT != tableHierarchy.end(); ++iT ){
136  std::map<std::string,TableInfo>::const_iterator iM = tableMap.find( *iT );
137  ret.push_back( iM->second );
138  }
139  return ret;
140 }
141 
142 void ora::MappingTree::printXML( std::ostream& outputStream ) const {
143  outputStream << "<?xml version=\'1.0\' encoding=\"UTF-8\"?>" << std::endl;
144  outputStream << "<!DOCTYPE OraDatabase SYSTEM \"InMemory\">" << std::endl;
145  outputStream << " <OraDatabase>" << std::endl;
146  outputStream << " <Mapping version=\""<<m_version<<"\" >"<< std::endl;
147  m_element.printXML( outputStream, " " );
148  outputStream << " </Mapping >"<< std::endl;
149  outputStream << " </OraDatabase>" << std::endl;
150 }
std::string m_version
Definition: MappingTree.h:115
tuple ret
prodAgent to be discontinued
void override(const MappingTree &source)
replace present data with the provided source
Definition: MappingTree.cc:58
std::auto_ptr< TableInfo > m_parentTable
Definition: MappingTree.h:122
const std::string & className() const
Definition: MappingTree.h:138
static std::string dependencyMappingElementType()
Returns the name of the dependent class mapping element type.
ElementType elementType() const
MappingElement & setTopElement(const std::string &className, const std::string &tableName, bool isDependent=false)
Definition: MappingTree.cc:40
MappingTree & operator=(const MappingTree &rhs)
Definition: MappingTree.cc:29
iterator begin()
Returns an iterator in the beginning of the sequence.
MappingTree()
Constructor.
Definition: MappingTree.cc:7
std::string m_tableName
Definition: MappingTree.h:40
~MappingTree()
Destructor.
Definition: MappingTree.cc:26
void scanElement(const MappingElement &element, const TableInfo &currentTable, bool isDependency, std::vector< std::string > &tableHierarchy, std::map< std::string, TableInfo > &tableMap)
Definition: MappingTree.cc:64
std::vector< TableInfo > tables() const
Definition: MappingTree.cc:123
const std::vector< std::string > & columnNames() const
void printXML(std::ostream &outputStream) const
Definition: MappingTree.cc:142
const std::string & variableType() const
std::map< std::string, MappingElement >::const_iterator const_iterator
std::vector< std::string > m_idColumns
Definition: MappingTree.h:41
iterator end()
Returns an iterator in the end of the sequence.
const std::string & tableName() const
void setDependency(const MappingTree &parentTree)
Definition: MappingTree.cc:52
static std::string classMappingElementType()
Returns the name of the class mapping element type.
static std::string const source
Definition: EdmProvDump.cc:43
MappingElement m_element
Definition: MappingTree.h:120
std::string className(const T &t)
Definition: ClassName.h:30