Index: topia/src/java/org/codelutin/topia/jdo/AbstractTopiaJDOPersistenceService.java diff -u topia/src/java/org/codelutin/topia/jdo/AbstractTopiaJDOPersistenceService.java:1.3 topia/src/java/org/codelutin/topia/jdo/AbstractTopiaJDOPersistenceService.java:1.4 --- topia/src/java/org/codelutin/topia/jdo/AbstractTopiaJDOPersistenceService.java:1.3 Fri May 28 15:40:16 2004 +++ topia/src/java/org/codelutin/topia/jdo/AbstractTopiaJDOPersistenceService.java Wed Jun 2 09:33:08 2004 @@ -23,10 +23,10 @@ * * @author Cédric Pineau * Copyright Code Lutin -* @version $Revision: 1.3 $ +* @version $Revision: 1.4 $ * -* Last update : $Date: 2004/05/28 15:40:16 $ -* by : $Author: pineau $ +* Last update : $Date: 2004/06/02 09:33:08 $ +* by : $Author: bpoussin $ */ package org.codelutin.topia.jdo; @@ -35,7 +35,7 @@ import javax.jdo.PersistenceManager; import javax.jdo.Transaction; -import org.codelutin.topia.AbstractTopiaService; +import org.codelutin.topia.AbstractTopiaPersistenceService; import org.codelutin.topia.TopiaEntity; import org.codelutin.topia.TopiaEntityDO; import org.codelutin.topia.TopiaEntityListener; @@ -49,28 +49,8 @@ /** * This abstract class propose a partial default TopiaPersistenceService implementation. */ -public abstract class AbstractTopiaJDOPersistenceService extends AbstractTopiaService - implements TopiaPersistenceService { - - ListenerSet listeners = new ListenerSet(); - - /** - * 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); - } +public abstract class AbstractTopiaJDOPersistenceService + extends AbstractTopiaPersistenceService { /** * Creates a transient tranferable TopiaEntity. @@ -89,11 +69,11 @@ * @return the persistent TopiaEntity. */ public TopiaEntity makePersistent(TopiaEntity topiaEntity) throws TopiaException { - if (topiaEntity._getTopiaId() != null) { - throw new TopiaException("Can't persist "+topiaEntity+" has it seems to exist, please use update instead !"); - } + if (topiaEntity._getTopiaId() != null) { + throw new TopiaException("Can't persist "+topiaEntity+" has it seems to exist, please use update instead !"); + } TopiaEntityTO _to = (TopiaEntityTO) Util.toTO(topiaEntity); - PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); + PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); Transaction transaction = persistenceManager.currentTransaction(); transaction.begin(); try { @@ -108,53 +88,15 @@ } /** - * 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 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 abstract 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 abstract 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 abstract int size(TopiaQuery query) 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 { - if (topiaEntity._getTopiaId() == null) { - throw new TopiaException("Can't update "+topiaEntity+" has it seems not to exist, please use makePersistent instead !"); - } + if (topiaEntity._getTopiaId() == null) { + throw new TopiaException("Can't update "+topiaEntity+" has it seems not to exist, please use makePersistent instead !"); + } TopiaEntityTO _to = (TopiaEntityTO) Util.toTO(topiaEntity); - PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); + PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); Transaction transaction = persistenceManager.currentTransaction(); transaction.begin(); try { @@ -172,11 +114,11 @@ * @param topiaEntity - the TopiaEntity to delete. */ public void delete(TopiaEntity topiaEntity) throws TopiaException { - if (topiaEntity._getTopiaId() == null) { - throw new TopiaException("Can't delete "+topiaEntity+" has it seems not to exist (no identity found) !"); - } + if (topiaEntity._getTopiaId() == null) { + throw new TopiaException("Can't delete "+topiaEntity+" has it seems not to exist (no identity found) !"); + } TopiaEntityTO _to = (TopiaEntityTO) Util.toTO(topiaEntity); - PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); + PersistenceManager persistenceManager = ((TopiaJDOPersistenceHelper) getContext().getPersistenceHelper()).getPersistenceManager(); Transaction transaction = persistenceManager.currentTransaction(); transaction.begin(); try { @@ -187,36 +129,5 @@ } transaction.commit(); } - - /** - * 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 abstract TopiaEntityTO toTO(TopiaEntityDO topiaEntityDO) throws TopiaException; - - /** - * Returns the TopiaEntity DataObject corresponding to the given TopiaEntity TransferObject. - * @param topiaEntityTO - the TopiaEntity TransferObject whose DataObject is wanted. - * @see topiaEntityTO - * @see topiaEntityDO - * - * @return the corresponding TopiaEntity DataObject. - */ - public abstract TopiaEntityDO toDO(TopiaEntityTO topiaEntityTO) throws TopiaException; - - /** - * Returns the updated TopiaEntity DataObject corresponding to the given TopiaEntity TransferObject. - * Update is made by applying changes made to the TopiaEntity TransferObject to the DataObject (thus making those change persistent). - * @param topiaEntityTO - the TopiaEntity TransferObject whose DataObject is wanted. - * @see topiaEntityTO - * @see topiaEntityDO - * - * @return the corresponding TopiaEntity DataObject. - */ - public abstract TopiaEntityDO toUpdatedDO(TopiaEntityTO topiaEntityTO) throws TopiaException; } Index: topia/src/java/org/codelutin/topia/jdo/TopiaJDOPersistenceHelper.java diff -u topia/src/java/org/codelutin/topia/jdo/TopiaJDOPersistenceHelper.java:1.2 topia/src/java/org/codelutin/topia/jdo/TopiaJDOPersistenceHelper.java:1.3 --- topia/src/java/org/codelutin/topia/jdo/TopiaJDOPersistenceHelper.java:1.2 Fri May 28 15:40:16 2004 +++ topia/src/java/org/codelutin/topia/jdo/TopiaJDOPersistenceHelper.java Wed Jun 2 09:33:08 2004 @@ -13,55 +13,59 @@ import javax.jdo.PersistenceManagerFactory; import org.codelutin.topia.TopiaPersistenceHelper; +import org.codelutin.queryparser.Query; +import org.codelutin.queryparser.QueryExecute; +import org.codelutin.queryjdo.JDOQueryExecute; -/** - * @author cedric - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ public class TopiaJDOPersistenceHelper extends TopiaPersistenceHelper { - PersistenceManager persistenceManager = null; + protected PersistenceManager persistenceManager = null; + protected QueryExecute queryExecute = null; - public PersistenceManager getPersistenceManager() { - if (persistenceManager == null) { - PersistenceManagerFactory pmf = - JDOHelper.getPersistenceManagerFactory(getJDOProperties()); - persistenceManager = pmf.getPersistenceManager(); - } - return persistenceManager; - } + public QueryExecute getQueryExecute(){ + if(queryExecute == null){ + queryExecute = new JDOQueryExecute(getPersistenceManager()); + } + return queryExecute; + } - public Properties getJDOProperties() { - java.util.Properties properties = new java.util.Properties(); - properties.setProperty( - "javax.jdo.PersistenceManagerFactoryClass", - getContext().getProperty( - "javax.jdo.PersistenceManagerFactoryClass")); - properties.setProperty( - "javax.jdo.option.ConnectionDriverName", - getContext().getProperty("javax.jdo.option.ConnectionDriverName")); - properties.setProperty( - "javax.jdo.option.ConnectionURL", - getContext().getProperty("javax.jdo.option.ConnectionURL")); - properties.setProperty( - "javax.jdo.option.ConnectionUserName", - getContext().getProperty("javax.jdo.option.ConnectionUserName")); - properties.setProperty( - "javax.jdo.PersistenceManagerFactoryClass", - getContext().getProperty( - "javax.jdo.PersistenceManagerFactoryClass")); - properties.setProperty( - "javax.jdo.option.ConnectionPassword", - getContext().getProperty("javax.jdo.option.ConnectionPassword")); - properties.setProperty( - "javax.jdo.option.NontransactionalRead", - getContext().getProperty("javax.jdo.option.NontransactionalRead")); - properties.setProperty( - "com.triactive.jdo.autoCreateTables", - getContext().getProperty("com.triactive.jdo.autoCreateTables")); - return properties; - } + public PersistenceManager getPersistenceManager() { + if (persistenceManager == null) { + PersistenceManagerFactory pmf = + JDOHelper.getPersistenceManagerFactory(getJDOProperties()); + persistenceManager = pmf.getPersistenceManager(); + } + return persistenceManager; + } + public Properties getJDOProperties() { + java.util.Properties properties = new java.util.Properties(); + properties.setProperty( + "javax.jdo.PersistenceManagerFactoryClass", + getContext().getProperty( + "javax.jdo.PersistenceManagerFactoryClass")); + properties.setProperty( + "javax.jdo.option.ConnectionDriverName", + getContext().getProperty("javax.jdo.option.ConnectionDriverName")); + properties.setProperty( + "javax.jdo.option.ConnectionURL", + getContext().getProperty("javax.jdo.option.ConnectionURL")); + properties.setProperty( + "javax.jdo.option.ConnectionUserName", + getContext().getProperty("javax.jdo.option.ConnectionUserName")); + properties.setProperty( + "javax.jdo.PersistenceManagerFactoryClass", + getContext().getProperty( + "javax.jdo.PersistenceManagerFactoryClass")); + properties.setProperty( + "javax.jdo.option.ConnectionPassword", + getContext().getProperty("javax.jdo.option.ConnectionPassword")); + properties.setProperty( + "javax.jdo.option.NontransactionalRead", + getContext().getProperty("javax.jdo.option.NontransactionalRead")); + properties.setProperty( + "com.triactive.jdo.autoCreateTables", + getContext().getProperty("com.triactive.jdo.autoCreateTables")); + return properties; + } }