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

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

This commit is Just before the refactoring to the new get/set approach

  • Property svn:executable set to *
Line 
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')
8#foreach( $parent in $tableModel.inherited)
9#set ($tp = $parent.associatedClass.name.toLowerCase())
10${tab}target.${tp}_id = next_id(connection, '${tp}_id_seq')
11${tab}target.${tm}_${tp}_id = target.${tp}_id
12#end
13#end
14
15#macro( joinInheritedClasses $tableModel)
16#if($tableModel.inherited.size() > 0)
17#foreach( $parent in $parents).join(${parent.associatedClass.name.toLowerCase()}_table)#end
18#end
19#end
20
21#macro( identicalAttributes $tableModel)
22#if($tableModel.oa.size() > 0)
23        #foreach( $oa in $tableModel.oa)
24                '${oa.attributeName}': [#tableName($tableModel.associatedClass.name).c.${oa.attributeName}
25                #foreach( $ovAttTable in $oa.models)
26                        , #tableName($ovAttTable.associatedClass.name).c.${oa.attributeName}
27                #end]
28                #if($foreach.hasNext),#end                     
29                #end
30        #end
31#end
32
33#macro( generateProperties $tableModel)
34        #if($tableModel.relationship.size() > 0 && $tableModel.oa.size() > 0)
35, properties  = {#identicalAttributes($tableModel), #relationColumns($tableModel)}
36        #elseif($tableModel.relationship.size() > 0)
37, properties  = {#relationColumns($tableModel)}
38##      #elseif($tableModel.oa.size() > 0)
39##, properties  = {#identicalAttributes($tableModel)}
40        #end
41#end
42
43mapper($tableModel.associatedClass.name, #tableName($tableModel)#inheritedClasses($tableModel)
44#generateProperties($tableModel))
45
Note: See TracBrowser for help on using the repository browser.