Skip to content

Commit

Permalink
[41] Use EMF's intrinsicIDToEObjectMap if present
Browse files Browse the repository at this point in the history
The previous commit (1f44029) completely disabled EMF's default
getEObjectByID in favor of using our own JSONResourceImpl-specific id
map. However there are cases where we still want to lookup elements by
their intrinsic (modeled) id instead of the IDManager-provided one,
without incurring the cost of an eAllContents() on failure.

This change allows for this to work, as long as the JSONResourceImpl
has been setup with a non-null intrinsicIDToEObjectMap. For example
right after the resource creation:

  ((ResourceImpl) resource).setIntrinsicIDToEObjectMap(new HashMap<>());

Once this is done, any new object added to the resource will get its
intrinsic id cached in this map (see ResourceImpl.attachedHelper())
and JsonResourceImpl.getEObjectById will find it there (if present)
while still bypassing the whole eAllContents() search in
super.getEObjectByID(id).

Bug: #41
Signed-off-by: Pierre-Charles David <[email protected]>
  • Loading branch information
pcdavid committed Jun 26, 2024
1 parent 9c0f15f commit fb95384
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ public void setID(EObject eObject, String id) {
@Override
protected EObject getEObjectByID(String id) {
if (this.useID) {
return this.idToEObjectMap.get(id);
EObject result = this.idToEObjectMap.get(id);
if (result == null && this.intrinsicIDToEObjectMap != null) {
result = this.intrinsicIDToEObjectMap.get(id);
}
return result;
}
return super.getEObjectByID(id);
}
Expand Down

0 comments on commit fb95384

Please sign in to comment.