I need some help in ATL transformation when use KDM [message #1007295] |
Tue, 05 February 2013 12:20 |
Rafael Durelli Messages: 72 Registered: September 2012 |
Member |
|
|
I have two metamodel a SQL Model and a KDM Data package. The former contains three metaclasses DataBase, Table and Column. The latter represents the artifacts related to persistent data, such as indexed files, relational databases, and other kinds of data storage.
In this context, I would like to transform the first metamodel (SQL Model) to the KDM Data package. Thus, I have created the following atl code.
-- @path MM=/SQLMODEL/model/sqlmodel.ecore
-- @nsURI MM1=http://www.eclipse.org/MoDisco/kdm/data
-- @nsURI MM1=http://www.eclipse.org/MoDisco/kdm/code
module teste;
create OUT : MM1 from IN : MM;
rule dataBase2RelationalSchema {
from
t : MM!Database
to
r : MM1!RelationalSchema (
name <- t.name,
dataElement <- t.tables
)
}
rule table2RelationalTable {
from
t : MM!Table
to
r : MM1!RelationalTable (
name <- t.name,
dataElement <- t.columns
)
}
rule column2ColumnSet {
from
t : MM!Column
to
r : MM1!ColumnSet (
name <- t.name,
itemUnit <- item
),
item : MM1!ItemUnit (
type <- type
),
type : MM1!Datatype (
name <- t.type
)
}
However it is not complete. Could someone help on this? Someone has an example ?
thanks in advance.
|
|
|
|
Re: I need some help in ATL transformation when use KDM [message #1007344 is a reply to message #1007314] |
Tue, 05 February 2013 15:20 |
Rafael Durelli Messages: 72 Registered: September 2012 |
Member |
|
|
Hello Hugo firstly thanks..
I would like to transform my column type, which is just a String, to IntegerType, StringType, BooleanType, etc. In addition my SQL model also has an meta attribute named isPrimaryKey, which describes if that columns is a primary Key. Thus, I would like also to transform the Columns (of the SQL Model) to IntegerType, StringType, etc and sign that such Colums is primaryKey using the UniqueKey...
|
|
|
|
|
|
Re: I need some help in ATL transformation when use KDM [message #1007398 is a reply to message #1007387] |
Tue, 05 February 2013 18:07 |
Rafael Durelli Messages: 72 Registered: September 2012 |
Member |
|
|
I'm trying to do what you have told me, but I didn't it right yet. See how is the source code now.
-- @path MM=/SQLMODEL/model/sqlmodel.ecore
-- @nsURI MM1=http://www.eclipse.org/MoDisco/kdm/data
-- @nsURI MM1=http://www.eclipse.org/MoDisco/kdm/code
module teste2;
create OUT : MM1 from IN : MM;
rule dataBase2RelationalSchema {
from
t : MM!Database
to
r : MM1!RelationalSchema (
name <- t.name,
dataElement <- t.tables
)
}
rule table2RelationalTable {
from
t : MM!Table
to
r : MM1!RelationalTable (
name <- t.name,
dataElement <- t.columns
)
}
rule column2ColumnSet {
from
t : MM!Column
to
r : MM1!ColumnSet (
name <- t.name,
itemUnit <- item
),
item : MM1!ItemUnit (
type <- type
),
type : MM1!Datatype (
name <- t.type
)
do{
if (t.type = 'VARCHAR') {
thisModule.addString(t.type);
} else {
type.name <- 'notVAR';
}
}
}
rule addString(n : String) {
to
out: MM1!StringType(
name <- n
)
}
The output of this code is as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:code="http://www.eclipse.org/MoDisco/kdm/code" xmlns:data="http://www.eclipse.org/MoDisco/kdm/data">
<data:RelationalSchema name="projectValter">
<dataElement xsi:type="data:RelationalTable" name="ALUNO">
<dataElement xsi:type="data:ColumnSet" name="RA">
<itemUnit type="/1"/>
</dataElement>
<dataElement xsi:type="data:ColumnSet" name="id">
<itemUnit type="/2"/>
</dataElement>
<dataElement xsi:type="data:ColumnSet" name="lastName">
<itemUnit type="/3"/>
</dataElement>
<dataElement xsi:type="data:ColumnSet" name="name">
<itemUnit type="/4"/>
</dataElement>
</dataElement>
<dataElement xsi:type="data:RelationalTable" name="CLIENTE">
<dataElement xsi:type="data:ColumnSet" name="usuario">
<itemUnit type="/5"/>
</dataElement>
<dataElement xsi:type="data:ColumnSet" name="usuario2">
<itemUnit type="/6"/>
</dataElement>
<dataElement xsi:type="data:ColumnSet" name="usuario3">
<itemUnit type="/7"/>
</dataElement>
<dataElement xsi:type="data:ColumnSet" name="usuario500">
<itemUnit type="/8"/>
</dataElement>
</dataElement>
<dataElement xsi:type="data:RelationalTable" name="PERSONS">
<dataElement xsi:type="data:ColumnSet" name="usuario">
<itemUnit type="/9"/>
</dataElement>
<dataElement xsi:type="data:ColumnSet" name="usuario2">
<itemUnit type="/10"/>
</dataElement>
<dataElement xsi:type="data:ColumnSet" name="usuario3">
<itemUnit type="/11"/>
</dataElement>
</dataElement>
<dataElement xsi:type="data:RelationalTable" name="USUARIOS">
<dataElement xsi:type="data:ColumnSet" name="email">
<itemUnit type="/12"/>
</dataElement>
<dataElement xsi:type="data:ColumnSet" name="usuario">
<itemUnit type="/13"/>
</dataElement>
</dataElement>
</data:RelationalSchema>
<code:Datatype name="VARCHAR"/>
<code:Datatype name="notVAR"/>
<code:Datatype name="VARCHAR"/>
<code:Datatype name="VARCHAR"/>
<code:Datatype name="notVAR"/>
<code:Datatype name="notVAR"/>
<code:Datatype name="notVAR"/>
<code:Datatype name="notVAR"/>
<code:Datatype name="notVAR"/>
<code:Datatype name="notVAR"/>
<code:Datatype name="notVAR"/>
<code:Datatype name="notVAR"/>
<code:Datatype name="notVAR"/>
<code:StringType name="VARCHAR"/>
<code:StringType name="VARCHAR"/>
<code:StringType name="VARCHAR"/>
</xmi:XMI>
I have created a rule named addString to create StringType when 'varchar' are found. However, it didn't work very well. Could you help me?
thanks.
[Updated on: Tue, 05 February 2013 18:09] Report message to a moderator
|
|
|
|
|
|
Re: I need some help in ATL transformation when use KDM [message #1007710 is a reply to message #1007545] |
Thu, 07 February 2013 08:43 |
Hugo Bruneliere Messages: 674 Registered: July 2009 |
Senior Member |
|
|
Hello,
I see two options here.
Option 1: use of rule inheritance
abstract rule column2ColumnSet {
from
t : MM!Column
to
r : MM1!ColumnSet (
name <- t.name,
itemUnit <- item
),
item : MM1!ItemUnit (
type <- type
),
type : MM1!Datatype (
name <- t.type
)
}
rule column2ColumnSet_1 extends column2ColumnSet {
from
t : MM!Column (
not t.primarykey
)
to
r : MM1!ColumnSet
}
rule column2ColumnSet_2 extends column2ColumnSet {
from
t : MM!Column (
t.primarykey
)
to
r : MM1!ColumnSet (
-- TODO set the "u" element how it has to be
),
u : MM1!UniqueKey (
-- TODO set values
)
}
Option 2: use of a lazy rule
rule column2ColumnSet {
from
t : MM!Column
to
r : MM1!ColumnSet (
name <- t.name,
itemUnit <- item
-- TODO set the required att using a call such as
-- if t.primarykey then
-- thisModule.createUniqueKey(t)
-- else
-- OclUndefined
-- endif
),
item : MM1!ItemUnit (
type <- type
),
type : MM1!Datatype (
name <- t.type
)
}
lazy rule createUniqueKey {
from
t : MM!Column
to
u : MM1!UniqueKey (
-- TODO set values
)
}
Hugo
--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04612 seconds