Index: topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java diff -u topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.21 topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.22 --- topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.21 Wed Jun 7 15:56:01 2006 +++ topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java Mon Jul 3 10:08:31 2006 @@ -23,9 +23,9 @@ * * @author poussin * - * @version $Revision: 1.21 $ + * @version $Revision: 1.22 $ * - * Last update: $Date: 2006/06/07 15:56:01 $ by : $Author: thimel $ + * Last update: $Date: 2006/07/03 10:08:31 $ by : $Author: thimel $ */ package org.codelutin.topia.framework; @@ -164,6 +164,11 @@ protected Session hibernate = null; /** + * Indique si le contexte a ete ferme + */ + protected boolean closed = false; + + /** * Propriete de configuration */ protected Properties config = null; @@ -244,6 +249,13 @@ childContext.put(child, null); } + public void removeChildContext(TopiaContextImplementor child) { + //On ne retire les fils que si ce contexte n'est pas deja ferme. Permet d'eviter les acces concurrentiels + if (!closed) { + childContext.remove(child); + } + } + /* * (non-Javadoc) * @@ -628,7 +640,8 @@ * * @see org.codelutin.topia.TopiaContext#beginTransaction() */ - public TopiaContext beginTransaction() throws TopiaNotFoundException { + public TopiaContext beginTransaction() throws TopiaException { + checkClosed("Ce contexte a ete ferme, impossible de commencer une transaction"); TopiaContextImpl result = new TopiaContextImpl(this); addChildContext(result); SessionFactory factory = getHibernateFactory(); @@ -655,6 +668,7 @@ throw new TopiaException( "Vous êtes sur le root context le commit est impossible"); } + checkClosed("Ce contexte a ete ferme, impossible de faire un commit"); try { for (TopiaDAO dao : daoCache.values()) { dao.commitTransaction(); @@ -682,6 +696,7 @@ throw new TopiaException( "Vous êtes sur le root context le rollback est impossible"); } + checkClosed("Ce contexte a ete ferme, impossible de faire un rollback"); try { for (TopiaDAO dao : daoCache.values()) { dao.rollbackTransaction(); @@ -699,10 +714,35 @@ } } + public void closeContext() throws TopiaException { + if (getRootContext() == this) { + throw new TopiaException( + "Vous ne pouvez pas fermer le root context"); + } + checkClosed("Ce contexte a deja ete ferme"); + this.closed = true; + for(TopiaContextImplementor child : childContext.keySet()) { + child.closeContext(); + } + hibernate.close(); + getParentContext().removeChildContext(this); + } + + public boolean isClosed() { + return closed; + } + + private void checkClosed(String message) throws TopiaException { + if (closed) { + throw new TopiaException(message); + } + } + /* (non-Javadoc) * @see org.codelutin.topia.TopiaContext#findByTopiaId(java.lang.String) */ public TopiaEntity findByTopiaId(String topiaId) throws TopiaException { + checkClosed("Ce contexte a ete ferme, impossible de faire une recherche"); TopiaEntity result = null; Class entityClass = TopiaId.getClassName(topiaId); TopiaDAO dao = getDAO(entityClass); @@ -711,6 +751,7 @@ } public List find(String hql, Object ... args) throws TopiaException { + checkClosed("Ce contexte a ete ferme, impossible de faire une recherche"); try { Query query = getHibernate().createQuery(hql); int i = 0; @@ -728,6 +769,7 @@ * @see org.codelutin.topia.TopiaContext#add(org.codelutin.topia.persistence.TopiaEntity) */ public void add(TopiaEntity e) throws TopiaException { + checkClosed("Ce contexte a ete ferme, impossible d'ajouter une entite"); String id = e.getTopiaId(); Class entityClass = TopiaId.getClassName(id); TopiaDAO dao = getDAO(entityClass); @@ -738,6 +780,7 @@ * @see org.codelutin.topia.TopiaContext#importXML(java.io.Reader) */ public void importXML(Reader xml) throws TopiaException { + checkClosed("Ce contexte a ete ferme, impossible d'effectuer l'import"); Document doc = null; SAXReader xmlReader = new SAXReader(); @@ -770,7 +813,8 @@ /** (non-Javadoc) * @see org.codelutin.topia.TopiaContext#exportXML(java.io.Writer, java.lang.Object...) */ - public void exportXML(Writer xml, Object... entityAndcondition) throws TopiaException { + public void exportXML(Writer xml, Object... entityAndcondition) throws TopiaException { + checkClosed("Ce contexte a ete ferme, impossible d'effectuer l'export"); try { Class entityClass = null; String condition = null; Index: topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java diff -u topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java:1.7 topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java:1.8 --- topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java:1.7 Tue Jun 6 15:28:33 2006 +++ topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java Mon Jul 3 10:08:31 2006 @@ -23,9 +23,9 @@ * Created: 3 janv. 2006 21:27:24 * * @author poussin - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ * - * Last update: $Date: 2006/06/06 15:28:33 $ + * Last update: $Date: 2006/07/03 10:08:31 $ * by : $Author: thimel $ */ @@ -202,4 +202,6 @@ */ public String getSecurityType(); + public void removeChildContext(TopiaContextImplementor child); + } //TopiaContextImplementor