Skip to content

Commit

Permalink
Adapt LDM in RegDNA so that composition is replaced #1340
Browse files Browse the repository at this point in the history
  • Loading branch information
RBirdwatcher committed Apr 9, 2024
1 parent 01548fb commit 683f3e4
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 15 deletions.
2 changes: 2 additions & 0 deletions bird/bird_utilities/ldm_tools/src/ldm_context/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ def __init__(self):
key_annotation_directive = ELAnnotationDirective(name='key', sourceURI='key')
il_mapping_annotation_directive = ELAnnotationDirective(name='il_mapping', sourceURI='il_mapping')
entity_hierarchy_annotation_directive = ELAnnotationDirective(name='entity_hierarchy', sourceURI='entity_hierarchy')
relationship_type_annotation_directive = ELAnnotationDirective(name='relationship_type', sourceURI='relationship_type')
self.input_tables_package.annotationDirectives.append(key_annotation_directive)
self.input_tables_package.annotationDirectives.append(il_mapping_annotation_directive)
self.input_tables_package.annotationDirectives.append(entity_hierarchy_annotation_directive)
self.input_tables_package.annotationDirectives.append(relationship_type_annotation_directive)
types = EcoreLiteTypes()
self.types_package.eClassifiers.append(types.e_string)
self.types_package.eClassifiers.append(types.e_double)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,19 @@ def create_attribute_to_column_links(self, context):
ldm_entity.eAnnotations.append(the_entity_annotation)

details = the_entity_annotation.details


il_tables_count = 0

for detail in details:
if detail.key.startswith("il_table"):
il_tables_count = il_tables_count + 1

detail1 = ELStringToStringMapEntry()
detail1.key = "il_table"
if il_tables_count ==0:
detail1.key = "il_table"
else:
detail1.key = "il_table" + str(il_tables_count)

detail1.value = table_name
details.append(detail1)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def import_disjoint_subtyping_information(self, context):
context.arc_name_to_arc_class_map[altered_arc_name] = arc_class
context.arc_to_source_map[altered_arc_name] = source_class
context.input_tables_package.eClassifiers.extend([arc_class])
containment_reference = ELReference()
containment_reference.name = altered_arc_name + "_delegate"
containment_reference.eType = arc_class
containment_reference.upperBound = 1
containment_reference.lowerBound = 0
containment_reference.containment = True
non_containment_reference = ELReference()
non_containment_reference.name = altered_arc_name + "_delegate"
non_containment_reference.eType = arc_class
non_containment_reference.upperBound = 1
non_containment_reference.lowerBound = 0
non_containment_reference.containment = False
pk_name = altered_arc_name + "_uniqueID"
attribute = ELAttribute()
attribute.name = pk_name
Expand All @@ -145,9 +145,29 @@ def import_disjoint_subtyping_information(self, context):
attribute.iD = True
attribute.lowerBound = 0
attribute.upperBound = 1
the_reference_annotation = ELAnnotation()
the_reference_annotation_directive = Utils.get_annotation_directive(source_class.eContainer(), "relationship_type")
the_reference_annotation.source = the_reference_annotation_directive
details = the_reference_annotation.details
mapentry = ELStringToStringMapEntry()
mapentry.key = "is_identifying_relationship"
mapentry.value = "true"
details.append(mapentry)
non_containment_reference.eAnnotations.append(the_reference_annotation)

arc_class.eStructuralFeatures.append(attribute)
the_identified_class_annotation = ELAnnotation()
the_identified_class_directive = Utils.get_annotation_directive(source_class.eContainer(), "relationship_type")
the_identified_class_annotation.source = the_identified_class_directive
details = the_identified_class_annotation.details
mapentry = ELStringToStringMapEntry()
mapentry.key = "is_identified_by"
mapentry.value = source_class.name + "." + non_containment_reference.name
details.append(mapentry)
arc_class.eAnnotations.append(the_identified_class_annotation)

source_class.eStructuralFeatures.append(
containment_reference)
non_containment_reference)


target_class = SQLDevLDMImport.find_class_with_name(self, context,Utils.make_valid_id(target_entity_name))
Expand Down Expand Up @@ -515,9 +535,48 @@ def add_ldm_relationships_between_classes(self, context):
ereference.eType = target_class

