CMS 3D CMS Logo

Public Member Functions | Private Attributes

ora::MappingGenerator Class Reference

#include <MappingGenerator.h>

List of all members.

Public Member Functions

void createNewDependentMapping (const Reflex::Type &dependentClassDictionary, const MappingTree &parentClassMapping, MappingTree &destination)
void createNewDependentMapping (const Reflex::Type &dependentClassDictionary, const MappingTree &parentClassMapping, const MappingTree &dependentClassBaseMapping, MappingTree &destination)
void createNewMapping (const std::string &containerName, const Reflex::Type &classDictionary, const MappingTree &baseMapping, MappingTree &destination)
void createNewMapping (const std::string &containerName, const Reflex::Type &classDictionary, MappingTree &destination)
 MappingGenerator (coral::ISchema &schema)
 Constructor.
 ~MappingGenerator ()
 Destructor.

Private Attributes

coral::ISchema & m_schema
TableRegister m_tableRegister

Detailed Description

Definition at line 23 of file MappingGenerator.h.


Constructor & Destructor Documentation

ora::MappingGenerator::MappingGenerator ( coral::ISchema &  schema) [explicit]

Constructor.

Definition at line 9 of file MappingGenerator.cc.

ora::MappingGenerator::~MappingGenerator ( )

Destructor.

Definition at line 14 of file MappingGenerator.cc.

{}

Member Function Documentation

void ora::MappingGenerator::createNewDependentMapping ( const Reflex::Type &  dependentClassDictionary,
const MappingTree parentClassMapping,
MappingTree destination 
)

Definition at line 58 of file MappingGenerator.cc.

References className(), ora::MappingRules::ClassNameLengthForSchema, ora::MappingRules::columnNameForId(), ora::MappingRules::columnNameForRefColumn(), ora::MappingRules::formatName(), i, ora::MappingRules::MaxColumnsPerTable, ora::MappingRules::MaxTableNameLength, ora::MappingRules::newNameForDepSchemaObject(), ora::RelationalMappingFactory::newProcessor(), ora::MappingElement::setColumnNames(), ora::MappingTree::setDependency(), ora::MappingTree::setTopElement(), ora::RelationalMapping::sizeInColumns(), ora::MappingElement::tableName(), ora::throwException(), and ora::MappingTree::topElement().

                                                                                 {
  std::string className = classDictionary.Name(Reflex::SCOPED);
  
  size_t sz = RelationalMapping::sizeInColumns( classDictionary );
  if(sz > MappingRules::MaxColumnsPerTable){
    std::stringstream messg;
    messg << "Cannot process default mapping for class \"" << className+"\"";
    messg << " : number of columns ("<<sz<<") required exceedes maximum="<< MappingRules::MaxColumnsPerTable;
    throwException( messg.str(),"MappingGenerator::processClass");
  }
  
  std::string mainTableName = parentClassMapping.topElement().tableName();
  std::string initialTable = mainTableName;
  std::string tableName = ora::MappingRules::newNameForDepSchemaObject( initialTable, 0, ora::MappingRules::MaxTableNameLength );
  unsigned int i=0;
  while(m_tableRegister.checkTable(tableName)){
    tableName = ora::MappingRules::newNameForDepSchemaObject( initialTable, i, ora::MappingRules::MaxTableNameLength );
    i++;
  }
  m_tableRegister.insertTable(tableName);

  destination.setDependency( parentClassMapping );
  ora::MappingElement& classElement = destination.setTopElement( className, tableName, true );
  // Set the id of the class
  std::vector<std::string> columns;
  columns.push_back( ora::MappingRules::columnNameForId() );
  columns.push_back( ora::MappingRules::columnNameForRefColumn() );
  classElement.setColumnNames( columns );
  m_tableRegister.insertColumns(tableName, columns );
  RelationalMappingFactory mappingFactory( m_tableRegister );
  std::auto_ptr<IRelationalMapping> processor( mappingFactory.newProcessor( classDictionary ) );
  std::string nameForSchema = MappingRules::formatName( className, MappingRules::ClassNameLengthForSchema );
  std::string scope("");
  processor->process( classElement,  className, nameForSchema, scope );
}
void ora::MappingGenerator::createNewDependentMapping ( const Reflex::Type &  dependentClassDictionary,
const MappingTree parentClassMapping,
const MappingTree dependentClassBaseMapping,
MappingTree destination 
)

