Enterprise Architect version 15.1

download
purchase

enzh-CNcsnlfrdehiiditkoplptruskessv

My Profile

Social Media Channels

facebook  twitter  youtube   linkedin

Tuesday, 08 September 2015 20:47

Using the Database Builder to import a DB Schema as enumerations classes

Written by
Rate this item
(1 Vote)

As part of an EA add'in implementation, I had to import all Enterprise Architect table and column names in enumeration classes.

Having access to a database that stores a Sparx Systems Enterprise Architect project (e.g. MySQL, SQL Server, or even an EAP file via ODBC), there was a number of ways to populate enumeration classes with literal values using a small application in C# or another programming language. As Enterprise Architect 12 includes the Database Builder, an integrated tool to work on DB schemas, I took the opportunity to use it. Compared with the result of a C# application, this feature would let me capture the enumeration classes in my EA modelling project in addition to generating C# enumeration classes in my add'in solution.

This article only covers a small portion of Sparx EA Database Builder features: it illustrates how I managed to import Enterprise Architect table names as literal values in the EADBTableType enumeration class, and their column names as literal values in separate enumeration classes e.g. t_diagramColumnType, t_objectColumnType...

Import all tables in Enterprise Architect

- Open the menu Tools > Database Builder

- Right click and select New Data Model:

- Select the DBMS used, e.g. MySQL and confirm Ok

- Right click on MySQL > Load

- Right click on Connections > Add new DB connection

- Open the new DB connection and select ODBC based datatype

- Select an existing ODBC DSN (or create one) to the DB that stores the Enterprise Architect project where the schema needs to be imported

- Right click on MySQL > Import DB Schema from ODBC

- Click on Import and select all tables:

- All tables, columns, primary keys, foreign keys, indexes, etc. have been imported.

- Go back to the Database builder and open the Tables tabs: all tables are displayed. Selecting one of the tables provides access to all columns' details.

Generate the enumeration classes

The Database Builder let me achieved what I needed. Having all tables and columns stored in a single package, I wrote a simple script to perform the following:

- create an enumeration class named EADBTableType

- for each table:

    - create a literal value with the table name in EADBTableType e.g. t_object

    - create an enumeration class named after the table based on the following format: <table name>ColumnType e.g. t_attributeColumnType

    - for each column in the table:

       - create a literal value with the column name in the current table's enumeration class (e.g. Classifier in t_attributeColumnType)

Having executed this script, the following enumeration classes have been generated:

Transform enumeration classes to dotNet C# classes

The MDA model transformation can be used to generate C# enumeration classes for the above enums:

- Right click on the package that contains all enums > Advanced > Transform Package

- Select C# as the target, select the package, and click on Do Transform

- Having all C# enumeration classes created, and making sure the namespace is correct (e.g. create packages myaddin.common.enums), the code can be generated: right click on package > Code Engineering > Generate Source Code.

- The generated code can be used in Visual Studio IDE:

Read 7838 times Last modified on Tuesday, 08 September 2015 22:59
Guillaume

Guillaume Finance

VISEO (Sparx EA Expert, OMG OCSMP Model User certified)
 
Modelling consultant and expert on Sparx Systems Enterprise Architect modelling tool and solution, I'm helping clients with the model-based approach using standards for a number of contexts including:
- Software analysis, design and architecture with UML.
- Systems Engineering and MBSE with SysML.
- Enterprise Architecture, IT landscape with UML or ArchiMate.
- Business processes with BPMN.
My other activities include:
- Defining and maintaining the model repository including requirements, analysis and design for software projects.
- Remote support and expertise on Sparx Enterprise Architect modelling.
- Running training sessions on UML or SysML with Sparx Systems Enterprise Architect.
- Installation and configuration of Prolaborate web solution for Sparx EA.
 
I publish articles and news about modelling languages and Enterprise Architect on my blog www.umlchannel.com, maintain eaUtils free addin: www.eautils.com, and I participate in the European EA User Group events www.eausergroup.com
Contact details: guillaume[at]umlchannel.com

www.umlchannel.com

1 comment

Login to post comments