Index: topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToJDOMetaGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToJDOMetaGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:03 2004 +++ topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToJDOMetaGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,79 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * JDOGenerator.java + * + * Created: 7 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators.jdo; + +import org.codelutin.topia.generators.ObjectModelToTopiaMetaGenerator; +import org.codelutin.topia.generators.jdo.tjdo.ObjectModelToJDOEntityMetaDataGenerator; +import org.codelutin.topia.generators.jdo.tjdo.ObjectModelToPersistenceHelperPropertiesGenerator; +import org.codelutin.topia.persistence.LazyEntityGenerator; +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModel; +import java.io.IOException; +import java.io.File; + +public class ObjectModelToJDOMetaGenerator extends ObjectModelGenerator { // JDOGenerator + + public ObjectModelToJDOMetaGenerator(){ + super(); + } + + public void generate(ObjectModel model, File destDir) throws IOException { + ObjectModelGenerator gen = null; + + System.out.println("Generation de ObjectModelToTopiaMetaGenerator"); + gen = new ObjectModelToTopiaMetaGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de ObjectModelToJDOEntityGenerator"); + gen = new ObjectModelToJDOEntityGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de ObjectModelToJDOEntityMetaDataGenerator"); + gen = new ObjectModelToJDOEntityMetaDataGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de LazyEntityGenerator"); + gen = new LazyEntityGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de ObjectModelToPersistenceHelperPropertiesGenerator"); + gen = new ObjectModelToPersistenceHelperPropertiesGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + } + +} // JDOGenerator + Index: topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToJDOEntityGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToJDOEntityGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:03 2004 +++ topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToJDOEntityGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,282 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * ObjectModelToJDOEntityGenerator.java + * + * Created: 6 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators.jdo; + +import org.codelutin.topia.generators.TopiaAbstractObjectModelGenerator; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; +import org.codelutin.generator.models.object.ObjectModelClassifier; +import org.codelutin.generator.models.object.ObjectModelInterface; +import org.codelutin.generator.models.object.ObjectModelOperation; +import java.io.File; + +public class ObjectModelToJDOEntityGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToJDOEntityGenerator + + public String getFilenameForClassifier(ObjectModelClassifier clazz) { + return (clazz.getPackageName()+".persistence.jdo.").replace('.', File.separatorChar)+clazz.getName()+"JDO.java"; + } + + public boolean accept(ObjectModelClassifier clazz){ + return Util.isEntity(clazz); + } + + ////////////////////////////////////////////////////////////////////// + // P A C K A G E + ////////////////////////////////////////////////////////////////////// + + public void generatePackageStatement(Writer output, ObjectModelClassifier clazz) + throws IOException { +/*{ +package <%=clazz.getPackageName()%>.persistence.jdo; + +}*/ + } + + ////////////////////////////////////////////////////////////////////// + // C L A S S D E C L A R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateImportStatement(Writer output, ObjectModelClassifier clazz) throws IOException { + super.generateImportStatement(output, clazz); +/*{ +import org.codelutin.topia.persistence.jdo.AbstractJDOEntity; +import org.codelutin.topia.persistence.jdo.JDOEntity; +import <%=clazz.getPackageName()%>.*; +}*/ + } + + public void generateClassDeclaration(Writer output, ObjectModelClassifier clazzifier) throws IOException { +/*{ +/** +<%=clazzifier.getDocumentation()%> + *)}*/ + if(clazzifier instanceof ObjectModelClass){ + ObjectModelClass clazz = (ObjectModelClass)clazzifier; +/*{ +public class <%=clazz.getName() + "JDO"%> extends }*/ + Iterator i = clazz.getSuperclasses().iterator(); + if (i.hasNext()) { + ObjectModelClass superclass = (ObjectModelClass) i.next(); + /*{<%=superclass.getName()%>JDO implements JDOEntity}*/ + } else { + /*{AbstractJDOEntity implements JDOEntity}*/ + } + }else{ +/*{ +public interface <%=clazzifier.getName() + "JDO"%> extends JDOEntity}*/ + } + + for (Iterator i = clazzifier.getInterfaces().iterator(); i.hasNext();) { + ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); + /*{, <%=interfacezz.getName()%>JDO }*/ + } + } + + ////////////////////////////////////////////////////////////////////// + // A T T R I B U T S D E C L A R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateNormalAttributeDeclaration(Writer output, ObjectModelAttribute attribute) throws IOException { + if(attribute.getDeclaringElement() instanceof ObjectModelClass){ +/*{ + public <%=Util.getAttributeType(attribute)%> <%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; +}*/ + } + } + + public void generateEntityAttributeDeclaration(Writer output, ObjectModelAttribute attribute) + throws IOException { + /*{ + public <%=Util.getJDOClassName(Util.getAttributeType(attribute))%> <%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; +}*/ + } + + ////////////////////////////////////////////////////////////////////// + // O T H E R + ////////////////////////////////////////////////////////////////////// + + public void generateOther(Writer output, ObjectModelClassifier clazzifier) throws IOException { + if(!(clazzifier instanceof ObjectModelClass)){ + return; + } + + ObjectModelClass clazz = (ObjectModelClass)clazzifier; +/*{ + + /** + * Return entity Class managed by this service + *) + public Class getEntityClass(){ + return <%=clazz.getName()%>.class; + } + + /** + * Retourne le persistenceService associé à cette entite. + *) + private <%=clazz.getName()%>PersistenceService getPersistenceService()throws TopiaException { + <%=clazz.getName()%>PersistenceService persistenceService = getAppContext().get<%=clazz.getName()%>PersistenceService(); + return persistenceService; + } + + /** + * Retourne le context d'application associe a cette entite + *) + public <%=model.getName()%>Context getAppContext(){ + <%=model.getName()%>Context context = (<%=model.getName()%>Context)getContext(); + return context; + } + + /** + * Met a jour l'objet jdo a partir de l'entity. Et appelle l'operation + * d'update sur les Entities elle meme modifié. + * @param topiaEntity une vrai entity et pas un Lazy + *) + public void update(TopiaEntity topiaEntity, HashSet done) throws TopiaException { + super.update(topiaEntity, done); + <%=clazz.getQualifiedName()%>Impl entity = (<%=clazz.getQualifiedName()%>Impl)topiaEntity; + }*/ + + // Iterate on each attribute + for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if(! Util.isDerived(attribute)){ +/*{ + if(entity.is_<%=attribute.getName()%>Modified_()){ +}*/ + if (! attribute.referenceClassifier()) { +/*{ + this.<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getName())%>(); +}*/ + } else { + if (!Util.isNMultiplicity(attribute)) { +/*{ + TopiaEntity te = (TopiaEntity)entity.get<%=Util.capitalize(attribute.getName())%>(); + if (te != null){ + JDOEntity tejdo = getPersistenceHelper().update(te, done); + this.<%=attribute.getName()%> = (<%=Util.getJDOClassName(Util.getAttributeType(attribute))%>)tejdo; + }else{ + this.<%=attribute.getName()%> = null; + } +}*/ + } else { +/*{ + ArrayList tmpIds = new ArrayList(); + for (Iterator i=entity.get<%=Util.capitalize(attribute.getName())%>().iterator(); i.hasNext();) { + TopiaEntity te = (TopiaEntity)i.next(); + if (te != null){ + JDOEntity tejdo = getPersistenceHelper().update(te, done); + tmpIds.add(tejdo); + }else{ + tmpIds.add(null); + } + } + this.<%=attribute.getName()%> = tmpIds; +}*/ + } + } +/*{ + } +}*/ + } + } +/*{ + } + + public TopiaEntity convertToEntity() throws TopiaException { + return convertToEntity(new <%=clazz.getName()%>Impl()); + } + + /** + * Converti l'objet JDO en objet normal du framework, chaque attribut et + * element de collection referencant une entity est encapsulé dans un + * LazyEntity + * @param result l'objet resultat a utiliser s'il est different de null, + * sinon on en instancie un nouveau. + * @return l'objet resultat est lui meme dans un Lazy + *) + protected TopiaEntity convertToEntity(TopiaEntity result) throws TopiaException { + <%=clazz.getName()%>Impl entity = (<%=clazz.getName()%>Impl)result; + + super.convertToEntity(entity); +}*/ + // Iterate on each attribute + for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if(! Util.isDerived(attribute)){ + if (!Util.isNMultiplicity(attribute)) { + if (! attribute.referenceClassifier()) { +/*{ + entity.set<%=Util.capitalize(attribute.getName())%>(<%=attribute.getName()%>); +}*/ + }else{ +/*{ + if(<%=attribute.getName()%> == null){ + entity.set<%=Util.capitalize(attribute.getName())%>(null); + }else{ + entity.set<%=Util.capitalize(attribute.getName())%>(new <%=Util.getLazyClassName(attribute.getType())%>(getContext(), <%=attribute.getName()%>.get_topiaId_(), <%=attribute.getName()%>.get_version_())); + } +}*/ + } + }else{ + if (! attribute.referenceClassifier()) { +/*{ + for(Iterator i=<%=attribute.getName()%>.iterator(); i.hasNext();){ + entity.add<%=Util.capitalize(attribute.getName())%>((<%=attribute.getType()%>)i.next()); + } +}*/ + }else{ +/*{ + for(Iterator i=<%=attribute.getName()%>.iterator(); i.hasNext();){ + JDOEntity e = (JDOEntity)i.next(); + entity.add<%=Util.capitalize(attribute.getName())%>(new <%=Util.getLazyClassName(attribute.getType())%>(getContext(), e.get_topiaId_(), e.get_version_())); + } +}*/ + } + } + } + } +/*{ + // ajouter le code qui indique que l'entity n'a pas ete modifie + // c-a-d remettre tous les ismodified a false + + return new <%=clazz.getName()%>Lazy(getContext(), result); + } +}*/ + } + +} // ObjectModelToJDOEntityGenerator + Index: topia/src/java/org/codelutin/topia/generators/jdo/Util.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/jdo/Util.java:1.1 --- /dev/null Fri Jul 30 14:39:03 2004 +++ topia/src/java/org/codelutin/topia/generators/jdo/Util.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,45 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * Util.java + * + * Created: 8 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators.jdo; + +public class Util extends org.codelutin.topia.generators.Util { // Util + + public static String getLazyClassName(String clazz){ + return org.codelutin.topia.persistence.jdo.Util.getLazyClassName(clazz); + } + + public static String getJDOClassName(String clazz){ + return org.codelutin.topia.persistence.jdo.Util.getJDOClassName(clazz); + } + +} // Util +