|
Re: Deleting elements efficiently [message #912496 is a reply to message #912366] |
Thu, 13 September 2012 16:57 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Tex,
If you look at what that does:
public static void delete(EObject eObject)
{
EObject rootEObject = getRootContainer(eObject);
Resource resource = rootEObject.eResource();
Collection<EStructuralFeature.Setting> usages;
if (resource == null)
{
usages = UsageCrossReferencer.find(eObject, rootEObject);
}
else
{
ResourceSet resourceSet = resource.getResourceSet();
if (resourceSet == null)
{
usages = UsageCrossReferencer.find(eObject, resource);
}
else
{
usages = UsageCrossReferencer.find(eObject, resourceSet);
}
}
for (EStructuralFeature.Setting setting : usages)
{
if (setting.getEStructuralFeature().isChangeable())
{
remove(setting, eObject);
}
}
remove(eObject);
}
You can imagine that doing a UsageCrossReferencer.findAll would visit
the whole model just once, looking for all the objects, rather than
visiting the whole model once per object. That ought to be a lot faster.
On 13/09/2012 2:41 PM, Tex Iano wrote:
> Hi,
>
> within my program I have to delete a UML package except some contained
> elements. I.e. something like:
>
> delete(Package package, List<Element> excepts)
>
> As I have not found a method that enables this I have created my own.
> Of course it is not simple as the parents of the exceptions are not
> allowed to be deleted etc. However: as result my method provides a
> list of all elements within the package that can be deleted:
>
> List<Element> deleteElements;
>
> Now I want to delete these elements:
>
>
> for (Element e : deleteElements) {
> EcoreUtil.delete(e);
> }
>
>
> Is this the best way to do it? Because as the list contains all
> elements not only grouping parent packages etc. this takes really
> long. My system manages to delete about 5 elements per seconds. In a
> huge model I have a lot of elements.
> Is there a more efficient way to delete elements? If not, I will have
> to improve my algorithm that it does only provide parent elements if
> possible and not all contained children that can be deleted.
>
> Regards,
>
> Tex
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.02357 seconds