Hello everybody,
I'm working on this project about a week, and since I'm a begginer in ATL and eCORE, I've started with the tutorial of FamilyToPerson and achieveded it successfully.
As you can see, my main project concist on transforming an UML Class diagram (a simple one with 3 or 4 classes max) to a relational database using ATL rules.
I've created the below metamodels, because I couldn't find something simple :
The UML Class diagram (I will need foreign keys in my DB , so I decided to add it in the Attribute class)
The MySQL metamodel
The source xmi model (a class diagram with two classes, Author(Auteur) and Book (Livre))
<?xml version="1.0" encoding="ASCII"?>
<uml_dc:Model
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:uml_dc="http://uml_dc/1.0"
xsi:schemaLocation="http://uml_dc/1.0 ../MetaModel/UML_DC.ecore">
<compose className="Livre"
classVisibility="public">
<attribs
attribName="nomLivre"
attribType="String"/>
<attribs
attribName="ISBN"
isPrimKey="true"
attribType="String"/>
<attribs
attribName="idAuteur"
isFrgnKey="true"
refFrgnKey="matricule"
refFrgnKeyClass="Auteur"/>
</compose>
<compose className="Auteur"
classVisibility="public">
<attribs
attribName="Matricule"
isPrimKey="true"
attribType="String"/>
<attribs
attribName="nomAuteur"
attribType="String"/>
<attribs
attribName="nbrPublications"
attribType="Integer"/>
</compose>
</uml_dc:Model>
The ATL rules
-- @path MySQL=/UMLtoDB/Metamodel/MySQL.ecore
-- @path UML=/UMLtoDB/Metamodel/UML_DC.ecore
module uml2sql;
create OUT : MySQL from IN : UML;
rule model_database {
from Model : UML!Model
to Database : MySQL!DataBase (
dbName <- Model.modelName
)
}
rule class_table {
from Class : UML!Class
to Table : MySQL!Table (
tblName <- Class.className
)
}
rule Attribut_column {
from Attribut : UML!Attribute
to Column : MySQL!Column (
clmnName <- Attribut.attribName,
clmnType <- Attribut.attType,
isFrgnKey <- Attribut.isFrgnKey,
isPrimKey <- Attribut.isPrimKey,
refFrgnKey <- Attribut.refFrgnKeyClass
)
}
The generated xmi database
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:mysql="http://mysql/1.0">
<mysql:DataBase/>
<mysql:Table tblName="Livre"/>
<mysql:Table tblName="Auteur"/>
<mysql:Column clmnName="nomLivre"/>
<mysql:Column clmnName="ISBN" isPrimKey="true"/>
<mysql:Column clmnName="idAuteur" isFrgnKey="true" refFrgnKey="Auteur"/>
<mysql:Column clmnName="Matricule" isPrimKey="true"/>
<mysql:Column clmnName="nomAuteur"/>
<mysql:Column clmnName="nbrPublications"/>
</xmi:XMI>
My questions are:
-is this the right way to go from uml to DB ?
-how to get the generatd xmi imbricated like this
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:mysql="http://mysql/1.0">
<mysql:DataBase/>
<mysql:Table tblName="Livre">
<mysql:Column clmnName="nomLivre"/>
<mysql:Column clmnName="ISBN" isPrimKey="true"/>
<mysql:Table tblName="Livre"/>
<mysql:Table tblName="Auteur">
<mysql:Column clmnName="idAuteur" isFrgnKey="true" refFrgnKey="Auteur"/>
<mysql:Column clmnName="Matricule" isPrimKey="true"/>
<mysql:Column clmnName="nomAuteur"/>
<mysql:Column clmnName="nbrPublications"/>
<mysql:Table tblName="Auteur"/>
</xmi:XMI>
-how can I generate the SQL code of the database?
thank you very much.