Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTO] creating recursive instances(how do i create instances of type A that have references to instances of type A when i don't know if they have already been created)
[QVTO] creating recursive instances [message #500679] Fri, 27 November 2009 13:45 Go to next message
Paul Klingelhuber is currently offline Paul KlingelhuberFriend
Messages: 1
Registered: November 2009
Junior Member
Hy,

i'm trying to write a qvto transformation that creates an ecore-model-instance from another xml-based serialization.

so i have a main ecore model (with which i want to work) and another one created from an xsd-file which represents the alternative serialization.

my problem is that in the main ecore model there is a class 'A' which has references to other 'A's.

in the alternative xml-serialization it might look like this:

<A id="instance1" following="instance2" />
<A id="instance5" following="instance2" />
<A id="instance2" following="instance5" />

i managed to write a transformation from the ecore model to this serialization form.

my problem is that when i want to get from this xml model to the real ecore model i have to set references to the other A-instances...
so when i create an instance for A with id "instance1" i need to set a reference to the A with id "instance2" but at this point i don't know if an A with instance2 has already been created.

how do i find this out? and how do i then set the reference to it?

my first idea was that i first create all A instances without their following-references set and then update them, but i'm also not really sure how to do that (the updating part, not the initial-creating)

i hope you can see my problem and my explanations weren't too confusing Smile

if someone could help me, i would really appreciate it! thanks!
Re: [QVTO] creating recursive instances [message #500697 is a reply to message #500679] Fri, 27 November 2009 14:39 Go to previous message
Eclipse UserFriend
Originally posted by: dvorak.radek.gmail.com

Hi Paul,

You have to options to solve your problem.
1) do not care if the the other referenced A instance has been
created or not and just call a mapping which should produce it.
If not yet created, it will be done by the mapping body execution,
if already created, it will just fetch the result from the previous
execution and return to the caller.

For detail understanding see the QVT OMC spec,
8.2.1.15 MappingOperation (sub-section "Execution Semantics")

2) you can use late resolve for the referenced target A-instance.
It's sort of forward relation to the target, where you say:
"I do not care if the result exist yet, but when it's ready
assign it here" ;)

See OMG spec,
8.1.10 Updating Objects and Resolving Object References
8.2.1.22 ResolveExp


Why do we have 1) and 2) ?

As for case 1) you should not get a stack overflow as long as
you call the mapping recursively after the init section (may be implicit),
at which point the relation already holds and trace record exists.
If so, the mapping can't be reentered but the result is already
available. Do not be surprised that the caller gets an object which
changes later. But mainly, you get the result reference ;).

Wit 2) the result is not available at the time of the calling late resolve,
as the returned value is null when called. So it's primarily a reference
based mechanism used in conjunction with reference assignments.
The transformation engine can guarantee that the late resolution actual
result will be assigned to a target reference in the end of the
transformation.
This approach is good if you really want to reflect the source objects
ordering in the target objects order.

Also, you can design your transf in multiple passes,
first create all A target instances and next connect its
references. With traces you can figure out which source has been mapped
to which target.
See OMG spec, "A.2.3 Uml to Rdbms" for inspiration.

All that is essential is to understand the mapping execution semantics
and how traces can be consulted using resolve. The rest is up to you
creativity ;).


Regards,
/Radek



On Fri, 27 Nov 2009 14:45:03 +0100, Paul Klingelhuber <mail.paul@gmx.net>
wrote:

> Hy,
>
> i'm trying to write a qvto transformation that creates an
> ecore-model-instance from another xml-based serialization.
>
> so i have a main ecore model (with which i want to work) and another one
> created from an xsd-file which represents the alternative serialization.
>
> my problem is that in the main ecore model there is a class 'A' which
> has references to other 'A's.
>
> in the alternative xml-serialization it might look like this:
>
> <A id="instance1" following="instance2" />
> <A id="instance5" following="instance2" />
> <A id="instance2" following="instance5" />
>
> i managed to write a transformation from the ecore model to this
> serialization form.
>
> my problem is that when i want to get from this xml model to the real
> ecore model i have to set references to the other A-instances...
> so when i create an instance for A with id "instance1" i need to set a
> reference to the A with id "instance2" but at this point i don't know if
> an A with instance2 has already been created.
>
> how do i find this out? and how do i then set the reference to it?
>
> my first idea was that i first create all A instances without their
> following-references set and then update them, but i'm also not really
> sure how to do that (the updating part, not the initial-creating)
>
> i hope you can see my problem and my explanations weren't too confusing
> :) if someone could help me, i would really appreciate it! thanks!
Previous Topic:[QVTO] What's the canonical way to set inherited attributes/references in a inheritance hierarchy
Next Topic:QVT - how to programatically retrieve the model(AST) from the transformation script
Goto Forum:
  


Current Time: Thu Aug 22 06:44:54 GMT 2019

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

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

Back to the top