10 #include "Reflex/Reflex.h"
11 #include "CoralBase/AttributeSpecification.h"
16 bool hasDependencies =
false;
21 std::pair<bool,size_t>
24 bool hasDependencies =
false;
26 return std::make_pair(hasDependencies,sz);
33 bool& hasDependencies ){
42 }
else if (typ.IsArray()){
45 if( arraySize < MappingRules::MaxColumnsForInlineCArray ) sz += arraySize;
46 else hasDependencies =
true;
48 typ.HasBase( Reflex::Type::ByTypeInfo(
typeid(
ora::Reference) ) )){
55 if( !isContainer && !isOraPointer ){
60 for (
size_t i=0;
i< typ.DataMemberSize();
i++){
61 Reflex::Member objMember = typ.DataMemberAt(
i);
64 if ( objMember.IsTransient() )
continue;
72 hasDependencies =
true;
80 bool& hasDependencies){
87 size_t arraySize = typ.ArrayLength();
89 size_t arrayElementSize = 0;
91 size_t totSize = arraySize*arrayElementSize;
97 m_tableRegister( tableRegister ){
104 bool blobStreaming ){
106 return new BlobMapping( attributeType, m_tableRegister );
112 else if ( resType.IsArray() ){
116 return new ArrayMapping( attributeType, m_tableRegister );
118 else if ( resType.IsPointer() || resType.IsReference() ){
128 resType.HasBase( Reflex::Type::ByTypeInfo(
typeid(
ora::Reference) ) ) ){
142 const std::string& elementType,
143 const std::string& typeName,
144 const std::string& attributeName,
145 const std::string& attributeNameForSchema,
146 const std::string& scopeNameForSchema,
150 "processLeafElement");
154 std::string columnName(inputCol);
166 m_type(attributeType),m_tableRegister( tableRegister ){
173 const std::string& attributeName,
174 const std::string& attributeNameForSchema,
175 const std::string& scopeNameForSchema ){
177 const std::type_info* attrType = &t.TypeInfo();
178 if(t.IsEnum()) attrType = &
typeid(
int);
181 std::string typeName = coral::AttributeSpecification::typeNameForId(*attrType);
187 attributeNameForSchema,
193 m_type(attributeType),m_tableRegister( tableRegister ){
199 const std::string& attributeName,
200 const std::string& attributeNameForSchema,
201 const std::string& scopeNameForSchema ){
202 std::string
className = m_type.Name(Reflex::SCOPED);
207 attributeNameForSchema,
213 m_type(attributeType),m_tableRegister( tableRegister ){
220 const std::string& attributeName,
221 const std::string& attributeNameForSchema,
222 const std::string& scopeNameForSchema ){
223 std::string
className = m_type.Name(Reflex::SCOPED);
225 if(!m_tableRegister.checkTable( parentElement.
tableName())){
227 "OraReferenceMapping::process");
231 std::vector<std::string> cols;
232 for(
unsigned int j=0;
j<2;
j++){
234 std::string columnName(inputCol);
236 while(m_tableRegister.checkColumn(parentElement.
tableName(),columnName)){
240 m_tableRegister.insertColumn(parentElement.
tableName(),columnName);
241 cols.push_back( columnName );
247 m_type(attributeType),m_tableRegister( tableRegister ){
254 const std::string& attributeName,
255 const std::string& attributeNameForSchema,
256 const std::string& scopeNameForSchema ){
258 std::string typeName = m_type.Name(Reflex::SCOPED);
259 if(!m_tableRegister.checkTable( parentElement.
tableName())){
261 "UniqueReferenceMapping::process");
265 std::vector< std::string > cols;
267 std::string columnName(inputCol);
269 while(m_tableRegister.checkColumn(parentElement.
tableName(),columnName)){
273 m_tableRegister.insertColumn(parentElement.
tableName(),columnName);
274 cols.push_back(columnName);
279 while(m_tableRegister.checkColumn(parentElement.
tableName(),columnName)){
283 m_tableRegister.insertColumn(parentElement.
tableName(),columnName);
284 cols.push_back(columnName);
290 m_type(attributeType), m_tableRegister( tableRegister ){
297 const std::string& attributeName,
298 const std::string& attributeNameForSchema,
299 const std::string& scopeNameForSchema ){
301 std::string typeName = m_type.Name(Reflex::SCOPED);
306 std::string ptrTypeName = ptrType.Name();
309 std::auto_ptr<IRelationalMapping> processor( factory.
newProcessor( ptrType ) );
310 processor->process( me, ptrTypeName, attributeNameForSchema, scopeNameForSchema );
314 m_type( attributeType ),
315 m_tableRegister( tableRegister ){
322 const std::string& attributeName,
323 const std::string& attributeNameForSchema,
324 const std::string& scopeNameForSchema ){
325 std::string typeName = m_type.Name(Reflex::SCOPED);
328 std::vector< std::string > cols;
330 std::string columnName(inputCol);
332 while(m_tableRegister.checkColumn(parentElement.
tableName(),columnName)){
336 m_tableRegister.insertColumn(parentElement.
tableName(),columnName);
337 cols.push_back(columnName);
344 m_type(attributeType), m_tableRegister( tableRegister ){
351 const std::string& attributeName,
352 const std::string& attributeNameForSchema,
353 const std::string& scopeNameForSchema ){
354 std::string tableName = parentElement.
tableName();
355 std::string initialTable(tableName);
357 std::string arrayTable(initialTable);
359 while(m_tableRegister.checkTable(arrayTable)){
363 m_tableRegister.insertTable(arrayTable);
365 std::string
className = m_type.Name(Reflex::SCOPED);
372 const std::vector<std::string>& parentColumns = parentElement.
columnNames();
373 if( parentColumns.empty()){
374 throwException(
"No column name found in the parent mapping element.",
"ArrayMapping::process");
377 std::vector<std::string> columns;
380 std::vector<std::string>::const_iterator iColumn = parentColumns.begin();
383 for ( ;iColumn != parentColumns.end(); iColumn++ ) {
390 m_tableRegister.insertColumns(arrayTable, columns );
392 std::string arrayScopeNameForSchema = scopeNameForSchema;
393 if( !arrayScopeNameForSchema.empty() ) arrayScopeNameForSchema +=
"_";
394 arrayScopeNameForSchema += attributeNameForSchema;
403 if( singleItemContainer ){
406 else if ( associativeContainer ) {
410 throwException(
"Cannot not resolve the type of the key item of container \""+m_type.Name(Reflex::SCOPED)+
"\".",
411 "ArrayMapping::process");
416 throwException(
"Container type=\""+m_type.Name(Reflex::SCOPED)+
"\".is not supported.",
417 "ArrayMapping::process");
421 throwException(
"Cannot not resolve the type of the content item of container \""+m_type.Name(Reflex::SCOPED)+
"\".",
422 "ArrayMapping::process");
426 std::string keyTypeName = keyType.Name();
428 std::auto_ptr<IRelationalMapping> keyProcessor( mappingFactory.
newProcessor( keyType ) );
429 keyProcessor->process( me, keyTypeName, keyTypeNameForSchema, arrayScopeNameForSchema );
431 std::string contentTypeName = contentType.Name();
433 std::auto_ptr<IRelationalMapping> contentProcessor( mappingFactory.
newProcessor( contentType ) );
434 contentProcessor->process( me, contentTypeName, contentTypeNameForSchema, arrayScopeNameForSchema );
438 m_type(attributeType), m_tableRegister( tableRegister ){
445 const std::string& attributeName,
446 const std::string& attributeNameForSchema,
447 const std::string& scopeNameForSchema ){
450 throwException(
"Cannot resolve the type of the content of the array \""+m_type.Name(Reflex::SCOPED)+
"\".",
451 "CArrayMapping::process");
454 if(!m_tableRegister.checkTable(parentElement.
tableName())){
456 "CArrayMapping::process");
458 std::string
className = m_type.Name(Reflex::SCOPED);
461 std::string arrayScopeNameForSchema = scopeNameForSchema;
462 if( !arrayScopeNameForSchema.empty() ) arrayScopeNameForSchema +=
"_";
463 arrayScopeNameForSchema += attributeNameForSchema;
467 size_t columnsInTable = m_tableRegister.numberOfColumns(parentElement.
tableName()) + arraySizeInColumns.second;
473 std::auto_ptr<IRelationalMapping> processor( mappingFactory.
newProcessor( arrayElementType ) );
474 for(
size_t i=0;
i<m_type.ArrayLength();
i++){
482 std::string tableName = parentElement.
tableName();
483 std::string initialTable(tableName);
485 std::string arrayTable(initialTable);
487 while(m_tableRegister.checkTable(arrayTable)){
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");
498 std::vector<std::string> columns;
501 std::vector<std::string>::const_iterator iColumn = parentColumns.begin();
504 for ( ;iColumn != parentColumns.end(); ++iColumn ) {
510 m_tableRegister.insertColumns(arrayTable, columns );
512 std::string contentTypeName = arrayElementType.Name();
514 std::auto_ptr<IRelationalMapping> processor( mappingFactory.
newProcessor( arrayElementType ) );
515 processor->process( me, contentTypeName, variableNameForSchema, arrayScopeNameForSchema );
519 m_type(attributeType), m_tableRegister( tableRegister ){
529 const std::string& scopeNameForSchema,
531 std::string
className = objType.Name(Reflex::SCOPED);
532 for (
size_t i=0;
i< objType.BaseSize();
i++){
536 throwException(
"Class for base \""+base.Name()+
"\" is not in the dictionary.",
"ObjectMapping::process");
541 for (
size_t j=0;
j< baseType.DataMemberSize();
j++){
542 Reflex::Member baseMember = baseType.DataMemberAt(
j);
544 if ( baseMember.IsTransient() || baseMember.IsStatic() )
continue;
548 std::string scope = declaringType.Name(Reflex::SCOPED);
553 std::string mappingType(
"");
554 Reflex::PropertyList memberProps = baseMember.Properties();
561 std::auto_ptr<IRelationalMapping> processor( mappingFactory.
newProcessor( type, blobStreaming ) );
562 processor->process( mappingElement, objectMemberName, objectMemberNameForSchema, scopeNameForSchema );
569 const std::string& attributeName,
570 const std::string& attributeNameForSchema,
571 const std::string& scopeNameForSchema ){
572 std::string
className = m_type.Name(Reflex::SCOPED);
582 std::string scope = attributeName;
583 std::string objectScopeNameForSchema = scopeNameForSchema;
584 if( !objectScopeNameForSchema.empty() ) objectScopeNameForSchema +=
"_";
585 objectScopeNameForSchema += attributeNameForSchema;
588 for (
size_t i=0;
i< objectType.DataMemberSize();
i++){
590 Reflex::Member objectMember = m_type.DataMemberAt(
i);
592 if ( objectMember.IsTransient() || objectMember.IsStatic() )
continue;
598 throwException(
"Type for data member \""+objectMember.Name()+
"\" of class \""+className+
599 "\" has not been found in the dictionary.",
600 "ObjectMapping::process");
605 if( declaringType != objectType ){
609 std::string objectMemberName = objectMember.Name();
610 std::string objectNameForSchema = objectMember.Name();
612 std::string mappingType(
"");
613 Reflex::PropertyList memberProps = objectMember.Properties();
619 std::auto_ptr<IRelationalMapping> processor( mappingFactory.
newProcessor( type, blobStreaming ) );
620 processor->process( me, objectMemberName, objectNameForSchema, objectScopeNameForSchema );
634 const std::string& ){
bool isTypeOraPointer(const Reflex::Type &typ)
static std::string namedReferenceMappingElementType()
Returns the name of the named reference element type.
static std::string blobMappingElementType()
Returns the name of the blob mapping element type.
static std::string arrayMappingElementType()
Returns the name of the array mapping element type.
NamedRefMapping(const Reflex::Type &attributeType, TableRegister &tableRegister)
static std::string columnNameForRefId(const std::string &variableName, const std::string &scope)
static std::string variableNameForArrayIndex(const std::string &arrayVariable, unsigned int index)
static std::string scopedVariableName(const std::string &variableName, const std::string &scope)
variable name manipulation
bool isTypeAssociativeContainer(const Reflex::Type &typ)
bool isTypeString(const Reflex::Type &typ)
static std::string variableNameForContainerKey()
static std::string primitiveMappingElementType()
Returns the name of the primitive mapping element type.
static std::string variableNameForArrayColumn(unsigned int arrayIndex)
bool isTypePVector(const Reflex::Type &typ)
static std::string variableNameForContainerValue()
static const size_t MaxColumnsForInlineCArray
void _sizeInColumnsForCArray(const Reflex::Type &typ, size_t &sz, bool &hasDependencies)
PrimitiveMapping(const Reflex::Type &attributeType, TableRegister &tableRegister)
static std::string scopedVariableForSchemaObjects(const std::string &variableName, const std::string &scope)
bool insertColumn(const std::string &tableName, const std::string &columnName)
RelationalMappingFactory(TableRegister &tableRegister)
static std::string OraReferenceMappingElementType()
Returns the name of the ORA reference mapping element type.
void process(MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema)
MappingElement & appendSubElement(const std::string &elementType, const std::string &variableName, const std::string &variableType, const std::string &tableName)
static std::string columnNameForVariable(const std::string &variableName, const std::string &scope, bool forData=true)
UniqueReferenceMapping(const Reflex::Type &attributeType, TableRegister &tableRegister)
bool isTypeUniqueReference(const Reflex::Type &typ)
static std::string mappingPropertyNameInDictionary()
class related parameters
BlobMapping(const Reflex::Type &attributeType, TableRegister &tableRegister)
Reflex::Type containerDataType(const Reflex::Type &typ)
static std::string columnNameForPosition()
bool isTypeContainer(const Reflex::Type &typ)
void process(MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema)
static std::string columnNameForOID(const std::string &variableName, const std::string &scope, unsigned int index)
std::pair< bool, size_t > sizeInColumnsForCArray(const Reflex::Type &arrayType)
static std::string objectMappingElementType()
Returns the name of the object mapping element type.
static std::string newNameForArraySchemaObject(const std::string &initialName, unsigned int index, size_t maxLength)
static bool isMappedToBlob(const std::string &mappingProperty)
static std::string columnNameForId()
static std::string uniqueReferenceMappingElementType()
Returns the name of the ORA polymorphic pointer mapping element type.
void process(MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema)
const std::vector< std::string > & columnNames() const
Reflex::Type containerKeyType(const Reflex::Type &typ)
Reflex::Type containerValueType(const Reflex::Type &typ)
CArrayMapping(const Reflex::Type &attributeType, TableRegister &tableRegister)
void process(MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema)
Reflex::Type resolvedType(const Reflex::Type &typ)
OraReferenceMapping(const Reflex::Type &attributeType, TableRegister &tableRegister)
virtual ~RelationalMappingFactory()
static std::string inlineCArrayMappingElementType()
Returns the name of the inline array mapping element type.
ObjectMapping(const Reflex::Type &attributeType, TableRegister &tableRegister)
static std::string columnNameForRefMetadata(const std::string &variableName, const std::string &scope)
bool checkColumn(const std::string &tableName, const std::string &columnName)
size_t sizeInColumns(const Reflex::Type &topLevelClassType)
void processLeafElement(MappingElement &parentElement, const std::string &elementType, const std::string &typeName, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema, TableRegister &tableRegister)
void process(MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema)
void process(MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema)
OraPtrMapping(const Reflex::Type &attributeType, TableRegister &tableRegister)
bool isTypePrimitive(const Reflex::Type &typ)
void process(MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema)
void processBaseClasses(MappingElement &mappingElement, const Reflex::Type &objType, const std::string &scopeNameForSchema, TableRegister &tableRegister)
static const size_t MaxColumnsPerTable
bool isTypeNamedReference(const Reflex::Type &typ)
static std::string columnNameForNamedReference(const std::string &variableName, const std::string &scope)
static std::string OraPointerMappingElementType()
Returns the name of the ORA pointer mapping element type.
static std::string OraArrayMappingElementType()
Returns the name of the ORA array mapping element type.
void process(MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema)
static const size_t MaxColumnNameLength
~UniqueReferenceMapping()
const std::string & tableName() const
void throwException(const std::string &message, const std::string &methodName)
ArrayMapping(const Reflex::Type &attributeType, TableRegister &tableRegister)
void process(MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema)
void _sizeInColumns(const Reflex::Type &typ, size_t &sz, bool &hasDependencies)
bool isTypeNonAssociativeContainer(const Reflex::Type &typ)
static const size_t MaxTableNameLength
bool checkTable(const std::string &tableName)
static std::string newNameForSchemaObject(const std::string &initialName, unsigned int index, size_t maxLength, char indexTrailer=0)
functions for new schema object name generation
static std::string CArrayMappingElementType()
Returns the name of the array mapping element type.
IRelationalMapping * newProcessor(const Reflex::Type &attributeType, bool blobStreaming=false)
std::string className(const T &t)
void process(MappingElement &parentElement, const std::string &attributeName, const std::string &attributeNameForSchema, const std::string &scopeNameForSchema)
void setColumnNames(const std::vector< std::string > &columns)
bool isTypeQueryableVector(const Reflex::Type &typ)