[QVTo] How to mapp association between two classes [message #1774446] |
Sat, 14 October 2017 16:09  |
Eclipse User |
|
|
|
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 #1795094 is a reply to message #1795089] |
Fri, 14 September 2018 08:14   |
Eclipse User |
|
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04996 seconds