Index: topia/src/java/org/codelutin/topia/TopiaPersistenceHelper.java diff -u topia/src/java/org/codelutin/topia/TopiaPersistenceHelper.java:1.1 topia/src/java/org/codelutin/topia/TopiaPersistenceHelper.java:1.2 --- topia/src/java/org/codelutin/topia/TopiaPersistenceHelper.java:1.1 Fri May 14 17:35:35 2004 +++ topia/src/java/org/codelutin/topia/TopiaPersistenceHelper.java Wed Jun 2 09:33:08 2004 @@ -6,32 +6,53 @@ */ package org.codelutin.topia; -/** - * @author cedric - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class TopiaPersistenceHelper { - - protected TopiaContext topiaContext; - - /** - * 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; - } - +import org.codelutin.queryparser.QueryExecute; +import org.codelutin.queryparser.QueryExecuteException; +import java.util.Collection; +import java.io.IOException; + +public abstract class TopiaPersistenceHelper { + + protected TopiaContext topiaContext; + + /** + * 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; + } + + /** + * Execute one query. Query must be complete with select, from, where, ... + */ + public Collection execute(TopiaQuery query) throws TopiaException{ + try{ + QueryExecute queryExecute = getQueryExecute(); + queryExecute.setQuery(query.getQueryString()); + queryExecute.setArgs(query.getArgs()); + return queryExecute.execute(); + }catch(IOException eee){ + throw new TopiaException("Error during query parsing", eee); + }catch(QueryExecuteException eee){ + throw new TopiaException("Error during query execution", eee); + } + } + + /** + * Child class must implement this method and return the right QueryExecute + * object for the persistence type. + */ + abstract public QueryExecute getQueryExecute(); + } Index: topia/src/java/org/codelutin/topia/TopiaPersistenceService.java diff -u topia/src/java/org/codelutin/topia/TopiaPersistenceService.java:1.3 topia/src/java/org/codelutin/topia/TopiaPersistenceService.java:1.4 --- topia/src/java/org/codelutin/topia/TopiaPersistenceService.java:1.3 Fri May 28 15:40:16 2004 +++ topia/src/java/org/codelutin/topia/TopiaPersistenceService.java Wed Jun 2 09:33:08 2004 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Mise a jour: $Date: 2004/05/28 15:40:16 $ - * par : $Author: pineau $ + * Mise a jour: $Date: 2004/06/02 09:33:08 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia; @@ -39,81 +39,87 @@ */ public interface TopiaPersistenceService extends TopiaService { - /** - * Adds a new TopiaEntityListener to the subscribers list. - * @param l - the TopiaEntityListener to add to the subscribers list. - */ - public void addTopiaEntityListener(TopiaEntityListener l) throws TopiaException; - - /** - * Removes a TopiaEntityListener from the subscribers list. - * @param l - the TopiaEntityListener to remove from the subscribers. - */ - public void removeTopiaEntityListener(TopiaEntityListener l) throws TopiaException; - - /** - * Creates a transient tranferable TopiaEntity. - * - * @return the transient transferable TopiaEntity. - */ - public TopiaEntity create(Class topiaEntityClass) throws TopiaException; - - /** - * Creates that is make persistent the given TopiaEntity. - * This operation returns either a copy or the given TopiaEntity itself (depending on the current context) feeded with a valid topiaId. - * @param topiaEntity - the TopiaEntity to persist. - * - * @return the persistent TopiaEntity. - */ - public TopiaEntity makePersistent(TopiaEntity topiaEntity) - throws TopiaException; - - /** - * Updates that is make change on the given TopiaEntity persistent. - * @param topiaEntity - the TopiaEntity whose changes must be made persistent. - */ - public TopiaEntity update(TopiaEntity topiaEntity) throws TopiaException; - - /** - * Returns all TopiaEntity related to this CRUD. - * - * @return a List containing all TopiaEntity related to this CRUD. - */ - public List findAll() throws TopiaException; - - /** - * 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. - * @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; - - /** - * Returns the number of TopiaEntity related to this CRUD. - * - * @return the number of TopiaEntity related to this CRUD. - */ - public int size() throws TopiaException; - - /** - * 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; - - /** - * Delete that is remove from persistence layer the given TopiaEntity. - * @param topiaEntity - the TopiaEntity to delete. - */ - public void delete(TopiaEntity topiaEntity) throws TopiaException; + /** + * Adds a new TopiaEntityListener to the subscribers list. + * @param l - the TopiaEntityListener to add to the subscribers list. + */ + public void addTopiaEntityListener(TopiaEntityListener l) throws TopiaException; + + /** + * Removes a TopiaEntityListener from the subscribers list. + * @param l - the TopiaEntityListener to remove from the subscribers. + */ + public void removeTopiaEntityListener(TopiaEntityListener l) throws TopiaException; + + /** + * Creates a transient tranferable TopiaEntity. + * + * @return the transient transferable TopiaEntity. + */ + public TopiaEntity create() throws TopiaException; + + /** + * Creates that is make persistent the given TopiaEntity. + * This operation returns either a copy or the given TopiaEntity itself (depending on the current context) feeded with a valid topiaId. + * @param topiaEntity - the TopiaEntity to persist. + * + * @return the persistent TopiaEntity. + */ + public TopiaEntity makePersistent(TopiaEntity topiaEntity) + throws TopiaException; + + /** + * Updates that is make change on the given TopiaEntity persistent. + * @param topiaEntity - the TopiaEntity whose changes must be made persistent. + */ + public TopiaEntity update(TopiaEntity topiaEntity) throws TopiaException; + + /** + * Returns all TopiaEntity related to this CRUD. + * + * @return a List containing all TopiaEntity related to this CRUD. + */ + public List findAll() throws TopiaException; + + /** + * 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. + * @see TopiaQuery + * @see #findAll() + * + * @return a List containing all TopiaEntity related to this CRUD according to the given TopiaQuery. + */ + public List find(TopiaQuery query) throws TopiaException; + + /** + * Returns the number of TopiaEntity related to this CRUD. + * + * @return the number of TopiaEntity related to this CRUD. + */ + public int size() throws TopiaException; + + /** + * 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; + + /** + * Delete that is remove from persistence layer the given TopiaEntity. + * @param topiaEntity - the TopiaEntity to delete. + */ + public void delete(TopiaEntity topiaEntity) throws TopiaException; + + + /** + * Return entity Class managed by this service + */ + public Class getEntityClass(); } Index: topia/src/java/org/codelutin/topia/TopiaQuery.java diff -u topia/src/java/org/codelutin/topia/TopiaQuery.java:1.2 topia/src/java/org/codelutin/topia/TopiaQuery.java:1.3 --- topia/src/java/org/codelutin/topia/TopiaQuery.java:1.2 Fri Apr 23 13:53:25 2004 +++ topia/src/java/org/codelutin/topia/TopiaQuery.java Wed Jun 2 09:33:08 2004 @@ -23,17 +23,75 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Mise a jour: $Date: 2004/04/23 13:53:25 $ - * par : $Author: pineau $ + * Mise a jour: $Date: 2004/06/02 09:33:08 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia; -/** -* Cette classe permet de construire une demande de recup?ration d'objet TO -*/ +import java.util.LinkedList; +import java.io.Serializable; +import java.util.List; + public class TopiaQuery { // TopiaQuery + + 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