Index: topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.21 topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.22 --- topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.21 Mon Sep 25 13:20:57 2006 +++ topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java Fri Oct 20 00:26:25 2006 @@ -24,10 +24,10 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.21 $ +* @version $Revision: 1.22 $ * -* Mise a jour: $Date: 2006/09/25 13:20:57 $ -* par : $Author: ruchaud $ +* Mise a jour: $Date: 2006/10/20 00:26:25 $ +* par : $Author: bpoussin $ */ package org.codelutin.topia.generator; @@ -40,6 +40,7 @@ import java.io.IOException; import java.io.Writer; import java.util.Iterator; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -50,6 +51,8 @@ import org.codelutin.generator.models.object.ObjectModelAttribute; import org.codelutin.generator.models.object.ObjectModelClass; import org.codelutin.generator.models.object.ObjectModelClassifier; +import org.codelutin.topia.framework.TopiaContextImplementor; +import org.codelutin.topia.persistence.TopiaEntity; /** * Generateur d'entites abstraites. Il s'agit de l'implatation par defaut d'une @@ -83,6 +86,10 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.codelutin.topia.TopiaException; import org.codelutin.topia.framework.TopiaContextImplementor; +import org.codelutin.topia.persistence.TopiaEntity; +import java.util.List; +import java.util.ArrayList; +import java.util.Collection; /** * Implantation POJO pour l'entité <%=Util.capitalize(clazz.getName())%>. @@ -119,8 +126,13 @@ for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); ObjectModelAttribute reverse = attr.getReverseAttribute(); - if (!attr.isNavigable() - && !hasUnidirectionalRelationOnAbstractType(reverse, model)) { + + // pour les asso quoi qu'il arrive il faut les lier des 2 cotes + // pour pouvoir supprimer en cascade l'asso lors de la suppression + // d'un des cotes + if (!(attr.isNavigable() + || hasUnidirectionalRelationOnAbstractType(reverse, model) + || attr.hasAssociationClass())) { continue; } /*{ /** @@ -143,7 +155,8 @@ }*/ } else { -/*{ <%=attr.getVisibility()%> <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>; + String assocAttrName = GeneratorUtil.getAssocAttrName(attr); +/*{ <%=attr.getVisibility()%> <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(assocAttrName)%>; }*/ } @@ -153,7 +166,8 @@ }*/ } else { -/*{ <%=attr.getVisibility()%> <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>; + String assocAttrName = GeneratorUtil.getAssocAttrName(attr); +/*{ <%=attr.getVisibility()%> <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(assocAttrName)%>; }*/ } @@ -184,16 +198,157 @@ } public void delete() throws TopiaException { +}*/ + for (ObjectModelAttribute attr : clazz.getAttributes()) { + ObjectModelAttribute reverse = attr.getReverseAttribute(); + if (!attr.hasAssociationClass() && reverse != null && reverse.isNavigable() + && Util.isNMultiplicity(attr) && Util.isNMultiplicity(reverse)) { + // On doit absolument supprimer pour les relations many-to-many + // le this de la collection de l'autre cote + +/*{ + { + List<<%=attr.getType()%>> list = ((TopiaContextImplementor)getTopiaContext()).getHibernate().createSQLQuery( + "SELECT {main.*} " + + "from <%=GeneratorUtil.getDBName(attr.getClassifier())%> main, <%=GeneratorUtil.getManyToManyTableName(attr)%> secondary " + + "where main.topiaid=secondary.<%=GeneratorUtil.getDBName(attr)%>" + + " and secondary.<%=GeneratorUtil.getReverseDBName(attr)%>='"+getTopiaId()+"'") + .addEntity("main", <%=attr.getType()%>Impl.class).list(); + for (<%=attr.getType()%> item : list) { + item.remove<%=Util.capitalize(attr.getReverseAttributeName())%>(this); + } + } +}*/ + } else if (!attr.hasAssociationClass() && reverse != null + && reverse.isNavigable() && !Util.isNMultiplicity(reverse)) { + // On doit mettre a null les attributs qui ont cette objet sur les + // autres entites en one-to-* + // TODO peut-etre qu'hibernate est capable de faire ca tout seul ? + /*{ + { + List<<%=attr.getType()%>> list = ((TopiaContextImplementor)getTopiaContext()) + .getDAO(<%=attr.getType()%>.class) + .findAllByProperties("<%=reverse.getName()%>", this); + for (<%=attr.getType()%> item : list) { + item.set<%=Util.capitalize(attr.getReverseAttributeName())%>(null); + } + } + }*/ + + } + } +/*{ ((TopiaContextImplementor)getTopiaContext()).getDAO(<%=clazz.getName()%>.class).delete(this); } }*/ + + /*{ + public List getAggregate() throws TopiaException { + List tmp = new ArrayList(); + // pour tous les attributs rechecher les composites et les class d'asso + // on les ajoute dans tmp + }*/ + for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { + ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); + if (attr.referenceClassifier() && attr.getClassifier().hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { + if (attr.isAggregate()) { + if (Util.isNMultiplicity(attr)) { + /*{ + tmp.addAll(get<%=Util.capitalize(attr.getName())%>()); + }*/ + } else { + /*{ + tmp.add(get<%=Util.capitalize(attr.getName())%>()); + }*/ + } + } + } + } + /*{ + // on refait un tour sur chaque entity de tmp pour recuperer leur + // composite + List result = new ArrayList(); + for (TopiaEntity entity : tmp) { + result.add(entity); + result.addAll(entity.getAggregate()); + } + + return result; + } + + }*/ + +/*{ + public List getComposite() throws TopiaException { + List tmp = new ArrayList(); + // pour tous les attributs rechecher les composites et les class d'asso + // on les ajoute dans tmp + }*/ + for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { + ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); + ObjectModelAttribute reverse = attr.getReverseAttribute(); + if (attr.referenceClassifier() && attr.getClassifier().hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { + if (attr.isComposite()) { + if (Util.isNMultiplicity(attr)) { +/*{ + tmp.addAll(get<%=Util.capitalize(attr.getName())%>()); +}*/ + } else { +/*{ + tmp.add(get<%=Util.capitalize(attr.getName())%>()); +}*/ + } + } else if (attr.hasAssociationClass()) { + String assocAttrName = GeneratorUtil.getAssocAttrName(attr); + if (!Util.isNMultiplicity(attr)) { +/*{ + if (this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%> != null) { + tmp.add(this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>); + } +}*/ + } else { + // On utilise pas l'attribut car il est potentiellement + // pas a jour, car pour les asso avec cardinalité + // personne ne fait de add. Ce qui est normal, mais + // pour pouvoir faire tout de meme des delete en cascade + // sur les asso, le champs est dans le mapping + // hibernate et donc il le faut aussi dans la classe + // sinon hibernate rale lorsqu'il charge l'objet +// if (this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%> != null) { +// tmp.addAll(this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>); +// } +/*{ + tmp.addAll(((TopiaContextImplementor)getTopiaContext()) + .getDAO(<%=attr.getAssociationClass().getQualifiedName()%>.class) + .findAllByProperties("<%=reverse.getName()%>", this)); +}*/ + } + } + } + } +/*{ + // on refait un tour sur chaque entity de tmp pour recuperer leur + // composite + List result = new ArrayList(); + for (TopiaEntity entity : tmp) { + if (entity != null) { + result.add(entity); + result.addAll(entity.getComposite()); + } + } + + return result; + } + +}*/ for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); ObjectModelAttribute reverse = attr.getReverseAttribute(); - if (!attr.isNavigable() - && !hasUnidirectionalRelationOnAbstractType(reverse, model)) { + + if (!(attr.isNavigable() + || hasUnidirectionalRelationOnAbstractType(reverse, model))) { continue; } if (!Util.isNMultiplicity(attr)) { @@ -225,16 +380,16 @@ * @see <%=clazz.getQualifiedName()%>#set<%=Util.capitalize(assocAttrName)%>(<%=attr.getAssociationClass().getQualifiedName()%>) *) public void set<%=Util.capitalize(assocAttrName)%>(<%=attr.getAssociationClass().getQualifiedName()%> association) { - <%=attr.getAssociationClass().getQualifiedName()%> _oldValue = this.<%=Util.toLowerCaseFirstLetter(attr.getName())%>; - this.<%=Util.toLowerCaseFirstLetter(attr.getName())%> = association; - fireOnModifyProperty("<%=attr.getName()%>", _oldValue, association); + <%=attr.getAssociationClass().getQualifiedName()%> _oldValue = this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>; + this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%> = association; + fireOnModifyProperty("<%=Util.toLowerCaseFirstLetter(assocAttrName)%>", _oldValue, association); } /* (non-Javadoc) * @see <%=clazz.getQualifiedName()%>#get<%=Util.capitalize(assocAttrName)%>() *) public <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>() { - return <%=Util.toLowerCaseFirstLetter(attr.getName())%>; + return <%=Util.toLowerCaseFirstLetter(assocAttrName)%>; } }*/ @@ -344,8 +499,8 @@ * @see <%=clazz.getQualifiedName()%>#add<%=Util.capitalize(assocAttrName)%>(<%=attr.getAssociationClass().getQualifiedName()%>) *) public void add<%=Util.capitalize(assocAttrName)%>(<%=attr.getAssociationClass().getQualifiedName()%> value) { - if (this.<%=Util.toLowerCaseFirstLetter(attr.getName())%> == null) { - this.<%=Util.toLowerCaseFirstLetter(attr.getName())%> = new java.util.ArrayList<<%=attr.getAssociationClass().getQualifiedName()%>>(); + if (this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%> == null) { + this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%> = new java.util.ArrayList<<%=attr.getAssociationClass().getQualifiedName()%>>(); } }*/ if (reverse != null && (reverse.isNavigable() || @@ -353,8 +508,8 @@ /*{ value.set<%=Util.capitalize(reverse.getName())%>(this); }*/ } -/*{ this.<%=Util.toLowerCaseFirstLetter(attr.getName())%>.add(value); - fireOnModifyIndexedProperty("<%=attr.getName()%>", this.<%=Util.toLowerCaseFirstLetter(attr.getName())%>.size(), null, value); +/*{ this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>.add(value); + fireOnModifyIndexedProperty("<%=Util.toLowerCaseFirstLetter(assocAttrName)%>", this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>.size(), null, value); } /* (non-Javadoc) @@ -376,16 +531,16 @@ // clear<%=Util.capitalize(assocAttrName)%>(); // addAll<%=Util.capitalize(assocAttrName)%>(values); // FIXME - <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> _oldValue = <%=Util.toLowerCaseFirstLetter(attr.getName())%>; - <%=Util.toLowerCaseFirstLetter(attr.getName())%> = values; - fireOnModifyProperty("<%=attr.getName()%>", _oldValue, values); + <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> _oldValue = <%=Util.toLowerCaseFirstLetter(assocAttrName)%>; + <%=Util.toLowerCaseFirstLetter(assocAttrName)%> = values; + fireOnModifyProperty("Util.toLowerCaseFirstLetter(assocAttrName)%>", _oldValue, values); } /* (non-Javadoc) * @see <%=clazz.getQualifiedName()%>#remove<%=Util.capitalize(assocAttrName)%>(<%=attr.getAssociationClass().getQualifiedName()%>) *) public void remove<%=Util.capitalize(assocAttrName)%>(<%=attr.getAssociationClass().getQualifiedName()%> value) { - if ((this.<%=Util.toLowerCaseFirstLetter(attr.getName())%> == null) || (!this.<%=Util.toLowerCaseFirstLetter(attr.getName())%>.remove(value))) { + if ((this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%> == null) || (!this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>.remove(value))) { throw new IllegalArgumentException("List does not contain given element"); } }*/ @@ -394,27 +549,27 @@ /*{ value.set<%=Util.capitalize(reverse.getName())%>(null); }*/ } -/*{ fireOnModifyIndexedProperty("<%=attr.getName()%>", this.<%=attr.getName()%>.size()+1, value, null); +/*{ fireOnModifyIndexedProperty("<%=Util.toLowerCaseFirstLetter(assocAttrName)%>", this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>.size()+1, value, null); } /* (non-Javadoc) * @see <%=clazz.getQualifiedName()%>#clear<%=Util.capitalize(assocAttrName)%>() *) public void clear<%=Util.capitalize(assocAttrName)%>() { - if (this.<%=Util.toLowerCaseFirstLetter(attr.getName())%> == null) { + if (this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%> == null) { return; } }*/ if (reverse != null && (reverse.isNavigable() || hasUnidirectionalRelationOnAbstractType(attr, model))) { -/*{ for (<%=attr.getAssociationClass().getQualifiedName()%> item : this.<%=Util.toLowerCaseFirstLetter(attr.getName())%>) { +/*{ for (<%=attr.getAssociationClass().getQualifiedName()%> item : this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>) { item.set<%=Util.capitalize(reverse.getName())%>(null); } }*/ } -/*{ java.util.List _oldValue = new java.util.ArrayList(this.<%=Util.toLowerCaseFirstLetter(attr.getName())%>); - this.<%=Util.toLowerCaseFirstLetter(attr.getName())%>.clear(); - fireOnModifyProperty("<%=attr.getName()%>", _oldValue, null); +/*{ java.util.List _oldValue = new java.util.ArrayList(this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>); + this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>.clear(); + fireOnModifyProperty("<%=Util.toLowerCaseFirstLetter(assocAttrName)%>", _oldValue, null); } }*/ @@ -445,17 +600,17 @@ * @see <%=clazz.getQualifiedName()%>#get<%=Util.capitalize(assocAttrName)%>() *) public <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> get<%=Util.capitalize(assocAttrName)%>() { - return <%=Util.toLowerCaseFirstLetter(attr.getName())%>; + return <%=Util.toLowerCaseFirstLetter(assocAttrName)%>; } /* (non-Javadoc) * @see <%=clazz.getQualifiedName()%>#get<%=Util.capitalize(assocAttrName)%>(<%=attr.getType()%>) *) public <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>(<%=attr.getType()%> value) { - if (value == null || <%=Util.toLowerCaseFirstLetter(attr.getName())%> == null) { + if (value == null || <%=Util.toLowerCaseFirstLetter(assocAttrName)%> == null) { return null; } - for (<%=attr.getAssociationClass().getQualifiedName()%> item : <%=Util.toLowerCaseFirstLetter(attr.getName())%>) { + for (<%=attr.getAssociationClass().getQualifiedName()%> item : <%=Util.toLowerCaseFirstLetter(assocAttrName)%>) { if (value.equals(item.get<%=Util.capitalize(attr.getName())%>())) { return item; } @@ -467,10 +622,10 @@ * @see <%=clazz.getQualifiedName()%>#size<%=Util.capitalize(assocAttrName)%>() *) public int size<%=Util.capitalize(assocAttrName)%>() { - if (<%=Util.toLowerCaseFirstLetter(attr.getName())%> == null) { + if (<%=Util.toLowerCaseFirstLetter(assocAttrName)%> == null) { return 0; } - return <%=Util.toLowerCaseFirstLetter(attr.getName())%>.size(); + return <%=Util.toLowerCaseFirstLetter(assocAttrName)%>.size(); } }*/ Index: topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java:1.29 topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java:1.30 --- topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java:1.29 Mon Sep 25 13:20:57 2006 +++ topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java Fri Oct 20 00:26:25 2006 @@ -24,10 +24,10 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.29 $ +* @version $Revision: 1.30 $ * -* Mise a jour: $Date: 2006/09/25 13:20:57 $ -* par : $Author: ruchaud $ +* Mise a jour: $Date: 2006/10/20 00:26:25 $ +* par : $Author: bpoussin $ */ package org.codelutin.topia.generator; @@ -91,7 +91,7 @@ } /*{ - + }*/ boolean haveSuper = clazz.getSuperclasses().size() > 0; @@ -130,29 +130,33 @@ for (Iterator it = clazz.getAttributes().iterator(); it.hasNext(); ) { ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); ObjectModelAttribute reverse = attr.getReverseAttribute(); - if (!attr.isNavigable() - && !hasUnidirectionalRelationOnAbstractType(reverse, model)) { - continue; - } - if (!Util.isNMultiplicity(attr)) { - if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) { - if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) { - generateHibernateManyToOne(output, attr); + + // pour les asso quoi qu'il arrive il faut les lier des 2 cotes + // pour pouvoir supprimer en cascade l'asso lors de la suppression + // d'un des cotes + if (attr.isNavigable() + || hasUnidirectionalRelationOnAbstractType(reverse, model) + || attr.hasAssociationClass()) { + if (!Util.isNMultiplicity(attr)) { + if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) { + if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) { + generateHibernateManyToOne(output, attr); + } else { + generateHibernateOneToOne(output, attr); + } } else { - generateHibernateOneToOne(output, attr); + generateHibernateProperty(output, attr); } } else { - generateHibernateProperty(output, attr); - } - } else { - if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) { - if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) { - generateHibernateManyToMany(output, attr); + if (attr.getClassifier() != null && attr.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) { + if (Util.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) { + generateHibernateManyToMany(output, attr); + } else { + generateHibernateOneToMany(output, attr); + } } else { - generateHibernateOneToMany(output, attr); + generateHibernateMany(output, attr); } - } else { - generateHibernateMany(output, attr); } } } @@ -325,7 +329,9 @@ if (attr.isComposite() || attr.hasAssociationClass()) { /*{ cascade="delete"}*/ } - //Pour le test suivant, on verifie d'abord que l'attribut a un reverse. S'il n'en a pas, cela signifie qu'il ne s'agit pas d'un entite (au sens stereotype entity), donc a donc pas besoin de faire un access=field. + // Pour le test suivant, on verifie d'abord que l'attribut a un reverse. + // S'il n'en a pas, cela signifie qu'il ne s'agit pas d'un entite + // (au sens stereotype entity), donc a donc pas besoin de faire un access=field. if (attr.getReverseAttribute() != null && hasUnidirectionalRelationOnAbstractType(attr.getReverseAttribute(), model)) { /*{ access="field"}*/ } @@ -343,7 +349,7 @@ // Note(poussin) 20060306: pour moi il n'y a pas jamais d'inverse pour many-to-many // car on est dans une table intermediaire specifique.<%=((!Util.isFirstAttribute(attr))?"inverse=\"true\" ":"")%> boolean isIndexed = attr.isIndexed(); -/*{ <<%=(isIndexed?"list":"bag")%> name="<%=getName(attr)%>" table="<%=getManyToManyTableName(attr)%>" lazy="true"<%=((attr.isComposite() || attr.hasAssociationClass())?" cascade=\"delete,delete-orphan\"":"")%> node="<%=getName(attr)%>" embed-xml="true"> +/*{ <<%=(isIndexed?"list":"bag")%> name="<%=getName(attr)%>" table="<%=GeneratorUtil.getManyToManyTableName(attr)%>" lazy="true"<%=((attr.isComposite() || attr.hasAssociationClass())?" cascade=\"delete,delete-orphan\"":"")%> node="<%=getName(attr)%>" embed-xml="true"> }*/ if (isIndexed) { @@ -355,38 +361,4 @@ }*/ } - /** - * Renvoie le nom unique de table pour une relation ManyToMany en fonction - * de l'attribut attr - *

- * Plusieurs cas de figure: - *

  • - * - * @param attr l'attribut servant de base au calcul du nom - * @return le nom de la table - */ - protected String getManyToManyTableName(ObjectModelAttribute attr) { - String result; - - if (attr.hasAssociationClass()) { - result = GeneratorUtil.getDBName(attr.getAssociationClass()); - } else { - 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(); -// } else { -// result = attr.getReverseAttribute().getDeclaringElement().getName() + "_" + attr.getDeclaringElement().getName(); -// } - return result.toLowerCase(); - } - } //EntityHibernateMappingGenerator Index: topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java diff -u topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java:1.16 topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java:1.17 --- topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java:1.16 Thu Sep 21 13:15:19 2006 +++ topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java Fri Oct 20 00:26:25 2006 @@ -25,9 +25,9 @@ * * @author Arnaud Thimel * - * @version $Revision: 1.16 $ + * @version $Revision: 1.17 $ * - * Mise a jour: $Date: 2006/09/21 13:15:19 $ par : $Author: thimel $ + * Mise a jour: $Date: 2006/10/20 00:26:25 $ par : $Author: bpoussin $ */ package org.codelutin.topia.generator; @@ -416,5 +416,39 @@ } return false; } + + /** + * Renvoie le nom unique de table pour une relation ManyToMany en fonction + * de l'attribut attr + *

    + * Plusieurs cas de figure: + *

  • + * + * @param attr l'attribut servant de base au calcul du nom + * @return le nom de la table + */ + static public String getManyToManyTableName(ObjectModelAttribute attr) { + String result; + + if (attr.hasAssociationClass()) { + result = GeneratorUtil.getDBName(attr.getAssociationClass()); + } else { + 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(); +// } else { +// result = attr.getReverseAttribute().getDeclaringElement().getName() + "_" + attr.getDeclaringElement().getName(); +// } + return result.toLowerCase(); + } } // GeneratorUtil