Book a Demo

Author Topic: GetByName or iterating Collections  (Read 5491 times)

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
GetByName or iterating Collections
« on: March 12, 2013, 02:28:28 am »
Hi,

Has anyone else noticed a marked performance difference using the Java API's Collection.GetByName as opposed to Iterating through the Collection. I want to do the latter as i want to compare Alias not Name fields. However the interator approach appears to run an order of magnitude slower (5 mins to update 2000 elements usign GetByName - over an hour using an iterator).

Any advice appreciated....

Regards,

Jon.

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: GetByName or iterating Collections
« Reply #1 on: March 12, 2013, 07:10:04 am »
Don't know about that but if i understand you correctly you are loading all repository elements in order to find those which match a certain alias in order to update these?

If that's so then using a named query with the Repository.GetElementsByQuery method should make a big difference.

regards,

Paulus
« Last Edit: March 12, 2013, 07:17:20 am by pmaessen »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: GetByName or iterating Collections
« Reply #2 on: March 12, 2013, 09:37:56 pm »
Jon,

I never ever use getByName() because I don't trust it.
In most cases it is possible that there are multiple elements with the same name in the collection, and in that case I don't know which one it will return.

Also, iterating EA.Collections is always a performance killer. I avoid it wherever possible.
If you are looking for elements you can indeed use the GetElementsByQuery, otherwise you case use Repository.SQLQuery to fetch the id('s) of what you are after use use the Repository.Get<XXX>ByID() operations to get the actual objects.

If you look at the EA Navigator code there are a lot of examples like that.

Geert
« Last Edit: March 12, 2013, 09:38:19 pm by Geert.Bellekens »

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: GetByName or iterating Collections
« Reply #3 on: March 12, 2013, 11:17:09 pm »
Thanks both for your responses. Ill check out the query approach...