#include <RelationalMapping.h>
Public Member Functions | |
ArrayMapping (const Reflex::Type &attributeType, TableRegister &tableRegister) | |
void | process (MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema) |
~ArrayMapping () | |
Private Attributes | |
TableRegister & | m_tableRegister |
Reflex::Type | m_type |
Definition at line 129 of file RelationalMapping.h.
ora::ArrayMapping::ArrayMapping | ( | const Reflex::Type & | attributeType, |
TableRegister & | tableRegister | ||
) |
Definition at line 351 of file RelationalMapping.cc.
: m_type(attributeType), m_tableRegister( tableRegister ){ }
ora::ArrayMapping::~ArrayMapping | ( | ) |
Definition at line 355 of file RelationalMapping.cc.
{ }
void ora::ArrayMapping::process | ( | MappingElement & | parentElement, |
const std::string & | attributeName, | ||
const std::string & | attributeNameForSchema, | ||
const std::string & | scopeNameForSchema | ||
) | [virtual] |
Implements ora::IRelationalMapping.
Definition at line 358 of file RelationalMapping.cc.
References ora::MappingElement::appendSubElement(), ora::MappingElement::arrayMappingElementType(), className(), ora::MappingRules::columnNameForId(), ora::MappingRules::columnNameForPosition(), ora::MappingElement::columnNames(), ora::ClassUtils::containerDataType(), ora::ClassUtils::containerKeyType(), ora::ClassUtils::containerValueType(), i, ora::ClassUtils::isTypeAssociativeContainer(), ora::ClassUtils::isTypeNonAssociativeContainer(), ora::ClassUtils::isTypePVector(), ora::ClassUtils::isTypeQueryableVector(), ora::MappingRules::MaxTableNameLength, ora::MappingRules::newNameForArraySchemaObject(), ora::RelationalMappingFactory::newProcessor(), ora::MappingElement::OraArrayMappingElementType(), ora::ClassUtils::resolvedType(), ora::MappingElement::setColumnNames(), ora::MappingElement::tableName(), ora::throwException(), ora::MappingRules::variableNameForContainerKey(), and ora::MappingRules::variableNameForContainerValue().
{ 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); std::string className = m_type.Name(Reflex::SCOPED); std::string elementType = ora::MappingElement::arrayMappingElementType(); if(ora::ClassUtils::isTypePVector(m_type) || ora::ClassUtils::isTypeQueryableVector(m_type)){ elementType = ora::MappingElement::OraArrayMappingElementType(); } ora::MappingElement& me = parentElement.appendSubElement( elementType,attributeName,className,arrayTable ); const std::vector<std::string>& parentColumns = parentElement.columnNames(); if( parentColumns.empty()){ throwException( "No column name found in the parent mapping element.","ArrayMapping::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 arrayScopeNameForSchema = scopeNameForSchema; if( !arrayScopeNameForSchema.empty() ) arrayScopeNameForSchema +="_"; arrayScopeNameForSchema += attributeNameForSchema; bool singleItemContainer = ora::ClassUtils::isTypeNonAssociativeContainer(m_type); bool associativeContainer = ora::ClassUtils::isTypeAssociativeContainer(m_type); Reflex::Type contentType; Reflex::Type keyType; if( singleItemContainer ){ contentType = ClassUtils::containerValueType(m_type); } else if ( associativeContainer ) { // This is an associative container type contentType = ClassUtils::containerDataType( m_type ); keyType = ClassUtils::containerKeyType( m_type ); if( !keyType || !ClassUtils::resolvedType(keyType) ){ throwException( "Cannot not resolve the type of the key item of container \""+m_type.Name(Reflex::SCOPED)+"\".", "ArrayMapping::process"); } } else { // Not supported container throwException( "Container type=\""+m_type.Name(Reflex::SCOPED)+"\".is not supported.", "ArrayMapping::process"); } if( !contentType || !ClassUtils::resolvedType(contentType) ){ throwException( "Cannot not resolve the type of the content item of container \""+m_type.Name(Reflex::SCOPED)+"\".", "ArrayMapping::process"); } RelationalMappingFactory mappingFactory( m_tableRegister ); if ( keyType ) { std::string keyTypeName = keyType.Name(); std::string keyTypeNameForSchema = MappingRules::variableNameForContainerKey(); std::auto_ptr<IRelationalMapping> keyProcessor( mappingFactory.newProcessor( keyType ) ); keyProcessor->process( me, keyTypeName, keyTypeNameForSchema, arrayScopeNameForSchema ); } std::string contentTypeName = contentType.Name(); std::string contentTypeNameForSchema = MappingRules::variableNameForContainerValue(); std::auto_ptr<IRelationalMapping> contentProcessor( mappingFactory.newProcessor( contentType ) ); contentProcessor->process( me, contentTypeName, contentTypeNameForSchema, arrayScopeNameForSchema ); }
TableRegister& ora::ArrayMapping::m_tableRegister [private] |
Definition at line 139 of file RelationalMapping.h.
Reflex::Type ora::ArrayMapping::m_type [private] |
Definition at line 138 of file RelationalMapping.h.