Created
October 20, 2015 14:27
-
-
Save jasmo2/15eb591230ab540d734f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Debemos crear una unica base de datos para todos | |
pre { | |
var db : new DB!Database; | |
} | |
-- Esta regla se encarga de todo! | |
rule MarketPlace2Relacional | |
transform | |
c : mp!ClassUnit | |
to | |
t : DB!Table | |
{ | |
-- Asignamos la tabla creada a la base de datos inicializada al comienzo y le ponemos el nombre de la clase sin el Entity | |
guard: (c.codeRelation.select(cr|cr.isTypeOf(mp!HasValue))->select(cr|cr.annotation.size()>0).select(a|a.`to`.Name = "Entity").size()>0 ) | |
t.database = db; | |
t.name = c.name.replace("Entity", ""); | |
t.columns = c.codeElement.equivalent(); | |
} | |
@lazy | |
rule CodeRelation2Column | |
transform | |
c : mp!StorableUnit | |
to | |
t : DB!Column{ | |
guard: (c.isPrimitiveType()) | |
t.name = c.name; | |
System.out.println("type.name: " + c.type.name); | |
System.out.println("type: " + c.type); | |
t.type = c.type.getType(); | |
} | |
operation Integer add1() : Integer { | |
return self + 1; | |
} | |
//devuelve el tipo | |
operation InterfaceUnit getType() | |
{ | |
switch (self.name) { | |
case "Long" : return DB!DataType#int; | |
case "Integer" : return DB!DataType#int; | |
case "String" : return DB!DataType#varchar; | |
default : return DB!DataType#unknow; | |
} | |
} | |
// Devuelve si es llave primaria o no | |
operation StorableUnit isPrimitiveType() | |
{ | |
if(self.codeRelation.select(a|a.isTypeOf(mp!HasValue)).select(a|a.annotation.size()>0).select(a|a.`to`.Name = "PrimaryKeyJoinColumn").size()=0) | |
{ | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment