CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
ora::CArrayMapping Class Reference

#include <RelationalMapping.h>

Inheritance diagram for ora::CArrayMapping:
ora::IRelationalMapping

Public Member Functions

 CArrayMapping (const Reflex::Type &attributeType, TableRegister &tableRegister)
 
void process (MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema)
 
 ~CArrayMapping ()
 
- Public Member Functions inherited from ora::IRelationalMapping
virtual ~IRelationalMapping ()
 

Private Attributes

TableRegisterm_tableRegister
 
Reflex::Type m_type
 

Detailed Description

Definition at line 143 of file RelationalMapping.h.

Constructor & Destructor Documentation

ora::CArrayMapping::CArrayMapping ( const Reflex::Type &  attributeType,
TableRegister tableRegister 
)

Definition at line 437 of file RelationalMapping.cc.

437  :
438  m_type(attributeType), m_tableRegister( tableRegister ){
439 }
TableRegister & m_tableRegister
ora::CArrayMapping::~CArrayMapping ( )

Definition at line 441 of file RelationalMapping.cc.

441  {
442 }

Member Function Documentation

void ora::CArrayMapping::process ( MappingElement parentElement,
const std::string &  attributeName,
const std::string &  attributeNameForSchema,
const std::string &  scopeNameForSchema 
)
virtual

otherwise, process as standard CArrays in separate tables

Implements ora::IRelationalMapping.

Definition at line 444 of file RelationalMapping.cc.

References ora::MappingElement::appendSubElement(), ora::MappingElement::CArrayMappingElementType(), className(), ora::MappingRules::columnNameForId(), ora::MappingRules::columnNameForPosition(), ora::MappingElement::columnNames(), i, ora::MappingElement::inlineCArrayMappingElementType(), ora::MappingRules::MaxColumnsForInlineCArray, ora::MappingRules::MaxColumnsPerTable, ora::MappingRules::MaxTableNameLength, ora::MappingRules::newNameForArraySchemaObject(), ora::RelationalMappingFactory::newProcessor(), ora::ClassUtils::resolvedType(), ora::MappingElement::setColumnNames(), ora::RelationalMapping::sizeInColumnsForCArray(), ora::MappingElement::tableName(), ora::throwException(), ora::MappingRules::variableNameForArrayColumn(), and ora::MappingRules::variableNameForArrayIndex().

Referenced by python.Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::dumpPython(), python.Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::open(), python.Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::outputEventContent(), python.Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::setProcess(), and python.Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::setProperty().

