|
|
Re: How to increment an id feature automatically [message #1786556 is a reply to message #1786551] |
Mon, 07 May 2018 08:26 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05816 seconds