Index: topia2/src/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java diff -u topia2/src/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java:1.8 topia2/src/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java:1.9 --- topia2/src/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java:1.8 Thu Feb 23 14:05:47 2006 +++ topia2/src/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java Fri Mar 17 15:10:36 2006 @@ -23,10 +23,10 @@ * Created: 31 déc. 2005 13:10:34 * * @author poussin - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * - * Last update: $Date: 2006/02/23 14:05:47 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2006/03/17 15:10:36 $ + * by : $Author: thimel $ */ package org.codelutin.topia.persistence; @@ -34,6 +34,7 @@ import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -422,7 +423,115 @@ List result = findAllByProperties(properties); return result; } - + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map) + */ + public Entity findContainsProperties(Map properties) + throws TopiaException { + List results = findAllContainsProperties(properties); + Entity result = null; + if (results.size() > 0) { + result = results.get(0); + } + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) + */ + public Entity findContainsProperties(String propertyName, Collection values, Object... others) + throws TopiaException { + Map properties = new HashMap(); + properties.put(propertyName, values); + Object name = null; + for (int i = 0; i < others.length;) { + try { + name = others[i++]; + values = (Collection)others[i++]; + properties.put((String) name, values); + } catch (ClassCastException eee) { + throw new IllegalArgumentException( + "Les noms des propriétés doivent être des chaines et non pas " + + propertyName.getClass().getName(), eee); + } catch (ArrayIndexOutOfBoundsException eee) { + throw new IllegalArgumentException( + "Le nombre d'argument n'est pas un nombre pair: " + + (others.length + 2) + " La dernière propriété était: " + name, eee); + } + } + Entity result = findContainsProperties(properties); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map) + */ + public List findAllContainsProperties(Map properties) + throws TopiaException { + List all = findAll(); + List result = new ArrayList(); + for (Entity e : all) { + boolean ok = true; + try { + for(Entry kv : properties.entrySet()) { + Collection entityValues = (Collection)PropertyUtils.getProperty(e, kv.getKey()); + Collection values = kv.getValue(); + if (!entityValues.containsAll(values)) { + ok = false; + break; + } + } + } catch (IllegalAccessException eee) { + ok = false; + if (log.isWarnEnabled()) { + log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); + } + } catch (InvocationTargetException eee) { + ok = false; + if (log.isWarnEnabled()) { + log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); + } + } catch (NoSuchMethodException eee) { + ok = false; + if (log.isWarnEnabled()) { + log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee); + } + } + if (ok) { + result.add(e); + } + } + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) + */ + public List findAllContainsProperties(String propertyName, Collection values, Object... others) + throws TopiaException { + Map properties = new HashMap(); + properties.put(propertyName, values); + Object name = null; + for (int i = 0; i < others.length;) { + try { + name = others[i++]; + values = (Collection)others[i++]; + properties.put((String) name, values); + } catch (ClassCastException eee) { + throw new IllegalArgumentException( + "Les noms des propriétés doivent être des chaines et non pas " + + propertyName.getClass().getName(), eee); + } catch (ArrayIndexOutOfBoundsException eee) { + throw new IllegalArgumentException( + "Le nombre d'argument n'est pas un nombre pair: " + + (others.length + 2) + " La dernière propriété était: " + name, eee); + } + } + List result = findAllContainsProperties(properties); + return result; + } + /* (non-Javadoc) * @see org.codelutin.topia.TopiaDAO#findByTopiaId() */ Index: topia2/src/java/org/codelutin/topia/persistence/TopiaDAO.java diff -u topia2/src/java/org/codelutin/topia/persistence/TopiaDAO.java:1.4 topia2/src/java/org/codelutin/topia/persistence/TopiaDAO.java:1.5 --- topia2/src/java/org/codelutin/topia/persistence/TopiaDAO.java:1.4 Fri Jan 13 15:25:06 2006 +++ topia2/src/java/org/codelutin/topia/persistence/TopiaDAO.java Fri Mar 17 15:10:36 2006 @@ -23,14 +23,15 @@ * Created: 30 déc. 2005 03:00:57 * * @author poussin - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Last update: $Date: 2006/01/13 15:25:06 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2006/03/17 15:10:36 $ + * by : $Author: thimel $ */ package org.codelutin.topia.persistence; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -182,6 +183,35 @@ public abstract List findAllByProperties(Map properties) throws TopiaException; -} + /* + * Find Contains + */ + /** + * Cherche et renvoie la première entité trouvée dont les propriétés en clé + * de Map contiennent toutes les valeurs de la Collection. + */ + public abstract Entity findContainsProperties(Map properties) + throws TopiaException; + + /** + * Cherche et renvoie la première entité trouvée dont la propriété + * propertyName contient values, ainsi de suite avec others. + */ + public abstract Entity findContainsProperties(String propertyName, Collection values, Object... others) + throws TopiaException; + /** + * Cherche et renvoie la première entité trouvée dont les propriétés en clé + * de Map contiennent toutes les valeurs de la Collection. + */ + public abstract List findAllContainsProperties(Map properties) + throws TopiaException; + + /** + * Cherche et renvoie toutes les entités trouvées dont la propriété + * propertyName contient values, ainsi de suite avec others. + */ + public abstract List findAllContainsProperties(String propertyName, Collection values, Object... others) + throws TopiaException; +} //TopiaDAO Index: topia2/src/java/org/codelutin/topia/persistence/TopiaDAODelegator.java diff -u topia2/src/java/org/codelutin/topia/persistence/TopiaDAODelegator.java:1.4 topia2/src/java/org/codelutin/topia/persistence/TopiaDAODelegator.java:1.5 --- topia2/src/java/org/codelutin/topia/persistence/TopiaDAODelegator.java:1.4 Fri Jan 13 15:25:06 2006 +++ topia2/src/java/org/codelutin/topia/persistence/TopiaDAODelegator.java Fri Mar 17 15:10:36 2006 @@ -23,14 +23,15 @@ * Created: 30 déc. 2005 22:28:48 * * @author poussin - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Last update: $Date: 2006/01/13 15:25:06 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2006/03/17 15:10:36 $ + * by : $Author: thimel $ */ package org.codelutin.topia.persistence; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -210,6 +211,31 @@ return getParentDAO().findAllByProperties(properties); } + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map) + */ + public Entity findContainsProperties(Map properties) throws TopiaException { + return getParentDAO().findContainsProperties(properties); + } + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) + */ + public Entity findContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException { + return getParentDAO().findContainsProperties(propertyName, values, others); + } + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map) + */ + public List findAllContainsProperties(Map properties) throws TopiaException { + return getParentDAO().findAllContainsProperties(properties); + } + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[]) + */ + public List findAllContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException { + return getParentDAO().findAllContainsProperties(propertyName, values, others); + } + }