Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Unique ID
Unique ID [message #832706] Fri, 30 March 2012 13:37 Go to next message
Stacey Hopkins is currently offline Stacey HopkinsFriend
Messages: 34
Registered: March 2012
Member
Currently using EMF to create a RCP.

Using XML for data storage - as not possible to have a database backend on a server in organisation Sad

Already have done a few releases and the customer is using the rcp... All good!

Now need to add a new attribute on DescribedElement (Super class for all EClass, used for common attributes e.g. Name, Description).... this attribute is to be called "Id".

The customer needs a numeric based Id to help linking to other items and for users to use as a short name..... I would guess it would be easier to do this by a GUID to ensure uniqueness.... but have customer constraint.

Can anyone advise on how to add a numeric based id to a ecore model .... is there something basic I am missing?

I think the reality of the project is that we will implement two id's one as numeric to satisfy customer short-term needs and one as a GUID to allow for future growth and doing things better in the future!

So any advice on how to add a GUID would be useful too!

....also thinking about how to backfit this id to data already out-there ... any thoughts?....

I have spotted when debugging the RCP a numeric id associated with EClass, is this something I can use or is this to do with memory?


I think the reality of the project is that we will implement two id's one as numeric to satisfy customer short-term needs and one as a GUID


hope this is enough info to comment on if not please let me know the gaps .... best regards.... Stacey
Re: Unique ID [message #832773 is a reply to message #832706] Fri, 30 March 2012 15:07 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

EMF already supports UUIDs; just override useUUIDs() to return true in
your derived Resource.

UUIDs are not normally visible in a model, so if you want your customer
to see them, you may want to create a derived attribute that makes the
value readable.

If you want to use numeric rather than alphabetic ids you will need to
take responsibility for their allocation; search for all uses of useUUIDs().

The numeric ids in the debugger are, I think, sequentially allocated by
the debugger as each object is displayed in the variables view. You
don't want to try to use these yourself.

Regards

Ed Willink

On 30/03/2012 09:37, Stacey Hopkins wrote:
> Currently using EMF to create a RCP.
>
> Using XML for data storage - as not possible to have a database
> backend on a server in organisation :(
>
> Already have done a few releases and the customer is using the rcp...
> All good!
>
> Now need to add a new attribute on DescribedElement (Super class for
> all EClass, used for common attributes e.g. Name, Description)....
> this attribute is to be called "Id".
>
> The customer needs a numeric based Id to help linking to other items
> and for users to use as a short name..... I would guess it would be
> easier to do this by a GUID to ensure uniqueness.... but have customer
> constraint.
>
> Can anyone advise on how to add a numeric based id to a ecore model
> .... is there something basic I am missing?
>
> I think the reality of the project is that we will implement two id's
> one as numeric to satisfy customer short-term needs and one as a GUID
> to allow for future growth and doing things better in the future!
>
> So any advice on how to add a GUID would be useful too!
>
> ...also thinking about how to backfit this id to data already
> out-there ... any thoughts?....
>
> I have spotted when debugging the RCP a numeric id associated with
> EClass, is this something I can use or is this to do with memory?
>
>
> I think the reality of the project is that we will implement two id's
> one as numeric to satisfy customer short-term needs and one as a GUID
>
>
> hope this is enough info to comment on if not please let me know the
> gaps .... best regards.... Stacey
>
Re: Unique ID [message #848581 is a reply to message #832773] Wed, 18 April 2012 11:29 Go to previous messageGo to next message
Stacey Hopkins is currently offline Stacey HopkinsFriend
Messages: 34
Registered: March 2012
Member
Thanks for the info I have extended the resource (XMIResourceImpl) and resourceFactory (XMIResourceFactoryImpl)

.....I have a concern though that I am now relying on XMI to provide the id, I feel this is me now setting a dependency on the storage type?.... something that would be an additional thing to manage if ever moving the storage .... Is this correct?

In addition is their any recommended good tutorials on using of derived attributes? {can't see any on my first look.} - Thanks Stacey
Re: Unique ID [message #848601 is a reply to message #848581] Wed, 18 April 2012 11:53 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Stacey,

Comments below.

On 18/04/2012 1:29 PM, Stacey Hopkins wrote:
> Thanks for the info I have extended the resource (XMIResourceImpl) and
> resourceFactory (XMIResourceFactoryImpl)
>
> ....I have a concern though that I am now relying on XMI to provide
> the id, I feel this is me now setting a dependency on the storage type?
Certainly a dependency on the resource implementation. Ideally other
resource implementations extend the XMI one and support their
specialized style via an option (like we do for OPTION_BINARY) and take
into account the object/id maps as part of what needs to be persisted.
> .... something that would be an additional thing to manage if ever
> moving the storage .... Is this correct?
Yes, potentially and perhaps likely, that's an issue.
>
> In addition is their any recommended good tutorials on using of
> derived attributes? {can't see any on my first look.} - Thanks Stacey
It's not that complicated. Typically you'd make the feature not
changeable, volatile, and derived in the model, and in that case only a
stub is generated for the getter in the implementation class so you must
implement the logic for it. You must ensure if your doing this for an
attribute that's an ID that the value you return will always be unique
with respect to all other IDs for objects in the same resource (even
objects of a different type).


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Teneo] import of xmi export fails for datastore
Next Topic:return type String[]
Goto Forum:
  


Current Time: Fri Apr 26 16:27:28 GMT 2024

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

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

Back to the top