Book a Demo

Author Topic: Tagging an Attribute as "Primary Key"  (Read 4674 times)

Guido Spadotto

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Tagging an Attribute as "Primary Key"
« on: June 09, 2009, 10:06:01 pm »
Hi all,
 is it possible, using just the automation interface, to set a «column» attribute of a «table» element to be a primary key (that is: the programmatic equivalent of manually ticking the "Primary Key" checkbox in the Attributes dialog for a «table» class)?

I doubt it, given that an attribute does not always represent a column within a table, but I might miss something.

I'm already creating the PK_${TABLE_NAME} method, but I miss the primary key definitions when I export the containing package to DDL.

I'm using EA Corporate V7.5.844 and its associated Automation Interface jar file.

Thanks.
« Last Edit: June 10, 2009, 12:38:04 am by guidospadotto »

Guido Spadotto

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Tagging an Attribute as "Primary Key"
« Reply #1 on: June 10, 2009, 06:31:52 am »
For future reference, these statements seem to do what I wanted:

targetAttribute.SetAllowDuplicates(true);
targetAttribute.SetIsOrdered(true);
targetAttribute.Update();



Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Tagging an Attribute as "Primary Key"
« Reply #2 on: June 10, 2009, 04:10:15 pm »
Quote
targetAttribute.SetAllowDuplicates(true);

Are you sure? This looks strange with a primary key.

Guido Spadotto

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Tagging an Attribute as "Primary Key
« Reply #3 on: June 10, 2009, 08:50:31 pm »
I know it doesn't make much sense, but that's the only way I've found to get what I wanted. The generated DDLs are perfect now.

I had to reverse engineer and compare the exported XMI files to figure this out.

On a compound primary key, each attribute that composes it is not required to be unique. It's the composition of them all that has to. This, however, would not apply to primary keys that are not "compound".

I'd like someone from Sparx to comment on this.

BTW, another example of "stretched semantic", from the help page for the "Attribute" class:
IsStatic Indicates if the current attribute is a static feature or not. If the attribute represents a database column, this when set represents the Unique option.
« Last Edit: June 10, 2009, 08:59:32 pm by guidospadotto »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Tagging an Attribute as "Primary Key"
« Reply #4 on: June 10, 2009, 09:34:24 pm »
This is a case where some 'custom' reuse of schema components is far from intuitive. This is balanced by the fact that it is also undocumented, so one really cannot claim that EA is failing to meet (some unknown) specifications...
No, you can't have it!