Changeset 8040


Ignore:
Timestamp:
22/12/11 17:33:24 (8 years ago)
Author:
mnagni
Message:

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

Location:
mauRepo/xmi2sqlalchemy/trunk/src/main
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/collect/AttributeModel.java

    r8009 r8040  
    174174                        return false; 
    175175                return true; 
     176        } 
     177 
     178        /* (non-Javadoc) 
     179         * @see java.lang.Object#toString() 
     180         */ 
     181        @Override 
     182        public String toString() { 
     183                return "AttributeModel [name=" + name + ", associatedType=" + associatedType + "]"; 
    176184        }        
    177185} 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/collect/ClassModel.java

    r8028 r8040  
    147147                        return false; 
    148148                return true; 
     149        } 
     150 
     151        /* (non-Javadoc) 
     152         * @see java.lang.Object#toString() 
     153         */ 
     154        @Override 
     155        public String toString() { 
     156                return "ClassModel [associatedClass=" + associatedClass + "]"; 
    149157        }                        
     158         
     159         
    150160} 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/GenerateTables.java

    r8029 r8040  
    241241                        solveForeignLoop(tm.next(), tb, closure); 
    242242                } 
    243                  
    244243        } 
    245244 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/GenerateTablesClosure.java

    r8029 r8040  
    155155                                        || am.isVoidable(); 
    156156 
    157                         Relationship rl = new Relationship(parent, child, am.getName(), nullable, true); 
     157                        Relationship rl = new Relationship(parent, child, am.getName(), nullable, am.hasMultiplicity()); 
    158158 
    159159                        if (am.hasMultiplicity() && parent.equals(child)) { 
     
    171171                                } else { 
    172172                                        rl.setRelationType(RELATION_TYPE.ONE_TO_ONE); 
    173                                         //rl.setUseList(false); 
    174173                                } 
    175174                                parent.getRelationship().add(rl); 
    176                         } 
    177  
    178                 } 
     175                                associateFKandRelationship(fk, rl); 
     176                        } 
     177 
     178                } 
     179        } 
     180         
     181        private void associateFKandRelationship(ForeignKey fk, Relationship relationship) { 
     182                fk.setAssociatedRelationship(relationship); 
     183                relationship.setAssociatedForeignKey(fk); 
    179184        } 
    180185         
     
    194199                        rl.setRelationType(RELATION_TYPE.ONE_TO_ONE); 
    195200                        child.getRelationship().add(rl); 
     201                        associateFKandRelationship(fk, rl); 
    196202                } 
    197203        }        
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/support/ForeignKey.java

    r8028 r8040  
    4040        private final String parentAttributeName; 
    4141        private boolean useAlter = false; 
    42         private Relationship associatedRelationship; 
    43          
     42        private Relationship associatedRelationship = null; 
     43 
    4444        /** 
    4545         * @param tableModel 
     
    5858        } 
    5959 
    60  
    61  
    6260        /** 
    6361         * @param associatedRelationship the associatedRelationship to set 
    6462         */ 
    65         public void setAssociatedRelationship(Relationship associatedRelationship) { 
     63        public void setAssociatedRelationship(Relationship associatedRelationship) {             
    6664                this.associatedRelationship = associatedRelationship; 
    6765        } 
    68  
    69  
    7066 
    7167        /** 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/support/Relationship.java

    r8028 r8040  
    3232package ndg.services.newmoon.velocity.python.support; 
    3333 
     34import org.apache.commons.httpclient.util.LangUtils; 
     35 
    3436/** 
    3537 * @author mnagni 
     
    4547        private RELATION_TYPE relationType = null; 
    4648        private String backrefName = null; 
    47         private boolean useList; 
    48         private ForeignKey associatedForeignKey; 
     49        //If true indicates that even if the relationType is MANY-to-MANY 
     50        //the relation is a ONE-to-ONE relation. 
     51        private final boolean useList; 
     52        private ForeignKey associatedForeignKey  = null; 
    4953         
    5054        /** 
     
    5963                this.toTable = toTable; 
    6064                this.name = name; 
    61                 this.nullable = nullable;                
    62                 this.useList = useList; 
     65                this.nullable = nullable; 
     66                this.useList = useList;          
    6367        } 
    6468         
     
    7781        } 
    7882 
     83 
     84 
    7985        /** 
    8086         * @return the useList 
     
    8490        } 
    8591 
    86         /** 
    87          * Sets the useList attribute. For topological reason some time is necessary 
    88          *  to set up a MANY-to-MANY relation between a two tables even if the  
    89          *  linking attribute has a multiplicity equal to 1. This parameter 
    90          *  guarantees that even the relation is a MANY-to-MANY the ORM is aware  
    91          *  that the relation expects just zero or one result.  
    92          * @param useList the useList to set 
    93          */ 
    94         public void setUseList(boolean useList) { 
    95                 this.useList = useList; 
    96         } 
     92 
    9793 
    9894        public boolean isManyToMany() { 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/resources/global_library.vm

    r8027 r8040  
    1 #macro( truncate $text) 
    2 #if($text.length() > 40) 
    3 $text.substring(0, 40)#else$text#end 
    4 #end 
    5  
    61#macro( substituteClassType $typeName) 
    72#if($typeName.equals('CharacterString')) 
     
    3833#set ($ft = $relation.fromTable.associatedClass.name) 
    3934#set ($tmn = $tableModel.associatedClass.name) 
    40 #set ($totalName_1 = "${tt.toLowerCase()}_${ft.toLowerCase()}") 
    41 #set ($totalName_2 = "${ft.toLowerCase()}_${relation.name.toLowerCase()}") 
    4235#if ($relation.isManyToMany()) 
    4336'${relation.name}': relationship(${tt},  
    44 secondary=${totalName_1}_table 
     37secondary=${tt.toLowerCase()}_${ft.toLowerCase()}_table 
    4538#if ($relation.backrefName), backref='${relation.backrefName}' #end 
    4639#elseif($relation.isOneToMany()) 
     
    4841#elseif($relation.isOneToOne()) 
    4942'${relation.name}': relationship(${tt}#end 
    50 #if($relation.isOneToOne() || !$relation.isUseList()) 
    51 , uselist=False 
     43#if($relation.isOneToOne() || !$relation.useList) 
     44, uselist=False, backref='${tmn.toLowerCase()}_${relation.name}' 
    5245#end 
    5346#if($tt == $tmn) 
     
    5548#else 
    5649#end 
    57 #if($relation.isOneToOne() || $relation.isOneToMany()) 
    58 , primaryjoin=${tt.toLowerCase()}_table.c.${totalName_2}==${tmn.toLowerCase()}_table.c.${tmn.toLowerCase()}_id 
     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 
    5955#end 
    6056)#end 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/association.vm

    r8027 r8040  
    44#set ($totalName = "${rn}_${ln}") 
    55${totalName}_table = Table('${totalName}', metadata, 
    6 ${tab}Column('left_node_id', Integer, ForeignKey(${rn}_table.c.${rn}_id)), 
    7 ${tab}Column('right_node_id', Integer, ForeignKey(${ln}_table.c.${ln}_id)) 
     6${tab}Column('left_node_id', Integer, ForeignKey(${rn}_table.c.id)), 
     7${tab}Column('right_node_id', Integer, ForeignKey(${ln}_table.c.id)) 
    88) 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/mapping.vm

    r8013 r8040  
    77${tab}if (target.${tm}_id is None): 
    88${tab}${tab}target.${tm}_id = next_id(connection, '${tm}_id_seq') 
    9 #foreach( $parent in $tableModel.inherited) 
    10 #set ($tp = $parent.associatedClass.name.toLowerCase()) 
    11 ${tab}target.${tp}_id = next_id(connection, '${tp}_id_seq') 
    12 ${tab}target.${tm}_${tp}_id = target.${tp}_id 
    13 #end  
     9##foreach( $parent in $tableModel.inherited) 
     10##set ($tp = $parent.associatedClass.name.toLowerCase()) 
     11##${tab}target.${tp}_id = next_id(connection, '${tp}_id_seq') 
     12##${tab}target.${tm}_${tp}_id = target.${tp}_id 
     13##end  
    1414#end 
    1515 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/pythonClass.vm

    r8017 r8040  
    7878 
    7979#macro( attributes $attributes, $parents) 
    80 #foreach($attribute in $attributes) 
    81 ${tab}${tab}self.${attribute.name} 
    82 #end 
    8380#if($parents) 
    8481#foreach( $parent in $parents) 
    8582${tab}${tab}self._${parent.associatedClass.name.toLowerCase()} = ${parent.associatedClass.name}()        
     83#end 
     84#foreach($attribute in $attributes) 
     85${tab}${tab}self.${attribute.name} 
    8686#end 
    8787#end 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/sqlAlchemyTables.vm

    r8027 r8040  
    2424#macro( fk $foreignKey, $tableModel) 
    2525#set ($fkName = ${foreignKey.tableModel.associatedClass.name.toLowerCase()}) 
    26 #set ($totalName = "${fkName}_${foreignKey.parentAttributeName.toLowerCase()}") 
    27 Column('${totalName}', Integer, ForeignKey('${fkName}.${fkName}_id'#checkUseAlter($foreignKey, $fkName))), 
     26#set ($relName = ${foreignKey.parentAttributeName}) 
     27#if($foreignKey.associatedRelationship.isOneToOne() || !$foreignKey.associatedRelationship.useList) 
     28Column('${fkName}_${relName}_id', Integer, ForeignKey('${fkName}.id'#checkUseAlter($foreignKey, $fkName))), 
     29#else 
     30Column('${fkName}_${relName}', Integer, ForeignKey('${fkName}.id'#checkUseAlter($foreignKey, $fkName))), 
     31#end 
    2832#end 
    2933 
    3034#macro( primaryKey $tableModel) 
    3135#set ($tn = ${tableModel.associatedClass.name.toLowerCase()}) 
    32 ${tab}Column('${tn}_id', Integer, Sequence('${tn}_id_seq'), primary_key=True), 
    33 #if($tableModel.inherited && $tableModel.inherited.size() > 0) 
    34         #foreach( $parent in $tableModel.inherited) 
    35                 #set ($pn = ${parent.associatedClass.name.toLowerCase()}) 
    36                 ${tab}Column('${pn}_id', Integer, ForeignKey('${pn}.${pn}_id')),#end 
    37 #end 
     36${tab}Column('id', Integer, Sequence('${tn}_id_seq'), primary_key=True), 
     37##if($tableModel.inherited && $tableModel.inherited.size() > 0) 
     38        ##foreach( $parent in $tableModel.inherited) 
     39                ##set ($pn = ${parent.associatedClass.name.toLowerCase()}) 
     40                ##${tab}Column('_${pn}', Integer, ForeignKey('${pn}.${pn}_id')),#end 
     41##end 
    3842#end 
    3943 
Note: See TracChangeset for help on using the changeset viewer.