Index: topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java:1.20 topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java:1.21 --- topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java:1.20 Mon Jun 7 10:20:47 2004 +++ topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java Wed Jun 16 09:41:26 2004 @@ -1,8 +1,5 @@ /* * Created on 7 janv. 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments */ package org.codelutin.topia.generators.jdo; @@ -19,55 +16,17 @@ import org.codelutin.generator.models.object.ObjectModelOperation; import org.codelutin.generator.models.object.ObjectModelParameter; import org.codelutin.topia.Util; +import org.codelutin.topia.generators.commons.ObjectModelToEntityTOClassGenerator; -/** - * @author cedric - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class ObjectModelToEntityDOClassGenerator extends ObjectModelGenerator { +public class ObjectModelToEntityDOClassGenerator + extends ObjectModelToEntityTOClassGenerator { public String getFilenameForClass(ObjectModelClass clazz) { return (clazz.getPackageName()+".persistence.").replace('.', File.separatorChar)+clazz.getName()+"JDODO.java"; } - public void generateFromClass(Writer output, ObjectModelClass clazz) + public void generateClassDeclaration(Writer output, ObjectModelClass clazz) throws IOException { - - // Consider only entities, return immediately if not an entity - if(! Util.isEntity(clazz)) return; - - // ------------- File Header - if (!"".equals(clazz.getPackageName())) { -/*{ -package <%=clazz.getPackageName()%>.persistence; - -}*/ - } - - // ------------- Imports -/*{ -import org.codelutin.topia.TopiaEntityDO; -import org.codelutin.topia.AbstractTopiaEntity; -import org.codelutin.topia.TopiaUser; -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.jdo.TopiaJDOPersistenceHelper; -import javax.jdo.PersistenceManager; -import <%=clazz.getQualifiedName()%>; -}*/ - - for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { - ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); -/*{ -import <%=clazz.getPackageName()%>.<%=interfacezz.getName()%>; -}*/ - } -/*{ - -}*/ - - // ------------- Class start /*{ public class <%=clazz.getName()%>JDODO}*/ Iterator i = clazz.getSuperclasses().iterator(); @@ -85,224 +44,85 @@ /*{ { }*/ - - // ------------- Attribute declaration - // Iterate on each attribute to generate declarations - for (i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if ((attribute.getMaxMultiplicity() == -1) || (attribute.getMaxMultiplicity()>1) || (attribute.getClassifier() == null)) { -/*{ - <%=attribute.getVisibility()%> <%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>; -}*/ - } else { - ObjectModelClassifier classifier = attribute.getClassifier(); -/*{ - <%=attribute.getVisibility()%> <%=classifier.getPackageName()+".persistence."+classifier.getName()%>JDODO <%=attribute.getName()%>DO; -}*/ - } - } -/*{ - protected String _version; - protected java.util.Date _creationDate; - protected java.util.Date _lastUpdateDate; - protected TopiaUser _lastUpdateUser; - - public <%=clazz.getName()%>JDODO() { super(); - - } - -}*/ - - // ------------- Accessors - // Iterate on each attribute to declare accessors - for (i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if (Util.isDerived(attribute)) { -/*{ - public <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException { - throw new TopiaException("get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>()%> is not implemented on data objects. You shall use transfer objets instead !"); - } -}*/ - if (!Util.isReadOnly(attribute)) { -/*{ - public void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException { - throw new TopiaException("set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) is not implemented on data objects. You shall use transfer objets instead !"); - } - -}*/ - } - continue; - } - - // Not a derived attribute : - - if (!Util.isReadOnly(attribute)) { - if ((attribute.getMaxMultiplicity() == -1) || (attribute.getMaxMultiplicity()>1)) { -/*{ - public <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException { - return <%=attribute.getName()%>; - } - public void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException { - this.<%=attribute.getName()%> = (<%=attribute.getName()%> == null)?<%=Util.getAttributeInitValue(attribute)%>:<%=attribute.getName()%>; - } - -}*/ - } else { - ObjectModelClassifier classifier = attribute.getClassifier(); - if (classifier == null) { -// -/*{ - public <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException { - return <%=attribute.getName()%>; } - public void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException { - this.<%=attribute.getName()%> = <%=attribute.getName()%>; - } - -}*/ - } else { -/*{ - public <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException { - return <%=attribute.getName()%>DO; - } - public <%=classifier.getPackageName()+".persistence."+classifier.getName()%>JDODO get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>DO() throws TopiaException { - return <%=attribute.getName()%>DO; - } - public void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException { - set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>DO((<%=classifier.getPackageName()+".persistence."+classifier.getName()%>JDODO) <%=attribute.getName()%>); - } - public void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>DO(<%=classifier.getPackageName()+".persistence."+classifier.getName()%>JDODO <%=attribute.getName()%>DO) throws TopiaException { - this.<%=attribute.getName()%>DO = <%=attribute.getName()%>DO; - } - -}*/ - } - } - } -/*{ -}*/ - } - - // ------------- Operations declarations - // Iterate on each operation to generate declarations - for (i = clazz.getOperations().iterator(); i.hasNext();) { - ObjectModelOperation operation = (ObjectModelOperation) i.next(); -/*{ - <%=operation.getVisibility()%> <%=operation.getReturnType()%> <%=operation.getName()%> (}*/ - // Iterate on each parameters to declare operation parameters - for (Iterator j = operation.getParameters().iterator(); - j.hasNext(); - ) { - ObjectModelParameter parameter = - (ObjectModelParameter) j.next(); -/*{ -<%=parameter.getType()+" "+parameter.getName()%>}*/ - if (j.hasNext()) { /*{, }*/ - } - } -/*{ -) throws TopiaException { + public void generateOperationBody(Writer output, ObjectModelOperation operation) + throws IOException { +/*{ { throw new TopiaException("<%=operation.getName()%>(...) is not implemented on data objects. You shall use transfer objets instead !"); } }*/ - } -/*{ - -}*/ + } - // ------------- Class end + public void generateTopiaIdOperation(Writer output, ObjectModelClassifier clazz) + throws IOException { /*{ - public Object _getTopiaId() throws TopiaException { + public Object get_topiaId_() throws TopiaException { PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); return persistenceManager.getObjectId(this); } - - public String _getVersion() throws TopiaException { - return _version; - } - public void _setVersion(String version) throws TopiaException { - this._version = version; - } - - public java.util.Date _getCreationDate() throws TopiaException { - return _creationDate; - } - public void _setCreationDate(java.util.Date creationDate) throws TopiaException { - this._creationDate = creationDate; - } - - public java.util.Date _getLastUpdateDate() throws TopiaException { - return _lastUpdateDate; - } - public void _setLastUpdateDate(java.util.Date lastUpdateDate) throws TopiaException { - this._lastUpdateDate = lastUpdateDate; - } - - public TopiaUser _getLastUpdateUser() throws TopiaException { - return _lastUpdateUser; - } - public void _setLastUpdateUser(TopiaUser lastUpdateUser) throws TopiaException { - this._lastUpdateUser = lastUpdateUser; - } - -} }*/ - - } - - public String getFilenameForInterface(ObjectModelInterface interfacez) { - return (interfacez.getPackageName()+".persistence.").replace('.', File.separatorChar)+interfacez.getName()+"JDODO.java"; } - public void generateFromInterface(Writer output, ObjectModelInterface interfacez) - throws IOException { - - // Consider only entities, return immediately if not an entity - if (! Util.isEntity(interfacez)) return; - - // ------------- File Header - if (!"".equals(interfacez.getPackageName())) { -/*{ -package <%=interfacez.getPackageName()%>.persistence; - -}*/ - } + 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 + *) + public void set_AllProperties_(TopiaEntity topiaEntity){ + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)topiaEntity; + + this._version_ = entity.get_version_(); + this._creationDate_ = entity.get_creationDate_(); + this._lastUpdateDate_ = entity.get_lastUpdateDate_(); + this._lastUpdateUser_ = entity.get_lastUpdateUser_(); + }*/ - // ------------- Imports + // Iterate on each attribute + for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if (! attribute.referenceClassifier()) { /*{ -import org.codelutin.topia.TopiaEntityDO; -import org.codelutin.topia.TopiaException; -import <%=interfacez.getQualifiedName()%>; + // field direct copy to not used specifique subclasse set or get methode + this.<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getName())%>(); }*/ - - for (Iterator i = interfacez.getInterfaces().iterator(); i.hasNext();) { - ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); + } else { + if (Util.isNMultiplicity(attribute)) { /*{ -import <%=interfacez.getPackageName()%>.<%=interfacezz.getName()%>; -}*/ + { + 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_); + }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()%>Id_ = tmpIds; } -/*{ - }*/ - - // ------------- Interface start + } else { /*{ - public interface <%=interfacez.getName()%>JDODO}*/ -/*{ extends <%=interfacez.getName()%>, TopiaEntityDO}*/ - for (Iterator i = interfacez.getInterfaces().iterator(); i.hasNext();) { - ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); -/*{, <%=interfacezz.getName()%>}*/ + 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_(); + } } -/*{ { - }*/ - - // ------------- Class end + } + } + } /*{ -} -}*/ - + } + }*/ } } Index: topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.7 topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.8 --- topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.7 Fri Jun 4 18:43:54 2004 +++ topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java Wed Jun 16 09:41:26 2004 @@ -23,9 +23,9 @@ * * @author Cédric Pineau * Copyright Code Lutin -* @version $Revision: 1.7 $ +* @version $Revision: 1.8 $ * -* Last update : $Date: 2004/06/04 18:43:54 $ +* Last update : $Date: 2004/06/16 09:41:26 $ * by : $Author: bpoussin $ */ package org.codelutin.topia.generators.jdo; @@ -45,15 +45,10 @@ public class ObjectModelToEntityPersistenceServiceClassGenerator extends ObjectModelGenerator { - public String getFilenameForClass(ObjectModelClass clazz) { - return (Util.getParentPackageName(clazz.getPackageName())+".services.jdo.").replace('.', File.separatorChar)+clazz.getName()+ "JDOPersistenceService.java"; - } - - public void generateFromClass(Writer output, ObjectModelClass clazz) - throws IOException { + public void generateCommonStatement(Writer output, ObjectModelClassifier clazz)throws IOException { // Consider only entities, return immediately if not an entity - if(! Util.isEntity(clazz)) return; + if (! Util.isEntity(clazz)) return; // ------------- File Header if (!"".equals(clazz.getPackageName())) { @@ -91,9 +86,6 @@ import java.util.logging.Logger; import java.util.logging.Level; -}*/ - -/*{ public class <%=clazz.getName()%>JDOPersistenceService extends AbstractTopiaJDOPersistenceService implements <%=clazz.getName()%>PersistenceService, TopiaPersistenceService { /** @@ -103,23 +95,29 @@ return <%=clazz.getName()%>.class; } + public <%=clazz.getName()%> makePersistent(<%=clazz.getName()%> <%=Util.toLowerCaseFirstLetter(clazz.getName())%>) throws TopiaException { + return (<%=clazz.getName()%>) super.makePersistent(<%=Util.toLowerCaseFirstLetter(clazz.getName())%>); + } + public <%=clazz.getName()%> create<%=clazz.getName()%>() throws TopiaException{ - return (<%=clazz.getName()%>)super.create(); + return (<%=clazz.getName()%>)create(); + } +}*/ } - public <%=clazz.getName()%> makePersistent(<%=clazz.getName()%> <%=Util.toLowerCaseFirstLetter(clazz.getName())%>) throws TopiaException { - return (<%=clazz.getName()%>) super.makePersistent(<%=Util.toLowerCaseFirstLetter(clazz.getName())%>); + public String getFilenameForClass(ObjectModelClass clazz) { + return (Util.getParentPackageName(clazz.getPackageName())+".services.jdo.").replace('.', File.separatorChar)+clazz.getName()+ "JDOPersistenceService.java"; } - public <%=clazz.getName()%> findByPrimaryKey(}*/ - // Iterate on each attribute to declare accessors - for (Iterator i = Util.getPrimaryKeyAttributes(clazz).iterator(); i.hasNext();) { - ObjectModelAttribute primaryKeyAttribute = (ObjectModelAttribute) i.next(); -/*{<%=Util.getAttributeType(primaryKeyAttribute)%> <%=primaryKeyAttribute.getName()%>}*/ - if (i.hasNext()) { /*{, }*/ } - } + public void generateFromClass(Writer output, ObjectModelClass clazz) + throws IOException { + + // Consider only entities, return immediately if not an entity + if(! Util.isEntity(clazz)) return; + generateCommonStatement(output, clazz); + /*{ -) throws TopiaException {}*/ + public <%=clazz.getName()%> findByPrimaryKey(<%=Util.getMethodParameterDeclaration(Util.getPrimaryKeyAttributes(clazz))%>) throws TopiaException {}*/ String filter = ""; String args = ""; for (Iterator i = Util.getPrimaryKeyAttributes(clazz).iterator(); i.hasNext();) { @@ -139,211 +137,8 @@ return (<%=clazz.getName()%>)result.iterator().next(); } - - /** - * Updates that is make change on the given TopiaEntity persistent. - * @param topiaEntity - the TopiaEntity whose changes must be made persistent. - *) - public void update(<%=clazz.getName()%> <%=Util.toLowerCaseFirstLetter(clazz.getName())%>) throws TopiaException { - super.update(<%=Util.toLowerCaseFirstLetter(clazz.getName())%>); - } - - /** - * Delete that is remove from persistence layer the given TopiaEntity. - * @param topiaEntity - the TopiaEntity to delete. - *) - public void delete(<%=clazz.getName()%> <%=Util.toLowerCaseFirstLetter(clazz.getName())%>) throws TopiaException { - super.delete(<%=Util.toLowerCaseFirstLetter(clazz.getName())%>); - } - - /** - * Returns the TopiaEntity TransferObject corresponding to the given TopiaEntity DataObject. - * @param topiaEntityDO - the TopiaEntity DataObject whose TransferObject is wanted. - * @see TopiaEntityDO - * @see TopiaEntityTO - * - * @return the corresponding TopiaEntity TransferObject. - *) - public TopiaEntityTO toTO(TopiaEntity topiaEntityDO) throws TopiaException { - return toTO((<%=clazz.getName()%>JDODO) topiaEntityDO); - } - - public <%=clazz.getName()%>TO toTO(<%=clazz.getName()%>JDODO _do) throws TopiaException { - <%=clazz.getName()%>TO _to = (<%=clazz.getName()%>TO) Cache.getInstance().get(_do._getTopiaId()); - if (_to == null) { - // Not found in cache, let's go and build a <%=clazz.getName()%>TO for this <%=clazz.getName()%>JDODO - // TODO Recherche par le context de la classe à instanciée - _to = new <%=clazz.getName()%>TO(); - Object object; -}*/ - boolean multiple = false; - // Iterate on each attribute - for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if (! attribute.referenceClassifier()) { -/*{ - _to.set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(_do.get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>()); -}*/ - } else { -/*{ - _to._<%=attribute.getName()%>ReferenceLoaded = false; - _to.<%=attribute.getName()%> = null; -}*/ - if ((attribute.getMaxMultiplicity() > 1) || (attribute.getMaxMultiplicity( )== -1)) { -/*{ - <%=(!multiple?"ArrayList ":"")%>_topiaIds = new ArrayList(); - for (Iterator i = _do.get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>().iterator(); i.hasNext();) { - object = i.next(); - if (object != null) _topiaIds.add(((<%=attribute.getType()%>) object)._getTopiaId()); - } - _to._<%=attribute.getName()%> = _topiaIds; -}*/ - multiple = true; - } else { -/*{ - object = _do.get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(); - if (object != null) _to._<%=attribute.getName()%> = ((<%=attribute.getType()%>) object)._getTopiaId(); -}*/ - } - } - } -/*{ - _to._setTopiaId(_do._getTopiaId()); - Cache.getInstance().put(_do._getTopiaId(), _to); - } - return _to; - } - - /** - * Returns the TopiaEntity DataObject corresponding to the given TopiaEntity TransferObject. - * @param topiaEntityTO - the TopiaEntity TransferObject whose DataObject is wanted. - * @see topiaEntityTO - * @see topiaEntityDO - * - * @return the corresponding TopiaEntity DataObject. - *) - public TopiaEntityDO toDO(TopiaEntity topiaEntityTO, HashMap pendingDOs) throws TopiaException { - return this.toDO((<%=clazz.getName()%>TO) topiaEntityTO, pendingDOs); - } - - - public <%=clazz.getName()%>JDODO toDO(<%=clazz.getName()%>TO _to) throws TopiaException { - return toDO(_to, new HashMap()); - } - - public <%=clazz.getName()%>JDODO toDO(<%=clazz.getName()%>TO _to, HashMap pendingDOs) throws TopiaException { - if (_to == null) return null; - <%=clazz.getName()%>JDODO _do; - Object objectTopiaId = _to._getTopiaId(); - if (objectTopiaId != null) { - PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); - System.out.println("DO existe pour "+objectTopiaId); - _do = (<%=clazz.getName()%>JDODO) persistenceManager.getObjectById(objectTopiaId, false); - _do.setContext(getContext()); - } else { - _do = newDO(_to, pendingDOs); - } - return _do; - } - - public <%=clazz.getName()%>JDODO newDO(<%=clazz.getName()%>TO _to, HashMap pendingDOs) throws TopiaException { - <%=clazz.getName()%>JDODO _do = (<%=clazz.getName()%>JDODO) pendingDOs.get(_to); - if (_do == null) { - // Not found in pending created DOs, go and create a new <%=clazz.getName()%>JDODO - _do = (<%=clazz.getName()%>JDODO)getContext().createEntityDO(<%=clazz.getQualifiedName()%>.class); - pendingDOs.put(_to, _do); -}*/ - // Iterate on each attribute - for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - String attNameCap = Util.toUpperCaseFirstLetter(attribute.getName()); - if (! attribute.referenceClassifier()) { -/*{ - _do.set<%=attNameCap%>(_to.get<%=attNameCap%>()); -}*/ - } else { - ObjectModelClassifier classifier = - (ObjectModelClassifier) attribute.getClassifier(); -/*{ - { - PrivateTopiaPersistenceService ps = (PrivateTopiaPersistenceService) - getContext().getPersistenceService(<%=classifier.getQualifiedName()%>.class); -}*/ - if ((attribute.getMaxMultiplicity() > 1) - || (attribute.getMaxMultiplicity( ) == -1)) { -/*{ - //_do.set<%=attNameCap%>((<%=Util.getAttributeType(attribute)%>) ps.toDO(_to.get<%=attNameCap%>(), pendingDOs)); - } -}*/ - } else { -/*{ - _do.set<%=attNameCap%>((<%=classifier.getQualifiedName()%>)ps.toDO(_to.get<%=attNameCap%>(), pendingDOs)); - } -}*/ - } - - } - } -/*{ - PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); - Transaction transaction = persistenceManager.currentTransaction(); - transaction.begin(); - try { - persistenceManager.makePersistent(_do); - transaction.commit(); - } catch (Throwable eee) { - transaction.rollback(); - throw (new TopiaException("Cannot make persistent !", eee)); - } - Logger.getLogger(getClass().getName() + ".newDO").log(Level.INFO, - "in new DO, topiaID is "+_do._getTopiaId()); - } - return _do; - } - - /** - * Returns the updated TopiaEntity DataObject corresponding to the given TopiaEntity TransferObject. - * Update is made by applying changes made to the TopiaEntity TransferObject to the DataObject (thus making those change persistent). - * @param topiaEntityTO - the TopiaEntity TransferObject whose DataObject is wanted. - * @see topiaEntityTO - * @see topiaEntityDO - * - * @return the corresponding TopiaEntity DataObject. - *) - public TopiaEntityDO toUpdatedDO(TopiaEntity topiaEntityTO) throws TopiaException { - return this.toUpdatedDO((<%=clazz.getName()%>TO) topiaEntityTO); - } - - public <%=clazz.getName()%>JDODO toUpdatedDO(<%=clazz.getName()%>TO _to) throws TopiaException { - if (_to == null) return null; - <%=clazz.getName()%>JDODO _do = toDO(_to); -}*/ - // Iterate on each attribute - for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if (! attribute.referenceClassifier()) { -/*{ - _do.set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(_to.get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>()); -}*/ - } else { -/*{ - if (_to._get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>ReferenceLoaded()) { - if (_to.get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() == null) { - _do.set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(null); - } else { - // TODO Recherche par le context _do.set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=attribute.getType()%>DAO.getInstance().toUpdatedDO(<%=Util.toLowerCaseFirstLetter(clazz.getName())%>DTO.get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>())); - } - } -}*/ - } - } -/*{ - return _do; - } - } }*/ - } public String getFilenameForInterface(ObjectModelInterface interfacez) { @@ -357,56 +152,8 @@ // Consider only entities, return immediately if not an entity if (! Util.isEntity(interfacez)) return; - - // ------------- File Header - if (!"".equals(interfacez.getPackageName())) { -/*{ -package <%=Util.getParentPackageName(interfacez.getPackageName())%>.services.jdo; - -}*/ - } - - // ------------- Imports -/*{ -import org.codelutin.topia.jdo.AbstractTopiaJDOPersistenceService; -import org.codelutin.topia.PrivateTopiaPersistenceService; -import org.codelutin.topia.TopiaEntity; -import org.codelutin.topia.TopiaEntityTO; -import org.codelutin.topia.TopiaEntityDO; -import org.codelutin.topia.TopiaPersistenceService; -import org.codelutin.topia.TopiaException; -import <%=interfacez.getQualifiedName()%>; -import <%=Util.getParentPackageName(interfacez.getPackageName())+".services."+interfacez.getName()%>PersistenceService; -import <%=interfacez.getPackageName()+".persistence."+interfacez.getName()%>JDODO; -import <%=interfacez.getPackageName()+".transfer."+interfacez.getName()%>TO; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Collection; -import java.util.List; -import org.codelutin.topia.jdo.TopiaJDOPersistenceHelper; - -import javax.jdo.PersistenceManager; -import javax.jdo.Query; - -}*/ - + generateCommonStatement(output, interfacez); /*{ -public class <%=interfacez.getName()%>JDOPersistenceService extends AbstractTopiaJDOPersistenceService implements <%=interfacez.getName()%>PersistenceService, TopiaPersistenceService { - - public <%=interfacez.getName()%> makePersistent(<%=interfacez.getName()%> <%=Util.toLowerCaseFirstLetter(interfacez.getName())%>) throws TopiaException { - return (<%=interfacez.getName()%>) super.makePersistent(<%=Util.toLowerCaseFirstLetter(interfacez.getName())%>); - } - - /** - * Return entity Class managed by this service - *) - public Class getEntityClass(){ - return <%=interfacez.getName()%>.class; - } - - public <%=interfacez.getName()%> create<%=interfacez.getName()%>() throws TopiaException{ - return (<%=interfacez.getName()%>)super.create(); - } /** * Creates a transient tranferable TopiaEntity. @@ -416,87 +163,6 @@ public TopiaEntity create() throws TopiaException { throw new TopiaException("You can't create an instance of <%=interfacez.getName()%> as it is an interface"); } - - /** - * Updates that is make change on the given TopiaEntity persistent. - * @param topiaEntity - the TopiaEntity whose changes must be made persistent. - *) - public void update(<%=interfacez.getName()%> <%=Util.toLowerCaseFirstLetter(interfacez.getName())%>) throws TopiaException { - super.update(<%=Util.toLowerCaseFirstLetter(interfacez.getName())%>); - } - - /** - * Delete that is remove from persistence layer the given TopiaEntity. - * @param topiaEntity - the TopiaEntity to delete. - *) - public void delete(<%=interfacez.getName()%> <%=Util.toLowerCaseFirstLetter(interfacez.getName())%>) throws TopiaException { - super.delete(<%=Util.toLowerCaseFirstLetter(interfacez.getName())%>); - } - - /** - * Returns the TopiaEntity TransferObject corresponding to the given TopiaEntity DataObject. - * @param topiaEntityDO - the TopiaEntity DataObject whose TransferObject is wanted. - * @see TopiaEntityDO - * @see TopiaEntityTO - * - * @return the corresponding TopiaEntity TransferObject. - *) - public TopiaEntityTO toTO(TopiaEntity topiaEntityDO) throws TopiaException { - <%=interfacez.getName()%>TO _to = null; - try{ - // Warning : don't replace that for a Class.forName(...) has it does NOT behave the same way ! - AbstractTopiaJDOPersistenceService _doCRUD = (AbstractTopiaJDOPersistenceService) getContext().getService(getClass().forName(topiaEntityDO.getClass().getName()+"CRUD")); - _to = (<%=interfacez.getName()%>TO) _doCRUD.toTO(topiaEntityDO); - } catch (Exception e) { - //TODO FAIRE des LOGS - e.printStackTrace(); - } - return _to; - } - - /** - * Returns the TopiaEntity DataObject corresponding to the given TopiaEntity TransferObject. - * @param topiaEntityTO - the TopiaEntity TransferObject whose DataObject is wanted. - * @see topiaEntityTO - * @see topiaEntityDO - * - * @return the corresponding TopiaEntity DataObject. - *) - public TopiaEntityDO toDO(TopiaEntity topiaEntityTO) throws TopiaException { - <%=interfacez.getName()%>JDODO _do = null; - try{ - // Warning : don't replace that for a Class.forName(...) has it does NOT behave the same way ! - AbstractTopiaJDOPersistenceService _toCRUD = (AbstractTopiaJDOPersistenceService) getContext().getService(getClass().forName(topiaEntityTO.getClass().getName()+"CRUD")); - _do = (<%=interfacez.getName()%>JDODO) _toCRUD.toDO(topiaEntityTO); - } catch (Exception e) { - //TODO FAIRE des LOGS - e.printStackTrace(); - } - return _do; - } - - /** - * Returns the updated TopiaEntity DataObject corresponding to the given TopiaEntity TransferObject. - * Update is made by applying changes made to the TopiaEntity TransferObject to the DataObject (thus making those change persistent). - * @param topiaEntityTO - the TopiaEntity TransferObject whose DataObject is wanted. - * @see topiaEntityTO - * @see topiaEntityDO - * - * @return the corresponding TopiaEntity DataObject. - *) - public TopiaEntityDO toUpdatedDO(TopiaEntity topiaEntityTO) throws TopiaException { - <%=interfacez.getName()%>JDODO _do = null; - try{ - // Warning : don't replace that for a Class.forName(...) has it does NOT behave the same way ! - AbstractTopiaJDOPersistenceService _toCRUD = (AbstractTopiaJDOPersistenceService) getContext().getService(getClass().forName(topiaEntityTO.getClass().getName()+"CRUD")); - _do = (<%=interfacez.getName()%>JDODO) _toCRUD.toUpdatedDO(topiaEntityTO); - } catch (Exception e) { - //TODO FAIRE des LOGS - e.printStackTrace(); - } - return _do; - } - } }*/