Book a Demo

Author Topic: How to change matching default DB type in transformations with CONVERT_DB_TYPE()  (Read 3093 times)

ea1020

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
I have a Domain Model, with various classes, their relationships and Attributes.  Each attribute has a generic data type.  Default options are


When I transform the Domain Model to the DDL language (to create a physical database), EA converts the data types where it can, and then defaults the remaining Attributes to varchar(50).


I found help for the CONVERT_DB_TYPE() macro at the following link.  CONVERT_DB_TYPE() is used in the DDL Language "Attribute" Template script to get the database data type.
https://sparxsystems.com/enterprise_architect_user_guide/15.2/model_domains/convertingtypes.html


But I do not know where in EA to go to alter mappings between the generic data types used in the Domain model and the database data types.


I want to do both of the following:
1) Create new generic data types that will be offered in the Domain model, when I am defining Attributes.  Or at least be recognized if I type them in.
2) For both the built-in generic data types, and any more that I create with #1 above, I want to change or define the default DB data type to be used in my SQL Server 2012 database.  For example, I want:
   - "money" in Domain model to convert to the database type "money" (EA currently sets "smallmoney")
   - "decimal(6,4)" in Domain model to convert to the database type "decimal(6,4)" (EA currently sets default of varchar(50))
   - "char(1)" in Domain model to convert to the database type "char(1)" (EA currently sets default of varchar(50))


I am using EA 15.2.  I have looked at the options in the Configure section of the ribbon (menu), but I don't see where to accomplish the two tasks above.

Thank you!

ea1020

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
I did play with Ribbon > Configure > Reference Data > Settings > Database Datatype.

But none of my changes here affected the data types created in the database, so apparently this is either the wrong area, or I am doing it wrong.

ea1020

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
In case anyone else has the same need to alter mappings for data types from the source class model to a destination model, such as DDL, here is a method that works.  There should be a better method, but I did not find it.


**********************************************************************
First, ensure the destination model in EA already has all appropriate data types defined. 
**********************************************************************
If your destination is a database and you want to use User Defined Data Types (UDDT) / Alias Data Types (ADT), create those in the model.

Configure \ Reference Data \ Settings \ Database Datatypes…

When you define the adt in EA in the Database Datatypes dialog:
    • select the None radio button in the Size group; not doing this will  result in EA creating DDL scripts for database generation with invalid syntax
        ◦ do not include a length for ADTs based on a type such as char or varchar;.
        ◦ do not include the precision and scale for ADTs based on a type such as decimal
    • Maybe include the schema name with the name of the ADT in the Datatype field, such as "dbo.adtYesNo" instead of "adtYesNo"


You will need to create the ADT in the target database, before executing DDL scripts generated by EA that use the ADT.  Sample script: 
create type dbo.adtTaxRate
    from decimal(9,8) not null;
create type dbo.adtYesNo
    from char(1) not null;
--drop type dbo.adtTaxRate;
--drop type dbo.adtYesNo;



**********************************************************************
Second, consider creating Type elements, for reuse and ease
**********************************************************************
I do not know if this is the best or proper method to create reusable data types, but it works.
    1. Create Types for use in the source Domain Model
    • In the Project Browser, create a "Types" package to hold the new types to be created
    • Right-click the "Types" package, choose "Add Element..."
    • In the New Element dialog:
        ◦ Enter a name for the type or alias data type (ADT)
        ◦ Set Type to "Type"
    2. In the classes in the Domain Model, set types for the various attributes as needed.
    • Select a class in the Domain Model
    • Open Features pane.  If necessary, move the selector to Attributes at the top, to show Attributes.
    • Use dropdown list for Type.  If the type you want is not already available; select "Select Type..."; browse to the package that holds your Types; select the appropriate type.


**********************************************************************
Third, correct the mapping
**********************************************************************
Open the Transformation Editor; see the “Opening the Transformation Editor” section.

Select the “DDL” language (this assumes destination model is DDL).
Select the Attribute template.
Modify the code starting about line 6, as shown below.  It will be necessary to make this correction in every EA project file.
Column
{
  %TRANSFORM_CURRENT("type", "stereotype", "collection", "constant", "containment", "ordered", "static", "volatile", "derived")%
  name=%qt%%CONVERT_NAME(attName, "Spaced", "Pascal Case")%%qt%
 
  %if attType == "adtTaxRate"%
   type=%qt%adtTaxRate%qt%
  %elseIf attType == "adtYesNo"%
    type=%qt%adtYesNo%qt%
  %elseIf attType == "money"%
    type=%qt%money%qt%
  %else%
   type=%qt%%CONVERT_DB_TYPE(genOptDefaultDatabase, attType)%%qt%
  %endIf%
}

This code might work to set a char(3) or varchar(11) data type:
        type = %qt%varchar%qt%
        length = %255%qt%