if identifying == "Y":
ereference.containment = True
ereference.containment = False
the_reference_annotation = ELAnnotation()
the_reference_annotation_directive = Utils.get_annotation_directive(the_class.eContainer(), "relationship_type")
the_reference_annotation.source = the_reference_annotation_directive
details = the_reference_annotation.details
mapentry = ELStringToStringMapEntry()
mapentry.key = "is_identifying_relationship"
mapentry.value = "true"
details.append(mapentry)
ereference.eAnnotations.append(the_reference_annotation)

the_identified_class_annotation = ELAnnotation()
the_identified_class_directive = Utils.get_annotation_directive(the_class.eContainer(), "relationship_type")
the_identified_class_annotation.source = the_identified_class_directive
details = the_identified_class_annotation.details
mapentry = ELStringToStringMapEntry()
mapentry.key = "is_identified_by"
mapentry.value = the_class.name + "." + ereference.name
details.append(mapentry)
target_class.eAnnotations.append(the_identified_class_annotation)

else:
ereference.containment = False
the_reference_annotation = ELAnnotation()
the_reference_annotation_directive = Utils.get_annotation_directive(the_class.eContainer(), "relationship_type")
the_reference_annotation.source = the_reference_annotation_directive
details = the_reference_annotation.details
mapentry = ELStringToStringMapEntry()
mapentry.key = "is_association_relationship"
mapentry.value = "true"
details.append(mapentry)
ereference.eAnnotations.append(the_reference_annotation)

the_associated_class_annotation = ELAnnotation()
the_associated_class_directive = Utils.get_annotation_directive(the_class.eContainer(), "relationship_type")
the_associated_class_annotation.source = the_associated_class_directive
details = the_associated_class_annotation.details
mapentry = ELStringToStringMapEntry()
mapentry.key = "is_associated_with"
mapentry.value = the_class.name + "." + ereference.name
details.append(mapentry)
target_class.eAnnotations.append(the_associated_class_annotation)

if source_optional.strip() == "Y":
if source_to_target_cardinality.strip() == "*":
Expand Down
22 changes: 19 additions & 3 deletions bird/bird_utilities/ldm_tools/src/ldm_processing/traverser.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,27 @@ def get_non_discriminator_references(self, context, entity):
reference_list = []
for ref in entity.eStructuralFeatures:
if isinstance(ref,ELReference):
if not(ref.name.endswith('_delegate')) and not(ref.containment):
if not(ref.name.endswith('_delegate')) and not(SubtypeExploder.reference_is_containment(self,ref)):
reference_list.append(ref)

return reference_list

def reference_is_containment(self,ref):
'''
check if the reference is a containment reference
'''
return_value = False
annotation = Utils.get_annotation_with_source(ref, "relationship_type")

if not(annotation is None):
details = annotation.details

for detail in details.items:
if detail.key == "is_identifying_relationship":
return_value = True

return return_value

def get_non_discriminator_containment_references(self, context, entity):
'''
get any containment references from the entity, which are not delegates.
Expand All @@ -288,7 +304,7 @@ def get_non_discriminator_containment_references(self, context, entity):
'''
reference_list = []
for ref in entity.eStructuralFeatures:
if isinstance(ref,ELReference) and ref.containment:
if isinstance(ref,ELReference) and SubtypeExploder.reference_is_containment(self,ref):
if not(ref.name.endswith('_delegate')):
reference_list.append(ref)

