6.1 Relational Model to Code Transformation

The result of the transformation from UML to relational model that is described in this section is a PSM, which is still a model. It is not the code to create the database with. Luckily, the PSM is closely linked to the relational database platform, and uses platform-specific concepts and constructs. From this model, it is easy to generate code.

From the relational model, a pair of SQL scripts is generated. One script is for creating the tables and the other script for dropping the tables. We will examine the creation script only, because the drop script is very simple and does not add much value to the example. The transformation is rather straightforward because the structure and amount of detail of the relational model is already similar to the SQL language. The following rules are used to generate the SQL creation script from the Relation model.

  1. For each table, generate a "CREATE TABLE" text, followed by the name of the table, and a "{", then execute rule 2, followed by rule 3, and end with "};".

  2. For each column in the table, generate the name of the column, followed by the name of the type, and (optional) size of the column, then generate "NOT" if the column may not have the NULL value and end with "NULL,".

  3. Generate a "PRIMARY KEY (" text, followed by a comma-separated list of the names of the columns of the primary key, and end with ")".

Fragments of the generated code can be found in Appendix B.

MDA Explained. The Model Driven Architecture(c) Practice and Promise 2003
Project Leadership (The Project Management Essential Library)
EAN: 2147483647
Year: 2004
Pages: 118

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net