Author Topic: How to find Instances of a Class  (Read 8047 times)

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
How to find Instances of a Class
« on: June 12, 2020, 12:41:09 am »
Hi,

I have a diagram with 2 Elements on it: a Class and an Instance of that class.

Is there a window in EA that shows the instances of a class? Instances are not listed in Property Window, Traceability Window, not under the class in the Project Browser, etc.

Is there a possibility in the EA Object Model to get the instances of a class? Or do I have to go through all DiagramObjects?

Are the instances of a class part of a collection of the class?

Furthermore I would like to change the classifier of the instance to another class via the EA OM. Can I just change the ClassifierID or is there something more to do?

V.

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: How to find Instances of a Class
« Reply #1 on: June 12, 2020, 01:24:01 am »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: How to find Instances of a Class
« Reply #2 on: June 12, 2020, 01:25:07 am »
Hello,

Is there a window in EA that shows the instances of a class? Instances are not listed in Property Window, Traceability Window, not under the class in the Project Browser, etc.
Traceability can show the classifier / instance relationship, but I think it's switched off by default. Check the options in the Traceability window.

Quote
Is there a possibility in the EA Object Model to get the instances of a class? Or do I have to go through all DiagramObjects?

Are the instances of a class part of a collection of the class?
Element.ClassifierID in the instance matches the classifier's .ElementID, but there's no collection in Element that holds its instances.
The simple solution is to call Repository.GetElementSet() with an SQL query along the lines of
    select Object_ID from t_object where Classifier = <classifier's ElementID>

Quote
Furthermore I would like to change the classifier of the instance to another class via the EA OM. Can I just change the ClassifierID or is there something more to do?
No, that's it. Not forgetting to call Element.Update() when you're done of course. :)


/Uffe
My theories are always correct, just apply them to the right reality.

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: How to find Instances of a Class
« Reply #3 on: June 12, 2020, 01:34:18 am »
Hello,
Is there a window in EA that shows the instances of a class? Instances are not listed in Property Window, Traceability Window, not under the class in the Project Browser, etc.
Traceability can show the classifier / instance relationship, but I think it's switched off by default. Check the options in the Traceability window.
Quote
Is there a possibility in the EA Object Model to get the instances of a class? Or do I have to go through all DiagramObjects?

Are the instances of a class part of a collection of the class?
Element.ClassifierID in the instance matches the classifier's .ElementID, but there's no collection in Element that holds its instances.
The simple solution is to call Repository.GetElementSet() with an SQL query along the lines of
    select Object_ID from t_object where Classifier = <classifier's ElementID>
Quote
Furthermore I would like to change the classifier of the instance to another class via the EA OM. Can I just change the ClassifierID or is there something more to do?
No, that's it. Not forgetting to call Element.Update() when you're done of course. :)
/Uffe

Thank you @Uffe for the select statement. I just need to copy and paste it  :)

Yes, Traceability Windows works now as expected.

But I do not understand why there is no collection.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: How to find Instances of a Class
« Reply #4 on: June 12, 2020, 06:59:06 pm »
Hello,
Are the instances of a class part of a collection of the class?
Element.ClassifierID in the instance matches the classifier's .ElementID, but there's no collection in Element that holds its instances.
But I do not understand why there is no collection.

If this was an actual design decision, rather than a simple omission, I suspect it's for performance reasons.

Pre-loading collections of elements from the database which might in many cases not be needed slows the API down. (If indeed collection contents are pre-loaded and not loaded on demand.)

/U
My theories are always correct, just apply them to the right reality.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to find Instances of a Class
« Reply #5 on: June 12, 2020, 07:07:49 pm »
Hello,
Are the instances of a class part of a collection of the class?
Element.ClassifierID in the instance matches the classifier's .ElementID, but there's no collection in Element that holds its instances.
But I do not understand why there is no collection.

If this was an actual design decision, rather than a simple omission, I suspect it's for performance reasons.

Pre-loading collections of elements from the database which might in many cases not be needed slows the API down. (If indeed collection contents are pre-loaded and not loaded on demand.)

/U
From my experience most collections are not preloaded.
Some don't even load completely when used. They load the objects when iterating. (you can see queries to the database when iterating a collection)

Especially this last one is a gotcha. We are using to think about collections as things that exist in memory, and that are cheap to iterate.
But some EA.Collections are really slow to iterate, as they have to load the objects details when doing a next.

So I learned myself to avoid EA.Collections as much as possible. The main thing is to get the ID's of what I need with an SQLQuery() and then get the objects using Repository.GetXXXByID
Doesn't work for everything, but it does speed up a lot of things.

Another thing is to never iterate an EA.Collection more than once.
If I have no choice but to iterate an EA.Collection (say I need the tagged values of a connector or something like that), and I'm going to need to iterate over it more then once, then I first put them in a regular collection such as a List<> (or ArrayList in vbscript)
Once that is done you can iterate the other collection as much as you want, without a performance penalty.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to find Instances of a Class
« Reply #6 on: June 12, 2020, 07:27:05 pm »
Once that is done you can iterate the other collection as much as you want, without a performance penalty.

Geert
Except you don't get noticed on updates under the hood done by other people. Usually not really an issue, but...

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to find Instances of a Class
« Reply #7 on: June 12, 2020, 07:31:26 pm »
Once that is done you can iterate the other collection as much as you want, without a performance penalty.

Geert
Except you don't get noticed on updates under the hood done by other people. Usually not really an issue, but...

