Skip to main content



      Home
Home » Modeling » Modeling (top-level project) » How to create an key attribute in the core
How to create an key attribute in the core [message #1218459] Fri, 29 November 2013 04:29 Go to next message
Eclipse UserFriend
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 #1218736 is a reply to message #1218459] Fri, 29 November 2013 07:08 Go to previous messageGo to next message
Eclipse UserFriend
Comments below.

On 29/11/2013 10:29 AM, dodo babab wrote:
> 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 is an EMF question best asked on the eclipse.tools.emf forum/newsgroup.
> 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.
You'll have to modify the generated code for that. Likely the best
approach is to modify the getter method so that if the field is null,
you initialize the field with a value using whatever logic you want to
use, and then return that value.
>
> Best Regards
Re: How to create an key attribute in the core [message #1262287 is a reply to message #1218736] Mon, 03 March 2014 08:13 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
Previous Topic:Are there any db modelers with eclipse plug-in
Next Topic:Converting models
Goto Forum:
  


Current Time: Sat Jul 05 02:51:53 EDT 2025

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

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

Back to the top