Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTO] Problem with containment references (objects moved instead of created)
[QVTO] Problem with containment references (objects moved instead of created) [message #94934] Mon, 10 November 2008 14:06 Go to next message
Marc Moser is currently offline Marc MoserFriend
Messages: 66
Registered: July 2009
Member
Hi,

I'm experiencing an unexpected behavior when working with containment
relations. Consider a simple meta-model with classes A, B, C. B has a
containment=true feature called 'values' and C has a containment=true
feature called 'subValues'. Further consider a transformation similar
to the following:

mapping packageA::classA::a2b(x: packageX::classX) : packageB::classB
{
values := x.elements->collect(e | self.map a2c(e))->asOrderedSet();
}

mapping packageA::classA::a2c(y: packageY::classY) : packageC::classC
{
subValues := y.elements->collect(e | self.map
a2b(e))->asOrderedSet();
}

Now I have multiple invocations of a2b(...), with parameters x0..xn,
BUT x0.elements == x1.elements == ... == xn.elements wich leads to
multiple invocations of a2c(...) but always with the same parameters
y0..yn (i.e. the "same" objects C get created for all B's...)

What I wanted to have at the end is several instances of B, each
having several C's in it's subValues feature. But what I got was
several instances of B, but only the last one having instances of C!
Looking at the generated trace, I can see that the C objects are
created when the first B object is created, but for the second B
instances, the mapping a2c(..) is not called at all, but the values
seem to be taken from some cache... in my scenario this is _not_
correct because I want to create new objects.


Is this a bug or a feature? In case it is a feature, is there a
possiblity to achieve what I would like to have?

Many thanks!
Best,
Marc
Re: [QVTO] Problem with containment references (objects moved instead of created) [message #94948 is a reply to message #94934] Mon, 10 November 2008 15:12 Go to previous messageGo to next message
Sergey Boyko is currently offline Sergey BoykoFriend
Messages: 171
Registered: July 2009
Senior Member
Hi Marc,

Qvto for your sample works just as required by specification. Refer to
8.2.1.15 MappingOperation, Execution Semantics.

In short, for the same source given mapping is executed only once, on
second and subsequent calls same result object is returned.
And as of containment ownership that object moves from first reference
to second and so on till last call reached.

You can modify sample in several ways:
- implicitly perform object{} expression (according to specification it
doesn't consider traces)
- provide addition temporary parameter of Integer type for a2c(..)
mapping (incremented after each call) so that trace record (trace tuple)
between calls wouldn't match


Regards,
Sergey

Marc Moser wrote:
> Hi,
>
> I'm experiencing an unexpected behavior when working with containment
> relations. Consider a simple meta-model with classes A, B, C. B has a
> containment=true feature called 'values' and C has a containment=true
> feature called 'subValues'. Further consider a transformation similar
> to the following:
>
> mapping packageA::classA::a2b(x: packageX::classX) : packageB::classB
> {
> values := x.elements->collect(e | self.map a2c(e))->asOrderedSet();
> }
>
> mapping packageA::classA::a2c(y: packageY::classY) : packageC::classC
> {
> subValues := y.elements->collect(e | self.map
> a2b(e))->asOrderedSet();
> }
>
> Now I have multiple invocations of a2b(...), with parameters x0..xn,
> BUT x0.elements == x1.elements == ... == xn.elements wich leads to
> multiple invocations of a2c(...) but always with the same parameters
> y0..yn (i.e. the "same" objects C get created for all B's...)
>
> What I wanted to have at the end is several instances of B, each
> having several C's in it's subValues feature. But what I got was
> several instances of B, but only the last one having instances of C!
> Looking at the generated trace, I can see that the C objects are
> created when the first B object is created, but for the second B
> instances, the mapping a2c(..) is not called at all, but the values
> seem to be taken from some cache... in my scenario this is _not_
> correct because I want to create new objects.
>
>
> Is this a bug or a feature? In case it is a feature, is there a
> possiblity to achieve what I would like to have?
>
> Many thanks!
> Best,
> Marc
Re: [QVTO] Problem with containment references (objects moved instead of created) [message #95042 is a reply to message #94948] Tue, 11 November 2008 06:45 Go to previous messageGo to next message
Marc Moser is currently offline Marc MoserFriend
Messages: 66
Registered: July 2009
Member
Hi Sergey,

Comments below.

>Qvto for your sample works just as required by specification. Refer to
>8.2.1.15 MappingOperation, Execution Semantics.
>
>In short, for the same source given mapping is executed only once, on
>second and subsequent calls same result object is returned.
>And as of containment ownership that object moves from first reference
>to second and so on till last call reached.

I did now read this part in the specification and I completely agree
with you.

>You can modify sample in several ways:
>- implicitly perform object{} expression (according to specification it
>doesn't consider traces)

I tried this, but I didn't really get it to work. Does it mean that
instead of creating mapping a2c(..) I would have to include the
mapping body as object {} expression in mapping a2b(..)?

>- provide addition temporary parameter of Integer type for a2c(..)
>mapping (incremented after each call) so that trace record (trace tuple)
>between calls wouldn't match

I did this using an intermediate property and it worked well. So my
actual problem is solved.

Thanks a lot for your quick answer!

Best,
Marc


>Regards,
> Sergey
>
>Marc Moser wrote:
>> Hi,
>>
>> I'm experiencing an unexpected behavior when working with containment
>> relations. Consider a simple meta-model with classes A, B, C. B has a
>> containment=true feature called 'values' and C has a containment=true
>> feature called 'subValues'. Further consider a transformation similar
>> to the following:
>>
>> mapping packageA::classA::a2b(x: packageX::classX) : packageB::classB
>> {
>> values := x.elements->collect(e | self.map a2c(e))->asOrderedSet();
>> }
>>
>> mapping packageA::classA::a2c(y: packageY::classY) : packageC::classC
>> {
>> subValues := y.elements->collect(e | self.map
>> a2b(e))->asOrderedSet();
>> }
>>
>> Now I have multiple invocations of a2b(...), with parameters x0..xn,
>> BUT x0.elements == x1.elements == ... == xn.elements wich leads to
>> multiple invocations of a2c(...) but always with the same parameters
>> y0..yn (i.e. the "same" objects C get created for all B's...)
>>
>> What I wanted to have at the end is several instances of B, each
>> having several C's in it's subValues feature. But what I got was
>> several instances of B, but only the last one having instances of C!
>> Looking at the generated trace, I can see that the C objects are
>> created when the first B object is created, but for the second B
>> instances, the mapping a2c(..) is not called at all, but the values
>> seem to be taken from some cache... in my scenario this is _not_
>> correct because I want to create new objects.
>>
>>
>> Is this a bug or a feature? In case it is a feature, is there a
>> possiblity to achieve what I would like to have?
>>
>> Many thanks!
>> Best,
>> Marc
Re: [QVTO] Problem with containment references (objects moved instead of created) [message #95119 is a reply to message #95042] Wed, 12 November 2008 14:10 Go to previous message
Sergey Boyko is currently offline Sergey BoykoFriend
Messages: 171
Registered: July 2009
Senior Member
Hi Marc,

Saying "implicitly perform object{} expression" I meant substitution like:

values := x.elements->collect(e | self.map a2c(e))->asOrderedSet();

with

values := x.elements->collect(e | object packageC::classC {subValues
:= ..})->asOrderedSet();

That's of course is not an elegant solution but it should work ;)

Wbr,
Sergey.

Marc Moser wrote:
> Hi Sergey,
>
> Comments below.
>
>> You can modify sample in several ways:
>> - implicitly perform object{} expression (according to specification it
>> doesn't consider traces)
>
> I tried this, but I didn't really get it to work. Does it mean that
> instead of creating mapping a2c(..) I would have to include the
> mapping body as object {} expression in mapping a2b(..)?
>
>
> Best,
> Marc
Previous Topic:[ATL] Match Stereotypes
Next Topic:[Declarative QVT] First build available.
Goto Forum:
  


Current Time: Fri Apr 26 20:03:48 GMT 2024

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

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

Back to the top