Index: topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java diff -u topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.45 topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.46 --- topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.45 Wed Nov 22 20:20:56 2006 +++ topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java Fri Jan 5 15:09:17 2007 @@ -23,9 +23,9 @@ * * @author poussin * - * @version $Revision: 1.45 $ + * @version $Revision: 1.46 $ * - * Last update: $Date: 2006/11/22 20:20:56 $ by : $Author: bpoussin $ + * Last update: $Date: 2007/01/05 15:09:17 $ by : $Author: bpoussin $ */ package org.codelutin.topia.framework; @@ -63,6 +63,7 @@ import java.util.zip.GZIPOutputStream; import org.apache.commons.collections.MapIterator; +import org.apache.commons.collections.set.MapBackedSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codelutin.topia.TopiaContext; @@ -180,7 +181,7 @@ * Set des sous context creer avec un beginTransaction et donc sur lequel * nous sommes listener */ - protected Map childContext = new WeakHashMap(); + protected Set childContext = MapBackedSet.decorate(new WeakHashMap()); /** key: service name; value: service instance */ protected Map services = null; @@ -283,11 +284,11 @@ } public Set getChildContext() { - return this.childContext.keySet(); + return this.childContext; } protected void addChildContext(TopiaContextImplementor child) { - childContext.put(child, null); + childContext.add(child); } public void removeChildContext(TopiaContextImplementor child) { @@ -686,17 +687,37 @@ // } checkClosed("Ce contexte a deja ete ferme"); - for (Iterator iter = childContext.keySet().iterator(); iter.hasNext();) { - TopiaContextImplementor child = (TopiaContextImplementor) iter.next(); - child.closeContext(); - iter.remove(); - } + + // suppression des contexts fils + TopiaContextImplementor [] childs = childContext.toArray(new TopiaContextImplementor[childContext.size()]); + for (TopiaContextImplementor child : childs) { + if (!child.isClosed()) { + child.closeContext(); + } + } +// for (Iterator iter = childContext.iterator(); iter.hasNext();) { +// TopiaContextImplementor child = (TopiaContextImplementor) iter.next(); +// child.closeContext(); +// iter.remove(); +// } + + // on se desenregistre du context pere et on ferme les connexions si + // on est pas le root context if (getRootContext() != this) { this.closed = true; hibernate.close(); + getParentContext().removeChildContext(this); } } +// /* (non-Javadoc) +// * @see java.lang.Object#finalize() +// */ +// @Override +// protected void finalize() throws Throwable { +// closeContext(); +// } + public boolean isClosed() { return closed; } @@ -735,6 +756,29 @@ } } + /** + * Execute HQL operation on data (Update, Delete) + * @param hql + * @param args + * @return The number of entities updated or deleted. + * @throws TopiaException + */ + public int execute(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; + for (Object arg : args) { + query.setParameter(i++, arg); + } + query.setFlushMode(FlushMode.AUTO); + int result = query.executeUpdate(); + return result; + } catch (HibernateException eee) { + throw new TopiaException("Error during query execution: " + hql, eee); + } + } + /* (non-Javadoc) * @see org.codelutin.topia.TopiaContext#add(org.codelutin.topia.persistence.TopiaEntity) */