Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Autogenerate ID for EMF objects(Generate IDs as soon as the object is created and not during serialisation)
Autogenerate ID for EMF objects [message #497603] Fri, 13 November 2009 09:42 Go to next message
Nirmal SasidharanFriend
Messages: 120
Registered: July 2009
Location: Germany
Senior Member
Hello,

I am looking for a way to automatically generate and assign UUID for EMF objects as soon as they are created.

I cannot overide useUUIDs() of the resource as I would like to get the ID assigned as soon as the object is created and not during serialization.

These were the approaches I could think of :

1. Create a volatile attribute ID
I don't prefer this as the same ID has to be returned everytime, results in modifying generated code and also the ID is not persisted.

2. Create a EContentAdapter and attach it to the resource.
I feel this is still not the most elegant solution as the Id is set only when the created object is attached to a container and the notification is fired.

3. Set the Id manually soon after creating the object
This would be least preferred

Is there a better way to achieve this. My requirement again is to generate Ids as soon as the object is created and they need to be serialized as well

Thanks in advance,

Nirmal
Re: Autogenerate ID for EMF objects [message #497990 is a reply to message #497603] Fri, 13 November 2009 12:03 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Nirmal,

Comments below.

Nirmal Sasidharan wrote:
> Hello,
>
> I am looking for a way to automatically generate and assign UUID for
> EMF objects as soon as they are created.
That sounds like a bad idea. Objects are created during deserialization
and the ID should come from the serialization not be created from scratch.
> I cannot overide useUUIDs() of the resource as I would like to get the
> ID assigned as soon as the object is created and not during
> serialization.
>
> These were the approaches I could think of :
>
> 1. Create a volatile attribute ID
> I don't prefer this as the same ID has to be returned everytime,
> results in modifying generated code and also the ID is not persisted.
The ID is persisted as long as it's not transient. You'd need isID to
be true for it to act as an ID.
>
> 2. Create a EContentAdapter and attach it to the resource.
> I feel this is still not the most elegant solution as the Id is set
> only when the created object is attached to a container and the
> notification is fired.
Resources already can assign IDs so not sure how this will be different...
>
> 3. Set the Id manually soon after creating the object
> This would be least preferred
You should rethink your goal.
>
> Is there a better way to achieve this. My requirement again is to
> generate Ids as soon as the object is created and they need to be
> serialized as well
If necessary, I'd override the getter method to never return null but
rather generate an ID when first asked for an ID and of course cache it
then.
>
> Thanks in advance,
>
> Nirmal


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:InvocationTargetException during conversion of an eDataType
Next Topic:Teneo: Deleting with EAV schema
Goto Forum:
  


Current Time: Thu Apr 25 10:02:18 GMT 2024

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

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

Back to the top