Book a Demo

Author Topic: Generation of check constraint (DDL) from UML  (Read 2871 times)

veerdhawal

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Generation of check constraint (DDL) from UML
« on: July 01, 2009, 06:34:07 pm »
Hi All,

I am trying to generate DDL scripts from the underlying UML model. In the UML model I have an enumeration (UNIT which has a set of predefined values 'cm²', 'm²' and 'km²' ) and a class (Rectangle) whose attribute 'area' is of the type UNIT. The DDL script generated is: Create table Rectangle { area UNIT,
                                     rectangleID Integer
                                  }

I want to change the datatype of the column 'unit' to nvarchar and also add a check constraint on the column. I add the following code to Transformation Templates (attribute template):
%if attType=="UNIT"%
  type = "nvarchar(max) check(%attName% in ('cm²','m²','km²'))"
%endIf%

This helps me get the result but I want to know a way to automate this procedure without hardcoding the values of the enumerartion. Also when the enumeration has bigger set of values the EA throws an error while generating the PSM and does not generate the desired scripts.

Kindly Help ...

Regards,
Veerdhawal

veerdhawal

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Generation of check constraint (DDL) from UML
« Reply #1 on: July 01, 2009, 10:39:34 pm »
Hi all,
            Modifying the query.

            I am trying to generate DDL scripts from the underlying UML model.
In the UML model I have an enumeration ‘UNIT’ (which has a set of predefined values 'cm²', 'm²' and 'km²' ), Validity, SeverityKind, AlarmKind and a class (Rectangle) whose attribute 'area'
is of the type UNIT.

 
The DDL script generated is:
Create table Rectangle
{
area UNIT,
            rectangleID Integer
}

I want to change the datatype of the column 'unit' to nvarchar and also add a check constraint on the column.

I have added the following code in Transformation Templates (attribute template):

%if attType=="UNIT"%

        type = "nvarchar(max) check(%attName% in ('cm²','m²','km²'))"
%endIf%

      %if attType == "Validity"%
type="nvarchar (max) check (%attName% in ('GOOD','QUESTIONABLE','INVALID'))"
      %endIf%
      %if attType == "Severitykind"%
          type="nvarchar (max) check (%attName% in ('none','U4','U3','U2','U1'))"
      %endIf%

      %if attType == "AlarmKind"%
          type="nvarchar (max) check (%attName% in ('process','system','sensor'))"
      %endIf%

This above code helps me get the result.

But we want to optimize the above code in such a way that we do not have to repeat the rule for each enumeration type and need not have to hardcode the attType value and the
enumeration values (like 'GOOD','QUESTIONABLE','INVALID' Validity type and similarly for other types)

Query 1. Is there a way I can create one generic rule similar to the above for all enumeration types so that I do not have to repeat the rule for each enumeration type and do not have
to hardcode the values of enumeration type (like say using %list% etc).

            Query 2. When the set of values defined for the enumeration is large, EA throws an error while generating the check constraint in the PSM and does not generate the desired scripts. Is
            there a way to handle such cases?