Index: topia2/src/java/org/codelutin/topia/generator/DAOAbstractGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/DAOAbstractGenerator.java:1.1.1.1 topia2/src/java/org/codelutin/topia/generator/DAOAbstractGenerator.java:1.2 --- topia2/src/java/org/codelutin/topia/generator/DAOAbstractGenerator.java:1.1.1.1 Mon Jan 2 13:54:35 2006 +++ topia2/src/java/org/codelutin/topia/generator/DAOAbstractGenerator.java Wed Jan 4 13:21:51 2006 @@ -24,9 +24,9 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.1.1.1 $ +* @version $Revision: 1.2 $ * -* Mise a jour: $Date: 2006/01/02 13:54:35 $ +* Mise a jour: $Date: 2006/01/04 13:21:51 $ * par : $Author: bpoussin $ */ @@ -49,7 +49,7 @@ * pour implanter d'autre methode find, ou bien laisser l'implantation par * defaut de l'autre generateur qui genere une classe DAO qui herite de celle-ci * mais completement vide. - * + * @author poussin * */ @@ -78,24 +78,25 @@ * Implantation DAO pour l'entité <%=Util.toUpperCaseFirstLetter(clazz.getName())%>. * Cette classe contient une implantation de TopiaDAO a laquel elle peut * deleguer des traitements + * *) -public abstract class <%=clazz.getName()%>DAOAbstract extends }*/ +public abstract class <%=clazz.getName()%>DAOAbstract> extends }*/ String extendClass = ""; for (Iterator i=clazz.getSuperclasses().iterator(); i.hasNext();) { ObjectModelClassifier parent = (ObjectModelClassifier)i.next(); extendClass += parent.getQualifiedName(); if (parent.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { - extendClass += "DAO"; + extendClass += "DAOImpl"; } if (i.hasNext()) { extendClass += ", "; } } if (extendClass.length() == 0) { - extendClass += "org.codelutin.topia.persistence.TopiaDAODelegator<" + clazz.getName() + ">"; + extendClass += "org.codelutin.topia.persistence.TopiaDAODelegator"; } - /*{<%=extendClass%> implements org.codelutin.topia.persistence.TopiaDAO<<%=clazz.getName()%>> { + /*{<%=extendClass%> implements org.codelutin.topia.persistence.TopiaDAO { }*/ for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); @@ -104,6 +105,17 @@ *) }*/ if (!Util.isNMultiplicity(attr)) { + generateNoNMultiplicity(output, attr); + } else { + generateNMultiplicity(output, attr); + } + } + +/*{} //<%=clazz.getName()%>DAOAbstract +}*/ + } + + protected void generateNoNMultiplicity(Writer output, ObjectModelAttribute attr) throws IOException { /*{ /** * Retourne le premier élément trouvé ayant comme valeur pour l'attribut @@ -111,8 +123,8 @@ * @param v la valeur que doit avoir <%=attr.getName()%> * @return un element ou null *) - public <%=clazz.getName()%> findBy<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException { - <%=clazz.getName()%> result = getParentDAO().findByProperty("<%=attr.getName()%>", v); + public E findBy<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException { + E result = getParentDAO().findByProperty("<%=attr.getName()%>", v); return result; } /** @@ -121,13 +133,14 @@ * @param v la valeur que doit avoir <%=attr.getName()%> * @return une liste *) - public List<<%=clazz.getName()%>> findAllBy<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException { - List<<%=clazz.getName()%>> result = getParentDAO().findAllByProperty("<%=attr.getName()%>", v); + public List findAllBy<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException { + List result = getParentDAO().findAllByProperty("<%=attr.getName()%>", v); return result; } - }*/ - } else { + } + + protected void generateNMultiplicity(Writer output, ObjectModelAttribute attr) throws IOException { /*{ /** * Retourne le premier élément trouvé dont l'attribut @@ -135,7 +148,7 @@ * @param v la valeur que doit contenir <%=attr.getName()%> * @return un element ou null *) - public <%=clazz.getName()%> findContains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) { + public E findContains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) { // TODO faire une recherche sur les elements qui contiennent tous les // elements de la collection passé en argument dans leur propre collection return null; @@ -146,18 +159,13 @@ * @param v la valeur que doit contenir <%=attr.getName()%> * @return une liste *) - public List<<%=clazz.getName()%>> findAllContains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) { + public List findAllContains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) { // TODO faire une recherche sur les elements qui contiennent tous les // elements de la collection passé en argument dans leur propre collection return null; } -}*/ - } - } - -/*{} //<%=clazz.getName()%>DAOAbstract -}*/ +}*/ } - + } //DAOAbstractGenerator Index: topia2/src/java/org/codelutin/topia/generator/DAOGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/DAOGenerator.java:1.1.1.1 topia2/src/java/org/codelutin/topia/generator/DAOGenerator.java:1.2 --- topia2/src/java/org/codelutin/topia/generator/DAOGenerator.java:1.1.1.1 Mon Jan 2 13:54:35 2006 +++ topia2/src/java/org/codelutin/topia/generator/DAOGenerator.java Wed Jan 4 13:21:51 2006 @@ -24,9 +24,9 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.1.1.1 $ +* @version $Revision: 1.2 $ * -* Mise a jour: $Date: 2006/01/02 13:54:35 $ +* Mise a jour: $Date: 2006/01/04 13:21:51 $ * par : $Author: bpoussin $ */ @@ -53,18 +53,17 @@ @Override public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { - if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY) || clazz.getOperations().size() > 0) { + if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { return; } /*{package <%=clazz.getPackageName()%>; /** - * Implantation du DAO pour l'entité <%=clazz.getName()%>. - * L'utilisateur peut remplacer cette classe par la sienne en la mettant - * simplement dans ces sources. Cette classe générée sera alors simplement - * écrasé. + * Cette classe etend le DAOImpl pour parametrer la classe avec le bon type + * Cette classe est marque finale car l'heritage entre les DAO se fait + * sur les DOAImpl, c-a-d que DAOAbstract peut etendre le DAOImpl *) -public class <%=clazz.getName()%>DAO extends <%=clazz.getQualifiedName()%>DAOAbstract { +public final class <%=clazz.getName()%>DAO extends <%=clazz.getQualifiedName()%>DAOImpl<<%=clazz.getName()%>> { }*/ Index: topia2/src/java/org/codelutin/topia/generator/DAOHelperGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/DAOHelperGenerator.java:1.1.1.1 topia2/src/java/org/codelutin/topia/generator/DAOHelperGenerator.java:1.2 --- topia2/src/java/org/codelutin/topia/generator/DAOHelperGenerator.java:1.1.1.1 Mon Jan 2 13:54:35 2006 +++ topia2/src/java/org/codelutin/topia/generator/DAOHelperGenerator.java Wed Jan 4 13:21:51 2006 @@ -25,9 +25,9 @@ * * @author Arnaud Thimel * - * @version $Revision: 1.1.1.1 $ + * @version $Revision: 1.2 $ * - * Mise a jour: $Date: 2006/01/02 13:54:35 $ par : $Author: bpoussin $ + * Mise a jour: $Date: 2006/01/04 13:21:51 $ par : $Author: bpoussin $ */ package org.codelutin.topia.generator; @@ -68,6 +68,7 @@ package <%=getProperty("defaultPackage")%>; import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.framework.TopiaContextImplementor; import org.codelutin.topia.TopiaException; public class <%=model.getName()%>DAOHelper { @@ -82,7 +83,8 @@ if(classifier.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)){ /*{ static public <%=classifier.getQualifiedName()%>DAO get<%=classifier.getName()%>DAO(TopiaContext context) throws TopiaException { - <%=classifier.getQualifiedName()%>DAO result = (<%=classifier.getQualifiedName()%>DAO)context.getDAO(<%=classifier.getQualifiedName()%>.class); + TopiaContextImplementor ci = (TopiaContextImplementor)context; + <%=classifier.getQualifiedName()%>DAO result = (<%=classifier.getQualifiedName()%>DAO)ci.getDAO(<%=classifier.getQualifiedName()%>.class); return result; } }*/ Index: topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.1.1.1 topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.2 --- topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.1.1.1 Mon Jan 2 13:54:35 2006 +++ topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java Wed Jan 4 13:21:51 2006 @@ -24,9 +24,9 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.1.1.1 $ +* @version $Revision: 1.2 $ * -* Mise a jour: $Date: 2006/01/02 13:54:35 $ +* Mise a jour: $Date: 2006/01/04 13:21:51 $ * par : $Author: bpoussin $ */ @@ -65,6 +65,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.apache.commons.lang.builder.ToStringBuilder; /** @@ -105,7 +106,7 @@ }*/ } else { -/*{ <%=attr.getVisibility()%> Collection<<%=attr.getType()%>> <%=attr.getName()%>; +/*{ <%=attr.getVisibility()%> List<<%=attr.getType()%>> <%=attr.getName()%>; }*/ } @@ -170,24 +171,25 @@ /* (non-Javadoc) * @see <%=clazz.getQualifiedName()%>#set<%=Util.toUpperCaseFirstLetter(attr.getName())%>(Collection<<%=attr.getType()%>>) *) - public void set<%=Util.toUpperCaseFirstLetter(attr.getName())%>(Collection<<%=attr.getType()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) { - this.<%=attr.getName()%> = <%=Util.toLowerCaseFirstLetter(attr.getName())%>; + public void set<%=Util.toUpperCaseFirstLetter(attr.getName())%>(Collection<<%=attr.getType()%>> v) { + clear<%=Util.toUpperCaseFirstLetter(attr.getName())%>(); + addAll<%=Util.toUpperCaseFirstLetter(attr.getName())%>(v); } /* (non-Javadoc) * @see <%=clazz.getQualifiedName()%>#remove<%=Util.toUpperCaseFirstLetter(attr.getName())%>(<%=attr.getType()%>) *) - public void remove<%=Util.toUpperCaseFirstLetter(attr.getName())%>(<%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) { - if ((this.<%=attr.getName()%> == null) || (!this.<%=attr.getName()%>.remove(<%=attr.getName()%>))) { + public void remove<%=Util.toUpperCaseFirstLetter(attr.getName())%>(<%=attr.getType()%> v) { + if ((this.<%=attr.getName()%> == null) || (!this.<%=attr.getName()%>.remove(v))) { throw new IllegalArgumentException("List does not contain given element"); } }*/ if (attr.getReverseAttribute() != null) { if (!Util.isNMultiplicity(attr.getReverseAttribute())) { -/*{ <%=attr.getName()%>.set<%=Util.toUpperCaseFirstLetter(attr.getReverseAttribute().getName())%>(null); +/*{ v.set<%=Util.toUpperCaseFirstLetter(attr.getReverseAttribute().getName())%>(null); }*/ } else { -/*{ <%=attr.getName()%>.get<%=Util.toUpperCaseFirstLetter(attr.getReverseAttribute().getName())%>().remove(this); +/*{ v.get<%=Util.toUpperCaseFirstLetter(attr.getReverseAttribute().getName())%>().remove(this); }*/ } } @@ -205,7 +207,7 @@ /* (non-Javadoc) * @see <%=clazz.getQualifiedName()%>#get<%=Util.toUpperCaseFirstLetter(attr.getName())%>() *) - public Collection<<%=attr.getType()%>> get<%=Util.toUpperCaseFirstLetter(attr.getName())%>() { + public List<<%=attr.getType()%>> get<%=Util.toUpperCaseFirstLetter(attr.getName())%>() { return <%=attr.getName()%>; } Index: topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java:1.1.1.1 topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java:1.2 --- topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java:1.1.1.1 Mon Jan 2 13:54:35 2006 +++ topia2/src/java/org/codelutin/topia/generator/EntityHibernateMappingGenerator.java Wed Jan 4 13:21:51 2006 @@ -24,9 +24,9 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.1.1.1 $ +* @version $Revision: 1.2 $ * -* Mise a jour: $Date: 2006/01/02 13:54:35 $ +* Mise a jour: $Date: 2006/01/04 13:21:51 $ * par : $Author: bpoussin $ */ @@ -79,11 +79,11 @@ }*/ boolean haveSuper = clazz.getSuperclasses().size() > 0; - ObjectModelClass superClass = (ObjectModelClass)clazz.getSuperclasses().iterator().next(); - String superClassname = superClass.getQualifiedName(); - log.debug("superClass for " + clazz.getQualifiedName() + " is " + superClassname); if (haveSuper) { + ObjectModelClass superClass = (ObjectModelClass)clazz.getSuperclasses().iterator().next(); + String superClassname = superClass.getQualifiedName(); + log.debug("superClass for " + clazz.getQualifiedName() + " is " + superClassname); /*{ }*/ } else { Index: topia2/src/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java:1.1.1.1 topia2/src/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java:1.2 --- topia2/src/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java:1.1.1.1 Mon Jan 2 13:54:35 2006 +++ topia2/src/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java Wed Jan 4 13:21:51 2006 @@ -24,9 +24,9 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.1.1.1 $ +* @version $Revision: 1.2 $ * -* Mise a jour: $Date: 2006/01/02 13:54:35 $ +* Mise a jour: $Date: 2006/01/04 13:21:51 $ * par : $Author: bpoussin $ */ @@ -75,6 +75,7 @@ /*{package <%=clazz.getPackageName()%>; import java.util.Collection; +import java.util.List; }*/ if (GeneratorUtil.hasDocumentation(clazz)) { @@ -183,9 +184,9 @@ /*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%> }*/ } -/*{ * @return La Collection de <%=attr.getName()%>. +/*{ * @return La List de <%=attr.getName()%>. *) - public Collection<<%=attr.getType()%>> get<%=Util.toUpperCaseFirstLetter(attr.getName())%>(); + public List<<%=attr.getType()%>> get<%=Util.toUpperCaseFirstLetter(attr.getName())%>(); }*/ } Index: topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java:1.1.1.1 topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java:1.2 --- topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java:1.1.1.1 Mon Jan 2 13:54:35 2006 +++ topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java Wed Jan 4 13:21:51 2006 @@ -24,9 +24,9 @@ * @author Grégoire DESSARD Copyright Code Lutin, Grégoire * Dessard * - * @version $Revision: 1.1.1.1 $ + * @version $Revision: 1.2 $ * - * Mise a jour: $Date: 2006/01/02 13:54:35 $ par : $Author: bpoussin $ + * Mise a jour: $Date: 2006/01/04 13:21:51 $ par : $Author: bpoussin $ */ package org.codelutin.topia.generator; @@ -72,6 +72,10 @@ gen.generate(model, destDir); // Génère les DAO par defaut des entités + gen = new DAOImplGenerator(this); + gen.generate(model, destDir); + + // Génère les DAO par defaut des entités gen = new DAOGenerator(this); gen.generate(model, destDir); Index: topia2/src/java/org/codelutin/topia/generator/DAOImplGenerator.java diff -u /dev/null topia2/src/java/org/codelutin/topia/generator/DAOImplGenerator.java:1.1 --- /dev/null Wed Jan 4 13:22:00 2006 +++ topia2/src/java/org/codelutin/topia/generator/DAOImplGenerator.java Wed Jan 4 13:21:51 2006 @@ -0,0 +1,75 @@ +/* *##% +* Copyright (C) 2002, 2003, 2004, 2005 Code Lutin, +* Cédric Pineau, Benjamin Poussin, +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +/* * +* EntityPOJOGenerator.java +* +* Created: 12 déc. 2005 +* +* @author Arnaud Thimel +* @version $Revision: 1.1 $ +* +* Mise a jour: $Date: 2006/01/04 13:21:51 $ +* par : $Author: bpoussin $ +*/ + +package org.codelutin.topia.generator; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; + +import org.codelutin.generator.Generator; +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class DAOImplGenerator extends ObjectModelGenerator { + + public DAOImplGenerator(Generator parent) { + super(parent); + } + + @Override + public String getFilenameForClass(ObjectModelClass clazz) { + return clazz.getQualifiedName().replace('.', File.separatorChar) + "DAOImpl.java"; + } + + @Override + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { + return; + } +/*{package <%=clazz.getPackageName()%>; + +/** + * Implantation du DAO pour l'entité <%=clazz.getName()%>. + * L'utilisateur peut remplacer cette classe par la sienne en la mettant + * simplement dans ces sources. Cette classe générée sera alors simplement + * écrasé. + *) +public class <%=clazz.getName()%>DAOImpl> extends <%=clazz.getQualifiedName()%>DAOAbstract { + +}*/ + +/*{} //<%=clazz.getName()%>DAO +}*/ + } + +} //DAOGenerator