Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xtend] modifying a model
[Xtend] modifying a model [message #537083] Tue, 01 June 2010 09:30 Go to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
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 #537088 is a reply to message #537083] Tue, 01 June 2010 09:47 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
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 11:32 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
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 13:35 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
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 14:11 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
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
Re: [Xtend] modifying a model [message #537167 is a reply to message #537083] Tue, 01 June 2010 14:29 Go to previous message
MaximeLecourt  is currently offline MaximeLecourt Friend
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...
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: Thu Apr 25 16:06:20 GMT 2024

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

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

Back to the top