| I need some help in ATL transformation when use KDM [message #1007295] |
Tue, 05 February 2013 07:20  |
Rafael Durelli Messages: 35 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 10:20   |
Rafael Durelli Messages: 35 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 #1007371 is a reply to message #1007352] |
Tue, 05 February 2013 11:22   |
Hugo Bruneliere Messages: 465 Registered: July 2009 |
Senior Member |
|
|
According to what you've explained, it seems that you also need to create IntegerType, StringType, etc elements in your rule in order to then be able to assign them to the attributes of the corresponding KDM elements.
You should also avoid to use the same name for different variables as this could produce conflicts: e.g. type : MM1!Datatype can be ambiguous with the type attribute of some KDM elements...
Concerning the isPrimaryKey boolean attribute, you have to write the required OCL expression on your input model elements (expression returning a boolean value) in order to set it.
Hugo
------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
|
|
|
|
| Re: I need some help in ATL transformation when use KDM [message #1007398 is a reply to message #1007387] |
Tue, 05 February 2013 13:07   |
Rafael Durelli Messages: 35 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 13:09] Report message to a moderator
|
|
|
| Re: I need some help in ATL transformation when use KDM [message #1007519 is a reply to message #1007398] |
Wed, 06 February 2013 05:18   |
Hugo Bruneliere Messages: 465 Registered: July 2009 |
Senior Member |
|
|
Hello,
It's not really clear to me what you want to do in your transformation: could you simply describe in a couple of sentences the conceptual mapping you're trying to implement between SQL and KDM?
Anyway, using such do imperative sections and imperative called rules is generally not recommended.
ATL is a declarative language so it is very often faster/clearer to use declarative match rules or lazy rules.
Best regards,
Hugo
------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
|
|
|
|
|
| Re: I need some help in ATL transformation when use KDM [message #1007710 is a reply to message #1007545] |
Thu, 07 February 2013 03:43   |
Hugo Bruneliere Messages: 465 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 - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
|
|
|
|
| Re: I need some help in ATL transformation when use KDM [message #1007783 is a reply to message #1007743] |
Thu, 07 February 2013 08:50   |
Hugo Bruneliere Messages: 465 Registered: July 2009 |
Senior Member |
|
|
The expression I've proposed you has to be used in an attribute value assignment, otherwise it cannot work (I don't know the name of the ColumnSet's reference to the UniqueKey element, you have to look to the KDM metamodel for this):
r : MM1!ColumnSet (
name <- t.name,
itemUnit <- item,
attributeToBeSet <- if t.primarykey then
thisModule.createUniqueKey(t)
else
OclUndefined
endif
),
Anyway, I encourage you to look to the ATL user guide to get more details on the base structure of the ATL language.
Hugo
------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
|
|
|
|
Powered by
FUDForum. Page generated in 0.02116 seconds