|
Re: ResourceSet and unloading of Resources [message #414793 is a reply to message #414790] |
Wed, 21 November 2007 16:20 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Christian,
At any time, even if there are still references to it, you can use
Resource.unload to turn all the contained objects into proxies. The
resource will reload if any proxy to it needs to be resolved. Afterwards
you could also use resourceSet.getResources().remove(resource),
although, since the contents are empty, that wouldn't save a significant
amount of space. EcoreUtil.delete might be useful for you as well;
there's a new version of it in 2.4 that recursively deletes the
contained children.
Christian Ernst wrote:
> Hi !
>
> Is there a way to unload a Resource from the ResourceSet ?
>
> The EcoreUtil.remove(obj) seems not to remove the Resource from the
> ResourceSet.
>
> In our case we have several Models with own Resources and
> containment proxy as cross references.
> The proxies in EMF allows to load parts of our
> Object Graph transparently and each Resource
> which is touched is added to the ResourceSet.
>
> Example:
> Object X from Model A is in Resource A
> Object Y from Model B is in Resource B
> Object Z from Model C is in Resource C
>
> Object X -containment-> Object Y -containment-> Object Z
>
> But our Resources are very heavy/expensive an we would like
> get rid of the Resource B and Resource C in case X doesn't reference
> anymore Object Y.
>
>
> Our current solution to manually remove all Resource from the
> ResourceSet which are in the containment graph:
> -----------------------------------------------
>
> ResourceSet set = getResourceSet();
>
> EcoreUtil.remove(objectY);
>
> Set<Resource> resources = new HashSet<Resource>();
> Iterator iter = EcoreUtil.getAllContents(objectY, false);
> while (iter.hasNext()) {
> resources.add(((EObject) iter.next()).eResource());
> }
> set.getResources().removeAll(resources);
> -----------------------------------------------
>
> But is this really the way it should be done ?
>
>
> cheers
> Christian
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.02916 seconds