Author Topic: Model Views  (Read 3731 times)

Tim Hosking

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Model Views
« on: November 03, 2015, 04:19:48 pm »
Hi, I can't see any way to access Model Views via the EA object model. Are they just another package? Would I get to the model views via a parent package called "Model Views"?

What I really want to do is to add elements to a Model View via a script. That is, how to add an existing element to the view. So, I guess the question is more about how I can do that than to get a reference to the package in the model view. Do I just do an "AddNew" on the collection of elements in the package and then set the ElementID to an existing element?

Thanks.
« Last Edit: November 03, 2015, 05:10:19 pm by TimHosking »

qwerty

  • EA Guru
  • *****
  • Posts: 13544
  • Karma: +395/-300
  • I'm no guru at all
    • View Profile
Re: Model Views
« Reply #1 on: November 03, 2015, 08:44:47 pm »
Model views are stored in t_xrefsystem. See 6.11.3 of my Inside book.

q.

Tim Hosking

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Model Views
« Reply #2 on: November 04, 2015, 01:18:15 pm »
So q, that's a no? Model views are not exposed via the EA object model and therefore not available to a script?


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13065
  • Karma: +544/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Model Views
« Reply #3 on: November 04, 2015, 03:42:04 pm »
Quote
So q, that's a no? Model views are not exposed via the EA object model and therefore not available to a script?


Tim,

There are many things that are not exposed in the API, but that doesn't stop us from using and manipulating them, it just make it harder.  ;)

You can use Repository.SQLQuery to execute a select query to the database.
If you want to modify something directly in the database you can use Repository.Execute() to execute an sql update statement.
A little word of warning though. Repository.Execute() is an undocumented and unsupported operation. If you get in trouble (and you can) then you are on your own.
So use it with caution and only if you are absolutely sure what you are doing.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13544
  • Karma: +395/-300
  • I'm no guru at all
    • View Profile
Re: Model Views
« Reply #4 on: November 04, 2015, 09:06:37 pm »
I try to favor the API over the direct table access. Sometimes there is information which is more easily to find the tables (at least for me) so I use that although the API offers the same info. Mostly because mapping to the API is not orthogonal. I cross checked in this case - but still I might have an oversight.

q.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Model Views
« Reply #5 on: November 04, 2015, 11:55:32 pm »
Hi Tim,


To clarify: No, model views are not directly accessible through the API. There is no class ModelView or similar, and you can't create a model view by calling AddNew() on any collection.

But they are stored in a table in the database, t_xrefsystem, and as such are available for manipulation through the API. The calls in question are:
  • Repository.SqlQuery(), which is officially supported but can only retrieve information (SQL 'select' clauses)
  • Repository.Execute(), which is undocumented and unsupported, but can be used to make changes to the database (SQL 'insert' and 'update' clauses).
The EA database schema is itself undocumented; you're simply not meant to go wandering about in there and if you do, and get something wrong, you will indeed find yourself as lonely as a cloud.
In this case, t_xrefsystem holds other things besides model views so you need to figure out what signifies that a row in that table represents a model view, and then how a view definition is represented.

This amounts to reverse engineering, and while I haven't heard of any instance where Sparx has actually gone after anyone for doing so (Geert and Thomas are still at large, after all), I would certainly think twice about going down that route if I were on a government contract. (Just guessing from your location.)

Cheers,


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