Author: tchemit Date: 2010-02-26 19:48:25 +0100 (Fri, 26 Feb 2010) New Revision: 1815 Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/CollectorTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java Log: - remove IDE headers - reformat code (80 caracters max on a line) - simplify exception managment in TopiaDAOImpl - improve loador api (based now on Binder) Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -69,7 +69,8 @@ } @Override - public void visit(TopiaEntity e, String propertyName, Class<?> type, Object value) { + public void visit(TopiaEntity e, String propertyName, Class<?> type, + Object value) { // si c'est une entité if (value instanceof TopiaEntity) { TopiaEntity entity = (TopiaEntity) value; @@ -90,8 +91,8 @@ } @Override - public void visit(TopiaEntity e, String propertyName, Class<?> collectionType, Class<?> type, - Object value) { + public void visit(TopiaEntity e, String propertyName, + Class<?> collectionType, Class<?> type,Object value) { Collection<?> cValue = (Collection<?>) value; if (cValue != null && !cValue.isEmpty()) { @@ -103,7 +104,9 @@ } @Override - public void visit(TopiaEntity e, String propertyName, Class<?> collectionType, Class<?> type, int index, Object value) { + public void visit(TopiaEntity e, String propertyName, + Class<?> collectionType, Class<?> type, int index, + Object value) { // si c'est une entité if (value instanceof TopiaEntity) { TopiaEntity entity = (TopiaEntity) value; @@ -118,7 +121,8 @@ } } else { if (delegateVisitor != null) { - delegateVisitor.visit(e, propertyName, collectionType, type, index, value); + delegateVisitor.visit(e, propertyName, collectionType, type, + index, value); } } } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -56,7 +56,8 @@ * @param type the type of the visited property * @param value the value of the visited property */ - void visit(TopiaEntity entity, String propertyName, Class<?> type, Object value); + void visit(TopiaEntity entity, String propertyName, Class<?> type, + Object value); /** * Visit a collection property for the given entity. @@ -69,7 +70,8 @@ * @param type the type of the visited property * @param value the value of the visited property */ - void visit(TopiaEntity entity, String propertyName, Class<?> collectionType, Class<?> type, Object value); + void visit(TopiaEntity entity, String propertyName, + Class<?> collectionType, Class<?> type, Object value); /** * Visit a indexed value from a collection property for the given entity. @@ -83,7 +85,8 @@ * @param index the index of the visited property in his container * @param value the value of the visited property */ - void visit(TopiaEntity entity, String propertyName, Class<?> collectionType, Class<?> type, int index, Object value); + void visit(TopiaEntity entity, String propertyName, + Class<?> collectionType, Class<?> type, int index, Object value); /** * Reset all states of the visitor. Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -26,8 +26,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.EntityVisitor; -import org.nuiton.topia.persistence.TopiaEntity; /** * Parcourt en largeur du modele et délegation à un autre visiteur. @@ -63,9 +61,6 @@ this.toVisitEntities = new ArrayList<TopiaEntity>(); } - /* - * @see org.nuiton.topia.persistence.EntityVisitor#start(org.nuiton.topia.persistence.TopiaEntity) - */ @Override public void start(TopiaEntity entity) { delegateVisitor.start(entity); @@ -74,11 +69,9 @@ } } - /* - * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Object) - */ @Override - public void visit(TopiaEntity entity, String propertyName, Class<?> type, Object value) { + public void visit(TopiaEntity entity, String propertyName, Class<?> type, + Object value) { // si c'est une entité if (value instanceof TopiaEntity) { TopiaEntity entityValue = (TopiaEntity) value; @@ -88,45 +81,40 @@ } } - /* - * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Class, java.lang.Object) - */ @Override - public void visit(TopiaEntity entity, String propertyName, Class<?> collectionType, - Class<?> type, Object value) { + public void visit(TopiaEntity entity, String propertyName, + Class<?> collectionType,Class<?> type, Object value) { Collection<?> values = (Collection<?>) value; if (values != null && !values.isEmpty()) { int i = 0; for (Object currentValue : values) { - visit(entity, propertyName, type, collectionType, i++, currentValue); + visit(entity, propertyName, type, collectionType, i++, + currentValue); } } } - /* - * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Class, int, java.lang.Object) - */ @Override - public void visit(TopiaEntity entity, String propertyName, Class<?> collectionType, - Class<?> type, int index, Object value) { + public void visit(TopiaEntity entity, String propertyName, + Class<?> collectionType, Class<?> type, int index, + Object value) { // si c'est une entité if (value instanceof TopiaEntity) { TopiaEntity entityValue = (TopiaEntity) value; toVisitEntities.add(entityValue); } else { - delegateVisitor.visit(entity, propertyName, collectionType, type, index, value); + delegateVisitor.visit(entity, propertyName, collectionType, type, + index, value); } } - /* - * @see org.nuiton.topia.persistence.EntityVisitor#end(org.nuiton.topia.persistence.TopiaEntity) - */ @Override public void end(TopiaEntity entity) { delegateVisitor.end(entity); // here, must revisit all remembered entities - List<TopiaEntity> currentEntities = new ArrayList<TopiaEntity>(toVisitEntities); + List<TopiaEntity> currentEntities = + new ArrayList<TopiaEntity>(toVisitEntities); // TODO verify if clearing here is enough toVisitEntities.clear(); for (TopiaEntity currentEntity : currentEntities) { @@ -143,9 +131,6 @@ } } - /* - * @see org.nuiton.topia.persistence.EntityVisitor#clear() - */ @Override public void clear() { alreadyExplored.clear(); Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -49,12 +49,12 @@ public interface TopiaDAO<Entity extends TopiaEntity> { /** - * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just - * after. + * When TopiaContextImpl create the TopiaDAOHibernate, it must call this + * method just after. * * @param context context * @param entityClass entity class - * @throws TopiaException + * @throws TopiaException if any pb while init */ void init(TopiaContextImplementor context, Class<Entity> entityClass) throws TopiaException; @@ -77,14 +77,14 @@ * car plusieurs type de persistence peuvent etre melangé, et il * serait bien que si l'une echoué les autres echoue aussi. * - * @throws TopiaException + * @throws TopiaException if any pb while commit */ void commitTransaction() throws TopiaException; /** * Appelé lorsque le context a eu un rollback de fait. * - * @throws TopiaException + * @throws TopiaException if any pb while rollback */ void rollbackTransaction() throws TopiaException; @@ -115,7 +115,7 @@ * de DAO * @param e l'entite a ajouter ou mettre a jour * @return l'entity passé en paramètre. - * @throws TopiaException + * @throws TopiaException if any pb while updating datas */ Entity update(Entity e) throws TopiaException; @@ -140,7 +140,7 @@ * Compte le nombre d'entites en base * * @return le nombre total d'entites existantes - * @throws TopiaException + * @throws TopiaException if any pb while getting datas */ long size() throws TopiaException; @@ -148,12 +148,15 @@ * Crée une requete basé sur l'entité lié au DAO. * Résultat attendu : "FROM Entity" * - * @return une nouvelle TopiaQuery vide. (uniquement avec le From sur le type d'entité) + * @return une nouvelle TopiaQuery vide. (uniquement avec le From sur le + * type d'entité) */ TopiaQuery createQuery(); /** - * Crée une requête basé sur l'entité lié au DAO et lui assigne un alias valable dans la requête. + * Crée une requête basé sur l'entité lié au DAO et lui assigne un alias + * valable dans la requête.. + * * Résultat attendu : "FROM Entity AS entityAlias" * * @param entityAlias alias permettant de manipuler l'entité dans la requête @@ -168,7 +171,7 @@ * @param query la requête * @return l'entité correspondant à la recherche ou null si aucune entité * n'a été trouvée - * @throws TopiaException + * @throws TopiaException if any pb while getting datas * @see org.nuiton.topia.framework.TopiaQuery#executeToEntity(org.nuiton.topia.TopiaContext, java.lang.Class) */ Entity findByQuery(TopiaQuery query) throws TopiaException; @@ -179,7 +182,7 @@ * * @param query la requête * @return la liste d'entités correspondant à la recherche - * @throws TopiaException + * @throws TopiaException if any pb while getting datas * @see org.nuiton.topia.framework.TopiaQuery#executeToEntityList(org.nuiton.topia.TopiaContext, java.lang.Class) */ List<Entity> findAllByQuery(TopiaQuery query) throws TopiaException; @@ -191,7 +194,7 @@ * * @param query la requête * @return la map d'entités correspondant à la recherche - * @throws TopiaException + * @throws TopiaException if any pb while getting datas * @see org.nuiton.topia.framework.TopiaQuery#executeToEntityMap(org.nuiton.topia.TopiaContext, java.lang.Class) */ Map<String, Entity> findAllMappedByQuery(TopiaQuery query) throws TopiaException; @@ -206,7 +209,7 @@ * @param keyName nom de la propriété de l'entité utilisée comme clé * @param keyClass type de la propriété de l'entité utilisée comme clé * @return la map d'entités correspondant à la recherche - * @throws TopiaException + * @throws TopiaException if any pb while getting datas * @see org.nuiton.topia.framework.TopiaQuery#executeToEntityMap(org.nuiton.topia.TopiaContext, java.lang.Class) */ <K> Map<K, Entity> findAllMappedByQuery(TopiaQuery query, @@ -229,11 +232,12 @@ * * @param k l'objet cle naturelle de la classe * @return l'entité trouvé - * @throws TopiaException + * @throws TopiaException if any pb while getting datas */ Entity findByPrimaryKey(Object... k) throws TopiaException; - Entity findByProperty(String propertyName, Object value) throws TopiaException; + Entity findByProperty(String propertyName, Object value) + throws TopiaException; /** * @@ -242,9 +246,10 @@ * @param others les autres proprietes doivent aller par 2 propertyName, * value * @return l'entité trouvé - * @throws TopiaException + * @throws TopiaException if any pb while getting datas */ - Entity findByProperties(String propertyName, Object value, Object... others) throws TopiaException; + Entity findByProperties(String propertyName, Object value, + Object... others) throws TopiaException; Entity findByProperties(Map<String, Object> properties) throws TopiaException; @@ -258,7 +263,7 @@ * @param others les autres proprietes doivent aller par 2 propertyName, * value * @return l'entité trouvé - * @throws TopiaException + * @throws TopiaException if any pb while getting datas */ List<Entity> findAllByProperties(String propertyName, Object value, Object... others) throws TopiaException; @@ -275,7 +280,7 @@ * * @param properties * @return l'entité trouvé - * @throws TopiaException + * @throws TopiaException if any pb while getting datas */ Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException; @@ -288,7 +293,7 @@ * @param values * @param others * @return l'entité trouvé - * @throws TopiaException + * @throws TopiaException if any pb while getting datas */ Entity findContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException; @@ -299,7 +304,7 @@ * * @param properties * @return l'entité trouvé - * @throws TopiaException + * @throws TopiaException if any pb while getting datas */ List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException; @@ -308,22 +313,52 @@ * Cherche et renvoie toutes les entités trouvées dont la propriété * propertyName contient values, ainsi de suite avec others. * - * @param propertyName + * @param propertyName the name of the property * @param values * @param others * @return l'entité trouvé - * @throws TopiaException + * @throws TopiaException if any pb while getting datas */ List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException; /** - * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas. + * Find usages of the given {@code entity} in the entities of the given + * {@code type}. + * + * @param type the type of entity to search + * @param entity the entity + * @param <U> tthe type of entity to search + * @return the list of entities of the given type which uses the given + * entity + * @throws TopiaException if any problem while getting data + * @since 2.3.0 + */ + <U extends TopiaEntity> List<U> findUsages(Class<U> type, Entity entity) + throws TopiaException; + + /** + * Find all usages of the given {@code entity}. * + * @param entity the entity + * @return the dictionnary of usages of the given entities (keys are entity + * usage container, values are the list of this type of entity to use the + * given entity). + * @throws TopiaException if any pb while getting data + * @since 2.3.0 + */ + + Map<Class<?>, List<? extends TopiaEntity>> findAllUsages(Entity entity) + throws TopiaException; + + /** + * Retourne les permissions a verifier pour l'acces a l'entite pour le + * service Taas. + * * @param topiaId topiaId d'une entite * @param actions * @return la liste des permissions - * @throws TopiaException + * @throws TopiaException if any pb while getting datas */ List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -96,21 +96,25 @@ ClassMetadata meta = getClassMetadata(); String idPropName = meta.getIdentifierPropertyName(); - Serializable result; try { + Serializable result; result = (Serializable) PropertyUtils.getSimpleProperty(e, idPropName); - } catch (IllegalAccessException eee) { + return result; + } catch (Exception eee) { throw new TopiaException("Impossible de récuperer l'identifiant " + idPropName + " de l'entite: " + e); - } catch (InvocationTargetException eee) { - throw new TopiaException("Impossible de récuperer l'identifiant " - + idPropName + " de l'entite: " + e); - } catch (NoSuchMethodException eee) { - throw new TopiaException("Impossible de récuperer l'identifiant " - + idPropName + " de l'entite: " + e); } - return result; +// } catch (IllegalAccessException eee) { +// throw new TopiaException("Impossible de récuperer l'identifiant " +// + idPropName + " de l'entite: " + e); +// } catch (InvocationTargetException eee) { +// throw new TopiaException("Impossible de récuperer l'identifiant " +// + idPropName + " de l'entite: " + e); +// } catch (NoSuchMethodException eee) { +// throw new TopiaException("Impossible de récuperer l'identifiant " +// + idPropName + " de l'entite: " + e); +// } } /** @@ -132,8 +136,8 @@ } /** - * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just - * after + * When TopiaContextImpl create the TopiaDAOHibernate, it must call this + * method just after. * * @param entityClass */ @@ -165,29 +169,37 @@ log.debug("Utilisation de la classe " + classname + "Impl" + " pour " + classname); } - } catch (InstantiationException eee) { + } catch (ClassNotFoundException eee) { if (log.isWarnEnabled()) { - log.warn("Impossible d'instancier " + classname + "Impl"); + log.warn("Impossible de trouver la classe " + classname + + "Impl"); } if (log.isDebugEnabled()) { log.debug("StackTrace", eee); } - } catch (IllegalAccessException eee) { + } catch (Exception eee) { if (log.isWarnEnabled()) { log.warn("Impossible d'instancier " + classname + "Impl"); } if (log.isDebugEnabled()) { log.debug("StackTrace", eee); } - } catch (ClassNotFoundException eee) { - if (log.isWarnEnabled()) { - log.warn("Impossible de trouver la classe " + classname - + "Impl"); - } - if (log.isDebugEnabled()) { - log.debug("StackTrace", eee); - } } +// } catch (InstantiationException eee) { +// if (log.isWarnEnabled()) { +// log.warn("Impossible d'instancier " + classname + "Impl"); +// } +// if (log.isDebugEnabled()) { +// log.debug("StackTrace", eee); +// } +// } catch (IllegalAccessException eee) { +// if (log.isWarnEnabled()) { +// log.warn("Impossible d'instancier " + classname + "Impl"); +// } +// if (log.isDebugEnabled()) { +// log.debug("StackTrace", eee); +// } +// } if (result == null) { // le impl n'est pas trouvé on essai avec la classe elle meme @@ -197,21 +209,29 @@ log.debug("Utilisation de la classe " + classname + " pour " + classname); } - } catch (InstantiationException eee) { + } catch (Exception eee) { if (log.isWarnEnabled()) { log.warn("Impossible d'instancier " + classname); } if (log.isDebugEnabled()) { log.debug("StackTrace", eee); } - } catch (IllegalAccessException eee) { - if (log.isWarnEnabled()) { - log.warn("Impossible d'instancier " + classname); - } - if (log.isDebugEnabled()) { - log.debug("StackTrace", eee); - } } +// } catch (InstantiationException eee) { +// if (log.isWarnEnabled()) { +// log.warn("Impossible d'instancier " + classname); +// } +// if (log.isDebugEnabled()) { +// log.debug("StackTrace", eee); +// } +// } catch (IllegalAccessException eee) { +// if (log.isWarnEnabled()) { +// log.warn("Impossible d'instancier " + classname); +// } +// if (log.isDebugEnabled()) { +// log.debug("StackTrace", eee); +// } +// } } if (result == null) { @@ -259,8 +279,8 @@ + propertyName); } catch (ClassCastException eee) { throw new IllegalArgumentException( - "Wrong argument type, wait property name as String and have " - + propertyName.getClass().getName()); + "Wrong argument type, wait property name as String and " + + "have " + propertyName.getClass().getName()); } E result = create(map); @@ -343,8 +363,9 @@ properties.put((String) name, value); } catch (ClassCastException eee) { throw new IllegalArgumentException( - "Les noms des propriétés doivent être des chaines et non pas " - + propertyName.getClass().getName(), eee); + "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: " @@ -369,8 +390,9 @@ properties.put((String) name, value); } catch (ClassCastException eee) { throw new IllegalArgumentException( - "Les noms des propriétés doivent être des chaines et non pas " - + propertyName.getClass().getName(), eee); + "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: " @@ -387,7 +409,7 @@ throws TopiaException { List<E> results = findAllContainsProperties(properties); E result = null; - if (results.size() > 0) { + if (!results.isEmpty()) { result = results.get(0); } return result; @@ -406,8 +428,9 @@ 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); + "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: " @@ -421,8 +444,8 @@ /** * Find all entities with a specific rule : - * When the entity have a Collection type property, you want to find all entites where some values are - * contained in the collection type property. + * When the entity have a Collection type property, you want to find all + * entites where some values are contained in the collection type property. * Example entity parameter : private Collection<Date> historicalDates; * You want some dates to be contained in historicalDates. * Collection<Date> myDates... @@ -435,7 +458,8 @@ * @throws org.nuiton.topia.TopiaException if any pb */ @Override - public List<E> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException { + public List<E> findAllContainsProperties(Map<String, + Collection> properties) throws TopiaException { List<E> all = findAll(); List<E> result = new ArrayList<E>(); for (E e : all) { @@ -450,28 +474,36 @@ break; } } - } catch (IllegalAccessException eee) { + } catch (Exception eee) { ok = false; if (log.isWarnEnabled()) { log.warn( - "Impossible d'acceder a la methode demandé pour l'obbjet " - + e, eee); + "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); - } } +// } 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); } @@ -492,8 +524,9 @@ 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); + "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: " @@ -523,6 +556,22 @@ return result; } + @Override + public <U extends TopiaEntity> List<U> findUsages(Class<U> type, E e) + throws TopiaException { + // must be implemented by specialized dao + throw new UnsupportedOperationException(); + } + + @Override + public Map<Class<?>, List<? extends TopiaEntity>> findAllUsages(E e) + throws TopiaException { + // must be implemented by specialized dao + throw new UnsupportedOperationException(); + } + + //TODO-TC20100225 Says since when it is deprecated (via javadoc annotations + //TODO-TC20100225 + tells what to use instead) @Deprecated private Criterion computeCriterions(Object... values) { if (values == null) { @@ -535,11 +584,13 @@ return criterion; } + //TODO-TC20100225 Says since when it is deprecated (via javadoc annotations + //TODO-TC20100225 + tells what to use instead) @Deprecated private Criterion computeCriterion(Object value) { Criterion criterion = null; SearchFields fields = entityClass.getAnnotation(SearchFields.class); - String textValue = "%" + value + "%"; + String textValue = "%" + value + '%'; //textFields String[] textFields = fields.txtFields(); for (String propName : textFields) { @@ -560,7 +611,7 @@ String[] numFields = fields.numFields(); for (String propName : numFields) { criterion = or(criterion, Restrictions.sqlRestriction(propName - + " like '" + textValue + "'")); + + " like '" + textValue + '\'')); } } //boolFields @@ -586,11 +637,13 @@ String[] timeFields = fields.dateFields(); for (String propName : timeFields) { criterion = or(criterion, Restrictions.sqlRestriction(propName - + " like '" + textValue + "'")); + + " like '" + textValue + '\'')); } return criterion; } + //TODO-TC20100225 Says since when it is deprecated (via javadoc annotations + //TODO-TC20100225 + tells what to use instead) @Deprecated private Criterion or(Criterion crit1, Criterion crit2) { if (crit1 == null) { @@ -735,14 +788,17 @@ } @Override - public Map<String, E> findAllMappedByQuery(TopiaQuery query) throws TopiaException { + public Map<String, E> findAllMappedByQuery(TopiaQuery query) + throws TopiaException { return query.executeToEntityMap(context, getEntityClass()); } @Override - public <K> Map<K, E> findAllMappedByQuery(TopiaQuery query, String keyName, Class<K> keyClass) + public <K> Map<K, E> findAllMappedByQuery(TopiaQuery query, String keyName, + Class<K> keyClass) throws TopiaException { - return query.executeToEntityMap(context, getEntityClass(), keyName, keyClass); + return query.executeToEntityMap(context, getEntityClass(), keyName, + keyClass); } @Override @@ -769,7 +825,8 @@ } /** - * Count number of existing entities using {@link org.nuiton.topia.framework.TopiaQuery#executeCount(org.nuiton.topia.TopiaContext) } + * Count number of existing entities using + * {@link TopiaQuery#executeCount(org.nuiton.topia.TopiaContext) } * FIXME-FD20091224 change type to int like in 2.2.2 version * * @return a long for the number of entities in database @@ -882,6 +939,7 @@ // } /** + * TODO-TC20100225 Should this method deprecated (it is never used ?) * Renvoie un Criteria créé avec l'entityClass * @param mode le FlushMode du Criteria * @return le Criteria nouvellement créé Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -54,49 +54,49 @@ String TOPIA_CREATE_DATE = "topiaCreateDate"; String TOPIA_VERSION = "topiaVersion"; - public String getTopiaId(); + String getTopiaId(); - public void setTopiaId(String v); + void setTopiaId(String v); - public long getTopiaVersion(); + long getTopiaVersion(); - public void setTopiaVersion(long v); + void setTopiaVersion(long v); /** * @return Returns the topiaCreateTime. */ - public Date getTopiaCreateDate(); + Date getTopiaCreateDate(); /** * @param topiaCreatedate the topiaCreateTime to set. */ - public void setTopiaCreateDate(Date topiaCreatedate); + void setTopiaCreateDate(Date topiaCreatedate); - public TopiaContext getTopiaContext(); + TopiaContext getTopiaContext(); /** * called just after object creation and initialisation * each entity impl can overide it to do something after creation * @throws TopiaException */ - public void postCreate() throws TopiaException; + void postCreate() throws TopiaException; - public void update() throws TopiaException; + void update() throws TopiaException; - public void delete() throws TopiaException; + void delete() throws TopiaException; /** * @return all object that must be deleted if this object is deleted * @throws TopiaException */ - public List<TopiaEntity> getComposite() throws TopiaException; + List<TopiaEntity> getComposite() throws TopiaException; /** * @return all object that are aggregate with this instance, aggreate object * are not removed automaticaly * @throws TopiaException */ - public List<TopiaEntity> getAggregate() throws TopiaException; + List<TopiaEntity> getAggregate() throws TopiaException; /** * Add listener for property writing. @@ -104,7 +104,7 @@ * @param propertyName * @param listener */ - public void addPropertyChangeListener(String propertyName, + void addPropertyChangeListener(String propertyName, PropertyChangeListener listener); /** @@ -112,22 +112,22 @@ * * @param listener */ - public void addPropertyChangeListener(PropertyChangeListener listener); + void addPropertyChangeListener(PropertyChangeListener listener); - public void addVetoableChangeListener(String propertyName, + void addVetoableChangeListener(String propertyName, VetoableChangeListener vetoable); - public void addVetoableChangeListener(VetoableChangeListener vetoable); + void addVetoableChangeListener(VetoableChangeListener vetoable); - public void removePropertyChangeListener(String propertyName, + void removePropertyChangeListener(String propertyName, PropertyChangeListener listener); - public void removePropertyChangeListener(PropertyChangeListener listener); + void removePropertyChangeListener(PropertyChangeListener listener); - public void removeVetoableChangeListener(String propertyName, + void removeVetoableChangeListener(String propertyName, VetoableChangeListener vetoable); - public void removeVetoableChangeListener(VetoableChangeListener vetoable); + void removeVetoableChangeListener(VetoableChangeListener vetoable); /** * Add listener for property reading. @@ -135,30 +135,30 @@ * @param propertyName * @param listener */ - public void addPropertyListener(String propertyName, - PropertyChangeListener listener); + void addPropertyListener(String propertyName, + PropertyChangeListener listener); /** * Add listener for property reading. * * @param listener */ - public void addPropertyListener(PropertyChangeListener listener); + void addPropertyListener(PropertyChangeListener listener); - public void addVetoableListener(String propertyName, + void addVetoableListener(String propertyName, VetoableChangeListener vetoable); - public void addVetoableListener(VetoableChangeListener vetoable); + void addVetoableListener(VetoableChangeListener vetoable); - public void removePropertyListener(String propertyName, + void removePropertyListener(String propertyName, PropertyChangeListener listener); - public void removePropertyListener(PropertyChangeListener listener); + void removePropertyListener(PropertyChangeListener listener); - public void removeVetoableListener(String propertyName, + void removeVetoableListener(String propertyName, VetoableChangeListener vetoable); - public void removeVetoableListener(VetoableChangeListener vetoable); + void removeVetoableListener(VetoableChangeListener vetoable); /** * Parcourt de l'entité via un visiteur. @@ -166,6 +166,6 @@ * @param visitor visitor le visiteur utilise * @throws TopiaException pour toute erreur pendant le parcours */ - public void accept(EntityVisitor visitor) throws TopiaException; + void accept(EntityVisitor visitor) throws TopiaException; } //TopiaEntity Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -66,80 +66,45 @@ transient protected TopiaContext topiaContext = null; - transient protected VetoableChangeSupport readVetoables = new VetoableChangeSupport( - this); - transient protected PropertyChangeSupport readListeners = new PropertyChangeSupport( - this); - transient protected VetoableChangeSupport writeVetoables = new VetoableChangeSupport( - this); - transient protected PropertyChangeSupport writeListeners = new PropertyChangeSupport( - this); + transient protected VetoableChangeSupport readVetoables = + new VetoableChangeSupport(this); + transient protected PropertyChangeSupport readListeners = + new PropertyChangeSupport(this); + transient protected VetoableChangeSupport writeVetoables = + new VetoableChangeSupport(this); + transient protected PropertyChangeSupport writeListeners = + new PropertyChangeSupport(this); - /* - * (non-Javadoc) - * - * @see org.nuiton.topia.persistence.TopiaEntity#getTopiaId() - */ @Override public String getTopiaId() { return topiaId; } - /* - * (non-Javadoc) - * - * @see org.nuiton.topia.persistence.TopiaEntity#setTopiaId(String) - */ @Override public void setTopiaId(String v) { this.topiaId = v; } - /* - * (non-Javadoc) - * - * @see org.nuiton.topia.persistence.TopiaEntity#getTopiaVersion() - */ @Override public long getTopiaVersion() { return topiaVersion; } - /* - * (non-Javadoc) - * - * @see org.nuiton.topia.persistence.TopiaEntity#setTopiaVersion(long) - */ @Override public void setTopiaVersion(long v) { this.topiaVersion = v; } - /* - * (non-Javadoc) - * - * @see org.nuiton.topia.persistence.TopiaEntity#getTopiaCreateTime() - */ @Override public Date getTopiaCreateDate() { return topiaCreateDate; } - /* - * (non-Javadoc) - * - * @see org.nuiton.topia.persistence.TopiaEntity#setTopiaCreateTime(java.util.Date) - */ @Override public void setTopiaCreateDate(Date topiaCreateDate) { this.topiaCreateDate = topiaCreateDate; } - /* - * (non-Javadoc) - * - * @see org.nuiton.topia.persistence.TopiaEntity#getTopiaContext() - */ @Override public TopiaContext getTopiaContext() { return topiaContext; @@ -162,37 +127,21 @@ // do nothing by default } - /* - * (non-Javadoc) - * - * @see org.nuiton.topia.persistence.TopiaEntity#update() - */ @Override public void update() throws TopiaException { throw new UnsupportedOperationException(); } - /* - * (non-Javadoc) - * - * @see org.nuiton.topia.persistence.TopiaEntity#delete() - */ @Override public void delete() throws TopiaException { throw new UnsupportedOperationException(); } - /* (non-Javadoc) - * @see org.nuiton.topia.persistence.TopiaEntity#getComposite() - */ @Override public List<TopiaEntity> getComposite() throws TopiaException { throw new UnsupportedOperationException(); } - /* (non-Javadoc) - * @see org.nuiton.topia.persistence.TopiaEntity#getAggregate() - */ @Override public List<TopiaEntity> getAggregate() throws TopiaException { throw new UnsupportedOperationException(); @@ -237,7 +186,8 @@ } protected void fireOnPreRead(String propertyName, Object value) { - TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext(); + TopiaContextImplementor contextImplementor = + (TopiaContextImplementor) getTopiaContext(); if (contextImplementor != null) { contextImplementor.getFiresSupport().fireOnPreRead(readVetoables, this, propertyName, value); @@ -245,15 +195,18 @@ } protected void fireOnPostRead(String propertyName, Object value) { - TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext(); + TopiaContextImplementor contextImplementor = + (TopiaContextImplementor) getTopiaContext(); if (contextImplementor != null) { contextImplementor.getFiresSupport().fireOnPostRead(readListeners, this, propertyName, value); } } - protected void fireOnPostRead(String propertyName, int index, Object value) { - TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext(); + protected void fireOnPostRead(String propertyName, int index, + Object value) { + TopiaContextImplementor contextImplementor = + (TopiaContextImplementor) getTopiaContext(); if (contextImplementor != null) { contextImplementor.getFiresSupport().fireOnPostRead(readListeners, this, propertyName, index, value); @@ -262,7 +215,8 @@ protected void fireOnPreWrite(String propertyName, Object oldValue, Object newValue) { - TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext(); + TopiaContextImplementor contextImplementor = + (TopiaContextImplementor) getTopiaContext(); if (contextImplementor != null) { contextImplementor.getFiresSupport().fireOnPreWrite(writeVetoables, this, propertyName, oldValue, newValue); @@ -271,7 +225,8 @@ protected void fireOnPostWrite(String propertyName, Object oldValue, Object newValue) { - TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext(); + TopiaContextImplementor contextImplementor = + (TopiaContextImplementor) getTopiaContext(); if (contextImplementor != null) { contextImplementor.getFiresSupport().fireOnPostWrite( writeListeners, this, propertyName, oldValue, newValue); @@ -280,7 +235,8 @@ protected void fireOnPostWrite(String propertyName, int index, Object oldValue, Object newValue) { - TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext(); + TopiaContextImplementor contextImplementor = + (TopiaContextImplementor) getTopiaContext(); if (contextImplementor != null) { contextImplementor.getFiresSupport().fireOnPostWrite( writeListeners, this, propertyName, index, oldValue, Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -58,6 +58,7 @@ public int hashCode() { if (topiaId == null) { + //TODO-TC20100225 : use commons-loggin api instead of jdk one Logger.getLogger(getClass().getName() + ".hashCode").log( Level.WARNING, "Use null topiaId", new Throwable()); return 0; @@ -88,7 +89,7 @@ while (Double.toString(random).contains("E-")) { random = Math.random(); } - return clazz.getName() + "#" + System.currentTimeMillis() + "#" + return clazz.getName() + '#' + System.currentTimeMillis() + '#' + random; } @@ -120,7 +121,7 @@ */ public static String getClassNameAsString(String topiaId) { String result = ""; - int i = topiaId.indexOf("#"); + int i = topiaId.indexOf('#'); if (i > 0) { result = topiaId.substring(0, i); } @@ -143,6 +144,7 @@ } return false; } catch (Exception eee) { + //TODO-TC20100225 : use commons-loggin api instead of jdk one Logger.getLogger(TopiaId.class.getName() + ".isValidId").log( Level.WARNING, "Error during verfication of topiaId", eee); return false; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -21,6 +21,8 @@ package org.nuiton.topia.persistence.util; +import org.nuiton.util.ObjectUtil; + import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; @@ -37,8 +39,8 @@ * Some factory methods are defined to simplify the generic cast, prefer used them * instead of the (protected) constructor. * + * @author tchemit < chemit@codelutin.com > * @param <E> type of bean to bind - * @author tchemit < chemit@codelutin.com > * @deprecated since 2.3.0, prefer use the {@link TopiaEntityBinder} */ @Deprecated @@ -47,12 +49,13 @@ public static <E> BeanPropertyLoador<E> newLoador(Class<E> klass, String... properties) { return new BeanPropertyLoador<E>(klass, properties); } + private static final long serialVersionUID = 1L; - protected static final Integer ZERO = 0; - protected static final Float ZEROF = 0f; - protected static final Long ZEROL = 0l; - protected static final Double ZEROD = 0.; - protected static final Byte ZEROB = 0; +// protected static final Integer ZERO = 0; +// protected static final Float ZEROF = 0f; +// protected static final Long ZEROL = 0l; +// protected static final Double ZEROD = 0.; +// protected static final Byte ZEROB = 0; protected List<String> properties; protected transient PropertyDescriptor[] descriptors; protected Class<E> klass; @@ -84,10 +87,15 @@ } @Override - public Map<String, Object> obtainProperties(E from) { + public Map<String, Object> obtainProperties(E from, String... propertyNames) { if (from == null) { return java.util.Collections.emptyMap(); } + if (propertyNames.length > 0) { + throw new IllegalArgumentException("The BeanPropertyLoader does " + + "not accept subset of properties, prefer use the " + + "org.nuiton.util.beans.Binder api instead now."); + } Map<String, Object> result = new HashMap<String, Object>(); for (PropertyDescriptor descriptor : getDescriptors()) { Object read; @@ -107,17 +115,12 @@ } @Override - @Deprecated - public Map<String, Object> obtainProgperties(E from) { - return obtainProperties(from); - } - - @Override - public void load(E from, E dst, boolean tech) { + public void load(E from, E dst, boolean tech, String... propertyNames) { if (from == null) { // reset all fields for (PropertyDescriptor descriptor : getDescriptors()) { - Object read = TopiaEntityHelper.getNullValue(descriptor.getPropertyType()); + Object read = + ObjectUtil.getNullValue(descriptor.getPropertyType()); setProperty(dst, descriptor, read); } } else { @@ -150,7 +153,7 @@ */ @Deprecated protected static Object getNullValue(Class<?> type) { - return TopiaEntityHelper.getNullValue(type); + return ObjectUtil.getNullValue(type); } /** @@ -160,7 +163,7 @@ */ @Deprecated public static boolean isNullValue(Object value) { - return TopiaEntityHelper.isNullValue(value); + return ObjectUtil.isNullValue(value); } protected void checkProperties() { Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -24,7 +24,8 @@ * A simple contract to hook the deletion of an entity. * * @author chemit - * @param <P> the parent of the entity to delete (if the entity has no parent says is not in a association + * @param <P> the parent of the entity to delete (if the entity has no parent + * says is not in a association) * of another entity, just used the {@link Void} type). * @param <E> the type of the entity to delete. */ Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -49,14 +49,14 @@ } @Override - public void load(E from, E dst, boolean tech) { + public void load(E from, E dst, boolean tech,String... propertyNames) { if (from == null) { from = empty; } if (tech) { TopiaEntityHelper.bindTechnical(from, dst); } - super.load(from, dst, tech); + super.load(from, dst, tech,propertyNames); } protected EntityLoador(Class<E> klass, E empty, String... properties) { Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -25,37 +25,37 @@ /** * A simple contract to load an object from another one. * + * @author chemit * @param <E> type of bean to load - * @author chemit - * @deprecated since 2.3.0, prefer use the {@link org.nuiton.util.beans.Binder} - * api (and {@link TopiaEntityBinder} extension. */ -@Deprecated public interface Loador<E> extends java.io.Serializable { /** - * Obtain from an entity all data to bind to another one according the definition of the loador. + * Obtain from an entity all data to bind to another one according the + * definition of the loador. * <p/> - * This method is usefull when you can not directly used the {@link #load(Object, Object, boolean)} method. + * This method is usefull when you can not directly used the + * {@link #load(Object, Object, boolean, String...)} method. * <p/> - * For example, when an entity has a immutable business key (says with an hibernate naturalId for example), - * and that you want to create the data in a db, you must give all the properties at the create time so - * this method allow you to do it). + * For example, when an entity has a immutable business key (says with an + * hibernate naturalId for example), + * and that you want to create the data in a db, you must give all the + * properties at the create time so this method allow you to do it). * - * @param from the entity to bind + * @param from the entity to bind + * @param propertyNames subset of properties to load * @return the map of properties to bind from the given entity. */ - Map<String, Object> obtainProperties(E from); + Map<String, Object> obtainProperties(E from, String... propertyNames); - @Deprecated - Map<String, Object> obtainProgperties(E from); - /** * Bind an entity to another. * * @param from the source entity * @param dst the destination entity - * @param tech a flag to bind or not the technical values of the entity (says TopiaId, TopiaVersion and TopiaCreateDate). + * @param tech a flag to bind or not the technical values of the entity + * (says TopiaId, TopiaVersion and TopiaCreateDate). + * @param propertyNames subset of properties to load */ - void load(E from, E dst, boolean tech); + void load(E from, E dst, boolean tech, String... propertyNames); } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -32,15 +32,15 @@ * <p/> * There is an internal sate {@link #empty} to deal with default values of * properties of an entity. + * <p/> + * <b>Note:</b> Should remove {@link Loador} contract soon. * - * <b>Note:</b> Should remove {@link Loador} contract soon (let it form the - * the moment for application using * @author tchemit < chemit@codelutin.com > * @param <E> the type of entity * @since 2.3.0 */ public class TopiaEntityBinder<E extends TopiaEntity> extends Binder<E, E> - implements Loador<E>{ + implements Loador<E> { private static final long serialVersionUID = 1L; protected E empty; @@ -49,24 +49,15 @@ this.empty = empty; } - public void copy(E source, E target, boolean tech) { + @Override + public void load(E source, E target, boolean tech, + String... propertyNames) { if (source == null) { source = empty; } if (tech) { TopiaEntityHelper.bindTechnical(source, target); } - copy(source, target); + copy(source, target, propertyNames); } - - @Override - public Map<String, Object> obtainProgperties(E from) { - throw new NotImplementedException("the method 'obtainProgperties' is" + - " no more implemented"); - } - - @Override - public void load(E from, E dst, boolean tech) { - copy(from,dst,tech); - } } \ No newline at end of file Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -18,10 +18,6 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. * ##%* */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package org.nuiton.topia.generator; import org.junit.Test; Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/CollectorTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/CollectorTest.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/CollectorTest.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -18,10 +18,6 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. * ##%* */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package org.nuiton.topia.persistence.util; import org.junit.AfterClass; Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java 2010-02-25 13:58:22 UTC (rev 1814) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -1,4 +1,4 @@ -/** +/* * *##% * ToPIA :: Persistence * Copyright (C) 2004 - 2009 CodeLutin Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java (rev 0) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java 2010-02-26 18:48:25 UTC (rev 1815) @@ -0,0 +1,92 @@ +/* + * *##% + * ToPIA :: Persistence + * Copyright (C) 2004 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * ##%* + */ +package org.nuiton.topia.persistence.util; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.nuiton.topia.TopiaTestDAOHelper; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaEntityEnum; +import org.nuiton.topiatest.Company; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderBuilder; +import org.nuiton.util.beans.BinderProvider; + +public class TopiaEntityBinderTest { + + static TopiaEntityEnum[] contracts; + + @BeforeClass + public static void setUpClass() throws Exception { + contracts = TopiaTestDAOHelper.getContracts(); + } + + public static class CompanyDTO { + protected String name; + protected int siret; + protected String id; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getSiret() { + return siret; + } + + public void setSiret(int siret) { + this.siret = siret; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + } + + @Before + public void setUp() { + BinderProvider.clear(); + } + + @Test + public void testBinder() { + + BinderBuilder builder = new BinderBuilder(); + builder.createBinderModel(Company.class, CompanyDTO.class); + builder.addSimpleProperties(Company.NAME, Company.SIRET); + builder.addProperties(TopiaEntity.TOPIA_ID, "id"); + BinderProvider.registerBinder(builder); + + Binder<Company, CompanyDTO> binder = + BinderProvider.getBinder(Company.class, CompanyDTO.class); + Assert.assertNotNull(binder); + } +} \ No newline at end of file Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL
participants (1)
-
tchemit@users.nuiton.org