CMS 3D CMS Logo

Public Member Functions | Private Attributes

ora::CArrayMapping Class Reference

#include <RelationalMapping.h>

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

List of all members.

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 ()

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.

                                                                                              :
  m_type(attributeType), m_tableRegister( tableRegister ){
}
ora::CArrayMapping::~CArrayMapping ( )

Definition at line 441 of file RelationalMapping.cc.

                                {
}

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().

                                                                       {
  Reflex::Type arrayElementType = m_type.ToType();
  if( !arrayElementType || !ClassUtils::resolvedType( arrayElementType ) ){
    throwException("Cannot resolve the type of the content of the array \""+m_type.Name(Reflex::SCOPED)+"\".",
                   "CArrayMapping::process");
  }

  if(!m_tableRegister.checkTable(parentElement.tableName())){
    throwException("Table \""+parentElement.tableName()+"\" has not been allocated.",
                   "CArrayMapping::process");
  }
  std::string className = m_type.Name(Reflex::SCOPED);
  RelationalMappingFactory mappingFactory( m_tableRegister );

  std::string arrayScopeNameForSchema = scopeNameForSchema;
  if( !arrayScopeNameForSchema.empty() ) arrayScopeNameForSchema +="_";
  arrayScopeNameForSchema += attributeNameForSchema;

  std::pair<bool,size_t> arraySizeInColumns = RelationalMapping::sizeInColumnsForCArray( m_type );
  if( !arraySizeInColumns.first && arraySizeInColumns.second < MappingRules::MaxColumnsForInlineCArray ) {
    size_t columnsInTable = m_tableRegister.numberOfColumns(parentElement.tableName()) + arraySizeInColumns.second;
    if( columnsInTable < MappingRules::MaxColumnsPerTable ){
      // Inline C-Array
      std::string mappingElementType = ora::MappingElement::inlineCArrayMappingElementType();
      ora::MappingElement& me = parentElement.appendSubElement( mappingElementType, attributeName, className, parentElement.tableName() );
      me.setColumnNames( parentElement.columnNames() );
      std::auto_ptr<IRelationalMapping> processor( mappingFactory.newProcessor( arrayElementType ) );
      for(size_t i=0;i<m_type.ArrayLength();i++){
        processor->process( me, MappingRules::variableNameForArrayIndex(attributeName,i), 
                            MappingRules::variableNameForArrayColumn(i), arrayScopeNameForSchema );
      }
      return;
    }
  }
  std::string tableName = parentElement.tableName();
  std::string initialTable(tableName);

  std::string arrayTable(initialTable);
  unsigned int i=0;
  while(m_tableRegister.checkTable(arrayTable)){
    arrayTable = ora::MappingRules::newNameForArraySchemaObject( initialTable, i, ora::MappingRules::MaxTableNameLength );
    i++;
  }
  m_tableRegister.insertTable(arrayTable);
  ora::MappingElement& me = parentElement.appendSubElement( ora::MappingElement::CArrayMappingElementType(),
                                                            attributeName, className, arrayTable );
  const std::vector<std::string>& parentColumns = parentElement.columnNames();
  if( parentColumns.empty()){
    throwException( "No column name found in the parent mapping element.","CArrayMapping::process");
  }
  std::vector<std::string> columns;
  // always comes the oid first
  columns.push_back( ora::MappingRules::columnNameForId() );
  std::vector<std::string>::const_iterator iColumn = parentColumns.begin();
  // then copy the columns except the id...
  iColumn++;
  for ( ;iColumn != parentColumns.end(); ++iColumn ) {
    columns.push_back( ora::MappingRules::columnNameForId() + "_" + *iColumn );
  }
  // and finally add the position!
  columns.push_back( ora::MappingRules::columnNameForPosition() );
  me.setColumnNames( columns );
  m_tableRegister.insertColumns(arrayTable, columns );

  std::string contentTypeName = arrayElementType.Name();
  std::string variableNameForSchema = MappingRules::variableNameForArrayColumn( m_type  );
  std::auto_ptr<IRelationalMapping> processor( mappingFactory.newProcessor( arrayElementType ) );
  processor->process( me, contentTypeName, variableNameForSchema, arrayScopeNameForSchema );
}

Member Data Documentation

Definition at line 153 of file RelationalMapping.h.

Reflex::Type ora::CArrayMapping::m_type [private]

Definition at line 152 of file RelationalMapping.h.