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 
13 ora::MappingTree::MappingTree( const std::string& version ):
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 ){
43  std::string elementType = ora::MappingElement::classMappingElementType();
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  break;
92  iT->second.m_dataColumns.insert( std::make_pair( dataCols[0],
93  coral::AttributeSpecification::typeNameForId( typeid(int) ) ));
94  iT->second.m_dataColumns.insert( std::make_pair( dataCols[1],
95  coral::AttributeSpecification::typeNameForId( typeid(int) ) ));
96  break;
98  iT->second.m_dataColumns.insert( std::make_pair( dataCols[0],
99  coral::AttributeSpecification::typeNameForId( typeid(std::string) ) ));
100  break;
102  iT->second.m_dataColumns.insert( std::make_pair( dataCols[0],
103  coral::AttributeSpecification::typeNameForId( typeid(std::string) ) ));
104  iT->second.m_dataColumns.insert( std::make_pair( dataCols[1],
105  coral::AttributeSpecification::typeNameForId( typeid(int) ) ));
106  break;
107  default:
108  break;
109  }
110  }
111  TableInfo currT = iT->second;
112  for( MappingElement::const_iterator iM = element.begin();
113  iM != element.end(); ++iM ){
114  scanElement( iM->second, currT, isDependency, tableHierarchy, tableMap );
115  }
116  }
117 
118 }
119 
120 std::vector<ora::TableInfo> ora::MappingTree::tables() const {
121  std::vector<std::string> tableHierarchy;
122  std::map<std::string,TableInfo> tableMap;
123  TableInfo mainTable;
124  bool isDependency = false;
125  if( m_parentTable.get() ){
126  isDependency = true;
127  mainTable = *m_parentTable;
128  }
129  scanElement( m_element, mainTable, isDependency, tableHierarchy, tableMap );
130  std::vector<TableInfo> ret;
131  for( std::vector<std::string>::const_iterator iT = tableHierarchy.begin();
132  iT != tableHierarchy.end(); ++iT ){
133  std::map<std::string,TableInfo>::const_iterator iM = tableMap.find( *iT );
134  ret.push_back( iM->second );
135  }
136  return ret;
137 }
138 
139 void ora::MappingTree::printXML( std::ostream& outputStream ) const {
140  outputStream << "<?xml version=\'1.0\' encoding=\"UTF-8\"?>" << std::endl;
141  outputStream << "<!DOCTYPE OraDatabase SYSTEM \"InMemory\">" << std::endl;
142  outputStream << " <OraDatabase>" << std::endl;
143  outputStream << " <Mapping version=\""<<m_version<<"\" >"<< std::endl;
144  m_element.printXML( outputStream, " " );
145  outputStream << " </Mapping >"<< std::endl;
146  outputStream << " </OraDatabase>" << std::endl;
147 }
std::string m_version
Definition: MappingTree.h:111
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:118
const std::string & className() const
Definition: MappingTree.h:134
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:37
~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:120
const std::vector< std::string > & columnNames() const
void printXML(std::ostream &outputStream) const
Definition: MappingTree.cc:139
const std::string & variableType() const
std::map< std::string, MappingElement >::const_iterator const_iterator
std::vector< std::string > m_idColumns
Definition: MappingTree.h:38
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.
MappingElement m_element
Definition: MappingTree.h:116
std::string className(const T &t)
Definition: ClassName.h:30