Index: topia/src/java/org/codelutin/topia/TopiaContext.java diff -u topia/src/java/org/codelutin/topia/TopiaContext.java:1.23 topia/src/java/org/codelutin/topia/TopiaContext.java:1.24 --- topia/src/java/org/codelutin/topia/TopiaContext.java:1.23 Fri May 28 15:40:16 2004 +++ topia/src/java/org/codelutin/topia/TopiaContext.java Fri Jun 4 18:43:54 2004 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.23 $ + * @version $Revision: 1.24 $ * - * Mise a jour: $Date: 2004/05/28 15:40:16 $ - * par : $Author: pineau $ + * Mise a jour: $Date: 2004/06/04 18:43:54 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia; @@ -42,6 +42,7 @@ 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 @@ -59,306 +60,364 @@ public class TopiaContext { // TopiaContext static final String PROPERTIES_FILENAME = "topiaContext.properties"; - - /** Static context */ - protected static HashMap contexts = new HashMap(); - - public static TopiaContext getContext() throws TopiaException { - return getContext(((Properties)null)); - } - - public static TopiaContext getContext(String propertiesFileName) throws TopiaException { - if (propertiesFileName == null) { - return getContext(((Properties)null)); - } - return getContext(getProperties(propertiesFileName)); - } - - public static TopiaContext getContext(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\x{00E9} s'appelle topiaContext.properties. Ce fichier doit - * etre a la racine d'une des resources du classpath - * @param prop les propri\x{00E9}t\x{00E9}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 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\x{00E9}t\x{00E9}s qui permette de param\x{00E8}trer le context */ - protected Properties properties = null; - - /** - */ - protected TopiaContext(Properties properties) { - this.properties = properties; - } - - /** - * Returns value of the given property - * INTERNAL TOPIA USE ONLY !!! - */ - public String getProperty(String propertyName) { - return properties.getProperty(propertyName); - } - - public CategorisedListenerSet getListeners() { - return listeners; - } - - /** - * Adds a new TopiaEntityListener to the subscribers list. - * @param topiaEntityListener - the TopiaEntityListener to add to the subscribers list. - */ - public void addTopiaEntityListener(TopiaEntityListener l) { - getListeners().add(this, l); - } - - /** - * Removes a TopiaEntityListener from the subscribers list. - * @param topiaEntityListener - the TopiaEntityListener to remove from the subscribers. - */ - public void removeTopiaEntityListener(TopiaEntityListener l) { - getListeners().remove(this, l); - } - - /** - * Recherche un entity - * @param serviceClass la class du entity souhaité, la classe est la classe - * de l'interface du entity. - */ - public TopiaEntity getEntity(Class entityClass) throws TopiaException { - TopiaEntity result = (TopiaEntity) getObject(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\x{00E9}, la classe est la classe - * de l'interface du entity. - */ - public TopiaService getToto(Class serviceClass) throws TopiaException { - TopiaService result = (TopiaService) getObject(serviceClass); - // TODO doit l'ajouter dans la hierarchie des listeners, si oui ou ? - // apres un CRUD, apres le context ? - return result; - } - - /** - * Recherche un service - * @param serviceClass la class du service souhaité, la classe est la classe - * de l'interface du service pour les CRUD. - */ - public TopiaService getService(Class serviceClass) throws TopiaException { - TopiaService result = (TopiaService) getProxiedObject(serviceClass); - listeners.addCategory(this, result); - return result; - } - - /** - * Recherche un controleur - * @param controlClass la classe du controleur souhaitée - */ - public TopiaControl getControl(Class controlClass) throws TopiaException { - return (TopiaControl) getProxiedObject(controlClass); - } - - /** - * Recherche un controleur - * @param controlClass la classe du controleur souhait\x{00E9}e - */ - public TopiaPersistenceHelper getPersistenceHelper() - throws TopiaException { - Object persistenceHelper = - proxiedObjects.get(TopiaPersistenceHelper.class); - if (persistenceHelper == null) { - String className = getClassName(TopiaPersistenceHelper.class); - 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 = mappedClass.newInstance(); - ((TopiaPersistenceHelper) persistenceHelper).setContext(this); - } catch (Exception eee) { - throw new TopiaNotFoundException( - "Persistence Helper can't be instanciated: " - + className - + " concret : " - + mappedClass, - eee); - } - } - return (TopiaPersistenceHelper) persistenceHelper; - } - - /** - * Retourne l'objet réelle à instancier en fonction de l'interface demandé. - * @param clazz la classe de l'interface souhaité - * @return l'objet demandé - */ - protected Object getObject(Class clazz) throws TopiaException { - Object result = instanciedObjects.get(clazz); - if (result == null) { - String className = getClassName(clazz); - if (className == null) { - throw new TopiaNotFoundException( - "Requested class 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); - - result = mappedClass.newInstance(); - - if (result instanceof TopiaElement) { - ((TopiaElement) result).setContext(this); - } - - instanciedObjects.put(clazz, result); - } catch (Exception eee) { - throw new TopiaNotFoundException( - "Requested class can't be instanciated: " - + className - + " concret : " - + mappedClass, - eee); - } - } - return result; - } - - /** - * Retourne l'objet r\x{00E9}elle \x{00E0} instancier en fonction de l'interface demand\x{00E9}. - * @param clazz la classe de l'interface souhait\x{00E9} - * @return un objet {@link java.lang.reflect.Proxy} qui implante l'interface - * demand\x{00E9} plus l'interface {@link Hookable}. - */ - protected Object getProxiedObject(Class clazz) throws TopiaException { - Object result = proxiedObjects.get(clazz); - if (result == null) { - Object o = getObject(clazz); - InvocationHandler handler = - new ProxyHookHandler( - o, - hasCallPre(), - hasCallMethode(), - hasCallPost()); - - result = - Proxy.newProxyInstance( - getClass().getClassLoader(), - new Class[] { clazz, Hookable.class }, - handler); - - proxiedObjects.put(clazz, result); - } - return result; - } - - /** - * Retourne le nom de la classe reelle a utilise en fonction de la class - * passé en parametre. - * @return le nom de la classe a souhaitée, null si pas de classe trouvé - */ - protected String getClassName(Class clazz) { - // cette methode est faite pour s'abstraire du fichier de propriete. - // car pour l'instant on a nomdeclass=nomdeclass mais peut-etre que - // dans le futur on aura mapping.class.nomdeclass=nomdeclass - // dans ce cas, seul cette methode sera a modifier - return getProperty(clazz.getName()); - } - - /** - * Si la valeur de de callPre n'est pas trouvé ou qu'elle n'est pas egal - * a false alors retourne vrai. - */ - protected boolean hasCallPre() { - return !"false".equals(getProperty("callPre")); - } - /** - * Si la valeur de de callMethode n'est pas trouvé ou qu'elle n'est pas egal - * a false alors retourne vrai. - */ - protected boolean hasCallMethode() { - return !"false".equals(getProperty("callMethode")); - } - /** - * Si la valeur de de callPost n'est pas trouvé ou qu'elle n'est pas egal - * a false alors retourne vrai. - */ - protected boolean hasCallPost() { - return !"false".equals(getProperty("callPost")); - } + 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; + + public static TopiaContext getContext() throws TopiaException { + return getContext(((Properties)null)); + } + + public static TopiaContext getContext(String propertiesFileName) throws TopiaException { + if (propertiesFileName == null) { + return getContext(((Properties)null)); + } + return getContext(getProperties(propertiesFileName)); + } + + public static TopiaContext getContext(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 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; + + /** + */ + protected TopiaContext(Properties properties) { + this.properties = properties; + } + + /** + * Returns value of the given property + * INTERNAL TOPIA USE ONLY !!! + */ + public String getProperty(String propertyName) { + return properties.getProperty(propertyName); + } + + public CategorisedListenerSet getListeners() { + return listeners; + } + + /** + * Adds a new TopiaEntityListener to the subscribers list. + * @param topiaEntityListener - the TopiaEntityListener to add to the subscribers list. + */ + public void addTopiaEntityListener(TopiaEntityListener l) { + getListeners().add(this, l); + } + + /** + * Removes a TopiaEntityListener from the subscribers list. + * @param topiaEntityListener - the TopiaEntityListener to remove from the subscribers. + */ + public void removeTopiaEntityListener(TopiaEntityListener l) { + getListeners().remove(this, l); + } + + /** + * 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 + */ + 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; + } + + /** + * Recherche un controleur + * @param controlClass la classe du controleur souhaitée + */ + public TopiaControl getControl(Class controlClass) throws TopiaException { + return (TopiaControl) getProxiedObject("control", controlClass, null); + } + + 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; + } + + /** + * Retourne l'objet réelle à instancier en fonction de l'interface demandé. + * @param clazz la classe de l'interface souhaité + * @return l'objet demandé + */ + 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; + } + + /** + * 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}. + */ + 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; + 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 +* @author Cédric Pineau * Copyright Code Lutin -* @version $Revision: 1.9 $ +* @version $Revision: 1.10 $ * -* Last update : $Date: 2004/05/19 10:33:03 $ -* by : $Author: pineau $ +* Last update : $Date: 2004/06/04 18:43:54 $ +* by : $Author: bpoussin $ */ package org.codelutin.topia; @@ -43,14 +43,14 @@ */ // TODO public Class getCRUDClass(); - public Object _getTopiaId() throws TopiaException; + 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 String _getVersion() throws TopiaException; + + public java.util.Date _getCreationDate() throws TopiaException; + + public java.util.Date _getLastUpdateDate() throws TopiaException; + + public TopiaUser _getLastUpdateUser() throws TopiaException; } // TopiaEntity Index: topia/src/java/org/codelutin/topia/TopiaPersistenceHelper.java diff -u topia/src/java/org/codelutin/topia/TopiaPersistenceHelper.java:1.2 topia/src/java/org/codelutin/topia/TopiaPersistenceHelper.java:1.3 --- topia/src/java/org/codelutin/topia/TopiaPersistenceHelper.java:1.2 Wed Jun 2 09:33:08 2004 +++ topia/src/java/org/codelutin/topia/TopiaPersistenceHelper.java Fri Jun 4 18:43:54 2004 @@ -53,6 +53,6 @@ * Child class must implement this method and return the right QueryExecute * object for the persistence type. */ - abstract public QueryExecute getQueryExecute(); + abstract protected QueryExecute getQueryExecute(); } Index: topia/src/java/org/codelutin/topia/TopiaUser.java diff -u topia/src/java/org/codelutin/topia/TopiaUser.java:1.1 topia/src/java/org/codelutin/topia/TopiaUser.java:1.2 --- topia/src/java/org/codelutin/topia/TopiaUser.java:1.1 Thu May 6 17:29:30 2004 +++ topia/src/java/org/codelutin/topia/TopiaUser.java Fri Jun 4 18:43:54 2004 @@ -21,12 +21,12 @@ * * Created: 14 janv. 2004 * -* @author C\x{00E9}dric Pineau +* @author Cédric Pineau * Copyright Code Lutin -* @version $Revision: 1.1 $ +* @version $Revision: 1.2 $ * -* Last update : $Date: 2004/05/06 17:29:30 $ -* by : $Author: pineau $ +* Last update : $Date: 2004/06/04 18:43:54 $ +* by : $Author: bpoussin $ */ package org.codelutin.topia; Index: topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java diff -u /dev/null topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java:1.1 --- /dev/null Fri Jun 4 18:43:59 2004 +++ topia/src/java/org/codelutin/topia/AbstractTopiaPersistenceService.java Fri Jun 4 18:43:54 2004 @@ -0,0 +1,170 @@ +/* *##% + * 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. + *##%*/ + +/* * + * AbstractTopiaPersistenceService.java + * + * Created: 1 juin 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/06/04 18:43:54 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia; + +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.TopiaEntityDO; +import org.codelutin.topia.TopiaQuery; +import org.codelutin.util.ListenerSet; +import org.codelutin.topia.TopiaEntityListener; +import java.util.List; +import java.util.Collection; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.HashMap; + +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 + * subscribers list. + */ + public void addTopiaEntityListener(TopiaEntityListener l) { + getContext().getListeners().add(this, l); + } + + /** + * Removes a TopiaEntityListener from the subscribers list. + * @param topiaEntityListener - the TopiaEntityListener to remove from the + * subscribers. + */ + public void removeTopiaEntityListener(TopiaEntityListener l) { + 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()); + } + + + /** + * Returns all TopiaEntity related to this CRUD. + * + * @return a List containing all TopiaEntity related to this CRUD. + */ + public List findAll() throws TopiaException { + return find(null); + } + + /** + * 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 (Collection) 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 + * @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; + + } + + /** + * Returns the number of TopiaEntity related to this CRUD. + * + * @return the number of TopiaEntity related to this CRUD. + */ + public int size() throws TopiaException{ + return size(null); + } + + /** + * 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(); + } + +} // AbstractTopiaPersistenceService + Index: topia/src/java/org/codelutin/topia/PrivateTopiaPersistenceService.java diff -u /dev/null topia/src/java/org/codelutin/topia/PrivateTopiaPersistenceService.java:1.1 --- /dev/null Fri Jun 4 18:43:59 2004 +++ topia/src/java/org/codelutin/topia/PrivateTopiaPersistenceService.java Fri Jun 4 18:43:54 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. + *##%*/ + +/* * + * PrivateTopiaPersistenceService.java + * + * Created: 4 juin 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/06/04 18:43:54 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia; + +import java.util.HashMap; + +/** +* Regroupement de tout les méthodes du framework pour les services de +* persistence que ne doivent pas voir les utilisateurs. +*/ +public interface PrivateTopiaPersistenceService extends TopiaPersistenceService { // PrivateTopiaPersistenceService + + // 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; + +} // PrivateTopiaPersistenceService +