CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MappingGenerator.cc
Go to the documentation of this file.
2 #include "MappingGenerator.h"
3 #include "RelationalMapping.h"
4 #include "MappingTree.h"
5 #include "MappingRules.h"
6 // externals
8 
10  m_schema( schema ),
11  m_tableRegister( schema ){
12 }
13 
15 
17  const edm::TypeWithDict& classDictionary,
18  MappingTree& destination ){
19  std::string className = classDictionary.cppName();
20 
21  size_t sz = RelationalMapping::sizeInColumns( classDictionary );
23  std::stringstream messg;
24  messg << "Cannot process default mapping for class \"" << className+"\"";
25  messg << " : number of columns ("<<sz<<") required exceedes maximum="<< MappingRules::MaxColumnsPerTable;
26  throwException( messg.str(),"MappingGenerator::processClass");
27  }
28 
30  if(m_tableRegister.checkTable(tableName)){
31  throwException( "Table \"" +tableName+ "\" already assigned, cannot be allocated for the mapping of class \""+className+"\"",
32  "MappingGenerator::processClass");
33  }
34  m_tableRegister.insertTable(tableName);
35  // Define the top level element
36  MappingElement& topElement = destination.setTopElement( className, tableName );
37  topElement.setColumnNames( std::vector< std::string >( 1, ora::MappingRules::columnNameForId() ) );
38  m_tableRegister.insertColumns(tableName, topElement.columnNames() );
39  RelationalMappingFactory mappingFactory( m_tableRegister );
40  std::auto_ptr<IRelationalMapping> processor( mappingFactory.newProcessor( classDictionary ) );
42  std::string scope("");
43  processor->process( topElement, className, nameForSchema, scope );
44 }
45 
47  const edm::TypeWithDict& classDictionary,
48  const MappingTree& baseMapping,
49  MappingTree& destination ){
50  createNewMapping( containerName, classDictionary, destination );
51  if(baseMapping.className()!=destination.className()){
52  throwException( "Mapping specified as base does not map the target class \"" + destination.className()+"\"",
53  "MappingGenerator::createNewMapping" );
54  }
55  destination.override( baseMapping );
56 }
57 
59  const MappingTree& parentClassMapping,
60  MappingTree& destination ){
61  std::string className = classDictionary.cppName();
62 
63  size_t sz = RelationalMapping::sizeInColumns( classDictionary );
65  std::stringstream messg;
66  messg << "Cannot process default mapping for class \"" << className+"\"";
67  messg << " : number of columns ("<<sz<<") required exceedes maximum="<< MappingRules::MaxColumnsPerTable;
68  throwException( messg.str(),"MappingGenerator::processClass");
69  }
70 
71  std::string mainTableName = parentClassMapping.topElement().tableName();
72  std::string initialTable = mainTableName;
74  unsigned int i=0;
75  while(m_tableRegister.checkTable(tableName)){
77  i++;
78  }
79  m_tableRegister.insertTable(tableName);
80 
81  destination.setDependency( parentClassMapping );
82  ora::MappingElement& classElement = destination.setTopElement( className, tableName, true );
83  // Set the id of the class
84  std::vector<std::string> columns;
85  columns.push_back( ora::MappingRules::columnNameForId() );
86  columns.push_back( ora::MappingRules::columnNameForRefColumn() );
87  classElement.setColumnNames( columns );
88  m_tableRegister.insertColumns(tableName, columns );
89  RelationalMappingFactory mappingFactory( m_tableRegister );
90  std::auto_ptr<IRelationalMapping> processor( mappingFactory.newProcessor( classDictionary ) );
92  std::string scope("");
93  processor->process( classElement, className, nameForSchema, scope );
94 }
95 
97  const MappingTree& parentClassMapping,
98  const MappingTree& dependentClassBaseMapping,
99  MappingTree& destination ){
100  createNewDependentMapping( classDictionary, parentClassMapping, destination );
101  if(dependentClassBaseMapping.className()!=destination.className()){
102  throwException( "Mapping specified as base does not map the target class \"" + destination.className()+"\"",
103  "MappingGenerator::createNewDependentMapping" );
104  }
105  destination.override( dependentClassBaseMapping );
106 }
107 
int i
Definition: DBlmapReader.cc:9
void override(const MappingTree &source)
replace present data with the provided source
Definition: MappingTree.cc:58
MappingGenerator(coral::ISchema &schema)
Constructor.
const std::string & className() const
Definition: MappingTree.h:138
static std::string newNameForDepSchemaObject(const std::string &initialName, unsigned int index, size_t maxLength)
void createNewDependentMapping(const edm::TypeWithDict &dependentClassDictionary, const MappingTree &parentClassMapping, MappingTree &destination)
static std::string columnNameForRefColumn()
MappingElement & setTopElement(const std::string &className, const std::string &tableName, bool isDependent=false)
Definition: MappingTree.cc:40
~MappingGenerator()
Destructor.
std::string cppName() const
IRelationalMapping * newProcessor(const edm::TypeWithDict &attributeType, bool blobStreaming=false)
const MappingElement & topElement() const
Definition: MappingTree.h:143
static std::string columnNameForId()
const std::vector< std::string > & columnNames() const
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
static const size_t MaxColumnsPerTable
Definition: MappingRules.h:21
static const size_t ClassNameLengthForSchema
size parameters for table creation
Definition: MappingRules.h:18
size_t sizeInColumns(const edm::TypeWithDict &topLevelClassType)
static std::string tableNameForItem(const std::string &itemName)
schema object naming
const std::string & tableName() const
void createNewMapping(const std::string &containerName, const edm::TypeWithDict &classDictionary, MappingTree &destination)
void setDependency(const MappingTree &parentTree)
Definition: MappingTree.cc:52
static const size_t MaxTableNameLength
Definition: MappingRules.h:19
static std::string formatName(const std::string &variableName, size_t maxLength)
formatting for variable names to schema object names
std::string className(const T &t)
Definition: ClassName.h:30
void setColumnNames(const std::vector< std::string > &columns)