Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » From UML Class diagram to Relational DB(need your feedback about my project)
icon7.gif  From UML Class diagram to Relational DB [message #1032589] Wed, 03 April 2013 07:25 Go to next message
sams good is currently offline sams goodFriend
Messages: 11
Registered: March 2013
Junior Member
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)
http://i47.tinypic.com/352enap.jpg

The MySQL metamodel
http://i47.tinypic.com/wtu68l.jpg

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.




Re: From UML Class diagram to Relational DB [message #1036685 is a reply to message #1032589] Mon, 08 April 2013 17:33 Go to previous message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

You should take a look to the Class2Relational example transformation as provided from http://www.eclipse.org/atl/atlTransformations/#Class2Relational.
I guess this could help/guide you.

Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Previous Topic:HOW CAI I DO
Next Topic:Rule transforming one element to several elements
Goto Forum:
  


Current Time: Thu Apr 25 18:55:45 GMT 2024

Powered by FUDForum. Page generated in 0.02884 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top