q.
Exactly, but that is what you would expect from a collection in memory right?
The problem with EA.Collections is that they are not fish nor flesh (is that even a saying in English?) they are sortof in memory, but also sometimes go back to the database ???, and you never really know when they behave like fish, or when they behave like flesh.

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: How to find Instances of a Class
« Reply #8 on: June 12, 2020, 07:54:30 pm »
Once that is done you can iterate the other collection as much as you want, without a performance penalty.
Except you don't get noticed on updates under the hood done by other people. Usually not really an issue, but...
Exactly, but that is what you would expect from a collection in memory right?
The problem with EA.Collections is that they are not fish nor flesh (is that even a saying in English?) they are sortof in memory, but also sometimes go back to the database ???, and you never really know when they behave like fish, or when they behave like flesh.
"Neither fish nor fowl" is what you're after there. :)

In general, it'd be very helpful if the API could provide more insight into / control over all the DB sync stuff. Last-retrieved timestamps, selective refresh, bulk write, all o' that.
So I learned myself to avoid EA.Collections as much as possible. The main thing is to get the ID's of what I need with an SQLQuery() and then get the objects using Repository.GetXXXByID
Doesn't work for everything, but it does speed up a lot of things.

I'll say. And for DocumentGenerator, fuggedaboudit. No more .DocumentElement for this sucker, it's custom templates and SQLQuery() from here on out.  8)

/U
My theories are always correct, just apply them to the right reality.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8607
  • Karma: +257/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How to find Instances of a Class
« Reply #9 on: June 13, 2020, 09:37:45 am »
Once that is done you can iterate the other collection as much as you want, without a performance penalty.

Geert
Except you don't get noticed on updates under the hood done by other people. Usually not really an issue, but...

q.
Exactly, but that is what you would expect from a collection in memory right?
The problem with EA.Collections is that they are not fish nor flesh (is that even a saying in English?) they are sort of in memory, but also sometimes go back to the database ???, and you never really know when they behave like fish, or when they behave like flesh.

Geert
The phrase (in English) is "neither fish nor fowl".  I suspect this is only really known in the Queen's English[1].  I've never heard a 'Merican say it.

HTH,
Paolo

[1] Principally, the UK and Commonwealth countries.
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: How to find Instances of a Class
« Reply #10 on: June 15, 2020, 08:03:18 am »
The problem with EA.Collections is that they are not fish nor flesh (is that even a saying in English?)

It's from Shakespeare (Henry IV):

– Falstaff: Setting thy womanhood aside, thou art a beast to say otherwise.
– Hostess: Say, what beast, thou knave thou?
– Falstaff: What beast? why an Otter.
– Prince: An Otter sir John, why an Otter?
– Falstaff: Why? shees neither fish nor flesh, a man knowes not where to have her.
The Sparx Team
[email protected]

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8083
  • Karma: +118/-20
    • View Profile
Re: How to find Instances of a Class
« Reply #11 on: June 15, 2020, 09:59:26 am »
But I do not understand why there is no collection.
There aren't a lot of those potentially useful collections available in the API.

RoyC

  • EA Administrator
  • EA Practitioner
  • *****
  • Posts: 1297
  • Karma: +21/-4
  • Read The Help!
    • View Profile
Re: How to find Instances of a Class
« Reply #12 on: June 15, 2020, 12:03:21 pm »
Fish nor fowl - There are variations on the theme. In English, some 20 years before the quote Neil gave you, it was said of a priest who was thought to have betrayed the Protestant church by promoting Catholic interpretations of the gospels that he was 'neither flesh nor fish'. And that was based on much older church advisories concerning the classification of things one could eat, an animal being either flesh, fish, or fowl. That is presumably where non-English versions of the phrase came from. The popular longer version is "Neither fish, nor flesh, nor good red herring" from Drydens's 'The Duke of Guise', some 60 years after Shakespeare wrote 'Henry V'.

Which is the 'fish' behaviour of Collections, and which the 'flesh'? (You've probably got 'fowl' behaviours already. And this whole aspect could be a 'Red Herring'.)
Best Regards, Roy

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8607
  • Karma: +257/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How to find Instances of a Class
« Reply #13 on: June 15, 2020, 03:18:17 pm »
Fish nor fowl - There are variations on the theme. In English, some 20 years before the quote Neil gave you, it was said of a priest who was thought to have betrayed the Protestant church by promoting Catholic interpretations of the gospels that he was 'neither flesh nor fish'. And that was based on much older church advisories concerning the classification of things one could eat, an animal being either flesh, fish, or fowl. That is presumably where non-English versions of the phrase came from. The popular longer version is "Neither fish, nor flesh, nor good red herring" from Dryden's 'The Duke of Guise', some 60 years after Shakespeare wrote 'Henry V'.

Which is the 'fish' behaviour of Collections, and which the 'flesh'? (You've probably got 'fowl' behaviours already. And this whole aspect could be a 'Red Herring'.)
That was amongst your best!   8)

I too saw the reference to the red herring, but didn't want to "muddy the waters".

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to find Instances of a Class
« Reply #14 on: June 15, 2020, 04:59:38 pm »
Which is the 'fish' behaviour of Collections, and which the 'flesh'? (You've probably got 'fowl' behaviours already. And this whole aspect could be a 'Red Herring'.)

Not sure if you were asking a serious question, but I'm gonna answer it anyway

"Fish" could be: behave like a regular collection in memory, once loaded do not go back to the database
"Flesh" could be: behave like a proxy for the database, don't keep anything in memory at all.

Currently it's somewhere in between (Fowl?), with variations depending on the type of object in the collection. (Connectors collection could behave differently from Attributes collection)

Geert