How to increment an id feature automatically [message #1786549] |
Mon, 07 May 2018 03:29  |
Eclipse User |
|
|
|
Hi folks,
I would like to know if it is possible to set an id feature of an object with 1 when the user creates it the first time. Then, other objects of the same type would have that id automatically incremented.
How to do this?
Regards
Adalberto Jr
|
|
|
|
Re: How to increment an id feature automatically [message #1786556 is a reply to message #1786551] |
Mon, 07 May 2018 04:26   |
Eclipse User |
|
|
|
Hi
You need to answer questions such as:
does a derived class share/override the counter of the base class?
are stale ids re-used after deletion? i.e. if {1,2,3} are created, then 2 is deleted leaving {1.3} , what is the next id?
- 2 (fill the gap) => {1,2,3}
- 3 (count the elements, as in the AQL snippet) - oops => {1,3,3}
- 4 (next all-time) => {1,3,4}
are missing ids re-used after reloading? if I save a model one day and continue the next, loading {56,57,58}, is the next id 1 or 59?
does reloading reuse old IDs or start from 1?
are IDs reassigned by copy and paste?
You can elaborate the AQL to avoid re-use of ids, but what you require is a class level operation for which some variant of allInstances() and/or search is necessary; clumsy and inefficient; an interesting optimization challenge for tool vendors. If you really want to do this, I would recommend a Java/EMF solution in which getID() lazily allocates the ID from a 'static' EClass Map/Set appropriately scoped by derived EClasses. setID() will be invoked automatically by the loader if you choose to persist the ID. The transient and volatile attributes should support your design choice.
Regards
Ed Willink
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: How to increment an id feature automatically [message #1786812 is a reply to message #1786811] |
Sat, 12 May 2018 15:41  |
Eclipse User |
|
|
|
Hi
Yes. Very confused. and you don't make it any clearer. Obviously the solution for the old goal won't suit a changed goal. I have no idea what your goal is now. I suggest you review my earlier answer.
Do you want an auto-allocated ID that is guaranteed to exist and be unique, or do you want a persisted name with an initial hint that the user should improve, or .... ?
Until you know what properties you want ID to exhibit, it is very difficult to implement it.
(The IDs in your current solution do not repeat; they are ALL REALLOCATED starting at 0).
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.06001 seconds