From b0b78e417ea683a9b7c17ac4f1b47fe903df0d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n?= Date: Thu, 19 Apr 2018 01:52:41 +0200 Subject: [PATCH] finale state --- hu.bme.mit.mdsd.m2m2c/plugin.xml | 19 +++++ .../m2m2c/ErdToRdbLiveTransformation.xtend | 43 +++++++++++- .../hu/bme/mit/mdsd/m2m2c/queries/queries.vql | 70 +++++++++++++++++++ .../mit/mdsd/m2m2c/queries/traceQueries.vql | 61 ++++++++++++++++ .../mdsd/m2m2c/rules/AttributeRule_C.xtend | 26 +++++++ .../mdsd/m2m2c/rules/AttributeRule_D.xtend | 28 ++++++++ .../mdsd/m2m2c/rules/AttributeRule_U.xtend | 33 +++++++++ .../mit/mdsd/m2m2c/rules/EntityRule_UD.xtend | 39 +++++++++++ .../mit/mdsd/m2m2c/rules/RelationRule_C.xtend | 45 ++++++++++++ .../mit/mdsd/m2m2c/rules/RelationRule_D.xtend | 26 +++++++ .../mit/mdsd/m2m2c/rules/RelationRule_U.xtend | 30 ++++++++ 11 files changed, 419 insertions(+), 1 deletion(-) create mode 100644 hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_C.xtend create mode 100644 hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_D.xtend create mode 100644 hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_U.xtend create mode 100644 hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/EntityRule_UD.xtend create mode 100644 hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_C.xtend create mode 100644 hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_D.xtend create mode 100644 hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_U.xtend diff --git a/hu.bme.mit.mdsd.m2m2c/plugin.xml b/hu.bme.mit.mdsd.m2m2c/plugin.xml index e726969..159c270 100644 --- a/hu.bme.mit.mdsd.m2m2c/plugin.xml +++ b/hu.bme.mit.mdsd.m2m2c/plugin.xml @@ -1,12 +1,31 @@ + + + + + + + + + + + + + + + + + + + diff --git a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/ErdToRdbLiveTransformation.xtend b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/ErdToRdbLiveTransformation.xtend index b1eac05..2b4a305 100644 --- a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/ErdToRdbLiveTransformation.xtend +++ b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/ErdToRdbLiveTransformation.xtend @@ -2,7 +2,14 @@ package hu.bme.mit.mdsd.m2m2c import hu.bme.mit.mdsd.erdiagram.EntityRelationDiagram import hu.bme.mit.mdsd.m2m2c.queries.Queries +import hu.bme.mit.mdsd.m2m2c.rules.AttributeRule_C +import hu.bme.mit.mdsd.m2m2c.rules.AttributeRule_D +import hu.bme.mit.mdsd.m2m2c.rules.AttributeRule_U import hu.bme.mit.mdsd.m2m2c.rules.EntityRule_C +import hu.bme.mit.mdsd.m2m2c.rules.EntityRule_UD +import hu.bme.mit.mdsd.m2m2c.rules.RelationRule_C +import hu.bme.mit.mdsd.m2m2c.rules.RelationRule_D +import hu.bme.mit.mdsd.m2m2c.rules.RelationRule_U import hu.bme.mit.mdsd.rdb.RdbPackage import org.eclipse.emf.ecore.resource.Resource import org.eclipse.emf.ecore.resource.ResourceSet @@ -33,8 +40,17 @@ class ErdToRdbLiveTransformation { private ViatraQueryEngine engine private ResourceSet resSet + private EntityRule_UD entityRule_UD private EntityRule_C entityRule_C + private AttributeRule_U attributeRule_U + private AttributeRule_D attributeRule_D + private AttributeRule_C attributeRule_C + + private RelationRule_U relationRule_U + private RelationRule_D relationRule_D + private RelationRule_C relationRule_C + private TraceRoot traceRoot private EntityRelationDiagram erdiagram @@ -64,7 +80,7 @@ class ErdToRdbLiveTransformation { val traceResource = getOrCreateResource("trace") val rdbResource = getOrCreateResource("rdb") - + val rdb = if (traceResource.contents.head === null) create(rdbResource, rdbPackage.relationalDataBase) as RelationalDataBase else @@ -78,8 +94,19 @@ class ErdToRdbLiveTransformation { } else { traceResource.contents.head as TraceRoot } + traceRoot = traceResource.contents.head as TraceRoot + + entityRule_UD = new EntityRule_UD(engine, manipulation, traceRoot) entityRule_C = new EntityRule_C(engine, manipulation, traceRoot) + attributeRule_U = new AttributeRule_U(engine, manipulation, traceRoot) + attributeRule_D = new AttributeRule_D(engine, manipulation, traceRoot) + attributeRule_C = new AttributeRule_C(engine, manipulation, traceRoot) + + relationRule_U = new RelationRule_U(engine, manipulation, traceRoot) + relationRule_D = new RelationRule_D(engine, manipulation, traceRoot) + relationRule_C = new RelationRule_C(engine, manipulation, traceRoot) + createTransformation } @@ -92,10 +119,24 @@ class ErdToRdbLiveTransformation { // Initialize event-driven transformation val fixedPriorityResolver = new InvertedDisappearancePriorityConflictResolver + fixedPriorityResolver.setPriority(entityRule_UD.rule.ruleSpecification, 1) fixedPriorityResolver.setPriority(entityRule_C.rule.ruleSpecification, 1) + fixedPriorityResolver.setPriority(attributeRule_U.rule.ruleSpecification, 2) + fixedPriorityResolver.setPriority(attributeRule_D.rule.ruleSpecification, 2) + fixedPriorityResolver.setPriority(attributeRule_C.rule.ruleSpecification, 2) + fixedPriorityResolver.setPriority(relationRule_U.rule.ruleSpecification, 3) + fixedPriorityResolver.setPriority(relationRule_D.rule.ruleSpecification, 3) + fixedPriorityResolver.setPriority(relationRule_C.rule.ruleSpecification, 3) transformation = EventDrivenTransformation.forEngine(engine).setConflictResolver(fixedPriorityResolver) + .addRule(entityRule_UD.rule) .addRule(entityRule_C.rule) + .addRule(attributeRule_U.rule) + .addRule(attributeRule_D.rule) + .addRule(attributeRule_C.rule) + .addRule(relationRule_U.rule) + .addRule(relationRule_D.rule) + .addRule(relationRule_C.rule) .setSchedulerFactory(Schedulers.getQueryEngineSchedulerFactory(engine) ).build diff --git a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/queries/queries.vql b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/queries/queries.vql index 4cebecb..92cd59a 100644 --- a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/queries/queries.vql +++ b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/queries/queries.vql @@ -4,6 +4,76 @@ import "http://mit.bme.hu/mdsd/erdiagram" as erdiagram import "hu.bme.mit.mdsd.trace" import "hu.bme.mit.mdsd.rdb" as rdb +pattern entityAttribute(e : Entity, attr : Attribute) { + Entity.attributes(e, attr); +} + +pattern superEntity(e : Entity, superEntity : Entity) { + Entity.isA(e, superEntity); +} + +pattern allSuperEntity(e : Entity, superEntity : Entity) { + find superEntity+(e, superEntity); +} or { + e == superEntity; +} + +pattern relationWithLeftEnding(r : Relation, rle : RelationEnding) { + Relation.leftEnding(r, rle); +} + +pattern relationWithRightEnding(r : Relation, rre : RelationEnding) { + Relation.rightEnding(r, rre); +} + +pattern multiplicity(relationEnding: RelationEnding, multiplicity: MultiplicityType){ + RelationEnding.multiplicity(relationEnding, multiplicity); +} + +pattern relationTarget(relationEnding: RelationEnding, entity : Entity){ + RelationEnding.target(relationEnding, entity); +} + +pattern relationLeftWithMany(relation: Relation, + relationEnding: RelationEnding, + entity: Entity +){ + find relationWithLeftEnding(relation, relationEnding); + find relationTarget(relationEnding, entity); +} + +pattern relationRightWithMany(relation: Relation, + relationEnding: RelationEnding, + entity: Entity +){ + find relationWithRightEnding(relation, relationEnding); + find relationTarget(relationEnding, entity); +} + +pattern relation(relation: Relation, + relationEndingLeft: RelationEnding, + relationEndingRight: RelationEnding, + entityLeft: Entity, + entityRight: Entity, + tableLeft: Table, + tableRight: Table +){ + find relationLeftWithMany(relation, relationEndingLeft, entityLeft); + find relationRightWithMany(relation, relationEndingRight, entityRight); + find traceOfElement(_, _, entityLeft, tableLeft); + find traceOfElement(_, _, entityRight, tableRight); +} + +pattern tracedAttributeOfTable(attribute : Attribute, table: Table){ + find traceOfElement(_, _, attribute, column); + Table.columns(table, column); +} + +pattern traceOfRootElement(traceRoot: TraceRoot, er: EntityRelationDiagram, rdb: RelationalDataBase){ + TraceRoot.erdiagramRoot(traceRoot, er); + TraceRoot.rdbRoot(traceRoot, rdb); +} + pattern traceOfElement(traceRoot: TraceRoot, trace: Trace, erElement: erdiagram::NamedElement, rdbElement: rdb::NamedElement){ TraceRoot.traces(traceRoot, trace); Trace.erdiagramElement(trace, erElement); diff --git a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/queries/traceQueries.vql b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/queries/traceQueries.vql index 7f8a86e..ff8d248 100644 --- a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/queries/traceQueries.vql +++ b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/queries/traceQueries.vql @@ -12,3 +12,64 @@ pattern entity_C(entity: Entity){ neg find traceOfElement(_, _, entity, _); } +pattern entity_UD(entity : Entity, trace: Trace, table: Table){ + find traceOfElement(_, trace, entity, table); +} + +/////////////////////////////////////// Attribute /////////////////////////////////////// + +pattern attribute_C(entity: Entity, superEntity: Entity, attribute : Attribute, trace: Trace, table: Table){ + find traceOfElement(_, trace, entity, table); + find entityAttribute(superEntity, attribute); + find allSuperEntity(entity, superEntity); + neg find tracedAttributeOfTable(attribute, table); +} + +pattern attribute_U(attribute : Attribute, trace: Trace, column: Column){ + find traceOfElement(_, trace, attribute, column); +} + +pattern attribute_D(entity: Entity, attribute : Attribute, trace: Trace, + isKey: java Boolean /* hack because column's key-ness is encoded in type */ +){ + find traceOfElement(_, _, entity, table); + find entityAttribute(superEntity, attribute); + find allSuperEntity(entity, superEntity); + find traceOfElement(_, trace, attribute, column); + Table.columns(table, column); + Attribute.isKey(attribute, isKey); +} + +/////////////////////////////////////// Relation //////////////////////////////////////// + +pattern relation_C(relation: Relation, + relationEndingLeft: RelationEnding, + relationEndingRight: RelationEnding, + entityLeft: Entity, + entityRight: Entity, + tableLeft: Table, + tableRight: Table +){ + find relation(relation, relationEndingLeft, relationEndingRight, entityLeft, entityRight, tableLeft, tableRight); + neg find traceOfElement(_, _, relation, _); +} + +pattern relation_D(relation: Relation, + relationEndingLeft: RelationEnding, + relationEndingRight: RelationEnding, + entityLeft: Entity, + entityRight: Entity, + tableLeft: Table, + tableRight: Table, + trace: Trace, + switchTable: Table +){ + find relation(relation, relationEndingLeft, relationEndingRight, entityLeft, entityRight, tableLeft, tableRight); + find traceOfElement(_, trace, relation, switchTable); +} + +pattern relation_U(relation: Relation, switchTable: Table){ + find traceOfElement(_, _, relation, switchTable); +} + + diff --git a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_C.xtend b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_C.xtend new file mode 100644 index 0000000..db9d415 --- /dev/null +++ b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_C.xtend @@ -0,0 +1,26 @@ +package hu.bme.mit.mdsd.m2m2c.rules + +import hu.bme.mit.mdsd.m2m2c.queries.Attribute_CMatcher +import hu.bme.mit.mdsd.rdb.Column +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine +import org.eclipse.viatra.transformation.evm.specific.crud.CRUDActivationStateEnum +import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations +import trace.TraceRoot + +class AttributeRule_C extends AbstractRule{ + + new(ViatraQueryEngine engine, IModelManipulations manipulation, TraceRoot traceRoot) { + super(engine, manipulation, traceRoot) + rule = createRule.name("AttributeRule") + // left hand side - queries a single entity + .precondition(Attribute_CMatcher.querySpecification) + .action(CRUDActivationStateEnum.CREATED) [ + println('''AttributeRule CREATED («attribute.name»)''') + + var column = attribute.createColumnFromAttribute(table) as Column + column.set(rdbPackage.namedElement_Name, attribute.name) + + createTrace(traceRoot, attribute, column) + ].build + } +} diff --git a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_D.xtend b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_D.xtend new file mode 100644 index 0000000..013c42c --- /dev/null +++ b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_D.xtend @@ -0,0 +1,28 @@ +package hu.bme.mit.mdsd.m2m2c.rules + +import hu.bme.mit.mdsd.m2m2c.queries.Attribute_DMatcher +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine +import org.eclipse.viatra.transformation.evm.specific.crud.CRUDActivationStateEnum +import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations +import trace.TraceRoot + +class AttributeRule_D extends AbstractRule{ + + new(ViatraQueryEngine engine, IModelManipulations manipulation, TraceRoot traceRoot) { + super(engine, manipulation, traceRoot) + + rule = createRule.name("AttributeRule") + // left hand side - queries a single entity + .precondition(Attribute_DMatcher.querySpecification) + .action(CRUDActivationStateEnum.CREATED) [ + println('''AttributeRule CREATED [empty RHS] («attribute.name»)''') + + ].action(CRUDActivationStateEnum.DELETED) [ + println('''AttributeRule DELETED («attribute.name»)''') + + deleteTrace(trace) + ].build + + } + +} diff --git a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_U.xtend b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_U.xtend new file mode 100644 index 0000000..a77c3a0 --- /dev/null +++ b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/AttributeRule_U.xtend @@ -0,0 +1,33 @@ +package hu.bme.mit.mdsd.m2m2c.rules + +import hu.bme.mit.mdsd.m2m2c.queries.Attribute_UMatcher +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine +import org.eclipse.viatra.transformation.evm.specific.crud.CRUDActivationStateEnum +import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations +import trace.TraceRoot + +class AttributeRule_U extends AbstractRule{ + + new(ViatraQueryEngine engine, IModelManipulations manipulation, TraceRoot traceRoot) { + super(engine, manipulation, traceRoot) + + rule = createRule.name("AttributeRule") + // left hand side - queries a single entity + .precondition(Attribute_UMatcher.querySpecification) + .action(CRUDActivationStateEnum.CREATED) [ + println('''AttributeRule CREATED [empty RHS] («attribute.name»)''') + + ].action(CRUDActivationStateEnum.UPDATED) [ + println('''AttributeRule UPDATED («attribute.name»)''') + + if(!attribute.name.equals(column.name)){ + column.set(rdbPackage.namedElement_Name, attribute.name) + } + if(!attribute.type.columnType.equals(column.type)){ + column.set(rdbPackage.column_Type, attribute.type.columnType) + } + ].build + + } + +} diff --git a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/EntityRule_UD.xtend b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/EntityRule_UD.xtend new file mode 100644 index 0000000..c95bd8f --- /dev/null +++ b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/EntityRule_UD.xtend @@ -0,0 +1,39 @@ +package hu.bme.mit.mdsd.m2m2c.rules + +import hu.bme.mit.mdsd.m2m2c.queries.Entity_UDMatcher +import hu.bme.mit.mdsd.rdb.Key +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine +import org.eclipse.viatra.transformation.evm.specific.crud.CRUDActivationStateEnum +import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations +import trace.TraceRoot + +class EntityRule_UD extends AbstractRule{ + + new(ViatraQueryEngine engine, IModelManipulations manipulation, TraceRoot traceRoot) { + super(engine, manipulation, traceRoot) + + rule = createRule.name("EntityRule") + // left hand side - queries a single entity + .precondition(Entity_UDMatcher.querySpecification) + .action(CRUDActivationStateEnum.CREATED) [ + println('''EntityRule CREATED [empty RHS] («entity.name»)''') + + ].action(CRUDActivationStateEnum.UPDATED) [ + println('''EntityRule UPDATED («entity.name»)''') + + if(!entity.name.equals(table.name)){ + table.set(rdbPackage.namedElement_Name, entity.name) + } + + val key = table.columns.filter(Key).head + if(!key.name.equals(entity.name + "_ID")){ + key.set(rdbPackage.namedElement_Name, entity.name + "_ID") + } + + ].action(CRUDActivationStateEnum.DELETED)[ + println('''EntityRule DELETED («entity.name»)''') + + deleteTrace(trace) + ].build + } +} diff --git a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_C.xtend b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_C.xtend new file mode 100644 index 0000000..9d114b3 --- /dev/null +++ b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_C.xtend @@ -0,0 +1,45 @@ +package hu.bme.mit.mdsd.m2m2c.rules + +import hu.bme.mit.mdsd.m2m2c.queries.Relation_CMatcher +import hu.bme.mit.mdsd.rdb.ColumnType +import hu.bme.mit.mdsd.rdb.ForeignKey +import hu.bme.mit.mdsd.rdb.Key +import hu.bme.mit.mdsd.rdb.Table +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine +import org.eclipse.viatra.transformation.evm.specific.crud.CRUDActivationStateEnum +import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations +import trace.TraceRoot + +class RelationRule_C extends AbstractRule{ + + new(ViatraQueryEngine engine, IModelManipulations manipulation, TraceRoot traceRoot) { + super(engine, manipulation, traceRoot) + + rule = createRule.name("RelationRule") + // left hand side - queries a single relation + .precondition(Relation_CMatcher.querySpecification) + .action(CRUDActivationStateEnum.CREATED) [ + println('''RelationRule CREATED («relation.name»)''') + + val joinTable = traceRoot.rdbRoot.createChild(rdbPackage.relationalDataBase_Tables, rdbPackage.table) as Table + joinTable.set(rdbPackage.namedElement_Name, relation.name.toFirstUpper + "_Relation") + val columnKey = joinTable.createChild(rdbPackage.table_Columns, rdbPackage.key) as Key + columnKey.set(rdbPackage.namedElement_Name, "id") + columnKey.set(rdbPackage.column_Type, ColumnType::INT) + + val columnLeft = joinTable.createChild(rdbPackage.table_Columns, rdbPackage.foreignKey) as ForeignKey + columnLeft.set(rdbPackage.foreignKey_ReferencedKey, tableLeft.columns.filter(Key).head) + columnLeft.set(rdbPackage.namedElement_Name, columnLeft.referencedKey?.name) + columnLeft.set(rdbPackage.column_Type, columnLeft.referencedKey?.type) + + val columnRight = joinTable.createChild(rdbPackage.table_Columns, rdbPackage.foreignKey) as ForeignKey + columnRight.set(rdbPackage.foreignKey_ReferencedKey, tableRight.columns.filter(Key).head) + columnRight.set(rdbPackage.namedElement_Name, columnRight.referencedKey?.name) + columnRight.set(rdbPackage.column_Type, columnRight.referencedKey?.type) + + createTrace(traceRoot, relation, joinTable) + ] + .build + } + +} diff --git a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_D.xtend b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_D.xtend new file mode 100644 index 0000000..52a78b6 --- /dev/null +++ b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_D.xtend @@ -0,0 +1,26 @@ +package hu.bme.mit.mdsd.m2m2c.rules + +import hu.bme.mit.mdsd.m2m2c.queries.Relation_DMatcher +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine +import org.eclipse.viatra.transformation.evm.specific.crud.CRUDActivationStateEnum +import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations +import trace.TraceRoot + +class RelationRule_D extends AbstractRule{ + + new(ViatraQueryEngine engine, IModelManipulations manipulation, TraceRoot traceRoot) { + super(engine, manipulation, traceRoot) + + rule = createRule.name("RelationRule") + // left hand side - queries a single relation + .precondition(Relation_DMatcher.querySpecification) + .action(CRUDActivationStateEnum.CREATED) [ + println('''RelationRule CREATED [empty RHS] («relation.name»)''') + + ].action(CRUDActivationStateEnum.DELETED)[ + println('''RelationRule DELETED («relation.name»)''') + + deleteTrace(trace) + ].build + } +} diff --git a/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_U.xtend b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_U.xtend new file mode 100644 index 0000000..ac93656 --- /dev/null +++ b/hu.bme.mit.mdsd.m2m2c/src/hu/bme/mit/mdsd/m2m2c/rules/RelationRule_U.xtend @@ -0,0 +1,30 @@ +package hu.bme.mit.mdsd.m2m2c.rules + +import hu.bme.mit.mdsd.m2m2c.queries.Relation_UMatcher +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine +import org.eclipse.viatra.transformation.evm.specific.crud.CRUDActivationStateEnum +import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations +import trace.TraceRoot + +class RelationRule_U extends AbstractRule{ + + new(ViatraQueryEngine engine, IModelManipulations manipulation, TraceRoot traceRoot) { + super(engine, manipulation, traceRoot) + + rule = createRule.name("RelationRule") + // left hand side - queries a single relation + .precondition(Relation_UMatcher.querySpecification) + .action(CRUDActivationStateEnum.CREATED) [ + println('''RelationRule CREATED [empty RHS] («relation.name»)''') + + ].action(CRUDActivationStateEnum.UPDATED) [ + println('''RelationRule UPDATED («relation.name»)''') + + if(!relation.name.equals(switchTable.name)){ + switchTable.set(rdbPackage.namedElement_Name, relation.name) + } + + ].build + } + +}