Index: topia/src/java/org/codelutin/topia/AbstractTopiaEntity.java diff -u topia/src/java/org/codelutin/topia/AbstractTopiaEntity.java:1.1 topia/src/java/org/codelutin/topia/AbstractTopiaEntity.java:1.2 --- topia/src/java/org/codelutin/topia/AbstractTopiaEntity.java:1.1 Wed May 19 10:33:03 2004 +++ topia/src/java/org/codelutin/topia/AbstractTopiaEntity.java Thu Jul 15 13:13:12 2004 @@ -1,38 +1,119 @@ -/* - * Created on May 20, 2004 +/* *##% + * Copyright (C) 2002, 2003 Code Lutin * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.codelutin.topia; - + * 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. + *##%*/ -/** - * @author cedric +/* * + * AbstractTopiaEntity.java * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.2 $ + * + * Mise a jour: $Date: 2004/07/15 13:13:12 $ + * par : $Author: bpoussin $ */ -public abstract class AbstractTopiaEntity implements TopiaEntity { - protected TopiaContext topiaContext; +package org.codelutin.topia; + +import java.util.Date; +import org.codelutin.util.VersionNumberUtil; + +public abstract class AbstractTopiaEntity extends AbstractTopiaElement implements TopiaEntity { // AbstractTopiaEntity - /** - * Sets current context. Used by the Topia environment to specify the context to de used. - * @param : context - the context to be used from now. - */ - public void setContext(TopiaContext topiaContext) { - this.topiaContext = topiaContext; - } - - /** - * Returns current context. - * You may use this operation in subclasses to get the context to use. - * - * @return the TopiaContext to use. - */ - public TopiaContext getContext() { - return topiaContext; - } + protected String _topiaId_ = null; + protected String _version_; + protected Date _creationDate_; + protected Date _lastUpdateDate_; + protected TopiaUser _lastUpdateUser_; + + public AbstractTopiaEntity() throws TopiaException { + set_topiaId_(TopiaId.create(getEntityClass())); + Date date = new Date(); + set_creationDate_(date); + set_lastUpdateDate_(date); + set_version_("0"); + } + + /** + * Is equals if and only if topiaId is equals and version is equals + */ + public boolean equals(Object o){ + if(o instanceof TopiaEntity){ + try{ + String topiaId = ((TopiaEntity)o).get_topiaId_(); + String version = ((TopiaEntity)o).get_version_(); + return _topiaId_.equals(topiaId) && VersionNumberUtil.equals(_version_,version); + }catch(TopiaException eee){ + throw new RuntimeException("Can't check equality", eee); + } + } + return false; + } + + public String toString(){ + return "Entity " + _topiaId_ + "(version " + _version_ + ")"; + } + + public String get_topiaId_() throws TopiaException { + return _topiaId_; + } + public void set_topiaId_(String topiaId) throws TopiaException { + // it's a good idea to check if topiaId exist + // but when we rebuild entity from DataStore + // the topiaId allready exist and framework can't change it :( + // But it seems better that is client side Entity that create + // topiaId for consistense + // FIXME + // How can authorize framework to change topiaId when it restore data + // and disallow all other change ? + +// if(_topiaId_ != null && !_topiaId_.equals(topiaId)){ +// throw new TopiaException("It's not allowed to change topiaId"); +// } + this._topiaId_ = topiaId; + } + public String get_version_() throws TopiaException { + return _version_; + } + public void set_version_(String version) throws TopiaException { + this._version_ = version; + } + + public Date get_creationDate_() throws TopiaException{ + return _creationDate_; + } + public void set_creationDate_(Date creationDate) throws TopiaException { + this._creationDate_ = creationDate; + } + + public Date get_lastUpdateDate_() throws TopiaException { + return _lastUpdateDate_; + } + public void set_lastUpdateDate_(Date lastUpdateDate) throws TopiaException { + this._lastUpdateDate_ = lastUpdateDate; + } + + public TopiaUser get_lastUpdateUser_() throws TopiaException { + return _lastUpdateUser_; + } + public void set_lastUpdateUser_(TopiaUser lastUpdateUser) throws TopiaException { + this._lastUpdateUser_ = lastUpdateUser; + } +} // AbstractTopiaEntity -} Index: topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java diff -u topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java:1.3 topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java:1.4 --- topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java:1.3 Wed Jun 30 13:40:36 2004 +++ topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java Thu Jul 15 13:13:12 2004 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Mise a jour: $Date: 2004/06/30 13:40:36 $ - * par : $Author: pineau $ + * Mise a jour: $Date: 2004/07/15 13:13:12 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia; @@ -39,8 +39,7 @@ import org.codelutin.util.ListenerSet; -public abstract class AbstractTopiaPersistenceService extends AbstractTopiaService - implements TopiaPersistenceService, PrivateTopiaPersistenceService { // AbstractTopiaPersistenceService +public abstract class AbstractTopiaPersistenceService extends AbstractTopiaService implements TopiaPersistenceService { // AbstractTopiaPersistenceService ListenerSet listeners = new ListenerSet(); @@ -67,68 +66,20 @@ * * @return the transient transferable TopiaEntity. */ - public TopiaEntityTO create() throws TopiaException { - TopiaEntityTO result = - getContext().createEntity(getEntityClass()); - Date date = new Date(); - result.set_creationDate_(date); - result.set_lastUpdateDate_(date); - result.set_version_("0"); + public TopiaEntity create() throws TopiaException { + TopiaEntity result = null; + result = getContext().getPersistenceHelper().create(getEntityClass()); 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; + public TopiaEntity makePersistent(TopiaEntity topiaEntity)throws TopiaException{ + return getContext().getPersistenceHelper().makePersistent(topiaEntity); } - - - - /** - * 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)); + public TopiaEntity update(TopiaEntity topiaEntity) throws TopiaException{ + return getContext().getPersistenceHelper().update(topiaEntity); } - - /** - * 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; + public void delete(TopiaEntity topiaEntity) throws TopiaException{ + getContext().getPersistenceHelper().delete(topiaEntity); } /** @@ -141,49 +92,16 @@ } /** - * 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 - * - * @return a List containing all TopiaEntity DataObjects related to this CRUD. - */ - public Collection findDO(TopiaQuery query) throws TopiaException { - String filter = ""; - Object [] args = null; - if(query != null && !query.getQueryString().equals("")){ - filter = " WHERE " + query.getQueryString(); - args = query.getArgs().toArray(); - } - filter = "SELECT o FROM " + getContext().getClassName( - getContext().MAPPING_ENTITY_DO, getEntityClass()) - + " AS o" + filter; - TopiaQuery newQuery = new TopiaQuery(filter, args); - - TopiaPersistenceHelper persistence = - getContext().getPersistenceHelper(); - return persistence.execute(newQuery); - } - - /** * Returns all TopiaEntity related to this CRUD according to the given TopiaQuery. * If topiaQuery is null, acts as findAll(). - * @param topiaQuery - the TopiaQuery to process. Query contains where clause only + * @param topiaQuery - the TopiaQuery to process. Query contains where clause only or it must be create with {@link #newQuery()} * @see TopiaQuery * @see #findAll() * * @return a List containing all TopiaEntity 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();) { - TopiaEntityDO _do = (TopiaEntityDO)i.next(); - _do.setContext(getContext()); - result.add(toTO(_do)); - } - return result; - + public List find(TopiaQuery query) throws TopiaException{ + return getContext().getPersistenceHelper().find(normalizeQuery(query)); } /** @@ -198,14 +116,34 @@ /** * 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. + * @param topiaQuery - the TopiaQuery to process. Query contains where clause only or it must be create with {@link #newQuery()} * @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 getContext().getPersistenceHelper().size(normalizeQuery(query)); + } + + public TopiaQuery newQuery(){ + TopiaQuery result = new TopiaQuery(); + return result.select("*").from(getEntityClass().getName()); + } + /** + * Retourne une nouvelle requete complete. La requete passée en paramètre + * ne contient ne contient pas la clause select ni from. Cette methode + * permet de les ajouter. + */ + protected TopiaQuery normalizeQuery(TopiaQuery query) { + TopiaQuery result = null; + if(query == null){ + result = newQuery(); + }else{ + result = query.copy(); + result.select("*").from(getEntityClass().getName()); + } + return result; } } // AbstractTopiaPersistenceService Index: topia/src/java/org/codelutin/topia/AbstractTopiaService.java diff -u topia/src/java/org/codelutin/topia/AbstractTopiaService.java:1.3 topia/src/java/org/codelutin/topia/AbstractTopiaService.java:1.4 --- topia/src/java/org/codelutin/topia/AbstractTopiaService.java:1.3 Fri May 14 17:22:17 2004 +++ topia/src/java/org/codelutin/topia/AbstractTopiaService.java Thu Jul 15 13:13:12 2004 @@ -1,61 +1,37 @@ /* *##% -* Copyright (C) 2002, 2003, 2004 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. -*##%*/ + * 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. + *##%*/ /* * -* AbstractTopiaJDOPersistenceService.java -* -* Created: 14 janv. 2004 -* -* @author Cédric Pineau -* Copyright Code Lutin -* @version $Revision: 1.3 $ -* -* Last update : $Date: 2004/05/14 17:22:17 $ -* by : $Author: pineau $ -*/ -package org.codelutin.topia; - -import org.codelutin.topia.TopiaContext; -import org.codelutin.topia.TopiaService; + * AbstractTopiaService.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.4 $ + * + * Mise a jour: $Date: 2004/07/15 13:13:12 $ + * par : $Author: bpoussin $ + */ -/** -* This abstract class propose a partial default TopiaService implementation. -*/ -public class AbstractTopiaService implements TopiaService { - - protected TopiaContext topiaContext; +package org.codelutin.topia; - /** - * Sets current context. Used by the Topia environment to specify the context to de used. - * @param : context - the context to be used from now. - */ - public void setContext(TopiaContext topiaContext) { - this.topiaContext = topiaContext; - } +public abstract class AbstractTopiaService extends AbstractTopiaElement implements TopiaService { // AbstractTopiaService - /** - * Returns current context. - * You may use this operation in subclasses to get the context to use. - * - * @return the TopiaContext to use. - */ - public TopiaContext getContext() { - return topiaContext; - } +} // AbstractTopiaService -} Index: topia/src/java/org/codelutin/topia/TopiaContext.java diff -u topia/src/java/org/codelutin/topia/TopiaContext.java:1.26 topia/src/java/org/codelutin/topia/TopiaContext.java:1.27 --- topia/src/java/org/codelutin/topia/TopiaContext.java:1.26 Mon Jul 5 10:48:41 2004 +++ topia/src/java/org/codelutin/topia/TopiaContext.java Thu Jul 15 13:13:12 2004 @@ -19,157 +19,52 @@ /* * * TopiaContext.java * - * Created: 22 avr. 2004 + * Created: 3 juil. 2004 * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.26 $ + * @version $Revision: 1.27 $ * - * Mise a jour: $Date: 2004/07/05 10:48:41 $ - * par : $Author: pineau $ + * Mise a jour: $Date: 2004/07/15 13:13:12 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia; +import org.codelutin.topia.distribution.DistributionHelper; +import org.codelutin.topia.persistence.PersistenceHelper; +import org.codelutin.topia.hook.HookHelper; +import org.codelutin.util.CategorisedListenerSet; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Proxy; -import java.net.URL; -import java.util.HashMap; -import java.util.Properties; -import java.util.logging.Level; import java.util.logging.Logger; +import java.util.logging.Level; +import java.util.Properties; -import org.codelutin.util.CategorisedListenerSet; -import org.codelutin.util.Resource; -import java.util.ArrayList; - -/** -*

Le context est le seul à savoir ou fonctionne vraiment l'application. Il -* retourne donc le bon objet demandé suivant le mode de foncitonnement de -* l'application. -*

-* Remarge: les objets retourné par les methodes getService et getControl sont -* castable en Hookable, et on peut alors ajouter des hooks sur les méthodes. -* On a pas vraiment moyen de faire autrement que ce cast, car si on fait en -* sorte que les services herite de Hookable on oblige alors les developpeurs -* a implanter des methodes qui ne serviront pas, et si les développeurs les -* laisse non implanter, on ne pourra pas instancier l'objet car il sera abstrait -*

-*/ public class TopiaContext { // TopiaContext - static final String PROPERTIES_FILENAME = "topiaContext.properties"; - public static final String MAPPING_ENTITY_TO= "entity.to"; - public static final String MAPPING_ENTITY_DO= "entity.do"; - public static final String MAPPING_SERVICE_PERSISTENCE = "service.persistence"; - - /** Static context */ - protected static HashMap contexts = new HashMap(); - protected TopiaPersistenceHelper persistenceHelper = null; - protected Cache cache = new Cache(); - - public static TopiaContext instantiateContext() throws TopiaException { - return instantiateContext(((Properties)null)); - } - - public static TopiaContext instantiateContext(String propertiesFileName) throws TopiaException { - if (propertiesFileName == null) { - return instantiateContext(((Properties)null)); - } - return instantiateContext(getProperties(propertiesFileName)); - } - - public static TopiaContext instantiateContext(Properties properties) - throws TopiaException { - TopiaContext context = (TopiaContext) contexts.get(properties); - if (context == null) { - if (properties == null) { - context = createContext(getProperties(getPropertiesFilename())); - } else { - context = createContext(properties); - } - contexts.put(properties, context); - } - return context; - } - - /** - * Constructeur qui recherche lui meme le fichier de propriete du context. - * Le fichier recherché s'appelle topiaContext.properties. Ce fichier doit - * etre a la racine d'une des resources du classpath - * @param prop les propriétés qui permette de param\x{00E8}trer le context - */ - protected static Properties getProperties(String propertiesFilename) throws TopiaException { - Properties properties = new Properties(); - try { - URL propURL = Resource.getURL(propertiesFilename); - Logger.getLogger(TopiaContext.class +".getDefaultProperties").log( - Level.INFO, - "Properties file used for context is: " + propURL); - properties.load(propURL.openStream()); - } catch (Exception eee) { - throw new TopiaNotFoundException( - "Properties file can't be found: " + propertiesFilename, - eee); - } - return properties; - } - - public static String getPropertiesFilename() { - return PROPERTIES_FILENAME; - } - - /** - */ - protected static TopiaContext createContext(Properties properties) throws TopiaNotFoundException { - TopiaContext context = null; - Class contextClass = null; - String contextClassName = - properties.getProperty( - "applicationContext", - "org.codelutin.topia.TopiaContext"); - try { - contextClass = Class.forName(contextClassName); - Constructor constructor = contextClass.getDeclaredConstructor(new Class[] {Properties.class}); - constructor.setAccessible(true); - context = (TopiaContext) constructor.newInstance(new Object[] {properties}); - } catch (Exception eee) { - throw new TopiaNotFoundException( - "TopiaContext can't be instanciated: " - + contextClassName - + " concret : " - + contextClass, - eee); - } - return context; - } + protected PersistenceHelper persistenceHelper = null; + protected DistributionHelper distributionHelper = null; + protected HookHelper hookHelper = null; + protected ContextHelper contextHelper = null; protected CategorisedListenerSet listeners = new CategorisedListenerSet(TopiaEntityListener.class); - /** Contient tous les proxy crees par le context */ - protected HashMap proxiedObjects = new HashMap(); - /** Contient tous les objets instancies par le context */ - protected HashMap instanciedObjects = new HashMap(); - /** Toutes les propriétés qui permette de paramètrer le context */ protected Properties properties = null; /** + * Constructeur du context. Il est protégé car les contexts doivent-être + * construit par {@TopiaContextFactory} */ protected TopiaContext(Properties properties) { this.properties = properties; + contextHelper = new ContextHelper(this, properties); } /** - * Returns value of the given property - * INTERNAL TOPIA USE ONLY !!! + * Retourne tous les listeners */ - public String getProperty(String propertyName) { - return properties.getProperty(propertyName); - } - public CategorisedListenerSet getListeners() { return listeners; } @@ -191,265 +86,115 @@ } /** - * Recherche un entity - * @param serviceClass la class du entity souhaité, la classe est la classe - * de l'interface du entity. - */ - public TopiaEntityTO createEntity(Class entityClass) throws TopiaException { - TopiaEntityTO result = (TopiaEntityTO) getObject(MAPPING_ENTITY_TO, entityClass); - // TODO doit l'ajouter dans la hierarchie des listeners, si oui ou ? - // apres un CRUD, apres le context ? - return result; - } - - /** - * Recherche un entity - * @param serviceClass la class du entity souhaité, la classe est la classe - * de l'interface du entity. - */ - public TopiaEntityDO createEntityDO(Class entityClass) throws TopiaException { - TopiaEntityDO result = - (TopiaEntityDO) getObject(MAPPING_ENTITY_DO, entityClass); - return result; - } - - /** - * Recherche un service - * @param entityClass l'interface de l'entity pour lequel on souhaite le service + * Retourne le service de persistance de l'entity demandé. Par defaut + * le service de persitence de l'entity se nome de la meme façon que + * l'entity avec PersistenceServiceImpl en plus + * @param entityClass la class de l'entité dont on souhaite le persistence + * service */ public TopiaPersistenceService getPersistenceService(Class entityClass) throws TopiaException { - TopiaPersistenceService result = (TopiaPersistenceService) - getProxiedObject(MAPPING_SERVICE_PERSISTENCE, entityClass, - new Class[]{PrivateTopiaPersistenceService.class}); - listeners.addCategory(this, result); - return result; - } + String className = entityClass.getName() + "PersistenceService"; + Class interfacez = Util.getClazz(className); - /** - * Recherche un controleur - * @param controlClass la classe du controleur souhaitée - */ - public TopiaControl getControl(Class controlClass) throws TopiaException { - return (TopiaControl) getProxiedObject("control", controlClass, null); - } + className = entityClass.getName() + "PersistenceServiceImpl"; + Class clazz = Util.getClazz(className); - public TopiaPersistenceHelper getPersistenceHelper() throws TopiaException { - if(persistenceHelper == null){ - String className = getPersistenceHelperClassName(); - if (className == null) { - throw new TopiaNotFoundException( - "Persistence Helper not found: " + className); - } - Class mappedClass = null; - try { - // Warning : don't replace that for a Class.forName(...) has it does NOT behave the same way ! - mappedClass = getClass().forName(className); - persistenceHelper = (TopiaPersistenceHelper)mappedClass.newInstance(); - persistenceHelper.setContext(this); - } catch (Exception eee) { - throw new TopiaNotFoundException( - "Persistence Helper can't be instanciated: " - + className - + " concret : " - + mappedClass, - eee); - } - } - return persistenceHelper; + Object result = contextHelper.getSingletonObject(clazz); + result = getHookHelper().addHookSupport(result, new Class[]{interfacez}); + listeners.addCategory(this, result); + return (TopiaPersistenceService)result; } /** - * Retourne l'objet réelle à instancier en fonction de l'interface demandé. - * @param clazz la classe de l'interface souhaité - * @return l'objet demandé + * Retourne l'objet implantant les operations de l'entity demandé. Par defaut + * cette classe se nome de la meme façon que + * l'entity avec Operation en plus + * @param entityClass la class de l'entité dont on souhaite les operations + * @see #getService(Class, boolean) */ - protected Object getObject(String category, Class clazz) throws TopiaException { - String className = getClassName(category, clazz); - if (className == null) { - throw new TopiaNotFoundException( - "Requested class not found: " + className); - } - - Object result = instanciedObjects.get(clazz); - if (result == null || !(result instanceof TopiaService)) { // seul les services peuvent-etre reutilisé - Class mappedClass = null; - try { - // Warning : don't replace that for a Class.forName(...) has it does NOT behave the same way ! - mappedClass = getClass().forName(className); - - result = mappedClass.newInstance(); - - if (result instanceof TopiaElement) { - ((TopiaElement) result).setContext(this); - } - - // TODO dans le futur ameliorer instanciedObjects pour qu'il - // compte le nombre de fois que l'on put une clef - // pourra servire pour des stats d'application - // nombre d'objet entity creer par exemple. - // s'il y a un meilleur endroit pour les stats alors - // decommater la condition suivante la condition - // et renommer instanciedObjects en instanciedService - // if(result instanceof TopiaService) - instanciedObjects.put(className, result); - } catch (Exception eee) { - throw new TopiaNotFoundException( - "Requested class can't be instanciated: " - + className - + " concret : " - + mappedClass, - eee); - } - } - Logger.getLogger(getClass().getName() + ".getObject").log(Level.INFO, - "category:"+category+ " clazz:"+ clazz+" result:"+result.getClass().getName()); - return result; + public TopiaEntityOperation getEntityOperation(Class entityClass) throws TopiaException { + String className = entityClass.getName() + "Operation"; + Class interfacez = Util.getClazz(className); + return (TopiaEntityOperation)getService(interfacez, false); } /** - * Retourne l'objet réelle à instancier en fonction de l'interface demandé. - * @param clazz la classe de l'interface souhaité - * @param other liste d'interface que le proxy doit aussi implanter si other != null - * @return un objet {@link java.lang.reflect.Proxy} qui implante l'interface - * demandé plus l'interface {@link Hookable}. + * Retourne le service demandé. + * @param local si vrai alors donne l'implantation local du service au + * lieu du Dist */ - protected Object getProxiedObject(String category, Class clazz, Class [] other) throws TopiaException { - Object result = proxiedObjects.get(clazz); - if (result == null) { - String interfaceName = getInterfaceName(category, clazz); - Class proxyInterfaceClazz = null; + public TopiaService getService(Class serviceInterfacez, boolean local) throws TopiaException { + Class clazz = null; + if(local){ try{ - proxyInterfaceClazz = getClass().forName(interfaceName); - }catch(ClassNotFoundException eee){ - throw new TopiaException("Can't find interface for category:" - + category + " class:" + clazz.getName(), eee); - } - - Object o = getObject(category, clazz); - InvocationHandler handler = - new ProxyHookHandler( - o, - hasCallPre(), - hasCallMethode(), - hasCallPost()); - - ArrayList classes = new ArrayList(); - classes.add(proxyInterfaceClazz); - classes.add(Hookable.class); - - if(other != null){ - for(int i=0; i * Copyright Code Lutin - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * - * Mise a jour: $Date: 2004/05/14 10:56:40 $ + * Mise a jour: $Date: 2004/07/15 13:13:12 $ * par : $Author: bpoussin $ */ @@ -42,7 +42,7 @@ * context to de used. * @param : context - the context to be used from now. */ - public void setContext(TopiaContext topiaContext); + public void setContext(TopiaContext topiaContext) throws TopiaException; /** * Returns current context. Index: topia/src/java/org/codelutin/topia/TopiaEntity.java diff -u topia/src/java/org/codelutin/topia/TopiaEntity.java:1.12 topia/src/java/org/codelutin/topia/TopiaEntity.java:1.13 --- topia/src/java/org/codelutin/topia/TopiaEntity.java:1.12 Fri Jun 18 18:29:19 2004 +++ topia/src/java/org/codelutin/topia/TopiaEntity.java Thu Jul 15 13:13:12 2004 @@ -23,23 +23,32 @@ * * @author Cédric Pineau * Copyright Code Lutin -* @version $Revision: 1.12 $ +* @version $Revision: 1.13 $ * -* Last update : $Date: 2004/06/18 18:29:19 $ +* Last update : $Date: 2004/07/15 13:13:12 $ * by : $Author: bpoussin $ */ package org.codelutin.topia; +import java.util.Date; + /** * Top Level common interface to all topia entityes. */ public interface TopiaEntity extends TopiaElement { // TopiaEntity - public Object get_topiaId_() throws TopiaException; + public Class getEntityClass(); + + public String 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 Date get_creationDate_() throws TopiaException; + public Date get_lastUpdateDate_() throws TopiaException; public TopiaUser get_lastUpdateUser_() throws TopiaException; - public Class getEntityClass(); + + public void set_topiaId_(String v) throws TopiaException; + public void set_version_(String v) throws TopiaException; + public void set_creationDate_(Date v) throws TopiaException; + public void set_lastUpdateDate_(Date v) throws TopiaException; + public void set_lastUpdateUser_(TopiaUser v) throws TopiaException; } // TopiaEntity Index: topia/src/java/org/codelutin/topia/TopiaPersistenceService.java diff -u topia/src/java/org/codelutin/topia/TopiaPersistenceService.java:1.5 topia/src/java/org/codelutin/topia/TopiaPersistenceService.java:1.6 --- topia/src/java/org/codelutin/topia/TopiaPersistenceService.java:1.5 Wed Jun 16 09:41:26 2004 +++ topia/src/java/org/codelutin/topia/TopiaPersistenceService.java Thu Jul 15 13:13:12 2004 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Mise a jour: $Date: 2004/06/16 09:41:26 $ + * Mise a jour: $Date: 2004/07/15 13:13:12 $ * par : $Author: bpoussin $ */ @@ -56,7 +56,7 @@ * * @return the transient transferable TopiaEntity. */ - public TopiaEntityTO create() throws TopiaException; + public TopiaEntity create() throws TopiaException; /** * Creates that is make persistent the given TopiaEntity. @@ -116,6 +116,11 @@ */ public void delete(TopiaEntity topiaEntity) throws TopiaException; + /** + * Retourne une TopiaQuery ou le select et le from sont convenablement + * positionné. + */ + public TopiaQuery newQuery(); /** * Return entity Class managed by this service Index: topia/src/java/org/codelutin/topia/TopiaQuery.java diff -u topia/src/java/org/codelutin/topia/TopiaQuery.java:1.3 topia/src/java/org/codelutin/topia/TopiaQuery.java:1.4 --- topia/src/java/org/codelutin/topia/TopiaQuery.java:1.3 Wed Jun 2 09:33:08 2004 +++ topia/src/java/org/codelutin/topia/TopiaQuery.java Thu Jul 15 13:13:12 2004 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Mise a jour: $Date: 2004/06/02 09:33:08 $ + * Mise a jour: $Date: 2004/07/15 13:13:12 $ * par : $Author: bpoussin $ */ @@ -35,26 +35,64 @@ import java.io.Serializable; import java.util.List; -public class TopiaQuery { // TopiaQuery +public class TopiaQuery implements Serializable { // TopiaQuery - protected String queryString = null; + protected String select = null; + protected int limitMin = -1; + protected int limitMax = -1; + protected String from = null; + protected String where = null; + protected String orderby = null; + +// protected String queryString = null; protected List args = new LinkedList(); - public TopiaQuery(String queryString, Object [] args){ - this.queryString = queryString; - if(args != null){ - for(int i=0; i 18 + */ + public TopiaQuery where(String v){ + where = v; + return this; + } + /** + * Attend un ordre. name desc, age asc, firstname desc + */ + public TopiaQuery orderby(String v){ + orderby = v; + return this; + } + /** + * Attend les limits du resultat a retourne, donc pour avoir seulement le + * premier element il faut faire (0, 1). pour avoir tous les elements + * (0, size()). Et pour avoir 5 elements a partir du 5eme, (5, 10) ou + * (5, 5+5) + * @min le premier element inclu a retourner + * @max le derniere element exclu a retourner + */ + public TopiaQuery limit(int min, int max){ + limitMin = min; + limitMax = max; + return this; + } + + public String getSelect() { + return select; + } + public int getLimitMin() { + return limitMin; + } + public int getLimitMax() { + return limitMax; + } + public String getFrom() { + return from; + } + public String getWhere() { + return where; + } + public String getOrderby() { + return orderby; } } // TopiaQuery Index: topia/src/java/org/codelutin/topia/Util.java diff -u topia/src/java/org/codelutin/topia/Util.java:1.9 topia/src/java/org/codelutin/topia/Util.java:1.10 --- topia/src/java/org/codelutin/topia/Util.java:1.9 Thu Jul 8 13:50:49 2004 +++ topia/src/java/org/codelutin/topia/Util.java Thu Jul 15 13:13:12 2004 @@ -1,50 +1,111 @@ /* *##% -* Copyright (C) 2002, 2003, 2004 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. -*##%*/ + * 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. + *##%*/ /* * -* AbstractTopiaJDOPersistenceService.java -* -* Created: 13 mai 2004 -* -* @author Cédric Pineau -* Copyright Code Lutin -* @version $Revision: 1.9 $ -* -* Last update : $Date: 2004/07/08 13:50:49 $ -* by : $Author: pineau $ -*/ + * Util.java + * + * Created: 6 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.10 $ + * + * Mise a jour: $Date: 2004/07/15 13:13:12 $ + * par : $Author: bpoussin $ + */ + package org.codelutin.topia; -/** - * Classe contenant des methodes utiles pour le framework à l'exécution. - */ -public class Util { +import java.util.logging.Logger; +import java.util.logging.Level; +import java.beans.Expression; + +public class Util { // Util + + public static Class getClazz(String className)throws TopiaNotFoundException{ + try{ + return Class.forName(className); + }catch(ClassNotFoundException eee){ + Logger.getLogger(Util.class + ".getClazz").log(Level.SEVERE, + "Can't find class " + className, eee); + throw new TopiaNotFoundException("Can't find class " + className, eee); + } + } /** - * Returns a TopiaEntityTO from a TopiaEntityTO or a TopiaEntityTOProxy. - * - * @return a TopiaEntityTO object if possible. + * Retourne le package de la classe */ - public static TopiaEntityTO toTO(TopiaEntity entity) throws TopiaException { - if (! (entity instanceof TopiaEntityTO)) { - throw new TopiaException("Can't cast "+entity+" to a TopiaEntityTO"); + public static String getPackageName(String classname){ + String result = classname.substring(0, classname.lastIndexOf('.')); + return result; + } + + /** + * Retourne le nom de la classe sans le package + */ + public static String getClassName(String classname){ + String result = classname.substring(classname.lastIndexOf('.') + 1); + return result; + } + + /** + * Retourne le package de la classe + */ + public static String getPackageName(Class clazz){ + String classname = clazz.getName(); + return getPackageName(classname); + } + + /** + * Retourne le nom de la classe sans le package + */ + public static String getClassName(Class clazz){ + String classname = clazz.getName(); + return getClassName(classname); + } + + /** + * Instancie un objet de la classe passé en paramètre. + */ + public static Object getInstance(Class clazz) throws TopiaNotFoundException{ + Object result = null; + try{ + result = clazz.newInstance(); + } catch (Exception eee) { + throw new TopiaNotFoundException( + "Requested class can't be instanciated: " + clazz.getName(), + eee); + } + return result; + } + + public static Object getInstance(Class clazz, Object [] args) throws TopiaNotFoundException{ + Object result = null; + try{ + Expression e = new Expression(clazz, "new", args); + result = e.getValue(); + } catch (Exception eee) { + throw new TopiaNotFoundException( + "Requested class can't be instanciated: " + clazz.getName(), + eee); } - return (TopiaEntityTO) entity; + return result; } -} +} // Util +