Index: topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.4 topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.5 --- topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.4 Fri May 28 15:40:16 2004 +++ topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java Wed Jun 2 09:33:08 2004 @@ -23,10 +23,10 @@ * * @author Cédric Pineau * Copyright Code Lutin -* @version $Revision: 1.4 $ +* @version $Revision: 1.5 $ * -* Last update : $Date: 2004/05/28 15:40:16 $ -* by : $Author: pineau $ +* Last update : $Date: 2004/06/02 09:33:08 $ +* by : $Author: bpoussin $ */ package org.codelutin.topia.generators.jdo; @@ -42,41 +42,35 @@ import org.codelutin.generator.models.object.ObjectModelInterface; import org.codelutin.topia.Util; -/** - * @author cedric - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ 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 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 generateFromClass(Writer output, ObjectModelClass clazz) + throws IOException { - // Consider only entities, return immediately if not an entity - if(! Util.isEntity(clazz)) return; + // Consider only entities, return immediately if not an entity + if(! Util.isEntity(clazz)) return; - // ------------- File Header - if (!"".equals(clazz.getPackageName())) { + // ------------- File Header + if (!"".equals(clazz.getPackageName())) { /*{ package <%=Util.getParentPackageName(clazz.getPackageName())%>.services.jdo; }*/ - } + } - // ------------- Imports + // ------------- Imports /*{ import org.codelutin.topia.jdo.AbstractTopiaJDOPersistenceService; +import org.codelutin.topia.TopiaQuery; import org.codelutin.topia.TopiaEntity; import org.codelutin.topia.TopiaEntityTO; import org.codelutin.topia.TopiaEntityDO; import org.codelutin.topia.TopiaPersistenceService; -import org.codelutin.topia.TopiaQuery; import org.codelutin.topia.TopiaException; import org.codelutin.topia.Cache; import <%=clazz.getQualifiedName()%>; @@ -99,117 +93,44 @@ /*{ public class <%=clazz.getName()%>JDOPersistenceService extends AbstractTopiaJDOPersistenceService implements <%=clazz.getName()%>PersistenceService, TopiaPersistenceService { - /** - * Creates a transient tranferable <%=clazz.getName()%>. - * - * @return the transient transferable <%=clazz.getName()%>. - *) - public final <%=clazz.getName()%> create() throws TopiaException { - return (<%=clazz.getName()%>) super.create(<%=clazz.getName()%>.class); - } + /** + * Return entity Class managed by this service + *) + public Class getEntityClass(){ + 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())%>); + return (<%=clazz.getName()%>) super.makePersistent(<%=Util.toLowerCaseFirstLetter(clazz.getName())%>); } - - 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(); + + 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()) { /*{, }*/ } - } -/*{ -) throws TopiaException { - PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); - Transaction transaction = persistenceManager.currentTransaction(); - - Query q = persistenceManager.newQuery(<%=clazz.getName()%>JDODO.class, "}*/ - // Iterate on each primary key attribute - for (Iterator i =Util.getPrimaryKeyAttributes(clazz).iterator(); i.hasNext();) { - ObjectModelAttribute primaryKeyAttribute = (ObjectModelAttribute) i.next(); -/*{<%=primaryKeyAttribute.getName()%> == <%=primaryKeyAttribute.getName()%>}*/ if (i.hasNext()) { /*{, }*/ } } -/*{"); - q.declareParameters("}*/ - // Iterate on each primary key attribute - for (Iterator i = Util.getPrimaryKeyAttributes(clazz).iterator(); i.hasNext();) { - ObjectModelAttribute primaryKeyAttribute = (ObjectModelAttribute) i.next(); -/*{<%=primaryKeyAttribute.getType()%> <%=primaryKeyAttribute.getName()%>}*/ - if (i.hasNext()) { /*{, }*/ } +/*{ +) throws TopiaException {}*/ + String filter = ""; + String args = ""; + for (Iterator i = Util.getPrimaryKeyAttributes(clazz).iterator(); i.hasNext();) { + ObjectModelAttribute key = (ObjectModelAttribute) i.next(); + filter += key.getName() + " == ?"; + args += ".addArg(" + key.getName() + ")"; + if(i.hasNext()){ + filter += " && "; + } } -/*{"); - Collection result = (Collection) q.execute(}*/ - // Iterate on each primary key attribute - for (Iterator i = Util.getPrimaryKeyAttributes(clazz).iterator(); i.hasNext();) { - ObjectModelAttribute primaryKeyAttribute = (ObjectModelAttribute) i.next(); -/*{<%=primaryKeyAttribute.getName()%>}*/ - if (i.hasNext()) { /*{, }*/ } +/*{ + TopiaQuery query = new TopiaQuery("<%=filter%>")<%=args%>; + Collection result = find(query); + if(result.size() == 0){ + throw new TopiaException("Object can't be find"); } -/*{); - <%=clazz.getName()%>JDODO _do = (<%=clazz.getName()%>JDODO) result.iterator().next(); - - return toTO(_do); - } - - /** - * Returns all TopiaEntity related to this CRUD as DataObjects. - * If topiaQuery is null, returns all topiaEntity DataObjects related to this CRUD. - * @param topiaQuery - the TopiaQuery to process. - * @see TopiaQuery - * @see <%=clazz.getName()%>DO - * - * @return a List containing all TopiaEntity DataObjects related to this CRUD. - *) - public Collection findDO(TopiaQuery topiaQuery) throws TopiaException { - // TODO : what is a TopiaQuery benj ;-) ? - // Warning : query may be null ! - PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); - Query query = persistenceManager.newQuery(<%=clazz.getName()%>JDODO.class); - return (Collection) query.execute(); - } - - /** - * Returns all TopiaEntity related to this CRUD according to the given TopiaQuery as TransferObjects. - * If topiaQuery is null, acts as findAll(). - * @param topiaQuery - the TopiaQuery to process. - * @see TopiaQuery - * @see #findAll() - * - * @return a List containing all TopiaEntity TranferObjects related to this CRUD according to the given TopiaQuery. - *) - public List find(TopiaQuery topiaQuery) throws TopiaException { - ArrayList result = new ArrayList(); - for (Iterator i = findDO(topiaQuery).iterator(); i.hasNext();) { - <%=clazz.getName()%>JDODO _do = (<%=clazz.getName()%>JDODO) i.next(); - _do.setContext(getContext()); - result.add(toTO(_do)); - } - return result; - } - - /** - * Returns the number of TopiaEntity related to this CRUD. - * - * @return the number of TopiaEntity related to this CRUD. - *) - public int size() throws TopiaException { - return findDO(null).size(); - } - - /** - * Returns the number of TopiaEntity related to this CRUD according to the given TopiaQuery. - * If topiaQuery is null, acts as size(). - * @param topiaQuery - the TopiaQuery to process. - * @see TopiaQuery - * @see #size() - * - * @return the number of TopiaEntity related to this CRUD according to the given TopiaQuery. - *) - public int size(TopiaQuery query) throws TopiaException { - return findDO(query).size(); + return (<%=clazz.getName()%>)result.iterator().next(); } /** @@ -217,7 +138,7 @@ * @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())%>); + super.update(<%=Util.toLowerCaseFirstLetter(clazz.getName())%>); } /** @@ -225,39 +146,39 @@ * @param topiaEntity - the TopiaEntity to delete. *) public void delete(<%=clazz.getName()%> <%=Util.toLowerCaseFirstLetter(clazz.getName())%>) throws TopiaException { - super.delete(<%=Util.toLowerCaseFirstLetter(clazz.getName())%>); + 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(TopiaEntityDO topiaEntityDO) throws TopiaException { - return toTO((<%=clazz.getName()%>JDODO) topiaEntityDO); - } + /** + * 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(TopiaEntityDO 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 + // 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()) { + // 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; }*/ @@ -268,50 +189,50 @@ object = i.next(); if (object != null) _topiaIds.add(((<%=attribute.getType()%>) object)._getTopiaId()); } - _to._<%=attribute.getName()%> = _topiaIds; + _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(TopiaEntityTO topiaEntityTO) throws TopiaException { - return this.toDO((<%=clazz.getName()%>TO) topiaEntityTO); - } - + /** + * 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(TopiaEntityTO topiaEntityTO) throws TopiaException { + return this.toDO((<%=clazz.getName()%>TO) topiaEntityTO); + } + 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; + <%=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); + 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 { + } else { _do = newDO(_to, pendingDOs); } return _do; @@ -319,40 +240,40 @@ 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 + if (_do == null) { + // Not found in pending created DOs, go and create a new <%=clazz.getName()%>JDODO _do = new <%=clazz.getName()%>JDODO(); _do.setContext(getContext()); pendingDOs.put(_to, _do); }*/ // Iterate on each attribute - for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + 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 { - ObjectModelClassifier classifier = (ObjectModelClassifier) attribute.getClassifier(); + ObjectModelClassifier classifier = (ObjectModelClassifier) attribute.getClassifier(); /*{ - { <%=Util.getParentPackageName(classifier.getPackageName())+".services.jdo."+classifier.getName()%>JDOPersistenceService <%=Util.toUpperCaseFirstLetter(classifier.getName())%>PersistenceService = (<%=Util.getParentPackageName(classifier.getPackageName())+".services.jdo."+classifier.getName()%>JDOPersistenceService) getContext().getToto(<%=Util.getParentPackageName(classifier.getPackageName())+".services."+classifier.getName()%>PersistenceService.class); -}*/ - if ((attribute.getMaxMultiplicity() > 1) || (attribute.getMaxMultiplicity( )== -1)) { + { <%=Util.getParentPackageName(classifier.getPackageName())+".services.jdo."+classifier.getName()%>JDOPersistenceService <%=Util.toUpperCaseFirstLetter(classifier.getName())%>PersistenceService = (<%=Util.getParentPackageName(classifier.getPackageName())+".services.jdo."+classifier.getName()%>JDOPersistenceService) getContext().getToto(<%=Util.getParentPackageName(classifier.getPackageName())+".services."+classifier.getName()%>PersistenceService.class); +}*/ + if ((attribute.getMaxMultiplicity() > 1) || (attribute.getMaxMultiplicity( )== -1)) { /*{ - //_do.set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>((<%=Util.getAttributeType(attribute)%>) <%=Util.toUpperCaseFirstLetter(classifier.getName())%>PersistenceService.toDO((<%=Util.getAttributeType(attribute)%>) _to.get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(), pendingDOs)); + //_do.set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>((<%=Util.getAttributeType(attribute)%>) <%=Util.toUpperCaseFirstLetter(classifier.getName())%>PersistenceService.toDO((<%=Util.getAttributeType(attribute)%>) _to.get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(), pendingDOs)); } -}*/ - } else { +}*/ + } else { /*{ - _do.set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>((<%=classifier.getPackageName()%>.persistence.<%=classifier.getName()%>JDODO) <%=Util.toUpperCaseFirstLetter(classifier.getName())%>PersistenceService.toDO((<%=classifier.getPackageName()%>.transfer.<%=classifier.getName()%>TO) _to.get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(), pendingDOs)); + _do.set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>((<%=classifier.getPackageName()%>.persistence.<%=classifier.getName()%>JDODO) <%=Util.toUpperCaseFirstLetter(classifier.getName())%>PersistenceService.toDO((<%=classifier.getPackageName()%>.transfer.<%=classifier.getName()%>TO) _to.get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(), pendingDOs)); } -}*/ - } +}*/ + } } - } + } /*{ - PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); + PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); Transaction transaction = persistenceManager.currentTransaction(); transaction.begin(); try { @@ -361,33 +282,33 @@ transaction.rollback(); throw (new TopiaException("Cannot make persistent !",t)); } - transaction.commit(); - System.out.println("in new DO, topiaID is "+_do._getTopiaId()); + transaction.commit(); + System.out.println("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(TopiaEntityTO topiaEntityTO) throws TopiaException { - return this.toUpdatedDO((<%=clazz.getName()%>TO) topiaEntityTO); - } + /** + * 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(TopiaEntityTO 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()) { + 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())%>()); }*/ @@ -406,40 +327,39 @@ /*{ return _do; } - + } }*/ - } + } + + public String getFilenameForInterface(ObjectModelInterface interfacez) { + return (Util.getParentPackageName(interfacez.getPackageName())+".services.jdo.").replace('.', File.separatorChar)+interfacez.getName()+ "JDOPersistenceService.java"; + } - public String getFilenameForInterface(ObjectModelInterface interfacez) { - return (Util.getParentPackageName(interfacez.getPackageName())+".services.jdo.").replace('.', File.separatorChar)+interfacez.getName()+ "JDOPersistenceService.java"; - } - - public void generateFromInterface( - Writer output, - ObjectModelInterface interfacez) - throws IOException { + public void generateFromInterface( + Writer output, + ObjectModelInterface interfacez) + throws IOException { - // Consider only entities, return immediately if not an entity - if (! Util.isEntity(interfacez)) return; + // Consider only entities, return immediately if not an entity + if (! Util.isEntity(interfacez)) return; - // ------------- File Header - if (!"".equals(interfacez.getPackageName())) { + // ------------- File Header + if (!"".equals(interfacez.getPackageName())) { /*{ package <%=Util.getParentPackageName(interfacez.getPackageName())%>.services.jdo; }*/ - } + } - // ------------- Imports + // ------------- Imports /*{ import org.codelutin.topia.jdo.AbstractTopiaJDOPersistenceService; import org.codelutin.topia.TopiaEntity; import org.codelutin.topia.TopiaEntityTO; import org.codelutin.topia.TopiaEntityDO; import org.codelutin.topia.TopiaPersistenceService; -import org.codelutin.topia.TopiaQuery; import org.codelutin.topia.TopiaException; import <%=interfacez.getQualifiedName()%>; import <%=Util.getParentPackageName(interfacez.getPackageName())+".services."+interfacez.getName()%>PersistenceService; @@ -460,104 +380,55 @@ 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 (<%=interfacez.getName()%>) super.makePersistent(<%=Util.toLowerCaseFirstLetter(interfacez.getName())%>); + } + + /** + * Return entity Class managed by this service + *) + public Class getEntityClass(){ + return <%=interfacez.getName()%>.class; + } + + /** + * Creates a transient tranferable TopiaEntity. + * + * @return the transient transferable TopiaEntity. + *) + public <%=interfacez.getName()%> 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())%>); } - /** - * Creates a transient tranferable TopiaEntity. - * - * @return the transient transferable TopiaEntity. - *) - public <%=interfacez.getName()%> create() throws TopiaException { - throw new TopiaException("You can't create an instance of <%=interfacez.getName()%> as it is an interface"); - } - - /** - * Returns all TopiaEntity related to this CRUD as DataObjects. - * If topiaQuery is null, returns all topiaEntity DataObjects related to this CRUD. - * @param topiaQuery - the TopiaQuery to process. - * @see TopiaQuery - * @see <%=interfacez.getName()%>DO - * - * @return a List containing all TopiaEntity DataObjects related to this CRUD. - *) - public Collection findDO(TopiaQuery topiaQuery) throws TopiaException { - // TODO : what is a TopiaQuery benj ;-) ? - // Warning : query may be null ! - PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); - Query query = persistenceManager.newQuery(<%=interfacez.getName()%>JDODO.class); - return (Collection) query.execute(); - } - - /** - * Returns all TopiaEntity related to this CRUD according to the given TopiaQuery as TransferObjects. - * If topiaQuery is null, acts as findAll(). - * @param topiaQuery - the TopiaQuery to process. - * @see TopiaQuery - * @see #findAll() - * - * @return a List containing all TopiaEntity TranferObjects related to this CRUD according to the given TopiaQuery. - *) - public List find(TopiaQuery topiaQuery) throws TopiaException { - ArrayList result = new ArrayList(); - for (Iterator i = findDO(topiaQuery).iterator(); i.hasNext();) { - result.add(toTO((<%=interfacez.getName()%>JDODO) i.next())); - } - return result; - } - - /** - * Returns the number of TopiaEntity related to this CRUD. - * - * @return the number of TopiaEntity related to this CRUD. - *) - public int size() throws TopiaException { - return findDO(null).size(); - } - - /** - * Returns the number of TopiaEntity related to this CRUD according to the given TopiaQuery. - * If topiaQuery is null, acts as size(). - * @param topiaQuery - the TopiaQuery to process. - * @see TopiaQuery - * @see #size() - * - * @return the number of TopiaEntity related to this CRUD according to the given TopiaQuery. - *) - public int size(TopiaQuery query) throws TopiaException { - return findDO(query).size(); - } - - /** - * 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(TopiaEntityDO topiaEntityDO) throws TopiaException { - <%=interfacez.getName()%>TO _to = null; + /** + * 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(TopiaEntityDO 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); + _to = (<%=interfacez.getName()%>TO) _doCRUD.toTO(topiaEntityDO); } catch (Exception e) { //TODO FAIRE des LOGS e.printStackTrace(); @@ -565,52 +436,52 @@ 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(TopiaEntityTO topiaEntityTO) throws TopiaException { - <%=interfacez.getName()%>JDODO _do = null; + /** + * 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(TopiaEntityTO 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); + _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(TopiaEntityTO topiaEntityTO) throws TopiaException { - <%=interfacez.getName()%>JDODO _do = null; + + /** + * 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(TopiaEntityTO 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); + _do = (<%=interfacez.getName()%>JDODO) _toCRUD.toUpdatedDO(topiaEntityTO); } catch (Exception e) { //TODO FAIRE des LOGS e.printStackTrace(); } return _do; - } - + } + } }*/ - } + } }