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

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

Minimal difference with rev 8013

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