Skip to content

Commit

Permalink
finale state
Browse files Browse the repository at this point in the history
  • Loading branch information
szocske19 committed Apr 18, 2018
1 parent 2231ef9 commit b0b78e4
Show file tree
Hide file tree
Showing 11 changed files with 419 additions and 1 deletion.
19 changes: 19 additions & 0 deletions hu.bme.mit.mdsd.m2m2c/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?><plugin>
<extension id="hu.bme.mit.mdsd.m2m2c.queries.Queries" point="org.eclipse.viatra.query.runtime.queryspecification">
<group group="org.eclipse.viatra.query.runtime.extensibility.SingletonExtensionFactory:hu.bme.mit.mdsd.m2m2c.queries.Queries" id="hu.bme.mit.mdsd.m2m2c.queries.Queries">
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.entityAttribute"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.superEntity"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.allSuperEntity"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.relationWithLeftEnding"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.relationWithRightEnding"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.multiplicity"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.relationTarget"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.relationLeftWithMany"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.relationRightWithMany"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.relation"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.tracedAttributeOfTable"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.traceOfRootElement"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.traceOfElement"/>
</group>
</extension>
<extension id="hu.bme.mit.mdsd.m2m2c.queries.TraceQueries" point="org.eclipse.viatra.query.runtime.queryspecification">
<group group="org.eclipse.viatra.query.runtime.extensibility.SingletonExtensionFactory:hu.bme.mit.mdsd.m2m2c.queries.TraceQueries" id="hu.bme.mit.mdsd.m2m2c.queries.TraceQueries">
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.entity_C"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.entity_UD"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.attribute_C"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.attribute_U"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.attribute_D"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.relation_C"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.relation_D"/>
<query-specification fqn="hu.bme.mit.mdsd.m2m2c.queries.relation_U"/>
</group>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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

}

}
Original file line number Diff line number Diff line change
@@ -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

}

}
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading

0 comments on commit b0b78e4

Please sign in to comment.