At this point we have:
We now want to combine transparently these evaluations to generate in one step SQL code from a UML model:
Change the TransformAndGenerate ruleset contents to:
package tutorial.uml2relational; public ruleset TransformAndGenerate(in source : uml21) { public rule main() { // create an empty Relational model var target = context.createModel("relational"); // Transform input UML model to Relational @UML2Relational(source, target).main(); // Generate SQL code $GenerateSQL(target); } }
This ruleset:
main
of the ruleset UML2Relational
),'$'
is the notation used to call a text template).The ruleset TransformAndGenerate takes an input UML model. Here the Relational model is not visible from the end-user. It's just a pivot model used to reduce the complexity of the evaluation: it enables to break into two distinct steps the transformation of a UML model into SQL code. Note that it is just a design choice, we may have chosen to declare the Relational model as an output model as well.
You can launch the ruleset TransformAndGenerate, using the product21.xmi file as UML input.
The evaluation report now contains a file generated/generatedTables.sql. Double-clicking on this file opens a text editor:
-- -- TABLE IdentifiedElement -- DROP TABLE IF EXISTS `IdentifiedElement`; CREATE TABLE `IdentifiedElement` ( `ID` INT ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- TABLE NamedElement -- DROP TABLE IF EXISTS `NamedElement`; CREATE TABLE `NamedElement` ( `NAME` VARCHAR(255) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ...