/** * Create and add mapping relationship with column pairs to mapping class. * The column pair for mappingRelationship is same order as the column * pair from foreign key. It is used for 1-1 or 1-M relationship * It is column pair between local table and foreign table * @param relationName relationship name for the declaring mapping class * @param mappingClass mapping class that holds the relationship * @param foreign key which hold column pair for the relationship * @throws ModelException */ private void addMappingRelationship(String relationName, MappingClassElement declaringClass, ForeignKeyElement fkey) throws ModelException { MappingRelationshipElement impl = new MappingRelationshipElementImpl( relationName, declaringClass); ColumnPairElement [] pairs = fkey.getColumnPairs(); for (int i = 0; i < pairs.length; i++) { ColumnPairElement pair = pairs[i]; impl.addColumn(pair); } declaringClass.addField(impl); }
/** * Create and add MappingRelationship with associated column pairs * for join table. The column pair for mappingRelationship is same * order as the column pair from foreign key. * It is for column pairs between the join table and the foreign table * @param relationName a String for relation name * @param mappingClass mapping class that holds the relationship * @param fkeyForeign holding column pair information for the relationship * @throws ModelException */ private void addAssocMappingRelationship(String relationName, MappingClassElement declaringClass, ForeignKeyElement fkeyForeign) throws ModelException { MappingRelationshipElement impl = (MappingRelationshipElement) declaringClass.getField( relationName); if (null == impl) { impl = new MappingRelationshipElementImpl( relationName, declaringClass); declaringClass.addField(impl); } // Add column pair for join table and foreign table ColumnPairElement [] pairs = fkeyForeign.getColumnPairs(); for (int i = 0; i < pairs.length; i++) { ColumnPairElement pair = pairs[i]; impl.addAssociatedColumn(pair); } }
impl = new MappingRelationshipElementImpl(relationName, declaringClass); declaringClass.addField(impl);
new RelationshipElementImpl(fieldName), pce); MappingRelationshipElement mre = new MappingRelationshipElementImpl(fieldName, mce);