source: mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/mapping.vm @ 7978

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

Now include a custom defined list of UMLClass to be included in the tables generation.
Removed the class_type as table column because the class inheritance can work even without it

  • Property svn:executable set to *
RevLine 
[7974]1## mapping.vm
2
3#macro( beforeInsertListener $tableModel)
4#set ($tm = $tableModel.associatedClass.name.toLowerCase())
5def ${tableModel.associatedClass.name}_before_insert_listener(mapper, connection, target):
6${tab}if (target.${tm}_id is None):
7${tab}${tab}target.${tm}_id = next_id(connection, '${tm}_id_seq')
[7978]8##if($tableModel.hasChildren)
9##${tab}target.${tm}_type = '${tm}'
10##end
[7974]11#foreach( $parent in $tableModel.inherited)
12#set ($tp = $parent.associatedClass.name.toLowerCase())
[7978]13##${tab}target.${tp}_type = '${tp}'
[7974]14${tab}target.${tp}_id = next_id(connection, '${tp}_id_seq')
15${tab}target.${tm}_${tp}_id = target.${tp}_id
16#end
17#end
18
19#macro( joinClass $class, $parents)
20#if($tableModel.inherited.size() > 0)
21#foreach( $parent in $parents).join(${parent.associatedClass.name.toLowerCase()}_table)#end
22#end
23#end
24
25#macro( generateProperties $tableModel)
26        #if($tableModel.relationship.size() > 0 && $tableModel.oa.size() > 0)
27, properties  = {
28#identicalAttributes($tableModel), #relationColumns($tableModel)}
29        #elseif($tableModel.relationship.size() > 0)
30, properties  ={
31#relationColumns($tableModel)}
32        #elseif($tableModel.oa.size() > 0)
33, properties  = {
34#identicalAttributes($tableModel)}
35        #end
36#end
37
38mapper($tableModel.associatedClass.name, #tableName($tableModel.associatedClass.name)#joinClass($tableModel.associatedClass.name, $tableModel.inherited)
39#generateProperties($tableModel))
40
41#if($tableModel.inherited.size() > 0 || $tableModel.hasChildren)
42#beforeInsertListener($tableModel)
43
44event.listen($tableModel.associatedClass.name, 'before_insert', ${tableModel.associatedClass.name}_before_insert_listener)
45#end
Note: See TracBrowser for help on using the repository browser.