Autogenerate ID for EMF objects [message #497603] |
Fri, 13 November 2009 09:42 |
Nirmal Sasidharan 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 |
Ed Merks 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/
|
|
|
Powered by
FUDForum. Page generated in 0.03151 seconds