source: mauRepo/xmi2sqlalchemy/trunk/src/main/resources/global_library.vm @ 8040

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/xmi2sqlalchemy/trunk/src/main/resources/global_library.vm@8040
Revision 8040, 2.1 KB checked in by mnagni, 8 years ago (diff)

Again uncompleted deployment in DB. Tomorrow have to check better the primaryjoins!

  • Property svn:executable set to *
Line 
1#macro( substituteClassType $typeName)
2#if($typeName.equals('CharacterString'))
3str#elseif($typeName.equals('Character'))
4str#else
5${typeName}
6#end
7#end
8
9#macro( substituteDBType $typeName)
10#if($typeName.equals('CharacterString'))
11TEXT#elseif($typeName.equals('Character'))
12TEXT#elseif($typeName.equals('Integer'))
13Integer#elseif($typeName.equals('Boolean'))
14BOOLEAN#elseif($typeName.equals('Real'))
15NUMERIC#elseif($typeName.equals('Vector'))
16ARRAY#elseif($typeName.equals('Number'))
17NUMERIC#else
18${typeName}
19#end
20#end
21
22#macro( tableName $tableModel)
23${tableModel.associatedClass.name.toLowerCase()}_table#end
24
25#macro( relationColumns $tableModel)
26#foreach( $relation in $tableModel.relationship)
27        #relationColumn($tableModel, $relation)#if($foreach.hasNext),#end
28#end
29#end
30
31#macro(relationColumn $tableModel, $relation)
32#set ($tt = $relation.toTable.associatedClass.name)
33#set ($ft = $relation.fromTable.associatedClass.name)
34#set ($tmn = $tableModel.associatedClass.name)
35#if ($relation.isManyToMany())
36'${relation.name}': relationship(${tt},
37secondary=${tt.toLowerCase()}_${ft.toLowerCase()}_table
38#if ($relation.backrefName), backref='${relation.backrefName}' #end
39#elseif($relation.isOneToMany())
40'${relation.name}': relationship(${tt}
41#elseif($relation.isOneToOne())
42'${relation.name}': relationship(${tt}#end
43#if($relation.isOneToOne() || !$relation.useList)
44, uselist=False, backref='${tmn.toLowerCase()}_${relation.name}'
45#end
46#if($tt == $tmn)
47, remote_side=[${tmn.toLowerCase()}_table.c.${tmn.toLowerCase()}_id]
48#else
49#end
50#if($relation.isOneToMany())
51, primaryjoin=${tt.toLowerCase()}_table.c.${ft.toLowerCase()}_${relation.name}==${tmn.toLowerCase()}_table.c.id
52#end
53#if($relation.isOneToOne())
54, primaryjoin=${tt.toLowerCase()}_table.c.${ft.toLowerCase()}_${relation.name}_id==${tmn.toLowerCase()}_table.c.id
55#end
56)#end
57
58
59#macro( inheritedClasses $tableModel)
60#set ($tln = ${tableModel.associatedClass.name.toLowerCase()})
61#if($tableModel.inherited.size() > 0)
62        #foreach( $parent in $tableModel.inherited)
63                #set ($pn = ${parent.associatedClass.name})
64                , polymorphic_on=${tln}_table.c.t_type, inherits=${pn}, polymorphic_identity='${tln}'#break#end
65#else   
66#end
67#end
Note: See TracBrowser for help on using the repository browser.