Skip to main content



      Home
Home » Modeling » EMF » Deleting many eobjects
Deleting many eobjects [message #1703745] Tue, 04 August 2015 11:56 Go to next message
Eclipse UserFriend
Dear EMF gurus,

we have the situation that we need to delete more than one element from an EMF model with EcoreUtil.delete(). However, we would like to avoid that EcoreUtil tries to find the references again for each invocation. Since EcoreUtil.delete with boolean flag recursive set to true, it seems that the code can handle more than one object.

The idea is to have a custom implementation of EcoreUtil.delete() that starts like this:

	/**
	 * Warning: ASSUMPTION is that all objects are either under the same root Object
	 * or in the same resource set.
	 * 
	 * @param eObjects
	 * @param recursive
	 */
	public static void delete(List<EObject> inList, boolean recursive) {
		if (inList.isEmpty())
			return;
		if (recursive) {
			EObject rootEObject = EcoreUtil.getRootContainer(inList.get(0));
			Resource resource = rootEObject.eResource();

			Set<EObject> eObjects = new HashSet<EObject>();
			Set<EObject> crossResourceEObjects = new HashSet<EObject>();
			eObjects.addAll(inList);
			for(EObject eObject : inList ) {
				for (@SuppressWarnings("unchecked")
				TreeIterator<InternalEObject> j = (TreeIterator<InternalEObject>) (TreeIterator<?>) eObject
						.eAllContents(); j.hasNext();) {
					InternalEObject childEObject = j.next();
					if (childEObject.eDirectResource() != null) {
						crossResourceEObjects.add(childEObject);
					} else {
						eObjects.add(childEObject);
					}
				}
			}


That basically means, not only collecting the descendents of one object, but of a list of objects that is being passed as argument.

Am I missing any inner workings of EMF that would break this?

Regards,

Andreas
Re: Deleting many eobjects [message #1703827 is a reply to message #1703745] Wed, 05 August 2015 04:47 Go to previous message
Eclipse UserFriend
Andreas,

I suppose a deleteAll method would be good. Of course one would want it
to be more general without assumptions. What you show below should be
okay given the assumption holds. Of course you'd want to augment the
"remove(eObject);" call to remove all the objects from their container...


On 04/08/2015 5:56 PM, Andreas Graf wrote:
> Dear EMF gurus,
>
> we have the situation that we need to delete more than one element
> from an EMF model with EcoreUtil.delete(). However, we would like to
> avoid that EcoreUtil tries to find the references again for each
> invocation. Since EcoreUtil.delete with boolean flag recursive set to
> true, it seems that the code can handle more than one object.
>
> The idea is to have a custom implementation of EcoreUtil.delete() that
> starts like this:
>
> /**
> * Warning: ASSUMPTION is that all objects are either under the
> same root Object
> * or in the same resource set.
> * * @param eObjects
> * @param recursive
> */
> public static void delete(List<EObject> inList, boolean recursive) {
> if (inList.isEmpty())
> return;
> if (recursive) {
> EObject rootEObject =
> EcoreUtil.getRootContainer(inList.get(0));
> Resource resource = rootEObject.eResource();
>
> Set<EObject> eObjects = new HashSet<EObject>();
> Set<EObject> crossResourceEObjects = new HashSet<EObject>();
> eObjects.addAll(inList);
> for(EObject eObject : inList ) {
> for (@SuppressWarnings("unchecked")
> TreeIterator<InternalEObject> j =
> (TreeIterator<InternalEObject>) (TreeIterator<?>) eObject
> .eAllContents(); j.hasNext();) {
> InternalEObject childEObject = j.next();
> if (childEObject.eDirectResource() != null) {
> crossResourceEObjects.add(childEObject);
> } else {
> eObjects.add(childEObject);
> }
> }
> }
>
> That basically means, not only collecting the descendents of one
> object, but of a list of objects that is being passed as argument.
>
> Am I missing any inner workings of EMF that would break this?
>
> Regards,
>
> Andreas
>
Previous Topic:[CDO]is the new client UI available?
Next Topic:[EMF Transaction] Exception during rollback
Goto Forum:
  


Current Time: Fri Jul 11 22:07:25 EDT 2025

Powered by FUDForum. Page generated in 0.05344 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top