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) ) ) ){
150 "processLeafElement");
161 std::vector<std::string> cols;
162 cols.push_back( columnName );
167 cols.push_back( metaDataColumnName );
174 m_type(attributeType),m_tableRegister( tableRegister ){
185 const std::type_info* attrType = &t.TypeInfo();
186 if(t.IsEnum()) attrType = &
typeid(
int);
189 std::string typeName = coral::AttributeSpecification::typeNameForId(*attrType);
195 attributeNameForSchema,
201 m_type(attributeType),m_tableRegister( tableRegister ){
215 attributeNameForSchema,
221 m_type(attributeType),m_tableRegister( tableRegister ){
233 if(!m_tableRegister.checkTable( parentElement.
tableName())){
235 "OraReferenceMapping::process");
239 std::vector<std::string> cols;
240 for(
unsigned int j=0;
j<2;
j++){
244 while(m_tableRegister.checkColumn(parentElement.
tableName(),columnName)){
248 m_tableRegister.insertColumn(parentElement.
tableName(),columnName);
249 cols.push_back( columnName );
255 m_type(attributeType),m_tableRegister( tableRegister ){
266 std::string typeName = m_type.Name(Reflex::SCOPED);
267 if(!m_tableRegister.checkTable( parentElement.
tableName())){
269 "UniqueReferenceMapping::process");
273 std::vector< std::string > cols;
277 while(m_tableRegister.checkColumn(parentElement.
tableName(),columnName)){
281 m_tableRegister.insertColumn(parentElement.
tableName(),columnName);
282 cols.push_back(columnName);
287 while(m_tableRegister.checkColumn(parentElement.
tableName(),columnName)){
291 m_tableRegister.insertColumn(parentElement.
tableName(),columnName);
292 cols.push_back(columnName);
298 m_type(attributeType), m_tableRegister( tableRegister ){
309 std::string typeName = m_type.Name(Reflex::SCOPED);
317 std::auto_ptr<IRelationalMapping> processor( factory.
newProcessor( ptrType ) );
318 processor->process( me, ptrTypeName, attributeNameForSchema, scopeNameForSchema );
322 m_type( attributeType ),
323 m_tableRegister( tableRegister ){
333 std::string typeName = m_type.Name(Reflex::SCOPED);
336 std::vector< std::string > cols;
340 while(m_tableRegister.checkColumn(parentElement.
tableName(),columnName)){
344 m_tableRegister.insertColumn(parentElement.
tableName(),columnName);
345 cols.push_back(columnName);
352 m_type(attributeType), m_tableRegister( tableRegister ){
367 while(m_tableRegister.checkTable(arrayTable)){
371 m_tableRegister.insertTable(arrayTable);
380 const std::vector<std::string>& parentColumns = parentElement.
columnNames();
381 if( parentColumns.empty()){
382 throwException(
"No column name found in the parent mapping element.",
"ArrayMapping::process");
385 std::vector<std::string> columns;
388 std::vector<std::string>::const_iterator iColumn = parentColumns.begin();
391 for ( ;iColumn != parentColumns.end(); iColumn++ ) {
398 m_tableRegister.insertColumns(arrayTable, columns );
400 std::string arrayScopeNameForSchema = scopeNameForSchema;
401 if( !arrayScopeNameForSchema.empty() ) arrayScopeNameForSchema +=
"_";
402 arrayScopeNameForSchema += attributeNameForSchema;
411 if( singleItemContainer ){
414 else if ( associativeContainer ) {
418 throwException(
"Cannot not resolve the type of the key item of container \""+m_type.Name(Reflex::SCOPED)+
"\".",
419 "ArrayMapping::process");
424 throwException(
"Container type=\""+m_type.Name(Reflex::SCOPED)+
"\".is not supported.",
425 "ArrayMapping::process");
429 throwException(
"Cannot not resolve the type of the content item of container \""+m_type.Name(Reflex::SCOPED)+
"\".",
430 "ArrayMapping::process");
436 std::auto_ptr<IRelationalMapping> keyProcessor( mappingFactory.
newProcessor( keyType ) );
437 keyProcessor->process( me, keyTypeName, keyTypeNameForSchema, arrayScopeNameForSchema );
441 std::auto_ptr<IRelationalMapping> contentProcessor( mappingFactory.
newProcessor( contentType ) );
442 contentProcessor->process( me, contentTypeName, contentTypeNameForSchema, arrayScopeNameForSchema );
446 m_type(attributeType), m_tableRegister( tableRegister ){
458 throwException(
"Cannot resolve the type of the content of the array \""+m_type.Name(Reflex::SCOPED)+
"\".",
459 "CArrayMapping::process");
462 if(!m_tableRegister.checkTable(parentElement.
tableName())){
464 "CArrayMapping::process");
469 std::string arrayScopeNameForSchema = scopeNameForSchema;
470 if( !arrayScopeNameForSchema.empty() ) arrayScopeNameForSchema +=
"_";
471 arrayScopeNameForSchema += attributeNameForSchema;
475 size_t columnsInTable = m_tableRegister.numberOfColumns(parentElement.
tableName()) + arraySizeInColumns.second;
481 std::auto_ptr<IRelationalMapping> processor( mappingFactory.
newProcessor( arrayElementType ) );
482 for(
size_t i=0;
i<m_type.ArrayLength();
i++){
495 while(m_tableRegister.checkTable(arrayTable)){
499 m_tableRegister.insertTable(arrayTable);
501 attributeName, className, arrayTable );
502 const std::vector<std::string>& parentColumns = parentElement.
columnNames();
503 if( parentColumns.empty()){
504 throwException(
"No column name found in the parent mapping element.",
"CArrayMapping::process");
506 std::vector<std::string> columns;
509 std::vector<std::string>::const_iterator iColumn = parentColumns.begin();
512 for ( ;iColumn != parentColumns.end(); ++iColumn ) {
518 m_tableRegister.insertColumns(arrayTable, columns );
520 std::string contentTypeName = arrayElementType.Name();
522 std::auto_ptr<IRelationalMapping> processor( mappingFactory.
newProcessor( arrayElementType ) );
523 processor->process( me, contentTypeName, variableNameForSchema, arrayScopeNameForSchema );
527 m_type(attributeType), m_tableRegister( tableRegister ){
537 Reflex::PropertyList memberProps = dataMember.Properties();
549 for (
size_t i=0;
i< objType.BaseSize();
i++){
553 throwException(
"Class for base \""+base.Name()+
"\" is not in the dictionary.",
"ObjectMapping::process");
558 for (
size_t j=0;
j< baseType.DataMemberSize();
j++){
559 Reflex::Member baseMember = baseType.DataMemberAt(
j);
565 std::string scope = declaringType.Name(Reflex::SCOPED);
571 Reflex::PropertyList memberProps = baseMember.Properties();
578 std::auto_ptr<IRelationalMapping> processor( mappingFactory.
newProcessor( type, blobStreaming ) );
579 processor->process( mappingElement, objectMemberName, objectMemberNameForSchema, scopeNameForSchema );
600 std::string objectScopeNameForSchema = scopeNameForSchema;
601 if( !objectScopeNameForSchema.empty() ) objectScopeNameForSchema +=
"_";
602 objectScopeNameForSchema += attributeNameForSchema;
605 for (
size_t i=0;
i< objectType.DataMemberSize();
i++){
607 Reflex::Member objectMember = m_type.DataMemberAt(
i);
615 throwException(
"Type for data member \""+objectMember.Name()+
"\" of class \""+className+
616 "\" has not been found in the dictionary.",
617 "ObjectMapping::process");
622 if( declaringType != objectType ){
626 std::string objectMemberName = objectMember.Name();
627 std::string objectNameForSchema = objectMember.Name();
630 Reflex::PropertyList memberProps = objectMember.Properties();
636 std::auto_ptr<IRelationalMapping> processor( mappingFactory.
newProcessor( type, blobStreaming ) );
637 processor->process( me, objectMemberName, objectNameForSchema, objectScopeNameForSchema );
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.
bool isLoosePersistencyOnWriting(const Reflex::Member &dataMember)
static std::string variableNameForArrayColumn(unsigned int arrayIndex)
bool isTypePVector(const Reflex::Type &typ)
static std::string variableNameForContainerValue()
static std::string persistencyPropertyNameInDictionary()
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 columnNameForBlobMetadata(const std::string &dataColumnName)
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)
static bool isLooseOnWriting(const std::string &persistencyProperty)
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)