Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » [QVTo] How to mapp association between two classes
[QVTo] How to mapp association between two classes [message #1774446] Sat, 14 October 2017 20:09 Go to next message
Bosko Susnjar is currently offline Bosko SusnjarFriend
Messages: 6
Registered: May 2017
Junior Member
Hello. I have final exam on my Faculty and i need to create QVT plugin for mapping database schema from conceptual model into relationship model.

So - for start - I have created two classes:
https://i.imgur.com/G9V7PPV.png

And create this transformation code:
modeltype uml "strict" uses uml('http://www.eclipse.org/uml2/3.0.0/UML');

transformation transf(in srcModel:uml, out destModel: uml);

main() {
   srcModel.rootObjects()[Model] -> map Model2Model();   

}

mapping Model:: Model2Model() : Model {
	name := self.name;
	
	packagedElement += self.packagedElement[Class] -> map Class2Class();
	packagedElement += self.packagedElement[Association] -> map Association2Association();
} 

mapping Class:: Class2Class() : Class {
	name := self.name;
	visibility := self.visibility;
	
	ownedAttribute += self.ownedAttribute[Property] -> map Property2Property();
	ownedOperation += self.ownedOperation[Operation] -> map Operation2Operation();
}

mapping Property:: Property2Property() : Property {
	name := self.name;
	type := self.type;
	
	--lower := self.lower;
	--upper := self.upper;
}

mapping Operation:: Operation2Operation() : Operation {
	name := self.name;
	
	ownedParameter += self.ownedParameter[Parameter] -> map Parameter2Parameter();
}

mapping Parameter :: Parameter2Parameter() : Parameter {
	name := self.name;
	type := self.type;
}

mapping Association :: Association2Association() : Association {
	name := self.name;
	visibility := self.visibility;
	memberEnd := self.memberEnd;
	
	ownedEnd += self.ownedEnd[Property] -> Property2PropertyA();
}
mapping Property :: Property2PropertyA() : Property {
	type := self.type;
	
	association := self.association;
	lowerValue := self.lowerValue;
	upperValue := self.upperValue;	
} 


But, when i run transformation, i get this error:

Severity	Description	Element	Parent	Type
Error	The feature 'uml::Relationship::relatedElement' of 'RootElement::residence' with 0 values must have at least 1 values	<Association> residence	RootElement	EMF Problem
Error	The feature 'uml::Association::memberEnd' of 'RootElement::residence' with 0 values must have at least 2 values	<Association> residence	RootElement	EMF Problem
Error	The feature 'uml::Association::endType' of 'RootElement::residence' with 0 values must have at least 1 values	<Association> residence	RootElement	EMF Problem


My problem is how to mapp Association between those two classes?
I know that on * side i need to have one more attribute and foreign key operation but don't know how to write it.

Can someone help me, please?
Re: [QVTo] How to mapp association between two classes [message #1774447 is a reply to message #1774446] Sat, 14 October 2017 20:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6066
Registered: July 2009
Senior Member
Hi

I'm sorry. This forum is unlikely to give you help on your exam problems.

Regards

Ed Willink
Re: [QVTo] How to mapp association between two classes [message #1795089 is a reply to message #1774447] Fri, 14 September 2018 09:57 Go to previous messageGo to next message
Bosko Susnjar is currently offline Bosko SusnjarFriend
Messages: 6
Registered: May 2017
Junior Member
Hi

Is there any good example of using resolve function(s) in QVT-O?

I have conceptual model like this https://i.imgur.com/09uqWBU.png and after I run my transformation I get this: https://i.imgur.com/QlOGPSz.png (Class "Sudjenje" (Trial) is not good. Class "Sudija" (Referee) have attribute and operation from class "Osoba" (Person) (since class "Osoba" (Person) is a generalization of class "Sudija" (Refree))).

Anyone know how to implement resolve function so that this works ok?
Re: [QVTo] How to mapp association between two classes [message #1795094 is a reply to message #1795089] Fri, 14 September 2018 12:14 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6066
Registered: July 2009
Senior Member
Hi

I'm not sure what 'resolve' has to do with mapping Associations ...

My personal experience with 'resolve' was not good. I found it confusing and untrustworthy and so preferred to maintain my mappings in a Dict that I could understand.

For QVT 1.3, I tried to pin down the semantics of traceability that underpins the resolve functions. This is written up as "8.1.11 Tracing and Resolving" and while it does not precisely correspond with the current Eclipse QVTo implementation, it is not significantly different. Areas where the Eclipse QVTo implementation needs to catch up concern the tracing of polymorphic mappings.

While QVTo has many declarative facilities, it is an operational/imperative language, so it is your responsibility as a programmer to ensure that if A2B needs to use the results of C2D, then C2D must execute first. If A2B 'resolves' something using C2D before C2D executes you get a null resolution. There is an underspecified "late resolve" facility that I cannot honestly recommend. IIRC, in Eclipse QVTo, late resolve works for a simple object reference, it does not work for an expression involving an object reference.

In practice many transformations need two passes, a first pass to create a composition tree of output objects and then a second pass to create the cross-references that support an output graph rather than tree. The second pass can use resolve to navigate the results of the first pass. In QVTo you need to code these two passes as separate suites of mappings that execute on before the other. (In QVTr you can specify everything a single mapping since a QVTr must understand the dependencies and sequence its actions accordingly.)

It is likely that problems that you encounter with resolve are through an over-optimistic attempt to use a one-pass solution for a two-pass problem. Statistically one might expect that 50% of resolves will 'work' and 50% will 'fail'.

Regards

Ed Willink
Re: [QVTo] How to mapp association between two classes [message #1795148 is a reply to message #1795094] Mon, 17 September 2018 06:23 Go to previous messageGo to next message
Bosko Susnjar is currently offline Bosko SusnjarFriend
Messages: 6
Registered: May 2017
Junior Member
Thank you, Ed, for your response.

I posted on this topic because I didn't want to start new since I am dealing with the same example, but this is expanded that have and generalization.

You are right, I have one supper class (Person) and class (Referee) connected with generalization. Class Referee doesn't have any own property, so he gets all from the superclass. But, I also have a class (Trial) that is connected with association with class Referee and there I have the problem. That class needs to have attributes from class Referee but I get null.
Can you, please, explain to me how I can ensure the "second pass" in qvt-o?
Re: [QVTo] How to mapp association between two classes [message #1795150 is a reply to message #1795148] Mon, 17 September 2018 07:10 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6066
Registered: July 2009
Senior Member
Hi

To do two passes, you do pass 1 then you do pass 2. e.g. from http://git.eclipse.org/c/ocl/org.eclipse.ocl.git/tree/examples/org.eclipse.ocl.examples.build/src/org/eclipse/ocl/examples/build/qvto/UML2EcoreSynthesizer.qvto

--
-- Pass 1: Create the output containment hierarchy
--
createPackages->map createPackage();
--
-- Pass 2: Resolve references within the output containment hierarchy
--
umlType2eClass->values()->sortedBy(name)->map resolveEClass();
umlProperty2eReference->values()->sortedBy(name)->map resolveEReference();

Regards

Ed Willink
Previous Topic:creating operation parameters
Next Topic:Announce QVTo 3.9.0
Goto Forum:
  


Current Time: Tue Oct 16 04:11:32 GMT 2018

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

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

Back to the top