Book a Demo

Author Topic: Get all Packages at once  (Read 4455 times)

Marcos Calleja

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Get all Packages at once
« on: March 05, 2015, 07:11:27 pm »
Hi! I'm doing an addin to EA and I search everywhere to do such thing, but I couldn't find anything. I'm using Repository.GetElementSet(sqlQuery) to access to all the EA Elements (or a specific part) at once, but I want also to access all the EA Packages.

I saw there's a way to make a query returning a string xml-formatted. And I can access all the id packages throught their database table, but then I don't know how to get fast all these packages. I can do Repository.GetPackageByID() for each but then is taken too much time for big projects.

Anyone knows a better way? Or this is the only one?.

Greetings and thanks for your time :)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13471
  • Karma: +571/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Get all Packages at once
« Reply #1 on: March 05, 2015, 07:38:03 pm »
Packages also have an element component (except for root packages). So if the data you need is on the element part you can use GetElementSet  for this.

But if performance is an issue then you are probably better of not initializing all those package objects.
What info do you need from these objects?
And is it absolutely necessary to have an automation object for each of them?

Geert

Marcos Calleja

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Get all Packages at once
« Reply #2 on: March 05, 2015, 08:30:33 pm »
Hi Geert! Thanks a lot for your answer. Yep, I forget to add that I did that,  but then the elements taken are not the same. It's a little bit complicated to explain and english is not my mother language but I will try:

The thing is that I need to have the path of all the elements and packages with a child/parent association

From what I've seen, the parent of an element is indicated by the property "parentID", until they dont' have more parents with element type. Then the parent (in a visual way in the project browser) is indicated by "packageID".

And then the parent of the package is indicated by "parentID" until the parentID is 0 what it means it doesn't have parent.

Thats using EA.Elements and EA.Packages.

The thing is if I take the packages using the GetElementSet (as you say), they will not have the same info. In this case, they will have the parent in the property "packageID" but I can't access the ID of the actual package, instead it will give me the object_id of this special package in element way. I saw that actually this id that i need is host in a special field in the database table called "PDATA1" but access to that will give me the same performance that to call of the packages separately.

Haha sorry as I said it's a little bit complicated :P

To be summarized in a table this is the info obtained in the different ways to access a package:


                                                       
[highlight]Access way[/highlight][highlight]ID[/highlight][highlight]PARENT_ID[/highlight]
EA.Element (using GetElementSET)fake one (i mean not useful)PackageID
EA.Package (using GetPackageByID)
PackageIDParentID
DB t_object
PDATA1PackageID
DB t_packagePackageIDParentID

I think I will have to accept the performance of access the packages one by one.

Anyway, thanks a lot for your help.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13471
  • Karma: +571/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Get all Packages at once
« Reply #3 on: March 05, 2015, 08:51:34 pm »
Ah, yes, getting the full path is a difficult problem, certainly if you want to do it in bulk.

I had a similar problem once, trying to make an excel export, and I ended up with something like this:

Code: [Select]
     /// <summary>
        /// returns an xml document with a flat list of the owned elements modified after the given date
        /// </summary>
        /// <param name="modifiedAfter">the date after wich the elements should be modified</param>
        /// <returns>the owned elements in xml format</returns>
        public XmlDocument exportOwnedElements(DateTime modifiedAfter)
        {
            string sqlDateModified = modifiedAfter.ToString("yyyy-MM-dd");
            string sqlQuery =
                " SELECT o.Object_ID as ID,o.Object_Type as Type,isNull(o.Name,'') as Name,ISNULL(t.value,0) as ImportanceLevel,isnull(o.Author,'') as Author,o.CreatedDate as Created,o.ModifiedDate as Modified,isnull(o.Note,'') as Documentation,isnull(o.Package_ID,'') as ParentID,isnull(p.name,'') as ParentName  " +
                " ,isnull(p9.Name +'.','') + isnull(p8.Name+'.','')+ isnull(p7.Name+'.','')+ isnull(p6.Name+'.','') " +
                " + isnull(p5.Name+'.','')+ isnull(p4.Name+'.','')+ isnull(p3.Name+'.','')+ isnull(p2.Name+'.','')+ isnull(p.Name,'') as QualifiedName " +
                " FROM ((((((((((t_object as o  " +
                " left join t_objectproperties t on t.Object_ID = o.Object_ID )" +
                " left join t_package p on o.Package_ID = p.Package_ID )" +
                " left join t_package p2 on p.Parent_ID = p2.Package_ID )" +
                " left join t_package p3 on p2.Parent_ID = p3.Package_ID )" +
                " left join t_package p4 on p3.Parent_ID = p4.Package_ID )" +
                " left join t_package p5 on p4.Parent_ID = p5.Package_ID )" +
                " left join t_package p6 on p5.Parent_ID = p6.Package_ID )" +
                " left join t_package p7 on p6.Parent_ID = p7.Package_ID )" +
                " left join t_package p8 on p7.Parent_ID = p8.Package_ID )" +
                " left join t_package p9 on p8.Parent_ID = p9.Package_ID )" +

                " where (t.Property = 'ImportanceLevel' or t.Property is null)" +
                " and o.ModifiedDate > '" + sqlDateModified + "' " +
                " and (p.package_ID = " + this.getPackageID() + "  " +
                    " or p2.package_ID = " + this.getPackageID() + "  " +
                    " or p3.package_ID = " + this.getPackageID() + "  " +
                    " or p4.package_ID = " + this.getPackageID() + "  " +
                    " or p5.package_ID = " + this.getPackageID() + "  " +
                    " or p6.package_ID = " + this.getPackageID() + "  " +
                    " or p7.package_ID = " + this.getPackageID() + "  " +
                    " or p8.package_ID = " + this.getPackageID() + "  " +
                    " or p9.package_ID = " + this.getPackageID() + " ) " +
                " order by QualifiedName";
            return ((EAModel)this.model).SQLQuery(sqlQuery);

        }
It's not complete nor ideal, but it was good enough, and it cuts the execution time from more then an hour to a couple of seconds.

Geert

Marcos Calleja

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Get all Packages at once
« Reply #4 on: March 09, 2015, 11:12:39 pm »
The only problem of that is I can't get EA.Package objects, and I need them to make access/changes.

Maybe I will do like you said, take a few fields that I'm using and the ID, and just in case I need the Package object I can take it with GetPackageByID.

Thanks a lot for helping me :)