Definition at line 96 of file MappingGenerator.cc.

References ora::MappingTree::className(), ora::MappingTree::override(), and ora::throwException().

                                                                                 {
  createNewDependentMapping( classDictionary, parentClassMapping, destination );
  if(dependentClassBaseMapping.className()!=destination.className()){
    throwException( "Mapping specified as base does not map the target class \"" + destination.className()+"\"",
                    "MappingGenerator::createNewDependentMapping" );
  }
  destination.override( dependentClassBaseMapping );
}
void ora::MappingGenerator::createNewMapping ( const std::string &  containerName,
const Reflex::Type &  classDictionary,
MappingTree destination 
)

Definition at line 16 of file MappingGenerator.cc.

References className(), ora::MappingRules::ClassNameLengthForSchema, ora::MappingRules::columnNameForId(), ora::MappingElement::columnNames(), ora::MappingRules::formatName(), ora::MappingRules::MaxColumnsPerTable, ora::RelationalMappingFactory::newProcessor(), ora::MappingElement::setColumnNames(), ora::MappingTree::setTopElement(), ora::RelationalMapping::sizeInColumns(), ora::MappingRules::tableNameForItem(), and ora::throwException().

Referenced by ora::ContainerSchema::create().

                                                                        {
  std::string className = classDictionary.Name(Reflex::SCOPED);

  size_t sz = RelationalMapping::sizeInColumns( classDictionary );
  if(sz > MappingRules::MaxColumnsPerTable){
    std::stringstream messg;
    messg << "Cannot process default mapping for class \"" << className+"\"";
    messg << " : number of columns ("<<sz<<") required exceedes maximum="<< MappingRules::MaxColumnsPerTable;
    throwException( messg.str(),"MappingGenerator::processClass");
  }

  std::string tableName = ora::MappingRules::tableNameForItem( containerName );
  if(m_tableRegister.checkTable(tableName)){
    throwException( "Table \"" +tableName+ "\" already assigned, cannot be allocated for the mapping of class \""+className+"\"",
                    "MappingGenerator::processClass");
  }
  m_tableRegister.insertTable(tableName);
  // Define the top level element
  MappingElement& topElement = destination.setTopElement( className, tableName );
  topElement.setColumnNames( std::vector< std::string >( 1, ora::MappingRules::columnNameForId() ) );
  m_tableRegister.insertColumns(tableName, topElement.columnNames() );
  RelationalMappingFactory mappingFactory( m_tableRegister );
  std::auto_ptr<IRelationalMapping> processor( mappingFactory.newProcessor( classDictionary ) );
  std::string nameForSchema = MappingRules::formatName( className, MappingRules::ClassNameLengthForSchema );
  std::string scope("");
  processor->process( topElement, className, nameForSchema, scope   );
}
void ora::MappingGenerator::createNewMapping ( const std::string &  containerName,
const Reflex::Type &  classDictionary,
const MappingTree baseMapping,
MappingTree destination 
)

Definition at line 46 of file MappingGenerator.cc.

References ora::MappingTree::className(), ora::MappingTree::override(), and ora::throwException().

                                                                        {
  createNewMapping( containerName, classDictionary, destination );
  if(baseMapping.className()!=destination.className()){
    throwException( "Mapping specified as base does not map the target class \"" + destination.className()+"\"",
                    "MappingGenerator::createNewMapping" );
  }
  destination.override( baseMapping );
}

Member Data Documentation

coral::ISchema& ora::MappingGenerator::m_schema [private]

Definition at line 44 of file MappingGenerator.h.

Definition at line 45 of file MappingGenerator.h.