Author: athimel Date: 2013-10-26 00:18:09 +0200 (Sat, 26 Oct 2013) New Revision: 2849 Url: http://nuiton.org/projects/topia/repository/revisions/2849 Log: Display a WARN message if some Legacy Dao is detected Modified: trunk/src/site/rst/migrate_to_3.0.rst trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java Modified: trunk/src/site/rst/migrate_to_3.0.rst =================================================================== --- trunk/src/site/rst/migrate_to_3.0.rst 2013-10-25 14:48:13 UTC (rev 2848) +++ trunk/src/site/rst/migrate_to_3.0.rst 2013-10-25 22:18:09 UTC (rev 2849) @@ -71,14 +71,7 @@ La classe sera supprimée. Pour manipuler les topiaId, il faut utiliser le **TopiaIdFactory**. -TopiaEntities#getTopiaIdFunction() ----------------------------------- -|RECOMMENDED| - -La méthode est dépréciée, il faut maintenant utiliser ``TopiaEntities#GET_TOPIA_ID``. - - TopiaContextImplementor est déprécié ------------------------------------ @@ -138,5 +131,53 @@ **TopiaSchemaListener**. +Transformer pour la génération des Dao +-------------------------------------- + +|RECOMMENDED| + +Si vous utilisiez explicitment le Transformer de DAO dans la configuration de votre plugin Eugene, il faut maintenant +changer le nouveau Transformer : org.nuiton.topia.generator.EntityDaoTransformer + +Exemple de configuration : + +:: + + <plugin> + <groupId>org.nuiton.eugene</groupId> + <artifactId>eugene-maven-plugin</artifactId> + <executions> + <execution> + <id>generate-entities</id> + <phase>generate-sources</phase> + <configuration> + <inputs>classpath:model:/:myProject.objectmodel</inputs> + <defaultPackage>org.project.entities</defaultPackage> + <templates> + org.nuiton.topia.generator.EntityDaoTransformer + </templates> + </configuration> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + </plugin> + + + +|RECOMMENDED| + +Si vous aviez surchargé certains des Dao générés, vous devrez probablement les renommer et changer leur signature. +Surveillez les logs de génération des Dao à la recherche des messages tels que : + +:: + + WARN [main] (EntityDaoTransformer.java:384) warnOnLegacyClassDetected - Legacy DAO detected ! + - You should consider renaming 'org.project.entities.ZoneDAOImpl' to 'org.project.entities.AbstractZoneTopiaDao' + - Expected class declaration is : public class AbstractZoneTopiaDao<E extends Zone> extends GeneratedZoneTopiaDao<E> { + + + .. |RECOMMENDED| image:: recommended.png .. |MANDATORY| image:: mandatory.png Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-25 14:48:13 UTC (rev 2848) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-25 22:18:09 UTC (rev 2849) @@ -38,7 +38,8 @@ * @author Arnaud Thimel <thimel@codelutin.com> * @since 3.0 */ -public interface TopiaPersistenceContext extends TopiaReplicationSupport, TopiaReplicationDestination, TopiaDaoSupplier, TopiaTransaction { +public interface TopiaPersistenceContext extends TopiaReplicationSupport, TopiaReplicationDestination, + TopiaDaoSupplier, TopiaTransaction { /** * Retrieve {@link org.nuiton.topia.persistence.TopiaEntity} using its unique {@code topiaId}. Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-25 14:48:13 UTC (rev 2848) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-25 22:18:09 UTC (rev 2849) @@ -27,6 +27,7 @@ /*{generator option: parentheses = false}*/ /*{generator option: writeString = +}*/ +import com.google.common.base.Strings; import com.google.common.collect.Sets; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -310,16 +311,24 @@ } protected void generateConcreteDao(ObjectModelClass clazz, String clazzName, String clazzFQN) { - ObjectModelClass daoClass = createClass(TopiaGeneratorUtil.getConcreteDaoName(clazz), clazz.getPackageName()); + String concreteDaoName = TopiaGeneratorUtil.getConcreteDaoName(clazz); + ObjectModelClass daoClass = createClass(concreteDaoName, clazz.getPackageName()); setDocumentation(daoClass, "/**\n" + " * Cette classe etend le DAOImpl pour parametrer la classe avec le bon type\n" + " * Cette classe est marque finale car l'heritage entre les DAO se fait\n" + " * sur les DOAImpl, c-a-d que DAOAbstract peut etendre le DAOImpl\n" + " */"); // to support legacy dao - setSuperClass(daoClass, TopiaGeneratorUtil.getLegacyDaoFqn(clazz)); + String superclassQualifiedName = TopiaGeneratorUtil.getLegacyDaoFqn(clazz); // TODO brendan 04/10/13 above line should be replaced by - // setSuperClass(daoClass, TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">"); +// String superclassQualifiedName = TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">"; + setSuperClass(daoClass, superclassQualifiedName); + + // TODO AThimel 25/10/13 Remove the next lines in ToPIA 3.1 + // Look for legacy Dao class, then warn user if found in classpath + String legacyConcreteDaoName = TopiaGeneratorUtil.getLegacyDaoName(clazz); + warnOnLegacyClassDetected(clazz.getPackageName(), legacyConcreteDaoName, concreteDaoName, null, + TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">"); } protected void generateAbstractDao(ObjectModelClass clazz, @@ -331,19 +340,52 @@ if (CollectionUtils.isEmpty(moreOperations)) { - // no business dao found, can safely generate the daoImpl class - - ObjectModelClass daoImplClass = createClass(TopiaGeneratorUtil.getAbstractDaoName(clazz) + "<E extends " + clazzName + ">", clazz.getPackageName()); - setDocumentation(daoImplClass, "/**\n" + - " Implantation du DAO pour l'entité " + clazzName + ".\n" + - " * L'utilisateur peut remplacer cette classe par la sienne en la mettant \n" + - " * simplement dans ces sources. Cette classe générée sera alors simplement\n" + - " * écrasée\n" + - " */"); - setSuperClass(daoImplClass, TopiaGeneratorUtil.getGeneratedDaoFqn(clazz) + "<E>"); + // no business Dao found, can safely generate the abstract Dao class + + String abstractDaoName = TopiaGeneratorUtil.getAbstractDaoName(clazz); + String daoGenerics = "<E extends " + clazzName + ">"; + ObjectModelClass abstractDaoClass = createClass(abstractDaoName + daoGenerics, clazz.getPackageName()); + String documentation = String.format("/**%n" + + " * Implantation du Dao pour l'entité '%s'.%n" + + " * L'utilisateur peut remplacer cette classe par la sienne en la mettant%n" + + " * simplement dans ses sources. Cette classe générée sera alors simplement%n" + + " * ignorée à la génération suivante.%n" + + " */", clazzName); + setDocumentation(abstractDaoClass, documentation); + String superclassQualifiedName = TopiaGeneratorUtil.getGeneratedDaoFqn(clazz) + "<E>"; + setSuperClass(abstractDaoClass, superclassQualifiedName); + + // TODO AThimel 25/10/13 Remove the next lines in ToPIA 3.1 + // Look for legacy Dao class, then warn user if found in classpath + String legacyDaoImplName = TopiaGeneratorUtil.getLegacyDaoName(clazz) + "Impl"; + warnOnLegacyClassDetected(clazz.getPackageName(), legacyDaoImplName, abstractDaoName, daoGenerics, + superclassQualifiedName); + } } + // TODO AThimel 25/10/13 Remove this method in ToPIA 3.1 + protected void warnOnLegacyClassDetected(String packageName, + String legacyDaoName, + String daoName, + String daoGenerics, + String superclassQualifiedName) { + + String legacyDaoFqn = String.format("%s.%s", packageName, legacyDaoName); + + // AThimel 25/10/13 Not using isInClassPath(fqn) because this method logs that file won't be generated + if (log.isWarnEnabled() && getFileInClassPath(legacyDaoFqn) != null) { + String format = "public class %s%s extends %s {"; + String superclassName = superclassQualifiedName.substring(superclassQualifiedName.lastIndexOf('.') + 1); + String daoDeclaration = String.format(format, daoName, Strings.nullToEmpty(daoGenerics), superclassName); + String warnMessage = "Legacy DAO detected !%n" + + " - You should consider renaming '%s' to '%s.%s'%n" + + " - Expected class declaration is : %s"; + log.warn(String.format(warnMessage, legacyDaoFqn, packageName, daoName, daoDeclaration)); + } + + } + protected void generateGeneratedDao(ObjectModelClass clazz, String clazzName, String clazzFQN) { @@ -373,13 +415,12 @@ // imports - Collection<ObjectModelOperation> DAOoperations = - getDAOOperations(clazz); + Collection<ObjectModelOperation> daoOperations = getDaoOperations(clazz); - if (TopiaGeneratorUtil.isCollectionNeeded(DAOoperations)) { + if (TopiaGeneratorUtil.isCollectionNeeded(daoOperations)) { addImport(daoAbstractClass, Collection.class); } - if (TopiaGeneratorUtil.isSetNeeded(DAOoperations)) { + if (TopiaGeneratorUtil.isSetNeeded(daoOperations)) { addImport(daoAbstractClass, Set.class); } addImport(daoAbstractClass, List.class); @@ -413,7 +454,7 @@ }*/ ); - generateDAOOperations(daoAbstractClass, DAOoperations); + generateDAOOperations(daoAbstractClass, daoOperations); generateDelete(clazz, daoAbstractClass); @@ -983,8 +1024,10 @@ * * @param clazz the clazz to test. * @return collections of extra operations, or empty collection if none found. + * @deprecated Dao operation will not be generated anymore in a very close future */ - public Collection<ObjectModelOperation> getDAOOperations( + @Deprecated + public Collection<ObjectModelOperation> getDaoOperations( ObjectModelClass clazz) { // // Note : this collection will contains extra operations for DAO. @@ -999,11 +1042,11 @@ // } // } - if (log.isWarnEnabled()) { - log.warn("dao contract in model will not be supported in topia 3.0"); - } Collection<ObjectModelOperation> extra = extraOperations.get(clazz.getQualifiedName()); + if (extra != null && !extra.isEmpty() && log.isWarnEnabled()) { + log.warn("Dao contract in model will not be supported in topia 3.0"); + } return extra; // if (extra != null) { // for (ObjectModelOperation op : extra) { Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2013-10-25 14:48:13 UTC (rev 2848) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2013-10-25 22:18:09 UTC (rev 2849) @@ -220,6 +220,7 @@ return input.getPackageName() + "." + getConcreteDaoName(input); } + @Deprecated public static String getLegacyDaoFqn(ObjectModelClass input) { return input.getPackageName() + "." + getLegacyDaoName(input); }