Index: topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java diff -u topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java:1.8 topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java:1.9 --- topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java:1.8 Thu Feb 23 14:05:47 2006 +++ topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java Tue Feb 28 17:20:07 2006 @@ -25,9 +25,9 @@ * * @author Arnaud Thimel * - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * - * Mise a jour: $Date: 2006/02/23 14:05:47 $ par : $Author: bpoussin $ + * Mise a jour: $Date: 2006/02/28 17:20:07 $ par : $Author: thimel $ */ package org.codelutin.topia.generator; @@ -204,7 +204,7 @@ if (notEmpty(element.getTagValue(TAG_DB_NAME))) { return element.getTagValue(TAG_DB_NAME); } - return toLowerCaseFirstLetter(element.getName()); + return element.getName().toLowerCase(); } public static Collection getElementsWithStereotype( @@ -254,12 +254,20 @@ return (attr.getReverseAttribute() != null) && (attr.getDeclaringElement().equals(attr.getReverseAttribute().getDeclaringElement())) && (!Util.isFirstAttribute(attr)); } + /** + * Renvoie le nom de l'attribut de classe d'association en fonction des cas: + * Si l'attribut porte le même nom que le type (extrémité inverse de + * l'association), on lui ajoute le nom de la classe d'association + * @param attr + * @return + */ public static String getAssocAttrName(ObjectModelAttribute attr) { String typeName = attr.getType().substring(attr.getType().lastIndexOf(".") + 1); + String result = attr.getName(); if (attr.getName().equalsIgnoreCase(typeName)) { - return attr.getName() + GeneratorUtil.capitalize(attr.getAssociationClass().getName()); + result += GeneratorUtil.capitalize(attr.getAssociationClass().getName()); } - return attr.getName(); + return result; } public static String getDOType(ObjectModelElement elem, ObjectModel model) { Index: topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java:1.16 topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java:1.17 --- topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java:1.16 Thu Feb 23 14:05:47 2006 +++ topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java Tue Feb 28 17:20:07 2006 @@ -24,10 +24,10 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.16 $ +* @version $Revision: 1.17 $ * -* Mise a jour: $Date: 2006/02/23 14:05:47 $ -* par : $Author: bpoussin $ +* Mise a jour: $Date: 2006/02/28 17:20:07 $ +* par : $Author: thimel $ */ package org.codelutin.topia.generator; @@ -88,7 +88,7 @@ if (haveSuper) { ObjectModelClass superClass = (ObjectModelClass)clazz.getSuperclasses().iterator().next(); String superClassname = superClass.getQualifiedName(); - log.debug("superClass for " + clazz.getQualifiedName() + " is " + superClassname); + if (log.isDebugEnabled()) {log.debug("superClass for " + clazz.getQualifiedName() + " is " + superClassname);} /*{ }*/ } else { @@ -108,7 +108,7 @@ } if (!Util.isNMultiplicity(attr)) { if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { - if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity())) { + if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) { generateHibernateManyToOne(output, attr); } else { generateHibernateOneToOne(output, attr); @@ -118,7 +118,7 @@ } } else { if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { - if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity())) { + if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) { generateHibernateManyToMany(output, attr); } else { generateHibernateOneToMany(output, attr); @@ -135,25 +135,26 @@ for (Iterator i = assoc.getParticipantsAttributes().iterator(); i.hasNext(); ) { ObjectModelAttribute attr = (ObjectModelAttribute) i.next(); if (attr != null) { - if (attr.getReverseAttribute() == null || !Util.isNMultiplicity(attr.getReverseAttribute())) { + if ((!attr.getReverseAttribute().isNavigable()) || !Util.isNMultiplicity(attr.getReverseAttribute())) { /*{ <%=(attr.isComposite()?" cascade=\"delete\"":"")%>/> }*/ } else { /*{ }*/ } - if (attr.getReverseAttribute() == null) { - String type = GeneratorUtil.getDOType(((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName(), model); - String name = Util.toLowerCaseFirstLetter(attr.getDeclaringElement().getName()); - if (log.isTraceEnabled()) {log.trace("reverse: " + type + " " + name);} - if (!Util.isNMultiplicity(attr)) { -/*{ -}*/ - } else { -/*{ -}*/ - } - } + //Ne sert plus grâce à l'utilisation de la navigabilité +// if (!attr.getReverseAttribute().isNavigable()) { +// String type = GeneratorUtil.getDOType(((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName(), model); +// String name = Util.toLowerCaseFirstLetter(attr.getDeclaringElement().getName()); +// if (log.isTraceEnabled()) {log.trace("reverse: " + type + " " + name);} +// if (!Util.isNMultiplicity(attr)) { +//{ +//} +// } +// } } } } @@ -237,7 +238,8 @@ protected void generateHibernateOneToMany(Writer output, ObjectModelAttribute attr) throws IOException { boolean isOrdered = attr.isOrdered(); -/*{ <<%=(isOrdered?"list":"bag")%> name="<%=getName(attr)%>"<%=((attr.getReverseAttribute()==null)?"":" inverse=\"true\"")%> lazy="true"<%=((attr.isComposite() || attr.hasAssociationClass())?" cascade=\"delete,delete-orphan\"":"")%>> + boolean isInverse = attr.getReverseAttribute().isNavigable(); +/*{ <<%=(isOrdered?"list":"bag")%> name="<%=getName(attr)%>"<%=((!isInverse)?"":" inverse=\"true\"")%> lazy="true"<%=((attr.isComposite() || attr.hasAssociationClass())?" cascade=\"delete,delete-orphan\"":"")%>> }*/ if (isOrdered) { @@ -298,15 +300,18 @@ protected String getManyToManyTableName(ObjectModelAttribute attr) { String result; - String name = attr.getName(); - String revers = attr.getReverseAttributeName(); - - if (name.compareToIgnoreCase(revers) < 0) { - result = name + "_" + revers; + if (attr.hasAssociationClass()) { + result = GeneratorUtil.getDBName(attr.getAssociationClass()); } else { - result = revers + "_" + name; + String name = attr.getName(); + String revers = attr.getReverseAttributeName(); + + if (name.compareToIgnoreCase(revers) < 0) { + result = name + "_" + revers; + } else { + result = revers + "_" + name; + } } - // String result; // if (!Util.isFirstAttribute(attr)) { // result = attr.getDeclaringElement().getName() + "_" + attr.getReverseAttribute().getDeclaringElement().getName(); Index: topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.13 topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.14 --- topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.13 Thu Feb 23 14:05:47 2006 +++ topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java Tue Feb 28 17:20:07 2006 @@ -24,10 +24,10 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.13 $ +* @version $Revision: 1.14 $ * -* Mise a jour: $Date: 2006/02/23 14:05:47 $ -* par : $Author: bpoussin $ +* Mise a jour: $Date: 2006/02/28 17:20:07 $ +* par : $Author: thimel $ */ package org.codelutin.topia.generator; @@ -139,12 +139,12 @@ if (clazz instanceof ObjectModelAssociationClass) { ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz; for (Iterator i = assoc.getParticipantsAttributes().iterator(); i.hasNext(); ) { - ObjectModelAttribute attr = (ObjectModelAttribute) i.next(); - if (attr != null) { + ObjectModelAttribute attr = (ObjectModelAttribute) i.next(); + if (attr != null) { /*{ <%=attr.getVisibility()%> <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>; }*/ - } + } } } @@ -316,12 +316,9 @@ this.<%=Util.toLowerCaseFirstLetter(attr.getName())%> = new java.util.ArrayList<<%=attr.getAssociationClass().getQualifiedName()%>>(); } }*/ - if (reverse != null && reverse.isNavigable()) { + if (reverse != null) { /*{ value.set<%=Util.capitalize(reverse.getName())%>(this); }*/ - } else { -/*{ value.set<%=Util.capitalize(attr.getDeclaringElement().getName())%>(this); -}*/ } /*{ this.<%=Util.toLowerCaseFirstLetter(attr.getName())%>.add(value); fireOnModifyIndexedProperty("<%=attr.getName()%>", this.<%=Util.toLowerCaseFirstLetter(attr.getName())%>.size(), null, value); @@ -455,12 +452,13 @@ String type = attr.getType(); String name = attr.getName(); generateAssociationAccessors(output, name, type); - ObjectModelAttribute reverse = attr.getReverseAttribute(); - if (reverse == null && reverse.isNavigable()) { - type = ((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName(); - name = attr.getDeclaringElement().getName(); - generateAssociationAccessors(output, name, type); - } +// //Ne sert plus à rien normalement avec la navigabilité +// ObjectModelAttribute reverse = attr.getReverseAttribute(); +// if (reverse == null) { +// type = ((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName(); +// name = attr.getDeclaringElement().getName(); +// generateAssociationAccessors(output, name, type); +// } } } }