Book a Demo

Author Topic: Package.Elements doesn't return all elements  (Read 17956 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Package.Elements doesn't return all elements
« on: April 16, 2010, 06:31:22 pm »
To my big surprise my validation tool returned less results in V8 then it did in V7.5.
After an intensive search I found out that Package.Elements doesn't return as much elements in V8 as it did in V7.5.
The reason is the parentID column in the t_object table.
Package.Elements doesn't return elements that have NULL as ParentID. (most of them have 0, but for some unknown reason others have NULL).

The project integrity check will not fix this.

Reported to Sparx

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Package.Elements doesn't return all elements
« Reply #1 on: April 16, 2010, 09:55:50 pm »
For those interested, my workaround includes:

Code: [Select]
/// <summary>
        /// returns all elements (directly) owned by this element (this should include packages)
        /// </summary>
        /// <returns></returns>
        public override List<UMLElement> getOwnedElements()
        {
            List<UMLElement> ownedElements = new List<UMLElement>();
            // get list of element id's
            string sqlGetOwnedElements = @" select o.object_id from t_object o
                                            where (o.ParentID = 0 or o.parentID is NULL)
                                            and o.Package_ID = " + this.getPackageID();
            XmlDocument ownedElementIDs = ((EAModel)this.model).SQLQuery(sqlGetOwnedElements);
            XmlNodeList ownedElementIDNodes = ownedElementIDs.SelectNodes("//object_id");
            foreach (XmlNode ownedElementID in ownedElementIDNodes)
            {
                int elementID;
                if (int.TryParse( ownedElementID.InnerText,out elementID))
                {
                    UMLElement element = ((EAModel)this.model).findElementByID(elementID);
                    ownedElements.Add(element);
                }
            }
            return ownedElements;

The EAModel.FindElementByID first looks in the cache I've build in before it uses Repository.getElementByID().

Geert

fwoolz

  • EA User
  • **
  • Posts: 435
  • Karma: +0/-0
  • We have met the enemy, and he is us.&lt;Pogo, 1970&gt;
    • View Profile
Re: Package.Elements doesn't return all elements
« Reply #2 on: April 17, 2010, 02:39:37 am »
Geert,

I seem to recall seeing something in the README that said Sparx had made this change on purpose...

Cheers,
Fred
Fred Woolsey
Interfleet Technology Inc.

Always be ready to laugh at yourself; that way, you beat everyone else to the punch.


MagnusH

  • EA User
  • **
  • Posts: 63
  • Karma: +0/-0
    • View Profile
Re: Package.Elements doesn't return all elements
« Reply #3 on: April 18, 2010, 01:37:07 am »
Hi,

EA 8.0 sells this as a improvement, see below an extract from release notes. Although I think the new behaviour is the correct I do not consider this to be a good way of doing things. One of the basic rules of COM, at least what I learned a decade ago, was to never changed a published interface and the reason is obvious. Geert run in a problem and so did I.

What they should have done was to create new properties/collection with the new behaviour.

But the interresting question is how we want it to be handled? Add a new collection with the old behaviour?

// Magnus

Improvements made to the following:
Package.VersionControlAdd() . Improved handling of the error condition where the object package is already under version control.
Package.VersionControlRemove() . No longer raises an exception when no error occurred. No longer attempts to delete the XMI package file. Now refreshes tree icon.
Repository.GetTreeXML() . Modified to ensure tree is fully loaded.
Repository.GetTreeXMLByGUID() . Modified to ensure tree is fully loaded.
Project.RunHTMLReport() . Updated to support GUIDs passed in as XML GUIDs or regular EA GUIDs.
Repository.GetElementSet() . Now returns an empty collection when provided with an object query that produces no results.
Package.Elements . Now excludes elements contained within sub-elements.
Package.Diagrams . Now excludes diagrams contained within sub-elements.
Diagram.DiagramLinks - Now includes connectors that haven't yet been saved on the diagram.

fwoolz

  • EA User
  • **
  • Posts: 435
  • Karma: +0/-0
  • We have met the enemy, and he is us.&lt;Pogo, 1970&gt;
    • View Profile
Re: Package.Elements doesn't return all elements
« Reply #4 on: April 18, 2010, 02:34:12 am »
Magnus,

You raise an excellent point. I agree that the current behavior is "correct," but the handling was, perhaps, less than correct. Addition of properties like "Children" (for immediate descendants) and "Descendants" (for all descendants in the "family tree") while leaving the existing property alone would have been a better approach, IMHO.

Fred W
Fred Woolsey
Interfleet Technology Inc.

Always be ready to laugh at yourself; that way, you beat everyone else to the punch.


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Package.Elements doesn't return all elements
« Reply #5 on: April 18, 2010, 04:19:05 am »
Actually, for me personally this change is welcome.
In my code I wrote a little test to check that the elements were not owned by another element, and I excluded those. (so exactly as they promise it would work).
The problem is that they've introduced a bug while doing the test.
I guess they are doing something like
Code: [Select]
select * from t_object where packageID = [someID] and parentID = 0
Now that works great if not some of the objects (seemingly random) have NULL as parentID and not 0.
Those of course don't get returned.

I could excuse this if at least the project consistency check would update the NULL values to 0, but that doesn't even happen.

Geert

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Package.Elements doesn't return all elements
« Reply #6 on: April 18, 2010, 12:41:45 pm »
Quote
Magnus,

You raise an excellent point. I agree that the current behavior is "correct," but the handling was, perhaps, less than correct. Addition of properties like "Children" (for immediate descendants) and "Descendants" (for all descendants in the "family tree") while leaving the existing property alone would have been a better approach, IMHO.

Fred W
Isn't it amazig that when you name things correctly they work correctly?

'Oyna  Fred!

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

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Package.Elements doesn't return all elements
« Reply #7 on: April 19, 2010, 08:22:29 am »
We did consider adding a new property instead of correcting the behavior of the existing one.  Ultimately we decided that this would add to the confusion for users of the automation interface.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Package.Elements doesn't return all elements
« Reply #8 on: April 19, 2010, 04:46:07 pm »
Just received an email from Sparx.
They indeed indicated that they have changed the behavior of Package.Elements so that it only returns element nested directly under the package.
They also admitted that there is a problem with the NULL values in the parentID and they've provided a patch file to fix the NULL values.
(basically setting the parentID of tables t_object and t_diagram to 0 where they are NULL)

A big hurray for the Sparx support team!

Geert

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Package.Elements doesn't return all elements
« Reply #9 on: April 19, 2010, 05:28:23 pm »
Quote
Just received an email from Sparx.
They indeed indicated that they have changed the behavior of Package.Elements so that it only returns element nested directly under the package.
They also admitted that there is a problem with the NULL values in the parentID and they've provided a patch file to fix the NULL values.
(basically setting the parentID of tables t_object and t_diagram to 0 where they are NULL)

A big hurray for the Sparx support team!

Geert
Hi Geert,

So does V8 inject the Nulls?  And is the patch file just some SQL?

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: Package.Elements doesn't return all elements
« Reply #10 on: April 19, 2010, 06:28:16 pm »
No, the NULL's where already there. I have no idea in which version they were introduced. (could be anything from 4.5 till 7.5)

Yep, the patch files literally have following content:
Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
<EAPatch>
      <EAPatch.content>
            <PatchDescription>This patch will reset all ParentID fields with a value of null to 0 in t_object.</PatchDescription>
            <PatchQuery> SELECT Count(*) AS NumRecords
                                      from t_object
                                      where
                          ParentID is null
            </PatchQuery>
            <PatchSQL> UPDATE t_object
                          set ParentID = 0
                                      where
                          ParentID is null
            </PatchSQL>
      </EAPatch.content>
</EAPatch>
and
Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
<EAPatch>
      <EAPatch.content>
            <PatchDescription>This patch will reset all ParentID fields with a value of null to 0 in t_diagram.</PatchDescription>
            <PatchQuery> SELECT Count(*) AS NumRecords
                                      from t_diagram
                                      where
                          ParentID is null
            </PatchQuery>
            <PatchSQL> UPDATE t_diagram
                          set ParentID = 0
                                      where
                          ParentID is null
            </PatchSQL>
      </EAPatch.content>
</EAPatch>

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Package.Elements doesn't return all elements
« Reply #11 on: April 20, 2010, 04:32:40 pm »
Received response from Sparx that they have identified the bug and will provide a fix for the package.Elements in the next build (856).

They haven't been able to figure out where the NULL values are coming from, so they asked me to report any additional NULL values in the parentID's.

Geert

MagnusH

  • EA User
  • **
  • Posts: 63
  • Karma: +0/-0
    • View Profile
Re: Package.Elements doesn't return all elements
« Reply #12 on: April 20, 2010, 05:09:50 pm »
Hi Geert,

I'm totally lost. What bug will they fix? The problem with the NULL values for ParentID when using Package.Elements? Shouldn't the patch fix that?

Sorry for the confusion but I use this alot and want some heads up for changes.

Thanks,
Magnus

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Package.Elements doesn't return all elements
« Reply #13 on: April 20, 2010, 05:23:44 pm »
No, they will fix the bug that Package.Elements doesn't return elements with parentID = NULL.
I guess they will rewrite the query
Code: [Select]
select * from t_object where
packageID = [packageID] and parentID = 0
to
Code: [Select]
select * from t_object where
packageID = [packageID]
and (parentID = 0 OR parentID is NULL)

Geert
« Last Edit: April 20, 2010, 05:24:17 pm by Geert.Bellekens »

MagnusH

  • EA User
  • **
  • Posts: 63
  • Karma: +0/-0
    • View Profile
Re: Package.Elements doesn't return all elements
« Reply #14 on: April 20, 2010, 05:34:04 pm »
Thanks Geert for the clarification. Then I'm happy :-)

// Magnus