Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [Xtend] modifying a model
[Xtend] modifying a model [message #537083] Tue, 01 June 2010 05:30 Go to next message
Eclipse UserFriend
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);


Re: [Xtend] modifying a model [message #537088 is a reply to message #537083] Tue, 01 June 2010 05:47 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

the result of an transformation is put into an outputslot. This outputslot has to be configured in the workflow:
<component id="transformations"
		class="org.eclipse.xtend.XtendComponent">
		<metaModel idRef="mm"/>
		<invoke
			value="transformations::transform(modelSlot)" />
		<outputSlot value="modelSlot2]" />
	</component>


You can override the model by setting modelSlot2 to modelSlot.

Regards
Darius
Re: [Xtend] modifying a model [message #537115 is a reply to message #537083] Tue, 01 June 2010 07:32 Go to previous messageGo to next message
Eclipse UserFriend
So I have to save a first step of the transformation, before calling the saved step to continue the transformation ?


Maxime
Re: [Xtend] modifying a model [message #537155 is a reply to message #537083] Tue, 01 June 2010 09:35 Go to previous messageGo to next message
Eclipse UserFriend
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 ?
Re: [Xtend] modifying a model [message #537163 is a reply to message #537155] Tue, 01 June 2010 10:11 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: [Xtend] modifying a model [message #537167 is a reply to message #537083] Tue, 01 June 2010 10:29 Go to previous message
Eclipse UserFriend
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.
Previous Topic:XPand et inheritance
Next Topic:[Xpand/Xtend 1.0 RC1] problem when calling a Java method from Xtend in an Xpand template
Goto Forum:
  


Current Time: Wed Jul 23 06:13:49 EDT 2025

Powered by FUDForum. Page generated in 0.05059 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top