Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [qvto] One-to-Many Mappings
[qvto] One-to-Many Mappings [message #107006] Tue, 23 June 2009 18:17 Go to next message
Rhett Hudson is currently offline Rhett HudsonFriend
Messages: 3
Registered: July 2009
Junior Member
I have a source model that contains an object whose data can cause
multiple objects to be instantiated in the target mapping. The source
model essentially represents a series of target model objects using a
'start' and 'stop' number. The mapping of the source element to the target
elements is potentially one-to-many.

I've tried several approaches to achieving this end. I've tried using a
while construct to loop around an object construct, but that appears to
simply create one object and update it even if I use +=. I've tried some
select/collect structures, but they produce collections that I then can't
iterate over to add to my target model.

Is there a viable pattern for solving this sort of problem?

Thanks,
Rhett
Re: [qvto] One-to-Many Mappings [message #107019 is a reply to message #107006] Wed, 24 June 2009 11:56 Go to previous messageGo to next message
Sergey Boyko is currently offline Sergey BoykoFriend
Messages: 171
Registered: July 2009
Senior Member
Hi Rhett,

One-to-many mapping can be archived in different ways.

First one is to pass addition parameter (like record number) to the mapping:

main() {
..
var index := 0;
while (...) {
targetModel.ownedMembers += scrElement.map srcToTarget(index);
index := index + 1;
}
}

Another choice is to define constructor and use explicit object
instantiation:

constructor MyTargetType::MyTargetType(srcElement : MySrcType) {
..
}

main() {
..
while (...) {
targetModel.ownedMembers += new MyTargetType(srcElement);
}
}

Mapping operates in update semantic only when repeatedly called on the
same source with the identical (to the previous invocation) mapping
arguments.

Regards,
Sergey.


Rhett Hudson wrote:
> I have a source model that contains an object whose data can cause
> multiple objects to be instantiated in the target mapping. The source
> model essentially represents a series of target model objects using a
> 'start' and 'stop' number. The mapping of the source element to the
> target elements is potentially one-to-many.
>
> I've tried several approaches to achieving this end. I've tried using a
> while construct to loop around an object construct, but that appears to
> simply create one object and update it even if I use +=. I've tried some
> select/collect structures, but they produce collections that I then
> can't iterate over to add to my target model.
>
> Is there a viable pattern for solving this sort of problem?
>
> Thanks,
> Rhett
>
Re: [qvto] One-to-Many Mappings [message #107048 is a reply to message #107006] Wed, 24 June 2009 12:36 Go to previous message
Radomil Dvorak is currently offline Radomil DvorakFriend
Messages: 249
Registered: July 2009
Senior Member
Hi Rhett,

There is a straightforward pattern for one-to-many mapping, expressed
directly in the operation signature using a collection return type.
You can use something like:

mapping Model::onetoMany() : Collection(Table) {
init {
result := Sequence {
object Table {},
object Table {}
};
}
}

Subsequent mapping calls on the same source object will retrieve
all the objects created in the first mapping call which actually
realized the one-to-many mapping.

Regards,
/Radek


On Tue, 23 Jun 2009 20:17:06 +0200, Rhett Hudson <rhudson@annapmicro.com>
wrote:

> I have a source model that contains an object whose data can cause
> multiple objects to be instantiated in the target mapping. The source
> model essentially represents a series of target model objects using a
> 'start' and 'stop' number. The mapping of the source element to the
> target elements is potentially one-to-many.
>
> I've tried several approaches to achieving this end. I've tried using a
> while construct to loop around an object construct, but that appears to
> simply create one object and update it even if I use +=. I've tried some
> select/collect structures, but they produce collections that I then
> can't iterate over to add to my target model.
>
> Is there a viable pattern for solving this sort of problem?
>
> Thanks,
> Rhett
>
Previous Topic:[ATL] Call an operation
Next Topic:problem with transformation QVTR.
Goto Forum:
  


Current Time: Tue May 14 07:19:54 GMT 2024

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

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

Back to the top