Kalliope OO - STARIONGROUP/Kalliope GitHub Wiki
Intermediate classes
We have chosen to create an intermediate layer between the ORM classes and the to be generated classes, like POCO's and DTO's.
Base classes:
StructuralFeature: abstract baseclass for allClassandPropertytype classes
Class classes:
Class: abstract baseclass for allClasstype classes, inherits fromStructuralFeatureEntityClass: A specific class to be used for Classes that exist based on an ORM EntityType, inherits from ClassObjectifiedClass: A specific class to be used for Classes that exist based on an ORM ObjectifiedType, inherits from Class
Property Classes:
Property: abstract base class for all property type classes, implementsIPropertyinterfaceValueTypeProperty: A specific class to be used for properties that exist based in an ORM ValueType, is a subclass ofProperty.ReferenceProperty: A class to be used for properties that exist based in an ORM EntityType, or ObjectifiedType, is a subclass ofProperty.
ClassGenerator
The ClassGenerator is the main entrance to convert an ORM model to an Object Oriented class structure.
It has a Generate() method that Finds all ORM EntityTypes and ORM ObjectifiedTypes in the ORM model and creates Class classes based on those types.
When creation of the Class classes is done, a loop through all classes is performed to set some extra properties, like SuperClasses and SubClasses, based on the SuperObjectTypes and SubObjectTypes properties that contain the super-and suptype ORM ObjectTypes.
ORM Concepts and their OO implementation:
EntityType conversion
An ORM EntityType in the model results in an EntityClass object. The EntityClass is a subtype of the Class class.
Upon creation of the EntityClass class all necessary data is collected from the Orm OrmModel and added to the EntityClass.
The Definition Text, and the Note are added to the EntityClass. The Name of the EntityClass is the EntityType's name converted to a TitleCase representation (EveryWordStartsWithACapitalLetter).
After that the system loops though all the PlayedRoles of the ORM EntityType.
If a PlayedRole is an ORM SubtypeMetaRole then its SuperType counterpart in the related ORM FactType is added to the EntityClass's SuperType list property.
If a PlayedRole is an ORM SupertypeMetaRole then its SubType counterpart in the related ORM FactType is added to the EntityClass's SubType list property.
When the ORM EntityType's PlayedRole is contained in an ORM ImpliedFactTType and the PlayedRole is an ORM RoleProxy, it means that the other ORM Role in the ORM ImpliedFactType has a reference to an ORM ObjectifiedType, or a list of that ORM ObjectifiedType. A new ObjectifiedClassProperty will be created for this.
When the ORM EntityType's PlayedRole is contained in an ORM FactType, it means that the other ORM Role properties in the ORM FactType have a reference to an ORM EntityType, or ORM ValueType, or a list of that ORM EntityType, or ORM ValueType. Based on the specific ORM ObjectType a ValueTypeProperty or a ClassProperty will be added to the EntityClass's Properties property.
When all properties have been added to the EntityClass's, or ObjectifiedClass's Properties property, the system searches for Name properties of the individual Properties that are the Equal to each other. A sequencial number starting from 1 is added as a suffix to all the "double name" properties. All properties in the Properties property are then sorted by their Name property.
For now the system expects the unique identifier of every OO Class to be a Guid.
ObjectifiedType conversion
An ORM ObjectifiedType in the model results in an ObjectifiedClass object. The ObjectifiedClass is a subtype of the Class class.
Upon creation of the ObjectifiedClass class all necessary data is collected from the ORM OrmModel and added to the ObjectifiedClass.
The Definition Text, and the Note are added to the ObjectifiedClass. The Name of the ObjectifiedClass is the ORM ObjectifiedType's name converted to a TitleCase representation (EveryWordStartsWithACapitalLetter).
After that the system loops though all the PlayedRoles of the ORM ObjectifiedType.
If a PlayedRole is an ORM SubtypeMetaRole then its SuperType counterpart in the related ORM FactType is added to the ObjectifiedClass's SuperType list property.
If a PlayedRole is an ORM SupertypeMetaRole then its SubType counterpart in the related ORM FactType is added to the ObjectifiedClass's SubType list property.
When the ORM ObjectifiedType's PlayedRole is contained in an ORM ImpliedFactTType and the PlayedRole is an ORM RoleProxy, it means that the other ORM Role in the ORM ImpliedFactType has a reference to an ORM ObjectifiedType, or a list of that ORM ObjectifiedType. A new ReferenceProperty will be created for this.
When the ORM ObjectifiedType's PlayedRole is contained in an ORM FacttType, it means that the other ORM Role properties have a reference to an ORM EntityType, or ORM ValueType, or to a list of that ORM EntityType, or ORM ValueType. Based on the specific ORM ObjectType a ValueTypeProperty or an ReferenceProperty will be added to the EntityClass's Properties property.
When all properties have been added to the EntityClass's, or ObjectifiedClass's Properties property the system searches for Name properties of the individual Properties that are the Equal to each other. A sequencial number starting from 1 is added as a suffix to all the "double name" properties. All properties in the Properties property are then sorted by their Name property.
For now the system expects the unique identifier of every OO Class to be a Guid.
Generic Property implementation
For every property type, the same basic functionality is implemented:
Upon creation of the Property class all relevant data is collected from the Orm OrmModel and added to the Property class.
The Definition Text, and the Note are added to the Property.
The Name of the Property is "calculated" in the specific subclasses of the Property class. It is then converted to a TitleCase representation (EveryWordStartsWithACapitalLetter).
DataType is added as a string property. The OrmDataType will hold the datatype from ORM's perspective.
ValueTypeProperty
A ValueTypeProperty has an extra property: IsImplicitBooleanValue. This property is set to the value of the IsImplicitBooleanValue property of the ORM ObjectType. When it is set to true, usually this means tat the property is the result of the presence of an Unary ORM FactType in the Model.
The DataType property of a ValueTypeProperty is based on the ORM ValueType's ConceptualDataType. Its DataTypeId is mapped to a string representation. If Multiplicity defines it, then the DataType returns a List.
If the ValueTypeProperty represents an ImplicitBooleanValue the Name of the ValueTypeProperty will be derived from the ORM FactType's ReadingOrders. Otherwise the Name of the ORM Role's name that resulted in the creation of the ValueTypeProperty will be set as the Name of the ValueTypeProperty. If that Name is empty, the ORM ObjectType's name will be set as the Name of the ValueTypeProperty.
ReferenceProperty
The DataType property of a ReferenceProperty is the ORM ObjectType's Name as a TitleCase representation (EveryWordStartsWithACapitalLetter).
Order of assumptions when "calculating" the name of a ReferenceProperty
- When the ORM Role's Name that resulted in the creation of the
ReferencePropertyis not empty, then the ORM Role's Name will be used as theReferenceProperty's Name. - If the ORM Class is an ORM
ObjectifiedTypethen the name of the ORMObjectTypewill be used as the property name. - When the
Classwhere theReferencePropertywill be added to is an ORM ObjectifiedType then the ORM ObjectifiedType's Name will be used as theReferenceProperty's Name. - When the first ORM ReadingOrder of the ORM FactType's ReadingOrders property is equal to the
Class's ORM ObjectType, the ORM ReadingOrder will be used to "calculate" and set theReferenceProperty's Name. - Otherwise the ORM FactType's name will be set as the
ReferenceProperty's Name. If that is emtpy, the ORM ObjectType's Name that resulted in the creation of theReferencePropertywill be set as theReferenceProperty's Name.
When the Multiplicity of the ORM Role that resulted in the creation of the ReferenceProperty is ORM Multiplicity.OneToMany or Multiplicity.ZeroToMany, an "s" is added as the suffix of the ReferenceProperty's Name.