Book a Demo

Author Topic: View indexes script  (Read 7636 times)

rupertkiwi

  • EA User
  • **
  • Posts: 133
  • Karma: +5/-0
    • View Profile
View indexes script
« on: January 17, 2018, 04:00:18 pm »
Hi there,

Does anyone know how to capture the indexes for a View in EA using a script?

Thanks,
Rupert

Arshad

  • EA User
  • **
  • Posts: 291
  • Karma: +21/-1
    • View Profile
Re: View indexes script
« Reply #1 on: January 17, 2018, 04:43:26 pm »
Hi rupertkiwi

From my understanding i think indexes you mean is position in tree .
If you need to get the position of a view from ea through API from script then you need to use TreePos property from package or element class.
Usually by default EA won't set any values in this property.If you rearranged objects manually in ea you can see the value get updated in the Tpos column of t_package or t_object table.

« Last Edit: January 17, 2018, 05:02:30 pm by EAUser3200 »

rupertkiwi

  • EA User
  • **
  • Posts: 133
  • Karma: +5/-0
    • View Profile
Re: View indexes script
« Reply #2 on: January 17, 2018, 05:06:00 pm »
Hi EAUser3200,

Apologies, I probably didn't explain it very well.

It is for an element with the stereotype of view that I want to return the indexes for.

Thanks,
Rupert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: View indexes script
« Reply #3 on: January 17, 2018, 05:20:15 pm »
Rupert,

Do you mean the indexes like the ones on tables?
These are stored as operations.
See https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/Databases/Index.cs for a wrapper class.

Geert

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: View indexes script
« Reply #4 on: January 17, 2018, 05:43:03 pm »
I didn't know Views had indexes.  They use indexes (in the underlying tables), but don't have any themselves.  Even "Materialized" Views aren't Views, per se, but dynamic tables.

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: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: View indexes script
« Reply #5 on: January 17, 2018, 06:38:05 pm »
I didn't know Views had indexes.  They use indexes (in the underlying tables), but don't have any themselves.  Even "Materialized" Views aren't Views, per se, but dynamic tables.

Paolo

"Have" might be the wrong term, but you can create indexes on views, yes.
Here's an explanation about that: https://stackoverflow.com/questions/1721448/how-do-indexes-work-on-views

And since in EA indexes are stored as part of the table/view I guess you could say a view "has" an index.

Geert

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: View indexes script
« Reply #6 on: January 18, 2018, 10:40:30 am »
As I read the whole set of responses, my original assertion stands.  (If you accept that "materialised views" are dynamic tables - as per response #5 in the link).

What is the syntax for defining an index directly on a view (that is not materialised)?

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: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: View indexes script
« Reply #7 on: January 18, 2018, 03:59:11 pm »
I don't know what "materialized views" are, but here's an example on how to create indexed views in SQL server.

https://docs.microsoft.com/en-us/sql/relational-databases/views/create-indexed-views

Geert

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: View indexes script
« Reply #8 on: January 18, 2018, 05:41:38 pm »
I don't know what "materialized views" are, but here's an example on how to create indexed views in SQL server.

https://docs.microsoft.com/en-us/sql/relational-databases/views/create-indexed-views

Geert
Thanks, Geert,

It looks like a SQL Server "Indexed View" is functionally equivalent to an Oracle "Materialized View" and consequently is a dynamic table in all but name.  Like Trump's Media Spokesperson calling a non-fact an "alternative fact".  It's either an objective fact or it isn't.  These kinds of objects are tables whose contents are maintained by means of triggers in other tables that respond to the "query specification".  They are VERY USEFUL but are just tables - dynamically maintained by the RDBMS.

The problem appears to be that EA doesn't recognise them as "tables" and, consequently, doesn't reverse engineer their indexes.

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

rupertkiwi

  • EA User
  • **
  • Posts: 133
  • Karma: +5/-0
    • View Profile
Re: View indexes script
« Reply #9 on: January 23, 2018, 12:06:09 pm »
Found it.

The indexes for a view are kept in the Methods collection for an element:

'Dumps the indexes for an element
Sub DumpIndexes(indent, currentElement, thePackage, j As Integer)
    Dim currentPackage As EA.Package
    Set currentPackage = thePackage
    Dim methods As EA.Collection
    Set methods = currentElement.methods
        For i = 0 To methods.Count - 1
            Dim currentmethod As EA.Method
            Set currentmethod = methods.GetAt(i)
            outputws.Cells(j, 1) = thePackage.Name
            outputws.Cells(j, 2) = currentmethod.Name
            outputws.Cells(j, 3) = currentmethod.Type
            outputws.Cells(j, 4) = currentmethod.AttributeID
            outputws.Cells(j, 5) = currentmethod.Stereotype
            outputws.Cells(j, 6) = currentmethod.ParentID
            j = j + 1
        Next
End Sub

Thanks,
Rupert

Arshad

  • EA User
  • **
  • Posts: 291
  • Karma: +21/-1
    • View Profile
Re: View indexes script
« Reply #10 on: January 23, 2018, 05:05:08 pm »
Hi Rupert

So in your function you're iterating method collection through index.
This can be done even in elements and packages level too.

More sample scripting you can find in scripting tab.
Manage Attributes and Methods or Recursive Dump scripts