Author Topic: [Solved] Order of transformed keys not preserved  (Read 5088 times)

Oliver F.

  • EA User
  • **
  • Posts: 573
  • Karma: +2/-1
  • Aren´t we all in the model business ?
    • View Profile
    • Karl Storz homepage
[Solved] Order of transformed keys not preserved
« on: September 19, 2009, 12:50:55 am »
We create the primary key of a table via transformation templates, explicitely from the attributes template.
To do this we assign the first attribute (which is guaranteed to be labeled as "Idx") to be the primary key.
Though this operation is done first and the attribute is per definition the first in the originating PIM model the PK is always moved to the end of the attributes list. However we have to keep the modeled attribute order for various reasons.
What is the prefered way of keeping the order of the attributes especially for the primary key?
Is there a way to explicitely set the attribute position in the template?

The code in the template:
Code: [Select]
%if attName=="Idx"%
  PrimaryKey
  {
    Column
    {
            %TRANSFORM_CURRENT("alias","stereotype", "collection", "constant", "containment", "ordered", "static", "volatile")%
  
            $value=%EXEC_ADD_IN("xbadsl", "attTaggedValueFromGUID", attClassifierGUID,"SQLType")%
            type=%qt%%CONVERT_TYPE(genOptDefaultDatabase,$value)%%qt%            
      }
  }
%else%
Column
{  
  %TRANSFORM_CURRENT("alias","stereotype", "collection", "constant", "containment", "ordered", "static", "volatile")%
  
  $value=%EXEC_ADD_IN("xbadsl", "attTaggedValueFromGUID", attClassifierGUID,"SQLType")%
  type=%qt%%CONVERT_TYPE(genOptDefaultDatabase,$value)%%qt%
}
%endIf%

Thanks for any hints.

Oliver
« Last Edit: September 25, 2009, 05:57:49 pm by ofels »

Oliver F.

  • EA User
  • **
  • Posts: 573
  • Karma: +2/-1
  • Aren´t we all in the model business ?
    • View Profile
    • Karl Storz homepage
Even worse...
« Reply #1 on: September 25, 2009, 01:13:53 am »
It is even worse than expected. EA obviously sorts the attributes internally by creation time.
First come first serve. This can be easily spotted by running a simple script over a table spitting out attributes and pos values:
Code: [Select]
element=Repository.GetTreeSelectedObject();
Session.Output(element.Name);

atts=element.Attributes;

for (i=0;i<atts.Count;i++)
{
      att=atts.GetAt(i);

      Session.Output(att.Name+":"+att.Pos);
}

What can be seen is that the order found is not consistent with the order visualised. Which makes sense from a developers point of view ("Hey, let's use an additional property for positions so we do not have to sort again") but kills my scenario.
Which is to import a database scheme with tables and attributes, transform it to a MDA PIM without primary and foreign keys and then in the future create DDL and SQL via PIM->PSM transformations only.
But now there seems to be no way to ensure that the attributes and especially the primary and foreign keys are placed in the same order as they were in the original database scheme which is mandatory. The Pos property of the attribute only affects the counter, not the real sorting. Otherwise the positions could be rearranged afterwards by a script or similar.

Sparx is giving me a hard challenge here...

Oliver

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8063
  • Karma: +118/-20
    • View Profile
Re: Order of transformed primary key not preserved
« Reply #2 on: September 25, 2009, 08:27:52 am »
As I said in a reply to an email recently.

You can copy the column definition out from the primary key, then reference it from the primary key.

eg.
Code: [Select]
%if attName=="Idx"%
  PrimaryKey
  {
    Column
    {
            %TRANSFORM_CURRENT("alias","stereotype", "collection", "constant", "containment", "ordered", "static", "volatile")%
  
            $value=%EXEC_ADD_IN("xbadsl", "attTaggedValueFromGUID", attClassifierGUID,"SQLType")%
            type=%qt%%CONVERT_TYPE(genOptDefaultDatabase,$value)%%qt%            
      }
  }
%endIf%
Column
{  
  %TRANSFORM_CURRENT("alias","stereotype", "collection", "constant", "containment", "ordered", "static", "volatile")%
  
  $value=%EXEC_ADD_IN("xbadsl", "attTaggedValueFromGUID", attClassifierGUID,"SQLType")%
  type=%qt%%CONVERT_TYPE(genOptDefaultDatabase,$value)%%qt%
}

Oliver F.

  • EA User
  • **
  • Posts: 573
  • Karma: +2/-1
  • Aren´t we all in the model business ?
    • View Profile
    • Karl Storz homepage
Re: Order of transformed primary key not preserved
« Reply #3 on: September 25, 2009, 05:57:09 pm »
Quote
As I said in a reply to an email recently.

You can copy the column definition out from the primary key, then reference it from the primary key.

Perfect, thanks Simon. I got the same email from Aaron so I was not aware that you were involved. I tried the same thing with foreign keys and it works as well.

Thanks a lot.

Oliver