Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.15 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.16 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.15 Thu Aug 11 16:32:03 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java Tue Aug 16 22:19:33 2005 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.15 $ + * @version $Revision: 1.16 $ * - * Mise a jour: $Date: 2005/08/11 16:32:03 $ - * par : $Author: thimel $ + * Mise a jour: $Date: 2005/08/16 22:19:33 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia.generators; @@ -47,7 +47,7 @@ public class ObjectModelToEntityGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToEntityGenerator - public ObjectModelToEntityGenerator(){ + public ObjectModelToEntityGenerator(){ super(); } @@ -69,7 +69,7 @@ public String generateMethodInfo(MethodType type, boolean isModifier, ObjectModelAttribute attr, boolean isAssociationFieldAccessor) { String output = "@MethodInfo (\n"; - output += " type = MethodType." + type; + output += " type = MethodType." + type; if (type == MethodType.FIELD_ACCESSOR) { if (isAssociationFieldAccessor) { output += ",\n field = \"" + Util.getAssociationClassName(attr) + "\""; @@ -111,20 +111,20 @@ } else { id = (Util.isFirstAttribute(attr)) ? "A" : "B"; } -/*{ +/*{ association<%=id%> = <%=attr.getType()%>.class, association<%=id%>Field = "<%=attr.getName()%>", association<%=id%>Cardinality = {<%=attr.getMinMultiplicity()%>, <%=attr.getMaxMultiplicity()%>}, -}*/// association<%=id%>IsComposition = ... /* TODO Vérifier si la valeur par défaut correspond */ +}*/// association<%=id%>IsComposition = ... /* TODO Vérifier si la valeur par défaut correspond */ } } -/*{ +/*{ schemaVersion = <%=Util.getSerialVersionUID((ObjectModelClass)clazz)%>L, fields = {<%=Util.getFieldList((ObjectModelClass)clazz)%>}, fieldTypes = {<%=Util.getFieldClassTypes((ObjectModelClass)clazz)%>} -}*/ /* TODO fieldValues = ... A changer si on veut mettre des valeurs par défaut aux attributs */ +}*/ /* TODO fieldValues = ... A changer si on veut mettre des valeurs par défaut aux attributs */ /*{) -}*/ +}*/ } public void generateClassDeclaration(Writer output, ObjectModelClassifier clazz) Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java:1.14 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java:1.15 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java:1.14 Fri Aug 12 16:17:14 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java Tue Aug 16 22:19:33 2005 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.14 $ + * @version $Revision: 1.15 $ * - * Mise a jour: $Date: 2005/08/12 16:17:14 $ - * par : $Author: thimel $ + * Mise a jour: $Date: 2005/08/16 22:19:33 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia.generators; @@ -116,6 +116,7 @@ }*/ } + /*{ /** * @return an entity Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java:1.14 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java:1.15 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java:1.14 Fri Aug 12 16:17:14 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java Tue Aug 16 22:19:33 2005 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.14 $ + * @version $Revision: 1.15 $ * - * Mise a jour: $Date: 2005/08/12 16:17:14 $ - * par : $Author: thimel $ + * Mise a jour: $Date: 2005/08/16 22:19:33 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia.generators; @@ -119,12 +119,36 @@ }*/ } + if(attribute.hasAssociationClass()){ + String associationClassName = attribute.getAssociationClass().getName(); /*{ /** * @return an entity *) public <%=currentClazz.getName()%> findBy<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException{ - List result = find(newQuery().where("<%=attribute.getName()%> = ?").addArg(value)); + <%=attribute.getAssociationClass().getQualifiedName()%>PersistenceService ps = ((<%=getProperty("defaultPackage") + "." + model.getName()%>Context)getContext()).get<%=associationClassName%>PersistenceService(); + List result = ps.find(ps.newQuery().where("<%=attribute.getName()%> = ?").limit(0,1).addArg(value)); + if(result.size() == 0){ + return null;/*throw new TopiaNotFoundException("Can't find object with attribute <%=attribute.getName()%> == " + value);*) + } + return (<%=currentClazz.getName()%>)result.get(0); + } + + /** + * @return an unmodifiable collection + *) + public List findAllBy<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException{ + <%=attribute.getAssociationClass().getQualifiedName()%>PersistenceService ps = ((<%=getProperty("defaultPackage") + "." + model.getName()%>Context)getContext()).get<%=associationClassName%>PersistenceService(); + return ps.find(ps.newQuery().where("<%=attribute.getName()%> = ?").addArg(value)); + } +}*/ + } else { +/*{ + /** + * @return an entity + *) + public <%=currentClazz.getName()%> findBy<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException{ + List result = find(newQuery().where("<%=attribute.getName()%> = ?").limit(0,1).addArg(value)); if(result.size() == 0){ return null;/*throw new TopiaNotFoundException("Can't find object with attribute <%=attribute.getName()%> == " + value);*) } @@ -138,6 +162,7 @@ return find(newQuery().where("<%=attribute.getName()%> = ?").addArg(value)); } }*/ + } } public void generateEntityAttributeDeclaration(Writer output, ObjectModelAttribute attribute) throws IOException { @@ -174,7 +199,7 @@ public void generateOther(Writer output, ObjectModelClassifier clazzifier) throws IOException { if(clazzifier instanceof ObjectModelClass){ - ObjectModelClass clazz = (ObjectModelClass)clazzifier; + ObjectModelClass clazz = (ObjectModelClass)clazzifier; generateAllOtherAttributeDeclaration(output, clazz); /*{ // /** @@ -191,21 +216,21 @@ // public <%=clazz.getName()%> makePersistent(<%=clazz.getName()%> entity) throws TopiaException { // if (! (entity instanceof <%=clazz.getName()%>)) { // throw new TopiaException("Wrong persistence service. You should use the entity related persistence service"); -// } +// } // return (<%=clazz.getName()%>)super.makePersistent(entity); // } // // public <%=clazz.getName()%> update(<%=clazz.getName()%> entity) throws TopiaException { // if (! (entity instanceof <%=clazz.getName()%>)) { // throw new TopiaException("Wrong persistence service. You should use the entity related persistence service"); -// } +// } // return (<%=clazz.getName()%>)super.update(entity); // } // // public void delete(<%=clazz.getName()%> entity) throws TopiaException { // if (! (entity instanceof <%=clazz.getName()%>)) { // throw new TopiaException("Wrong persistence service. You should use the entity related persistence service"); -// } +// } // super.delete(entity); // } @@ -225,14 +250,14 @@ } protected String [] fieldNames = new String[] { -}*/ +}*/ for (Iterator it = clazz.getAttributes().iterator(); it.hasNext(); ) { /*{ "<%=((ObjectModelAttribute)it.next()).getName()%>", -}*/ +}*/ } for (Iterator it = clazz.getAllOtherAttributes().iterator(); it.hasNext(); ) { /*{ "<%=((ObjectModelAttribute)it.next()).getName()%>", -}*/ +}*/ } /*{ }; @@ -241,10 +266,10 @@ } }*/ } else { - ObjectModelInterface interfacz = (ObjectModelInterface)clazzifier; + ObjectModelInterface interfacz = (ObjectModelInterface)clazzifier; /*{ - /** + /** * Return new entity *) public <%=interfacz.getName()%> create<%=interfacz.getName()%>() throws TopiaException { @@ -254,21 +279,21 @@ public <%=interfacz.getName()%> makePersistent(<%=interfacz.getName()%> entity) throws TopiaException { if (! (entity instanceof <%=interfacz.getName()%>)) { throw new TopiaException("Wrong persistence service. You should use the entity related persistence service"); - } + } return (<%=interfacz.getName()%>)super.makePersistent(entity); } public <%=interfacz.getName()%> update(<%=interfacz.getName()%> entity) throws TopiaException { if (! (entity instanceof <%=interfacz.getName()%>)) { throw new TopiaException("Wrong persistence service. You should use the entity related persistence service"); - } + } return (<%=interfacz.getName()%>)super.update(entity); } public void delete(<%=interfacz.getName()%> entity) throws TopiaException { if (! (entity instanceof <%=interfacz.getName()%>)) { throw new TopiaException("Wrong persistence service. You should use the entity related persistence service"); - } + } super.delete(entity); } @@ -292,9 +317,9 @@ } }*/ - + } - + } } // OjectModelToEntityPersistenceServiceImplGenerator Index: topia/src/java/org/codelutin/topia/generators/TopiaObjectModelModifier.java diff -u topia/src/java/org/codelutin/topia/generators/TopiaObjectModelModifier.java:1.5 topia/src/java/org/codelutin/topia/generators/TopiaObjectModelModifier.java:1.6 --- topia/src/java/org/codelutin/topia/generators/TopiaObjectModelModifier.java:1.5 Fri Jul 29 13:19:12 2005 +++ topia/src/java/org/codelutin/topia/generators/TopiaObjectModelModifier.java Tue Aug 16 22:19:33 2005 @@ -23,10 +23,10 @@ * * @author Arnaud Thimel * Copyright Code Lutin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Mise a jour: $Date: 2005/07/29 13:19:12 $ - * par : $Author: thimel $ + * Mise a jour: $Date: 2005/08/16 22:19:33 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia.generators; @@ -56,7 +56,7 @@ // (cf. TODO de lutingenerator). // Pour l'instant, on se restreint au objets // org.codelutin.generator.models.object.xml.* - + /* (non-Javadoc) * @see org.codelutin.topia.ObjectModelModifier#modify(org.codelutin.generator.models.object.ObjectModel) */ @@ -77,19 +77,19 @@ if (Util.isAttributeEntity(attribute)) { String qualifiedAssociationClassName = Util.getQualifiedAssociationClassName(attribute); // Si la classe existe déjà, on ne la recréé pas ! - if (modelImpl.getClass(qualifiedAssociationClassName) == null) { + if (!modelImpl.haveClass(qualifiedAssociationClassName)) { ObjectModelAssociationClassImpl assocClassImpl = (ObjectModelAssociationClassImpl)modelImpl.parsetAssociationClass(null); - + assocClassImpl.parsetType(qualifiedAssociationClassName); assocClassImpl.parsetName(qualifiedAssociationClassName.substring(qualifiedAssociationClassName.lastIndexOf(".") + 1)); assocClassImpl.parsetPackage(qualifiedAssociationClassName.substring(0, qualifiedAssociationClassName.lastIndexOf("."))); - + // participant 1 ObjectModeImplAssociationClassParticipant part = assocClassImpl.parsetParticipant(null); part.parsetName(((ObjectModelClass)attribute.getDeclaringElement()).getQualifiedName()); part.parsetAttribute(attribute.getName()); assocClassImpl.parsetParticipant(part); - + // participant 2 if (attribute.getReverseAttribute() != null) { ObjectModelAttribute reverse = (ObjectModelAttribute)attribute.getReverseAttribute(); @@ -98,16 +98,16 @@ part.parsetAttribute(reverse.getName()); assocClassImpl.parsetParticipant(part); } - + // stéréotypes ObjectModelImplRef ref = assocClassImpl.parsetStereotype(null); ref.parsetName("entity"); assocClassImpl.parsetStereotype(ref); - + ref = assocClassImpl.parsetStereotype(null); ref.parsetName("associationClassGenerated"); assocClassImpl.parsetStereotype(ref); - + modelImpl.parsetAssociationClass(assocClassImpl); } } @@ -116,5 +116,5 @@ return modelImpl; } - + } Index: topia/src/java/org/codelutin/topia/generators/Util.java diff -u topia/src/java/org/codelutin/topia/generators/Util.java:1.12 topia/src/java/org/codelutin/topia/generators/Util.java:1.13 --- topia/src/java/org/codelutin/topia/generators/Util.java:1.12 Thu Aug 11 16:32:03 2005 +++ topia/src/java/org/codelutin/topia/generators/Util.java Tue Aug 16 22:19:33 2005 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.12 $ + * @version $Revision: 1.13 $ * - * Mise a jour: $Date: 2005/08/11 16:32:03 $ - * par : $Author: thimel $ + * Mise a jour: $Date: 2005/08/16 22:19:33 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia.generators; @@ -303,8 +303,8 @@ for(Iterator i=clazzifier.getAttributes().iterator(); i.hasNext();) { ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - result += Math.abs(attribute.getType().hashCode()); - result += Math.abs(attribute.getName().hashCode()); + result += Math.abs((attribute.getType()==null?0:attribute.getType().hashCode())); + result += Math.abs((attribute.getName()==null?0:attribute.getName().hashCode())); } return result; }