How to create an key attribute in the core [message #1218459] |
Fri, 29 November 2013 09:29 |
dodo babab Messages: 6 Registered: January 2013 |
Junior Member |
|
|
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 09:32] Report message to a moderator
|
|
|
|
Re: How to create an key attribute in the core [message #1262287 is a reply to message #1218736] |
Mon, 03 March 2014 13:13 |
|
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 09:52 |
Hussein MHANNA Messages: 45 Registered: February 2014 Location: LAVAL |
Member |
|
|
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
ALL4TEC
|
|
|
Powered by
FUDForum. Page generated in 0.01815 seconds