Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 09:29 Go to next message
dodo babab is currently offline dodo bababFriend
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 #1218736 is a reply to message #1218459] Fri, 29 November 2013 12:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
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 13:13 Go to previous messageGo to next message
Jonathan Dumont is currently offline Jonathan DumontFriend
Messages: 58
Registered: March 2011
Location: Laval
Member
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 Go to previous message
Hussein MHANNA is currently offline Hussein MHANNAFriend
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
Previous Topic:Are there any db modelers with eclipse plug-in
Next Topic:Converting models
Goto Forum:
  


Current Time: Sat Nov 22 14:30:52 GMT 2014

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

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