447  {
448  Reflex::Type arrayElementType = m_type.ToType();
449  if( !arrayElementType || !ClassUtils::resolvedType( arrayElementType ) ){
450  throwException("Cannot resolve the type of the content of the array \""+m_type.Name(Reflex::SCOPED)+"\".",
451  "CArrayMapping::process");
452  }
453 
454  if(!m_tableRegister.checkTable(parentElement.tableName())){
455  throwException("Table \""+parentElement.tableName()+"\" has not been allocated.",
456  "CArrayMapping::process");
457  }
458  std::string className = m_type.Name(Reflex::SCOPED);
459  RelationalMappingFactory mappingFactory( m_tableRegister );
460 
461  std::string arrayScopeNameForSchema = scopeNameForSchema;
462  if( !arrayScopeNameForSchema.empty() ) arrayScopeNameForSchema +="_";
463  arrayScopeNameForSchema += attributeNameForSchema;
464 
465  std::pair<bool,size_t> arraySizeInColumns = RelationalMapping::sizeInColumnsForCArray( m_type );
466  if( !arraySizeInColumns.first && arraySizeInColumns.second < MappingRules::MaxColumnsForInlineCArray ) {
467  size_t columnsInTable = m_tableRegister.numberOfColumns(parentElement.tableName()) + arraySizeInColumns.second;
468  if( columnsInTable < MappingRules::MaxColumnsPerTable ){
469  // Inline C-Array
470  std::string mappingElementType = ora::MappingElement::inlineCArrayMappingElementType();
471  ora::MappingElement& me = parentElement.appendSubElement( mappingElementType, attributeName, className, parentElement.tableName() );
472  me.setColumnNames( parentElement.columnNames() );
473  std::auto_ptr<IRelationalMapping> processor( mappingFactory.newProcessor( arrayElementType ) );
474  for(size_t i=0;i<m_type.ArrayLength();i++){
475  processor->process( me, MappingRules::variableNameForArrayIndex(attributeName,i),
476  MappingRules::variableNameForArrayColumn(i), arrayScopeNameForSchema );
477  }
478  return;
479  }
480  }
482  std::string tableName = parentElement.tableName();
483  std::string initialTable(tableName);
484 
485  std::string arrayTable(initialTable);
486  unsigned int i=0;
487  while(m_tableRegister.checkTable(arrayTable)){
489  i++;
490  }
491  m_tableRegister.insertTable(arrayTable);
493  attributeName, attributeName, arrayTable );
494  const std::vector<std::string>& parentColumns = parentElement.columnNames();
495  if( parentColumns.empty()){
496  throwException( "No column name found in the parent mapping element.","CArrayMapping::process");
497  }
498  std::vector<std::string> columns;
499  // always comes the oid first
500  columns.push_back( ora::MappingRules::columnNameForId() );
501  std::vector<std::string>::const_iterator iColumn = parentColumns.begin();
502  // then copy the columns except the id...
503  iColumn++;
504  for ( ;iColumn != parentColumns.end(); ++iColumn ) {
505  columns.push_back( ora::MappingRules::columnNameForId() + "_" + *iColumn );
506  }
507  // and finally add the position!
508  columns.push_back( ora::MappingRules::columnNameForPosition() );
509  me.setColumnNames( columns );
510  m_tableRegister.insertColumns(arrayTable, columns );
511 
512  std::string contentTypeName = arrayElementType.Name();
513  std::string variableNameForSchema = MappingRules::variableNameForArrayColumn( m_type );
514  std::auto_ptr<IRelationalMapping> processor( mappingFactory.newProcessor( arrayElementType ) );
515  processor->process( me, contentTypeName, variableNameForSchema, arrayScopeNameForSchema );
516 }
int i
Definition: DBlmapReader.cc:9
static std::string variableNameForArrayIndex(const std::string &arrayVariable, unsigned int index)
static std::string variableNameForArrayColumn(unsigned int arrayIndex)
bool insertColumns(const std::string &tableName, const std::vector< std::string > &columns)
static const size_t MaxColumnsForInlineCArray
Definition: MappingRules.h:22
size_t numberOfColumns(const std::string &tableName)
MappingElement & appendSubElement(const std::string &elementType, const std::string &variableName, const std::string &variableType, const std::string &tableName)
static std::string columnNameForPosition()
void insertTable(const std::string &tableName)
std::pair< bool, size_t > sizeInColumnsForCArray(const Reflex::Type &arrayType)
static std::string newNameForArraySchemaObject(const std::string &initialName, unsigned int index, size_t maxLength)
static std::string columnNameForId()
const std::vector< std::string > & columnNames() const
TableRegister & m_tableRegister
Reflex::Type resolvedType(const Reflex::Type &typ)
Definition: ClassUtils.cc:380
static std::string inlineCArrayMappingElementType()
Returns the name of the inline array mapping element type.
static const size_t MaxColumnsPerTable
Definition: MappingRules.h:21
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
static const size_t MaxTableNameLength
Definition: MappingRules.h:19
bool checkTable(const std::string &tableName)
static std::string CArrayMappingElementType()
Returns the name of the array mapping element type.
std::string className(const T &t)
Definition: ClassName.h:30
void setColumnNames(const std::vector< std::string > &columns)

Member Data Documentation

TableRegister& ora::CArrayMapping::m_tableRegister
private

Definition at line 153 of file RelationalMapping.h.

Reflex::Type ora::CArrayMapping::m_type
private

Definition at line 152 of file RelationalMapping.h.