Expand Down Expand Up @@ -328,7 +344,7 @@ def get_discriminators(self, context, entity):
reference_list = []
for ref in entity.eStructuralFeatures:
if isinstance(ref,ELReference):
if ref.containment:
if SubtypeExploder.reference_is_containment(self,ref):
# if we are refering to an entity in a differnt hierarchy then
# we don't consider it a discriminator.
if not(SubtypeExploder.different_il_tables(self, context, entity,ref.eType)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import org.eclipse.efbt.regdna.model.regdna.SelectDerivedColumnAs
import org.eclipse.efbt.regdna.model.regdna.Report
import org.eclipse.efbt.regdna.model.regdna.ReportModule
import org.eclipse.efbt.regdna.model.regdna.CellBasedReport
import org.eclipse.efbt.regdna.model.regdna.ELStructuralFeature
import org.eclipse.efbt.regdna.model.regdna.ELAnnotation

/**
* Generates code from your model files on save.
Expand Down Expand Up @@ -312,12 +314,18 @@ class RegdnaGenerator extends AbstractGenerator {
@«annotion.source.name» («FOR detail : annotion.details SEPARATOR ","» «detail.key»="«detail.value»"«ENDFOR»)
«ENDFOR»
«IF elclass.EAbstract»abstract «ENDIF»class «elclass.name» «IF elclass.ESuperTypes.length == 1» extends «elclass.ESuperTypes.get(0).name» «ENDIF»{
«FOR annotation : elclass.EAnnotations»
«IF annotation.identifying_class() !== null » refers «annotation.identifying_class()» [1..1] parent_«annotation.identifying_class()» opposite «annotation.identifying_feature()»«ENDIF»
«IF annotation.associated_class() !== null » refers «annotation.associated_class()» linked_«annotation.associated_class()»_«annotation.associated_feature()» opposite «annotation.associated_feature()»«ENDIF»
«ENDFOR»
«FOR elmember : elclass.EStructuralFeatures»
«FOR annotion : elmember.EAnnotations»
«IF true» @«annotion.source.name» («FOR detail : annotion.details SEPARATOR ","» «detail.key»="«detail.value»"«ENDFOR»)«ENDIF»
«ENDFOR»
«IF elmember instanceof ELAttribute» «IF elmember.ID»id «ENDIF»«elmember.EAttributeType.name» «IF elmember.upperBound == -1»[] «ELSEIF !((elmember.lowerBound == 0) && ( (elmember.upperBound == 1) || (elmember.upperBound == 0)) ) »[«elmember.lowerBound»..«elmember.upperBound»]«ENDIF» «elmember.name» «ENDIF»
«IF elmember instanceof ELReference» «IF elmember.containment»contains «ELSE»refers«ENDIF» «elmember.EType.name» «IF elmember.upperBound == -1»[] «ELSEIF !((elmember.lowerBound == 0) && ( (elmember.upperBound == 1) || (elmember.upperBound == 0)) ) »[«elmember.lowerBound»..«elmember.upperBound»]«ENDIF» «elmember.name»«ENDIF»
«IF elmember instanceof ELReference» «IF elmember.containment»contains «ELSE»refers«ENDIF» «elmember.EType.name» «IF elmember.upperBound == -1»[] «ELSEIF !((elmember.lowerBound == 0) && ( (elmember.upperBound == 1) || (elmember.upperBound == 0)) ) »[«elmember.lowerBound»..«elmember.upperBound»]«ENDIF» «elmember.name»«ENDIF» «IF elmember.is_identifying_relationship() » opposite parent_«elclass.name»«ENDIF»«IF elmember.is_association_relationship() » opposite linked_«elclass.name»_«elmember.name»«ENDIF»
«ENDFOR»
«FOR eloperation : elclass.EOperations»
«FOR annotion : eloperation.EAnnotations»
Expand Down Expand Up @@ -352,6 +360,86 @@ class RegdnaGenerator extends AbstractGenerator {
''')
}

def String identifying_feature(ELAnnotation annotation) {
var String value = null
var String return_value = null
for (detail : annotation.details)
{
if (detail.key == "is_identified_by") {
value = detail.value
return_value = value.substring(value.indexOf('.')+1,value.length)
}
}
return return_value
}

def String associated_feature(ELAnnotation annotation) {
var String value = null
var String return_value = null
for (detail : annotation.details)
{
if (detail.key == "is_associated_with") {
value = detail.value
return_value = value.substring(value.indexOf('.')+1,value.length)
}
}
return return_value
}

def String identifying_class(ELAnnotation annotation)
{
var String value = null
var String return_value = null
for (detail : annotation.details)
{
if (detail.key == "is_identified_by") {
value = detail.value
return_value = value.substring(0,detail.value.indexOf('.'))
}
}
return return_value
}

def String associated_class(ELAnnotation annotation)
{
var String value = null
var String return_value = null
for (detail : annotation.details)
{
if (detail.key == "is_associated_with") {
value = detail.value
return_value = value.substring(0,detail.value.indexOf('.'))
}
}
return return_value
}

def boolean is_identifying_relationship(ELStructuralFeature feature) {
var return_value = false
for (annotation : feature.EAnnotations) {
for (detail : annotation.details)
{
if (detail.key == "is_identifying_relationship") {
return_value = true
}
}
}
return return_value
}

def boolean is_association_relationship(ELStructuralFeature feature) {
var return_value = false
for (annotation : feature.EAnnotations) {
for (detail : annotation.details)
{
if (detail.key == "is_association_relationship") {
return_value = true
}
}
}
return return_value
}


def EPackage processPackage(ELPackage elpackage,IFileSystemAccess2 fsa ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
version="1.3.0.qualifier">

<description url="http://www.example.com/description">

Orchestrator
</description>

<copyright>
Expand Down

0 comments on commit 683f3e4

Please sign in to comment.