Book a Demo

Author Topic: Influencing how DDL Transform creates Foreign Keys  (Read 4930 times)

wiebehordijk

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Influencing how DDL Transform creates Foreign Keys
« on: April 17, 2008, 11:50:44 pm »
Is it possible to influence how the DDL Transform creates Foreign Keys in the target model? What I want is: when I have a 1-many association, the column on which the FK constraint gets defined should have 'notNull' set.

I have tried to alter the transformation template of Connector. Under ForeignKey - Source - Column I have added a property 'notnull'. This gets written to the intermediary file correctly, and no errors are shown when transforming the package. However, in the resulting DDL package, the foreign key is defined on a nullable column.

Does anyone have suggestions about how to influence the way foreign key columns are generated? Thanks in advance!

Ondrej Kolenaty

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Re: Influencing how DDL Transform creates Foreign Keys
« Reply #1 on: April 19, 2008, 10:41:33 pm »
See the intermediate file. Probably you have there defined the foreign key twice. This is since EA is going trough the Conector template twice. Once for source element and second for target element.

I am filtering the second template call and everithing works fine. Also my experience is to create the column out of foreign key definition and in the FK definition just use the "name" of the column.

Code: [Select]
Column
{
  name="XXX"
 ...
}

ForeignKey
{
  Source
  {
    // Xreference to source table
    Column
    {
      name="XXX"
    }
  }
  Target
  {
    // Xreference to dest table
    Column
    {
      name="thePrimaryKey"
    }
  }
}

wiebehordijk

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Influencing how DDL Transform creates Foreign Keys
« Reply #2 on: April 22, 2008, 10:40:57 pm »
That works very well Ondrej, thanks a lot. I wish that the intermediate language were better documented, these issues are very hard to find out. For others interested, I include some code snippets that might be useful.

I used this code at the start of the foreign key template to suppress the second output of the foreign key:
Code: [Select]
%if classGUID != connectorSourceElemGUID%
%endTemplate%

I used this code to trigger generation of columns from connectors in the class template:
Code: [Select]
%list="Connector__FKColumn" @separator="\n" @indent="  "%
And here is the code for the Connector__FKColumn template. The if statements at the start are to make sure only to generate a column if the multiplicity of the relationship as seen from the current class is not more than one; grouping boolean expressions with brackets did not seem to work.
Code: [Select]
%if classGUID == connectorSourceElemGUID%
%if connectorDestMultiplicity != "1" and connectorDestMultiplicity != "0..1"%
%endTemplate%
%endIf%
%endIf%
%if classGUID == connectorDestElemGUID%
%if connectorSourceMultiplicity != "1" and connectorSourceMultiplicity != "0..1"%
%endTemplate%
%endIf%
%endIf%
Column
{
  name=%qt%%CONVERT_NAME(connectorDestElemName, "Pascal Case","Camel Case")%ID%qt%
  type=%qt%%CONVERT_TYPE(genOptDefaultDatabase,"Integer")%%qt%
%if connectorDestMultiplicity == "1" or connectorType == "Generalization"%
  notnull
%endIf%
}
%endIf%

Cheers,
Wiebe