Index: topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java diff -u topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java:1.1 topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java:1.2 --- topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java:1.1 Fri Jun 4 18:43:54 2004 +++ topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java Wed Jun 16 09:41:26 2004 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * - * Mise a jour: $Date: 2004/06/04 18:43:54 $ + * Mise a jour: $Date: 2004/06/16 09:41:26 $ * par : $Author: bpoussin $ */ @@ -41,17 +41,13 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.HashMap; +import java.util.Date; public abstract class AbstractTopiaPersistenceService extends AbstractTopiaService implements TopiaPersistenceService, PrivateTopiaPersistenceService { // AbstractTopiaPersistenceService ListenerSet listeners = new ListenerSet(); - public TopiaEntityDO toDO(TopiaEntity topiaEntityTO) - throws TopiaException{ - return toDO(topiaEntityTO, new HashMap()); - } - /** * Adds a new TopiaEntityListener to the subscribers list. * @param topiaEntityListener - the TopiaEntityListener to add to the @@ -70,24 +66,74 @@ getContext().getListeners().remove(this, l); } -// /** -// * Creates a transient tranferable TopiaEntity. -// * -// * @return the transient transferable TopiaEntity. -// */ -// public TopiaEntity create(Class topiaEntityClass) throws TopiaException { -// return getContext().createEntity(topiaEntityClass); -// } - /** * Creates a transient tranferable TopiaEntity. * * @return the transient transferable TopiaEntity. */ - public TopiaEntity create() throws TopiaException { - return getContext().createEntity(getEntityClass()); + public TopiaEntityTO create() throws TopiaException { + TopiaEntityTO result = + (TopiaEntityTO)getContext().createEntity(getEntityClass()); + Date date = new Date(); + result.set_creationDate_(date); + result.set_lastUpdateDate_(date); + result.set_version_("0"); + return result; } + /** + * 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 _do) throws TopiaException { + TopiaEntityTO _to = getContext().getCache(_do); + if (_to == null) { + // Not found in cache, let's go and build a TO for this DO + _to = create(); + _to.set_allProperties_(_do); + + getContext().putCache(_to); + } + return _to; + } + + + + /** + * Recherche tous les entities possible de la liste d'id passé en argument + * Si un id dans la liste ne correspond pas a un objet, il est tout + * simplement passé. Pour être sur d'avoir bien tous les objets + * correspondants aux Ids, il faut utiliser la méthode findByTopiaId qui ne + * prend qu'un Id en argument. + * On a donc len(ids) >= len(result) + */ + public List findByTopiaId(List ids) throws TopiaException{ + return find(new TopiaQuery("_topiaId_ in ?").addArg(ids)); + } + + public TopiaEntityTO findByTopiaId(Object id) throws TopiaException { + return toTO(findDOByTopiaId(id)); + } + + /** + * Framework method + */ + public TopiaEntityDO findDOByTopiaId(Object id) throws TopiaException { + Collection result = findDO(new TopiaQuery("_topiaId_ = ?").addArg(id)); + if(result == null || result.size() == 0){ + throw new TopiaException("Object can't be found for id: " + id); + } + if(result.size() > 1){ + throw new TopiaException("Too much object for this id: " + id); + } + TopiaEntityDO resultEntity = (TopiaEntityDO)result.iterator().next(); + resultEntity.setContext(getContext()); + return resultEntity; + } /** * Returns all TopiaEntity related to this CRUD. Index: topia/src/java/org/codelutin/topia/Cache.java diff -u topia/src/java/org/codelutin/topia/Cache.java:1.1 topia/src/java/org/codelutin/topia/Cache.java:1.2 --- topia/src/java/org/codelutin/topia/Cache.java:1.1 Thu Apr 29 16:13:21 2004 +++ topia/src/java/org/codelutin/topia/Cache.java Wed Jun 16 09:41:26 2004 @@ -1,25 +1,13 @@ /* * Created on Apr 29, 2004 * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments */ package org.codelutin.topia; import java.util.HashMap; -/** - * @author cedric - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ public class Cache extends HashMap { - protected static Cache _instance = new Cache(); - - public static Cache getInstance() { - return _instance; - } + // TODO surcharger get et put pour que les objets soit des softReference } Index: topia/src/java/org/codelutin/topia/PrivateTopiaPersistenceService.java diff -u topia/src/java/org/codelutin/topia/PrivateTopiaPersistenceService.java:1.1 topia/src/java/org/codelutin/topia/PrivateTopiaPersistenceService.java:1.2 --- topia/src/java/org/codelutin/topia/PrivateTopiaPersistenceService.java:1.1 Fri Jun 4 18:43:54 2004 +++ topia/src/java/org/codelutin/topia/PrivateTopiaPersistenceService.java Wed Jun 16 09:41:26 2004 @@ -23,15 +23,16 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * - * Mise a jour: $Date: 2004/06/04 18:43:54 $ + * Mise a jour: $Date: 2004/06/16 09:41:26 $ * par : $Author: bpoussin $ */ package org.codelutin.topia; import java.util.HashMap; +import java.util.List; /** * Regroupement de tout les méthodes du framework pour les services de @@ -42,12 +43,14 @@ // pas besoin de donner le type exacte (DO ou TO) TopiaEntity suffit car // la première chose que l'on fait est un cast dans l'implantation. // et ces méthodes ne doivent être utilisé que par le framework - public TopiaEntityTO toTO(TopiaEntity topiaEntityDO) - throws TopiaException; - public TopiaEntityDO toDO(TopiaEntity topiaEntityTO, HashMap pendingDOs) - throws TopiaException; - public TopiaEntityDO toUpdatedDO(TopiaEntity topiaEntityTO) - throws TopiaException; + public TopiaEntityTO toTO(TopiaEntity _do) throws TopiaException; + public TopiaEntityDO toDO(TopiaEntity _to) throws TopiaException; + public TopiaEntityDO findDOByTopiaId(Object id) throws TopiaException; + public TopiaEntityTO findByTopiaId(Object id) throws TopiaException; + /** + * Recherche tous les objets correspondant à une liste d'Id + */ + public List findByTopiaId(List id) throws TopiaException; } // PrivateTopiaPersistenceService Index: topia/src/java/org/codelutin/topia/TopiaContext.java diff -u topia/src/java/org/codelutin/topia/TopiaContext.java:1.24 topia/src/java/org/codelutin/topia/TopiaContext.java:1.25 --- topia/src/java/org/codelutin/topia/TopiaContext.java:1.24 Fri Jun 4 18:43:54 2004 +++ topia/src/java/org/codelutin/topia/TopiaContext.java Wed Jun 16 09:41:26 2004 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.24 $ + * @version $Revision: 1.25 $ * - * Mise a jour: $Date: 2004/06/04 18:43:54 $ + * Mise a jour: $Date: 2004/06/16 09:41:26 $ * par : $Author: bpoussin $ */ @@ -67,6 +67,7 @@ /** Static context */ protected static HashMap contexts = new HashMap(); protected TopiaPersistenceHelper persistenceHelper = null; + protected Cache cache = new Cache(); public static TopiaContext getContext() throws TopiaException { return getContext(((Properties)null)); @@ -369,6 +370,33 @@ proxiedObjects.put(clazz, result); } return result; + } + + /** + * Methode du framework qui permet d'ajouter des enities dans le cache + */ + public void putCache(TopiaEntityTO entity) throws TopiaException { + cache.put(entity.get_topiaId_(), entity); + } + + /** + * Methode du framework qui permet de retrouver une enity dans le cache + * @param entity l'entity DO dont on souhaite le TO + * @return l'entity ayant le meme id que l'entity passé en paramètre, ou + * null si l'entity n'est pas dans le cache + */ + protected TopiaEntityTO getCache(TopiaEntity entity) throws TopiaException { + return (TopiaEntityTO)cache.get(entity.get_topiaId_()); + } + + /** + * Methode du framework qui permet de retrouver une enity dans le cache + * @param id l'id de l'objet a rechercher + * @return l'entity ayant l'id passé en paramètre, ou null si l'entity n'est + * pas dans le cache + */ + protected TopiaEntityTO getCache(Object id){ + return (TopiaEntityTO)cache.get(id); } /** Index: topia/src/java/org/codelutin/topia/TopiaEntity.java diff -u topia/src/java/org/codelutin/topia/TopiaEntity.java:1.10 topia/src/java/org/codelutin/topia/TopiaEntity.java:1.11 --- topia/src/java/org/codelutin/topia/TopiaEntity.java:1.10 Fri Jun 4 18:43:54 2004 +++ topia/src/java/org/codelutin/topia/TopiaEntity.java Wed Jun 16 09:41:26 2004 @@ -23,9 +23,9 @@ * * @author Cédric Pineau * Copyright Code Lutin -* @version $Revision: 1.10 $ +* @version $Revision: 1.11 $ * -* 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; @@ -35,22 +35,10 @@ */ public interface TopiaEntity extends TopiaElement { // TopiaEntity - /** - * Permet d'avoir la class du CRUD a utiliser pour cet objet Entity - * @return la classe de l'interface du CRUD utiliser par le context pour - * gérer cette classe. - * @see org.codelutin.topia.TopiaContext#getService - */ - // TODO public Class getCRUDClass(); - - public Object _getTopiaId() throws TopiaException; - - public String _getVersion() throws TopiaException; - - public java.util.Date _getCreationDate() throws TopiaException; - - public java.util.Date _getLastUpdateDate() throws TopiaException; - - public TopiaUser _getLastUpdateUser() throws TopiaException; + public Object get_topiaId_() throws TopiaException; + public String get_version_() throws TopiaException; + public java.util.Date get_creationDate_() throws TopiaException; + public java.util.Date get_lastUpdateDate_() throws TopiaException; + public TopiaUser get_lastUpdateUser_() throws TopiaException; } // TopiaEntity Index: topia/src/java/org/codelutin/topia/TopiaEntityDO.java diff -u topia/src/java/org/codelutin/topia/TopiaEntityDO.java:1.5 topia/src/java/org/codelutin/topia/TopiaEntityDO.java:1.6 --- topia/src/java/org/codelutin/topia/TopiaEntityDO.java:1.5 Mon May 10 14:38:12 2004 +++ topia/src/java/org/codelutin/topia/TopiaEntityDO.java Wed Jun 16 09:41:26 2004 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Mise a jour: $Date: 2004/05/10 14:38:12 $ - * par : $Author: pineau $ + * Mise a jour: $Date: 2004/06/16 09:41:26 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia; @@ -36,14 +36,6 @@ * Interface que doivent implanter tous les objets de type DO (Data Object) qui * sont les objets r?ellement stock?. */ -public interface TopiaEntityDO extends TopiaEntity { - - public void _setVersion(String version) throws TopiaException; - - public void _setCreationDate(java.util.Date creationDate) throws TopiaException; - - public void _setLastUpdateDate(java.util.Date lastUpdateDate) throws TopiaException; - - public void _setLastUpdateUser(TopiaUser lastUpdateUser) throws TopiaException; +public interface TopiaEntityDO extends TopiaEntity, PrivateTopiaEntity { } Index: topia/src/java/org/codelutin/topia/TopiaEntityTO.java diff -u topia/src/java/org/codelutin/topia/TopiaEntityTO.java:1.5 topia/src/java/org/codelutin/topia/TopiaEntityTO.java:1.6 --- topia/src/java/org/codelutin/topia/TopiaEntityTO.java:1.5 Mon May 10 14:38:12 2004 +++ topia/src/java/org/codelutin/topia/TopiaEntityTO.java Wed Jun 16 09:41:26 2004 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Mise a jour: $Date: 2004/05/10 14:38:12 $ - * par : $Author: pineau $ + * Mise a jour: $Date: 2004/06/16 09:41:26 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia; @@ -36,19 +36,11 @@ /** * TO (Transferata Object) * Interface que doivent implanter tous les objets de type TO (Transfer Object) -* qui sont les objects qui servent r?ellemnt dans l'application. Ces objets -* doivent ?tre serializable +* qui sont les objects qui servent réellemnt dans l'application. Ces objets +* doivent être serializable */ -public interface TopiaEntityTO extends TopiaEntity, Serializable { // TopiaEntityTO +public interface TopiaEntityTO extends TopiaEntity, PrivateTopiaEntity, Serializable { // TopiaEntityTO - public void _setTopiaId(Object topiaId) throws TopiaException; - - public void _setVersion(String version) throws TopiaException; - - public void _setCreationDate(java.util.Date creationDate) throws TopiaException; - - public void _setLastUpdateDate(java.util.Date lastUpdateDate) throws TopiaException; - - public void _setLastUpdateUser(TopiaUser lastUpdateUser) throws TopiaException; + public void set_topiaId_(Object topiaId) throws TopiaException; } // TopiaEntityTO Index: topia/src/java/org/codelutin/topia/TopiaPersistenceService.java diff -u topia/src/java/org/codelutin/topia/TopiaPersistenceService.java:1.4 topia/src/java/org/codelutin/topia/TopiaPersistenceService.java:1.5 --- topia/src/java/org/codelutin/topia/TopiaPersistenceService.java:1.4 Wed Jun 2 09:33:08 2004 +++ topia/src/java/org/codelutin/topia/TopiaPersistenceService.java Wed Jun 16 09:41:26 2004 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Mise a jour: $Date: 2004/06/02 09:33:08 $ + * Mise a jour: $Date: 2004/06/16 09:41:26 $ * par : $Author: bpoussin $ */ @@ -56,7 +56,7 @@ * * @return the transient transferable TopiaEntity. */ - public TopiaEntity create() throws TopiaException; + public TopiaEntityTO create() throws TopiaException; /** * Creates that is make persistent the given TopiaEntity. Index: topia/src/java/org/codelutin/topia/Util.java diff -u topia/src/java/org/codelutin/topia/Util.java:1.5 topia/src/java/org/codelutin/topia/Util.java:1.6 --- topia/src/java/org/codelutin/topia/Util.java:1.5 Wed May 19 10:33:03 2004 +++ topia/src/java/org/codelutin/topia/Util.java Wed Jun 16 09:41:26 2004 @@ -23,10 +23,10 @@ * * @author Cédric Pineau * Copyright Code Lutin -* @version $Revision: 1.5 $ +* @version $Revision: 1.6 $ * -* Last update : $Date: 2004/05/19 10:33:03 $ -* by : $Author: pineau $ +* Last update : $Date: 2004/06/16 09:41:26 $ +* by : $Author: bpoussin $ */ package org.codelutin.topia; @@ -135,6 +135,15 @@ return "true".equals(value); } + public static boolean isDerived(ObjectModelClass clazz){ + for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if (isDerived(attribute)) { + return true; + } + } + return false; + } /** * Returns the creation pattern for this auto valued attribute. @@ -182,16 +191,16 @@ return "true".equals(value); } - /** - * Returns a TopiaEntityTO from a TopiaEntityTO or a TopiaEntityTOProxy. - * - * @return a TopiaEntityTO object if possible. - */ - public static TopiaEntityTO toTO(TopiaEntity entity) throws TopiaException { - if (! (entity instanceof TopiaEntityTO)) { - throw new TopiaException("Can't cast "+entity+" to a TopiaEntityTO"); - } - return (TopiaEntityTO) entity; - } + /** + * Returns a TopiaEntityTO from a TopiaEntityTO or a TopiaEntityTOProxy. + * + * @return a TopiaEntityTO object if possible. + */ + public static TopiaEntityTO toTO(TopiaEntity entity) throws TopiaException { + if (! (entity instanceof TopiaEntityTO)) { + throw new TopiaException("Can't cast "+entity+" to a TopiaEntityTO"); + } + return (TopiaEntityTO) entity; + } } Index: topia/src/java/org/codelutin/topia/PrivateTopiaEntity.java diff -u /dev/null topia/src/java/org/codelutin/topia/PrivateTopiaEntity.java:1.1 --- /dev/null Wed Jun 16 09:41:32 2004 +++ topia/src/java/org/codelutin/topia/PrivateTopiaEntity.java Wed Jun 16 09:41:26 2004 @@ -0,0 +1,53 @@ +/* *##% + * 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. + *##%*/ + +/* * + * PrivateTopiaEntity.java + * + * Created: 8 juin 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/06/16 09:41:26 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia; + +/** +* Methode utilisée par le framework, elles se retrouvent sur les TO et les DO +*/ +public interface PrivateTopiaEntity { // PrivateTopiaEntity + + public void set_version_(String version) throws TopiaException; + public void set_creationDate_(java.util.Date creationDate) throws TopiaException; + public void set_lastUpdateDate_(java.util.Date lastUpdateDate) throws TopiaException; + public void set_lastUpdateUser_(TopiaUser lastUpdateUser) throws TopiaException; + + /** + * Permet de modifier toutes les proprietes de l'objet, Id compris en + * copiant les informations de l'entity passé en paramètre. + * @param entity une entity respectant l'interface de l'objet ou un enfant + * de cette interface. + */ + public void set_allProperties_(TopiaEntity enity) throws TopiaException; + +} // PrivateTopiaEntity +