How to create an key attribute in the core [message #1218459] |
Fri, 29 November 2013 04:29  |
Eclipse User |
|
|
|
Hi,
Please,can anyone help me. I want to create an attribute of one class,in the meta-model (ecore), as a key attribute. This attribute should take automatically a random value in the instance of the mat model. the concept is the same with the key of one table in database.
Best Regards
[Updated on: Fri, 29 November 2013 04:32] by Moderator
|
|
|
|
Re: How to create an key attribute in the core [message #1262287 is a reply to message #1218736] |
Mon, 03 March 2014 08:13   |
Eclipse User |
|
|
|
If you want to use a custom attribute as an ID, an other way to do this is to override the ResourceImpl used.
For example, if you use an XMLResourceImpl, you will have some methods that you can adapt, like :
- useUUIDs, to specify that your objects are identified by UUID (true)
- assignIDsWhileLoading, to specify if an ID must be set during the resource load (false)
- createXMLSave, overridden to use a custom XMLSaveImpl which will not save the ID using the standard mechanisms, but only the save value in your attribute
It's a bit tricky, but it's working.
|
|
|
Re: How to create an key attribute in the core [message #1269039 is a reply to message #1262287] |
Tue, 11 March 2014 05:52  |
Eclipse User |
|
|
|
If you want to generate automatically an uuid and if you haven't an ID attribute in your ecore model and if it isn't necessary for you to keep the same uuid each time you load the resource, then you can override the assignIDsWhileLoading and the useUUIDs and return true on both methods so an uuid will be generated automatically and saved in a map in the resource class and then you can retrieve this uuid by using the getEObjectByID method (this method is protected so you must ovveride it as public to can access it from outside the class itself).
This is applicable to any instance of XMLResourceImpl (for example XMIResourceImpl which extends the XMLResourceImpl).
Hussein
|
|
|
Powered by
FUDForum. Page generated in 0.03050 seconds