| [Xtend] modifying a model [message #537083] |
Tue, 01 June 2010 05:30  |
MaximeLecourt Messages: 108 Registered: February 2010 Location: France |
Senior Member |
|
|
Hi,
For a m2m transformation using Xtend, I created an extension to transform from a model to another.
| Quote: | create relationnel::Schema transform (metamodel::Package p) :
let opprelation=p.classes().birelations().relationsWithOpposites () :
// creates a RDatatype for every ODatatype
setTypes(p.datatypes().createType()) ->
// adds a RInteger to model, all keys will reference it
types.add(getKey()) ->
// creates a RTable for every OClass, with their foreign keys
types.addAll(p.classes().createTable()) ->
// creates a RTable for every opposite relation, with it's foreign keys
types.addAll(opprelation.collect(r|r.createLinkTable(
this.tables().select(e| (e.name.toLowerCase() == r.opposite.type.name.toLowerCase() || e.name.toLowerCase() == r.type.name.toLowerCase()))))) ->
// adds a foreign key for every composition
p.classes().compositions().getRTable(this) ->
// create a RTable for every agregation, whose cardinality is different from 0..1
types.addAll(p.classes().agregations().createAgregateTable(t his,p)) ->
// adds a foreign key for every reference
p.classes().references().addReferences(this,p) ->
this.tables().collect(e|e.addInheritance(this,p)) ->
this;
|
I thought that with the getRTable extension, I could modify the Schema, but I realised modification have not been taken into account once transformation is over. How can I make the transformation last ?
| Quote: | getRTable(OAttribute a,Schema s) :
// select the tables in which the foreign key is to be added (should return a List with one element)
let compotable = s.tables().select(e|e.name == a.opposite.type.name) :
// select the table that is to be added as foreign key
let newkey = s.tables().select(e|e.name == a.type.name) :
compotable.collect(e|e.addForeignKeys(newkey.first())) ->
newkey.info();
// adds RTable c as a foreign key to RTable t, called by getRTable
addForeignKeys(RTable t,RTable c):
t.info()->
t.foreignKeys.add(c) ->
t.setComposed(true);
|
One day I shall master M2T, but that day has yet to come...
|
|
|
|
| Re: [Xtend] modifying a model [message #537115 is a reply to message #537083] |
Tue, 01 June 2010 07:32   |
MaximeLecourt Messages: 108 Registered: February 2010 Location: France |
Senior Member |
|
|
So I have to save a first step of the transformation, before calling the saved step to continue the transformation ?
Maxime
One day I shall master M2T, but that day has yet to come...
|
|
|
| Re: [Xtend] modifying a model [message #537155 is a reply to message #537083] |
Tue, 01 June 2010 09:35   |
MaximeLecourt Messages: 108 Registered: February 2010 Location: France |
Senior Member |
|
|
There is something I don't understand.
in my transform extension shown before,
p.classes().compositions().getRTable(this) ->
That line doesn't modify the output,
p.classes().references().addReferences(this,p) ->
but that line does.
addReferences does the modification alone, while getRTable calls another extension, is that why the modifications from addReferences stays when the one from getRTable aren't taken into account ?
One day I shall master M2T, but that day has yet to come...
|
|
|
| Re: [Xtend] modifying a model [message #537163 is a reply to message #537155] |
Tue, 01 June 2010 10:11   |
Sven Efftinge Messages: 1667 Registered: July 2009 |
Senior Member |
|
|
Maxime Lecourt schrieb:
> There is something I don't understand.
>
> in my transform extension shown before,
>
> p.classes().compositions().getRTable(this) ->
> That line doesn't modify the output,
>
> p.classes().references().addReferences(this,p) ->
> but that line does.
>
> addReferences does the modification alone, while getRTable calls another
> extension, is that why the modifications from addReferences stays when
> the one from getRTable aren't taken into account ?
Often people are surprised by side effects EMF does on the models,
because of containment and bi-directional references.
That is if you add an EObject to a containment reference it will be
removed from its previous container. Not sure if something like that
happens in your case.
Sven
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
|
|
|
| Re: [Xtend] modifying a model [message #537167 is a reply to message #537083] |
Tue, 01 June 2010 10:29  |
MaximeLecourt Messages: 108 Registered: February 2010 Location: France |
Senior Member |
|
|
I found out I had a bug in my m2m.
Well now I have two, as I got the results I needed, so whatever failed here is added somewhere else where it shouldn't be on another test.
One day I shall master M2T, but that day has yet to come...
|
|
|
Powered by
FUDForum. Page generated in 0.12302 seconds