Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xtend] problem in m2m transformation(random type (if any) after transformation)
[Xtend] problem in m2m transformation [message #525888] Thu, 08 April 2010 08:03 Go to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
Hi,
I'm still trying my transformation from object to relationnal model, but my relationnal model (the destination model) is incomplete.

This is my Xtend m2m file :
import metamodel;
import relationnel;

extension metamodel::Extensions reexport;
extension object2relationnal::SQLExtensions reexport;

//takes a Package as parameter, and creating a Database from it
create relationnel::Base transform (metamodel::Package p) :
	this.setTables(p.classes().createTable());

// transforms all classes into SQL tables
create relationnel::Table createTable (metamodel::Class c) :
	this.setName(c.name) ->
	this.setColumn(c.attributs().createColumn());

// create a Column for every attribute which is not a composition or agregation
create relationnel::Column createColumn(metamodel::Attribute a) :
	this.setName(a.name) ->
	this.setType(a.type.createType());

create relationnel::RBool createType(metamodel::GBool t):
	this.setName(t.name);

create relationnel::RString createType(metamodel::GString t):
	this.setName(t.name);

create relationnel::RFloat createType(metamodel::GFloat t):
	this.setName(t.name);

create relationnel::RInteger createType(metamodel::GInteger t):
	this.setName(t.name);

create relationnel::LimitedString createType(metamodel::LimitedString t):
	this.setName(t.name) ->
	this.setSize(t.size);

create relationnel::UnlimitedString createType(metamodel::UnlimitedString t):
	this.setName(t.name);

create relationnel::Datatype createType(metamodel::Type t):
	this.setName(t.name);


I have tried with every type in my model, and whenever the type is GString in my source model, the type in my destination model is either nonexistant, or RString (but mostly nonexistant).

Something else I've realized, in the following m2t transformation, the final printed type for every Column without type (those that should be RString) is a random type.

To print the type in the Xpand template, I defined a tosql function.
I defined tosql for every possible type in my metamodel :
«DEFINE tosql FOR RInteger»INTEGER«ENDDEFINE»
«DEFINE tosql FOR RBool»BOOLEAN«ENDDEFINE»


One day I shall master M2T, but that day has yet to come...
Re: [Xtend] problem in m2m transformation [message #525921 is a reply to message #525888] Thu, 08 April 2010 09:43 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hallo Maxime,

please try the info()-extension from org::eclipse::xtend::util::stdlib::io
inside this extension
create relationnel::RString createType(metamodel::GString t):
	info(t.name) ->
        this.setName(t.name);

to prove if this extension is executed for every GString in your model.
Maybe the every type in your model is a containment of your property.
So every type has an exclisive owner.
In this case, you should remove the containment flag.

Regards
Darius
Re: [Xtend] problem in m2m transformation [message #526212 is a reply to message #525888] Fri, 09 April 2010 09:14 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
Adding the stdlib jar and the info(t.name) didn't change anything (I couldn't see any difference), and looking back at my model, I think I have found why.

In my model, I have to define types outside of classes, so I can use them multiple times in the classes.

All thoses types have Datatype as ESuper Type, but I don't know how to define an Xtend function that would get all Datatypes objects and all objects that have Datatype as a ESuper Type (recursively).

Also, once that is donne, how can I merge two List (one list consists of Datatypes, the other of Tables, both of which are Type)?


One day I shall master M2T, but that day has yet to come...
Re: [Xtend] problem in m2m transformation [message #526520 is a reply to message #526212] Mon, 12 April 2010 06:59 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hello Maxime

Quote:
Adding the stdlib jar and the info(t.name) didn't change anything.


Adding the info() extensin is a logging extension. Smile

Quote:

... but I don't know how to define an Xtend function that would get all Datatypes objects and all objects that have Datatype as a ESuper Type (recursively).


anyObject.eRootContainer.eAllContents.typeSelect(ESuperType)

Quote:

Also, once that is donne, how can I merge two List (one list consists of Datatypes, the other of Tables, both of which are Type)?


list1.addAll(list2)

Regards
Darius
Re: [Xtend] problem in m2m transformation [message #526521 is a reply to message #526520] Mon, 12 April 2010 07:17 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
Darius Jockel wrote on Mon, 12 April 2010 08:59

anyObject.eRootContainer.eAllContents.typeSelect(ESuperType)


Ok, I know what was wrong. I have Datatype in both my models, and the transformation used the wrong one. I'll change all names in my metamodel so that never happens again Smile

Darius Jockel wrote on Mon, 12 April 2010 08:59

Quote:

Also, once that is donne, how can I merge two List (one list consists of Datatypes, the other of Tables, both of which are Type)?


list1.addAll(list2)


Thanks.


Regards,

Maxime


One day I shall master M2T, but that day has yet to come...
Re: [Xtend] problem in m2m transformation [message #526556 is a reply to message #525888] Mon, 12 April 2010 09:45 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
Darius Jockel wrote on Thu, 08 April 2010 11:43

create relationnel::RString createType(metamodel::GString t):
	info(t.name) ->
        this.setName(t.name);

to prove if this extension is executed for every GString in your model.
Maybe the every type in your model is a containment of your property.
So every type has an exclisive owner.
In this case, you should remove the containment flag.



750 INFO IOExtensions -
That line got added to my Console when running the workflow
As I have 5 OString, shouldn't there be 4 of those lines ?

My problem is that when I remove the containment flag, I get following error.

782  ERROR WorkflowRunner     - Workflow interrupted. Reason: Problems writing xmi file to src-gen/outModel.xmi : The object 'org.eclipse.emf.ecore.impl.DynamicEObjectImpl@9be79a (eClass: org.eclipse.emf.ecore.impl.EClassImpl@161dfb5 (name: RDatatype) (instanceClassName: null) (abstract: false, interface: false))' is not contained in a resource.


But the file that get's generated is nearly what I want.

Without the containment flag, I get the error and all types inheriting form ODatatype are transformed as should be.

With the containment flag, the ODatatypes are transformed as should be, but I get my initial problem, only one instance for each EClass inheriting from ODatatype is transformed as should be.



One day I shall master M2T, but that day has yet to come...
Re: [Xtend] problem in m2m transformation [message #526574 is a reply to message #526556] Mon, 12 April 2010 10:33 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Quote:

My problem is that when I remove the containment flag, I get following error.


Ah, of cause all Elements must have an owner.
There are two ways to solve this:

1. The model contains Datatypes and the properties refer them.
Something like this (from Fornax Hibernate Cartridge)
create PrimitiveType createLongType(Model model):
	setName("long") ->
	model.ownedType.add(this) ->
	this;

2. Every Property contains another datatype with the same name
Something like this
create PrimitiveType createLongType(Property property):
	setName("long") ->
	this;


Please have in mind that the create extensions are cached extensions.
Therefore the first extension will return one unique PrimitiveType per model. If this type in contained by a property and not by the model and you apply this type to another property, the last property type will be removed.
The second will create a PrimitiveType for every Property.

Regards
Darius
Re: [Xtend] problem in m2m transformation [message #526653 is a reply to message #525888] Mon, 12 April 2010 14:07 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
I putted container back to true, but I can't seem to find the ownedType function.

Quote:
Therefore the first extension will return one unique PrimitiveType per model. If this type in contained by a property and not by the model and you apply this type to another property, the last property type will be removed.


So every time I've been calling createType(String), I lost the former result.

I did not understand the solution you gave. From what I understood, I have to use extension 2 (Every Property contains another datatype with the same name), but it's already what I'm using (I think).

Quote:
create relationnel::Schema transform (metamodel::Package p) :
setTypes(p.datatypes().createType()) ->
types.addAll(p.classes().createTable()) ->
this;

create relationnel::RTable createTable (metamodel::OClass c) :
setName(c.name) ->
setColumn(c.attributs().createColumn()) ->
this;

create relationnel::RColumn createColumn(metamodel::OAttribute a) :
setName(a.name) ->
setType(createType(a.type)) ->
this;

create relationnel::RBool createType(metamodel::OBool t):
setName(t.name) ->
this;


One day I shall master M2T, but that day has yet to come...
Re: [Xtend] problem in m2m transformation [message #526660 is a reply to message #526653] Mon, 12 April 2010 14:20 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hello,
what I wanted to say is that you have to differ between references to a type and an containment of a type.
Do both metamodels handel types in the same way?

I think that inside your OMetamodel the types are a containment of the model and the properties refer them and in your RMetamodel the types are a containment of properties.

If this is not the case, please provide an minimal sample model Razz

Regards
Darius
Re: [Xtend] problem in m2m transformation [message #526877 is a reply to message #526660] Tue, 13 April 2010 11:36 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
There might be a difference in the way both models handle types.

In my OMetamodel, the EClass OAttribute has an EReference type (to OType), and Containment is false.

In the RMetamodel, the Eclass RColumn has an EReference type (to RType), and if Containment is false the workflow states an error, and if true I get my problems with multiple use of a type.

When I wrote my model, I had to create my OType (OString or OBool or others) outside of OAttribute to refer to it.

I thought I could do the same in my destination model from my m2m transformation, apparently not, or at least not that way.


Regards,

Maxime


One day I shall master M2T, but that day has yet to come...

[Updated on: Tue, 13 April 2010 11:37]

Report message to a moderator

Re: [Xtend] problem in m2m transformation [message #526901 is a reply to message #525888] Tue, 13 April 2010 13:03 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
I did not put it there at first, not sure about how it was related.
I made a simple sample model, only with GStrings, which worked perfectly.

Once I added OTypedef, I got the same error message than before.

OTypedef is an OType, same as ODatatype, and it's containment is set as false. if set at true, I can't reference a OType anymore.

  <eClassifiers xsi:type="ecore:EClass" name="OTypedef" eSuperTypes="#//OType">
    <eStructuralFeatures xsi:type="ecore:EReference" name="reftype" lowerBound="1"
        eType="#//OType"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ODatatype" eSuperTypes="#//OType"/>



One day I shall master M2T, but that day has yet to come...
Re: [Xtend] problem in m2m transformation [message #526909 is a reply to message #526901] Tue, 13 April 2010 13:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hello Maxime,

lets say you have containment = false, shouldn't you then store the EObject (Type) elsewhere in the model with containment = true.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xtend] problem in m2m transformation [message #526932 is a reply to message #526909] Tue, 13 April 2010 14:19 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
Well, following ESuper Types
OTypedef -> OType
OType -> ODeclaration

and Package (my entry point) has a EReference named declaration ( type ODeclaration) with containment flag at true.

Si are my OTypedef not contained in Package.declaration ?


One day I shall master M2T, but that day has yet to come...
Re: [Xtend] problem in m2m transformation [message #526965 is a reply to message #526932] Tue, 13 April 2010 15:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hello i think you have to add them there explicitely (in your m2m)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 13 April 2010 15:15]

Report message to a moderator

Re: [Xtend] problem in m2m transformation [message #527419 is a reply to message #525888] Thu, 15 April 2010 08:34 Go to previous message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
Problem solved !

I did not resolve types for my OTypedef when creating a RColumn, only when creating RDatatypes, so i was trying to make a reference to some OMetamodel types in my RModel.

Thank you.

Maxime


One day I shall master M2T, but that day has yet to come...
Previous Topic:[Xpand] Change in behavior of "-" sign to skip whitespaces?
Next Topic:[Acceleo] Problems with AcceleoService.doGenerate
Goto Forum:
  


Current Time: Fri Mar 29 09:48:31 GMT 2024

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

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

Back to the top