Index: topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java:1.21 topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java:1.22 --- topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java:1.21 Wed Jun 16 09:41:26 2004 +++ topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java Fri Jun 18 18:29:19 2004 @@ -21,10 +21,52 @@ public class ObjectModelToEntityDOClassGenerator extends ObjectModelToEntityTOClassGenerator { + + public String getFilenameForInterface(ObjectModelInterface interfacez) { + return (interfacez.getPackageName()+".persistence.").replace('.', File.separatorChar)+interfacez.getName()+"JDODO.java"; + } + + protected void generateImport(Writer output, ObjectModelClassifier clazz) + throws IOException{ + super.generateImport(output, clazz); +/*{ +import java.util.HashSet; +import org.codelutin.topia.TopiaEntityTO; +import org.codelutin.topia.TopiaEntityDO; +import org.codelutin.topia.AbstractTopiaEntityDO; +import org.codelutin.topia.PrivateTopiaPersistenceService; +import org.codelutin.topia.jdo.TopiaJDOPersistenceHelper; +import javax.jdo.PersistenceManager; +import <%=clazz.getPackageName()%>.transfer.<%=clazz.getName()%>TO; +}*/ + if(clazz instanceof ObjectModelClass){ + for (Iterator i=((ObjectModelClass)clazz).getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if(attribute.referenceClassifier()){ + ObjectModelClassifier classifier = attribute.getClassifier(); +/*{ +import <%=classifier.getPackageName()%>.transfer.<%=classifier.getName()%>TO; +import <%=classifier.getPackageName()%>.persistence.<%=classifier.getName()%>JDODO; +}*/ + } + } + } + } + public String getFilenameForClass(ObjectModelClass clazz) { return (clazz.getPackageName()+".persistence.").replace('.', File.separatorChar)+clazz.getName()+"JDODO.java"; } + public void generatePackageStatement(Writer output, ObjectModelClassifier clazz) + throws IOException { + if (!"".equals(clazz.getPackageName())) { +/*{ +package <%=clazz.getPackageName()%>.persistence; + +}*/ + } + } + public void generateClassDeclaration(Writer output, ObjectModelClass clazz) throws IOException { /*{ @@ -34,7 +76,7 @@ ObjectModelClass superclass = (ObjectModelClass) i.next(); /*{ extends <%=superclass.getName()%>JDODO}*/ } else { -/*{ extends AbstractTopiaEntity}*/ +/*{ extends AbstractTopiaEntityDO}*/ } /*{ implements <%=clazz.getName()%>, TopiaEntityDO}*/ for (i = clazz.getInterfaces().iterator(); i.hasNext();) { @@ -46,6 +88,108 @@ }*/ } + + + + + /** + * Permet la generation de la declaration des attributs + */ + protected void generateAttributeDeclaration(Writer output, ObjectModelAttribute attribute)throws IOException{ + if (!Util.isDerived(attribute)) { + if(!attribute.referenceClassifier()){ +/*{ + protected <%=Util.getAttributeTypeForDO(attribute)%> _<%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; +}*/ + }else{ + if(Util.isNMultiplicity(attribute)){ +/*{ + protected <%=Util.getAttributeTypeForDO(attribute)%> _<%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; +}*/ + }else{ +/*{ + protected <%=attribute.getClassifier().getName()%>JDODO _<%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; +}*/ + } + } + } + } + + + + + + /** + * Permet la generation des methodes d'acces aux attributs + */ + protected void generateGetAttributeAccessor(Writer output, ObjectModelAttribute attribute)throws IOException{ + if (!Util.isDerived(attribute)) { +/*{ + public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + return _<%=attribute.getName()%>; + } +}*/ + } + } + + + /** + * Permet la generation des methode d'acces aux attributs + */ + protected void generateSetAttributeAccessor(Writer output, ObjectModelAttribute attribute)throws IOException{ + if (!Util.isReadOnly(attribute) && !Util.isDerived(attribute)) { + if(!Util.isNMultiplicity(attribute)){ + if(!attribute.referenceClassifier()){ +/*{ + public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException { + this._<%=attribute.getName()%> = value; + } +}*/ + }else{ + ObjectModelClassifier classifier = attribute.getClassifier(); +/*{ + public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException { + if(!(value instanceof TopiaEntityDO)){ + throw new TopiaException("Only DO can be used for entity attribute"); + } + this._<%=attribute.getName()%> = (<%=classifier.getName()%>JDODO)value; + } +}*/ + + } + }else{ +/*{ + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { + <% if(attribute.referenceClassifier()) { %> + if(!(value instanceof TopiaEntityDO)){ + throw new TopiaException("Only DO can be used for entity attribute"); + } + <% } %> + this._<%=attribute.getName()%>.add(value); + } + + public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { + <% if(attribute.referenceClassifier()) { %> + if(!(value instanceof TopiaEntityDO)){ + throw new TopiaException("Only DO can be used for entity attribute"); + } + <% } %> + this._<%=attribute.getName()%>.remove(value); + } + + public void clear<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + this._<%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; + } +}*/ + } + } + } + + + + + + public void generateOperationBody(Writer output, ObjectModelOperation operation) throws IOException { /*{ { @@ -65,13 +209,14 @@ } protected void generateSetAllFrameworkProperties(Writer output, ObjectModelClass clazz) throws IOException { - /*{ +/*{ /** * Prend toutes les valeurs de l'objet passé en paramètre et les utilises * comme valeur pour l'objet courant, ceci inclue l'id de l'objet + * @param done liste des objets deja convertis *) - public void set_AllProperties_(TopiaEntity topiaEntity){ - <%=clazz.getName()%> entity = (<%=clazz.getName()%>)topiaEntity; + public void set_allProperties_(TopiaEntityTO topiaEntity, HashSet done) throws TopiaException { + <%=clazz.getName()%>TO entity = (<%=clazz.getName()%>TO)topiaEntity; this._version_ = entity.get_version_(); this._creationDate_ = entity.get_creationDate_(); @@ -82,47 +227,47 @@ // Iterate on each attribute for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if (! attribute.referenceClassifier()) { + if(! Util.isDerived(attribute)){ + if (! attribute.referenceClassifier()) { /*{ - // field direct copy to not used specifique subclasse set or get methode - this.<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getName())%>(); + this._<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getName())%>(); }*/ - } else { - if (Util.isNMultiplicity(attribute)) { + } else { + if (!Util.isNMultiplicity(attribute)) { /*{ - { - ArrayList tmpIds = new ArrayList(); - if(entity instanceof TopiaEnityTO && !((<%=clazz.getName()%>TO)entity)._<%=attribute.getName()%>ReferenceLoaded_){ - // if we can do more faster, we do :) - tmpIds.addAll(entity._<%=attribute.getName()%>Id_); + if(entity.is_<%=attribute.getName()%>Modified_()){ + TopiaEntityTO te = (TopiaEntityTO)entity.get<%=Util.capitalize(attribute.getName())%>(); + if (te != null){ + this._<%=attribute.getName()%> = (<%=attribute.getClassifier().getName()%>JDODO)te.toDO(done); }else{ - // else we use get method - for (Iterator i=entity.get<%=Util.capitalize(attribute.getName())%>().iterator(); i.hasNext();) { - TopiaEnity te = (TopiaEnity)i.next(); - if (object != null) tmpIds.add(te.get_topiaId_()); - } + this._<%=attribute.getName()%> = null; } - this._<%=attribute.getName()%>Id_ = tmpIds; } }*/ - } else { + } else { /*{ - if(entity instanceof TopiaEnityTO && !((<%=clazz.getName()%>TO)entity)._<%=attribute.getName()%>ReferenceLoaded_){ - // if we can do more faster, we do :) - this._<%=attribute.getName()%>Id_ = entity._<%=attribute.getName()%>Id_; - }else{ - TopiaEnity te = entity.get<%=Util.capitalize(attribute.getName())%>(); - if (te != null){ - this._<%=attribute.getName()%>Id_ = te.get_topiaId_(); + { + if( entity.is_<%=attribute.getName()%>Modified_()){ + ArrayList tmpIds = new ArrayList(); + for (Iterator i=entity.get<%=Util.capitalize(attribute.getName())%>().iterator(); i.hasNext();) { + TopiaEntityTO te = (TopiaEntityTO)i.next(); + if (object != null){ + tmpIds.add(te.toDO(done)); + }else{ + tmpIds.add(null); + } + } + this._<%=attribute.getName()%> = tmpIds; } } }*/ - } + } + } } } /*{ } - }*/ +}*/ } } Index: topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.8 topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.9 --- topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.8 Wed Jun 16 09:41:26 2004 +++ topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java Fri Jun 18 18:29:19 2004 @@ -23,9 +23,9 @@ * * @author Cédric Pineau * Copyright Code Lutin -* @version $Revision: 1.8 $ +* @version $Revision: 1.9 $ * -* Last update : $Date: 2004/06/16 09:41:26 $ +* Last update : $Date: 2004/06/18 18:29:19 $ * by : $Author: bpoussin $ */ package org.codelutin.topia.generators.jdo; @@ -101,6 +101,14 @@ public <%=clazz.getName()%> create<%=clazz.getName()%>() throws TopiaException{ return (<%=clazz.getName()%>)create(); + } + + public void delete(<%=clazz.getName()%> entity) throws TopiaException { + super.delete(entity); + } + + public void update(<%=clazz.getName()%> entity) throws TopiaException { + super.update(entity); } }*/ }