Author: tchemit Date: 2009-02-25 11:18:11 +0000 (Wed, 25 Feb 2009) New Revision: 1401 Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/TopiaEntityHelper.java Log: ajout methode utile, javadoc + @Override Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java 2009-02-20 16:56:16 UTC (rev 1400) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java 2009-02-25 11:18:11 UTC (rev 1401) @@ -1059,7 +1059,7 @@ @Override public <T extends TopiaEntity> void replicateEntities(TopiaContext dstCtxt, List<T> entities) throws TopiaException, IllegalArgumentException { - checkClosed("Ce contexte a ete ferme, impossible d'effectuer l'export"); + checkClosed("Ce contexte a ete ferme, impossible d'effectuer l'export"); TopiaContextImpl dstContextImpl = (TopiaContextImpl) dstCtxt; dstContextImpl.checkClosed("Ce contexte a ete ferme, impossible d'effectuer l'export"); if (getRootContext().equals(dstContextImpl.getRootContext())) { Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2009-02-20 16:56:16 UTC (rev 1400) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2009-02-25 11:18:11 UTC (rev 1401) @@ -50,6 +50,7 @@ * Cette persistence accède à l'objet Session hibernate pour exécuter * les différentes demandes de persistences. * + * @param <Entity> le type de l'entite. * @author poussin * */ @@ -78,6 +79,7 @@ /* (non-Javadoc) * @see org.codelutin.topia.TopiaDAO#update(Entity) */ + @Override public Entity update(Entity e) throws TopiaException { try { getSession().saveOrUpdate(e); @@ -91,6 +93,7 @@ /* (non-Javadoc) * @see org.codelutin.topia.TopiaDAO#delete(Entity) */ + @Override public void delete(Entity e) throws TopiaException { try { getSession().delete(e); @@ -124,6 +127,7 @@ } } + @Override public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException { try { @@ -164,6 +168,7 @@ /* (non-Javadoc) * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map) */ + @Override public List<Entity> findAllByProperties(Map<String, Object> properties) throws TopiaException { return queryAll(Restrictions.allEq(properties)); @@ -281,6 +286,7 @@ * (non-Javadoc) * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int) */ + @Override public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException { return null; Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/TopiaEntityHelper.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/TopiaEntityHelper.java 2009-02-20 16:56:16 UTC (rev 1400) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/util/TopiaEntityHelper.java 2009-02-25 11:18:11 UTC (rev 1401) @@ -13,8 +13,10 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.URI; +import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; +import java.util.List; /** * Une classe avec des méthodes utiles sur les entités. @@ -218,6 +220,7 @@ /** * Obtain a new {@link Comparator} pour {@link TopiaEntity} based * on the {@link TopiaEntity#getTopiaId()} method. + * @return the new instanciated comparator */ public static Comparator<TopiaEntity> getTopiaIdComparator() { return new Comparator<TopiaEntity>() { @@ -235,4 +238,22 @@ }; } + /** + * Filter a list of entities, and keep only the ones from a given type. + * + * @param entities the list of entities to filter + * @param filterClass the type of entities to keep + * @return the list of filtered entities for the given entity type in the list + * @since 2.1.4 + */ + public static List<TopiaEntity> filter(Collection<TopiaEntity> entities, Class<? extends TopiaEntity> filterClass) { + List<TopiaEntity> result = new ArrayList<TopiaEntity>(); + for (TopiaEntity e : entities) { + if (filterClass.isAssignableFrom(e.getClass())) { + result.add(e); + } + } + return result; + } + }