Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 346636

Summary: Root resource should not be contained in resource set
Product: [Modeling] EMF Reporter: Martin Fluegge <martin.fluegge>
Component: cdo.coreAssignee: Martin Fluegge <martin.fluegge>
Status: CLOSED FIXED QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3 CC: caspar_d, vroldanbet
Version: 4.0Flags: stepper: review+
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Patch v1 none

Description Martin Fluegge CLA 2011-05-20 06:56:13 EDT
Currently the root resource is added to the resource set. This can lead to various problems e.g. if there are self adapting adapters attached to the resource set like EContentAdapters, CrossreferenceAdapters or TransactionChangeListeners. Hence it would be better to not attach the root resource to the resource set.
Comment 1 Eike Stepper CLA 2011-05-20 06:58:45 EDT
We consider the fact acceptable that resource.getEObject(URI.createURI("cdo://repo1/#L1")) can no longer deliver the root resource instance through EMF API.
Comment 2 Victor Roldan Betancort CLA 2011-05-20 07:38:06 EDT
Oh, this topic sounds familiar to me :P

251467: Load the root resource only optionally into the ResourceSet
https://bugs.eclipse.org/bugs/show_bug.cgi?id=251467

We solved it in a different way: Use LazyContentAdapters and LazyCrossReferenceAdapters. Only adapt elements that are actually loaded.
Comment 3 Martin Fluegge CLA 2011-05-20 09:36:50 EDT
Hi Vik,

thanks for pointing us to this bugzilla. It is indeed quite related to this one. Eike and I worked for several hours on Bug 345858 and finally came to the conclusion that it is best to remove the root resource completely from the resource set. Using the LazyAdapter is a good idea, but I think this solution will also work in cases where the user cannot change the implementation of the self adapting adapter. ;)
Comment 4 Martin Fluegge CLA 2011-05-20 09:38:17 EDT
Created attachment 196218 [details]
Patch v1

Attached a patch which removes the root resource from the resource set and changed all related tests.
Comment 5 Martin Fluegge CLA 2011-05-20 09:55:07 EDT
*** Bug 345858 has been marked as a duplicate of this bug. ***
Comment 6 Victor Roldan Betancort CLA 2011-05-20 10:05:36 EDT
Martin,

> thanks for pointing us to this bugzilla. It is indeed quite related to this
> one. Eike and I worked for several hours on Bug 345858 and finally came to the
> conclusion that it is best to remove the root resource completely from the
> resource set. Using the LazyAdapter is a good idea, but I think this solution
> will also work in cases where the user cannot change the implementation of the
> self adapting adapter. ;)

thats right, the responsible is indeed the root resource, and this may be seen as a *workaround*. However, the root problem is still there: GMF uses content adapters which forces to load the whole model, which invalidates many of the main features of CDO. This also removes the possibility to deal huge models: it may be the case that the diagram requires to load a model as big as your java heap. 

I understand that the implementation cannot be changed. I thought Dawn used fragments to override GMF Code. In our case we overrode TransactionalEditingDomain to use these adapters. We are now able to load HUGE diagrams. Diagrams that are so big that it make no sense to visualize them :P Without the lazy adapters, loading those models was simply impossible.

In any case, the root resource modification is something really interesting that I requested long time ago, but could not find a solution for it. I though it would require deep changes in the framework. I will be welcome!
Comment 7 Martin Fluegge CLA 2011-05-20 12:19:12 EDT
(In reply to comment #6)
> thats right, the responsible is indeed the root resource, and this may be seen
> as a *workaround*. However, the root problem is still there: GMF uses content
> adapters which forces to load the whole model, which invalidates many of the
> main features of CDO. This also removes the possibility to deal huge models: it
> may be the case that the diagram requires to load a model as big as your java
> heap. 
> 
> I understand that the implementation cannot be changed. I thought Dawn used
> fragments to override GMF Code.

It does. ;)
This patch should also help other uses/frameworks beside GMF to work with SelfAdapters if they cannot change these.

> In our case we overrode
> TransactionalEditingDomain to use these adapters.

That is similar to what I do. But I have to admit that currently I did not implement anything to handle huge models. But this must be done soon. I think your LazyAdapters will be a perfect solution for it. :)
Comment 8 Martin Fluegge CLA 2011-05-23 14:41:01 EDT
Committed revision 7825
Comment 9 Eike Stepper CLA 2011-06-23 03:40:57 EDT
Available in R20110608-1407
Comment 10 Eike Stepper CLA 2011-07-16 09:50:35 EDT
*** Bug 251467 has been marked as a duplicate of this bug. ***