r2811 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/generator test/java/org/nuiton/topiatest test/java/org/nuiton/topiatest/deletetest
Author: bleny Date: 2013-10-04 14:26:57 +0200 (Fri, 04 Oct 2013) New Revision: 2811 Url: http://nuiton.org/projects/topia/repository/revisions/2811 Log: refs #2086 rename DAOs Added: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/AbstractExtraDAOEntityTopiaDao.java trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/AbstractContact2TopiaDao.java Removed: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/ExtraDAOEntityDAOImpl.java trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/Contact2DAOImpl.java Modified: 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/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-03 16:30:27 UTC (rev 2810) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2013-10-04 12:26:57 UTC (rev 2811) @@ -213,30 +213,43 @@ String clazzName = clazz.getName(); String clazzFQN = clazz.getQualifiedName(); - if (isGenerateDAO(clazz)) { + if (isGenerateGeneratedDao(clazz)) { + generateGeneratedDao(clazz, clazzName, clazzFQN); + } - // generate DAO - generateDAOClass(clazz, clazzName, clazzFQN); + if (isGenerateAbstractDao(clazz)) { + generateAbstractDao(clazz, clazzName, clazzFQN); + } + if (isGenerateLegacyDao(clazz)) { + generateLegacyDao(clazz, clazzName, clazzFQN); } - if (isGenerateImpl(clazz)) { - // generate DAOImpl - generateDAOImpl(clazz, clazzName, clazzFQN); + if (isGenerateConcreteDao(clazz)) { + generateConcreteDao(clazz, clazzName, clazzFQN); } - if (isGenerateDAOAbstract(clazz)) { + } - // generate DAOAbstract - generateDAOAbstract(clazz, clazzName, clazzFQN); + protected boolean isGenerateLegacyDao(ObjectModelClass input) { + + String daoLegacyFqn = TopiaGeneratorUtil.getLegacyDaoFqn(input); + + if (isInClassPath(daoLegacyFqn)) { + + // already in class-path + return false; } + + // can safely generate the dao impl + return true; } - protected boolean isGenerateDAO(ObjectModelClass input) { + protected boolean isGenerateConcreteDao(ObjectModelClass input) { - String fqn = input.getQualifiedName() + "DAO"; + String daoConcreteFqn = TopiaGeneratorUtil.getConcreteDaoFqn(input); - if (isInClassPath(fqn)) { + if (isInClassPath(daoConcreteFqn)) { // already in class-path return false; @@ -246,11 +259,11 @@ return true; } - protected boolean isGenerateDAOAbstract(ObjectModelClass input) { + protected boolean isGenerateGeneratedDao(ObjectModelClass input) { - String fqn = input.getQualifiedName() + "DAOAbstract"; + String daoGeneratedFqn = TopiaGeneratorUtil.getGeneratedDaoFqn(input); - if (isInClassPath(fqn)) { + if (isInClassPath(daoGeneratedFqn)) { // already in class-path return false; @@ -258,11 +271,12 @@ // can safely generate the dao impl return true; + } - protected boolean isGenerateImpl(ObjectModelClass input) { + protected boolean isGenerateAbstractDao(ObjectModelClass input) { - String fqn = input.getQualifiedName() + "DAOImpl"; + String fqn = TopiaGeneratorUtil.getAbstractDaoFqn(input); if (isInClassPath(fqn)) { @@ -275,28 +289,43 @@ if (CollectionUtils.isNotEmpty(moreOperations)) { - // no user operations, can generate it + // no user operations, can not generate it return false; } // can safely generate the dao impl return true; + } - protected void generateDAOClass(ObjectModelClass clazz, String clazzName, String clazzFQN) { - ObjectModelClass daoClass = createClass(clazzName + "DAO", clazz.getPackageName()); + protected void generateLegacyDao(ObjectModelClass clazz, String clazzName, String clazzFQN) { + ObjectModelClass daoClass = createClass(TopiaGeneratorUtil.getLegacyDaoName(clazz), clazz.getPackageName()); + addAnnotation(daoClass, daoClass, Deprecated.class); 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" + " */"); - setSuperClass(daoClass, clazzFQN + "DAOImpl<" + clazzName + ">"); + setSuperClass(daoClass, TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">"); } - protected void generateDAOImpl(ObjectModelClass clazz, - String clazzName, - String clazzFQN) { + protected void generateConcreteDao(ObjectModelClass clazz, String clazzName, String clazzFQN) { + ObjectModelClass daoClass = createClass(TopiaGeneratorUtil.getConcreteDaoName(clazz), 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)); + // TODO brendan 04/10/13 above line should be replaced by + // setSuperClass(daoClass, TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">"); + } + protected void generateAbstractDao(ObjectModelClass clazz, + String clazzName, + String clazzFQN) { + Collection<ObjectModelOperation> moreOperations = extraOperations.get(clazz.getQualifiedName()); @@ -304,42 +333,40 @@ // no business dao found, can safely generate the daoImpl class - ObjectModelClass daoImplClass = createClass(clazzName + "DAOImpl<E extends " + clazzName + ">", clazz.getPackageName()); + 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, clazzFQN + "DAOAbstract<E>"); + setSuperClass(daoImplClass, TopiaGeneratorUtil.getGeneratedDaoFqn(clazz) + "<E>"); } } - protected void generateDAOAbstract(ObjectModelClass clazz, + protected void generateGeneratedDao(ObjectModelClass clazz, String clazzName, String clazzFQN) { - ObjectModelClass daoAbstractClass = createAbstractClass( - clazzName + "DAOAbstract<E extends " + clazzName + '>', + ObjectModelClass daoAbstractClass = createAbstractClass(TopiaGeneratorUtil.getGeneratedDaoName(clazz) + "<E extends " + clazzName + '>', clazz.getPackageName()); // super class - String extendClass = ""; + String superClassName = null; for (ObjectModelClass parent : clazz.getSuperclasses()) { - extendClass = parent.getQualifiedName(); if (TopiaGeneratorUtil.isEntity(parent)) { - extendClass += "DAOImpl<E>"; + superClassName = TopiaGeneratorUtil.getAbstractDaoFqn(parent) + "<E>"; // in java no multi-inheritance break; } } - if (extendClass.length() == 0) { - extendClass = daoImplementation.getName() + "<E>"; + if (superClassName == null) { + superClassName = daoImplementation.getName() + "<E>"; } if (log.isDebugEnabled()) { - log.debug("super class = " + extendClass); + log.debug("super class = " + superClassName); } - setSuperClass(daoAbstractClass, extendClass); + setSuperClass(daoAbstractClass, superClassName); String prefix = getConstantPrefix(clazz, ""); setConstantPrefix(prefix); @@ -521,6 +548,8 @@ // THIMEL: J'ai remplacé reverse.getName() par reverseAttrName sans certitude addImport(result, attrType); String attrSimpleType = TopiaGeneratorUtil.getClassNameFromQualifiedName(attrType); + // XXX brendan 04/10/13 do not hard code concrete dao name + String attrConcreteDaoClassName = attrSimpleType + "TopiaDao"; String getName = getJavaBeanMethodName("get", reverseAttrName); String setName = getJavaBeanMethodName("set", reverseAttrName); @@ -528,7 +557,7 @@ /*{ { List<<%=attrSimpleType%>> list = topiaDAOSupplier - .getDAO(<%=attrSimpleType%>.class, <%=attrSimpleType%>DAO.class) + .getDAO(<%=attrSimpleType%>.class, <%=attrConcreteDaoClassName%>.class) .forProperties(<%=attrSimpleType%>.<%=getConstantName(reverseAttrName)%>, entity).findAll(); for (<%=attrSimpleType%> item : list) { 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-03 16:30:27 UTC (rev 2810) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2013-10-04 12:26:57 UTC (rev 2811) @@ -171,19 +171,39 @@ return input.getName(); } - public static String getDaoAbstractName(ObjectModelClass input) { + public static String getAbstractDaoName(ObjectModelClass input) { return "Abstract" + input.getName() + "TopiaDao"; } - public static String getDaoGeneratedName(ObjectModelClass input) { + public static String getGeneratedDaoName(ObjectModelClass input) { return "Generated" + input.getName() + "TopiaDao"; } - public static String getDaoConcreteName(ObjectModelClass input) { -// return input.getName() + "TopiaDao"; + public static String getConcreteDaoName(ObjectModelClass input) { + return input.getName() + "TopiaDao"; + } + + @Deprecated + public static String getLegacyDaoName(ObjectModelClass input) { return input.getName() + "DAO"; } + public static String getAbstractDaoFqn(ObjectModelClass input) { + return input.getPackageName() + "." + getAbstractDaoName(input); + } + + public static String getGeneratedDaoFqn(ObjectModelClass input) { + return input.getPackageName() + "." + getGeneratedDaoName(input); + } + + public static String getConcreteDaoFqn(ObjectModelClass input) { + return input.getPackageName() + "." + getConcreteDaoName(input); + } + + public static String getLegacyDaoFqn(ObjectModelClass input) { + return input.getPackageName() + "." + getLegacyDaoName(input); + } + public static String getEntityPackage(ObjectModelTransformerToJava transformer, ObjectModel model, ObjectModelClassifier input) { Copied: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/AbstractExtraDAOEntityTopiaDao.java (from rev 2809, trunk/topia-persistence/src/test/java/org/nuiton/topiatest/ExtraDAOEntityDAOImpl.java) =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/AbstractExtraDAOEntityTopiaDao.java (rev 0) +++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/AbstractExtraDAOEntityTopiaDao.java 2013-10-04 12:26:57 UTC (rev 2811) @@ -0,0 +1,40 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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>. + * #L% + */ +package org.nuiton.topiatest; + +import org.nuiton.topia.TopiaException; + +/** + * Created: 26 mai 2010 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + */ +public class AbstractExtraDAOEntityTopiaDao<E extends ExtraDAOEntity> extends GeneratedExtraDAOEntityTopiaDao<E> { + + @Override + public void extra() throws TopiaException { + } +} Deleted: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/ExtraDAOEntityDAOImpl.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/ExtraDAOEntityDAOImpl.java 2013-10-03 16:30:27 UTC (rev 2810) +++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/ExtraDAOEntityDAOImpl.java 2013-10-04 12:26:57 UTC (rev 2811) @@ -1,40 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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>. - * #L% - */ -package org.nuiton.topiatest; - -import org.nuiton.topia.TopiaException; - -/** - * Created: 26 mai 2010 - * - * @author fdesbois <fdesbois@codelutin.com> - * @version $Id$ - */ -public class ExtraDAOEntityDAOImpl<E extends ExtraDAOEntity> extends ExtraDAOEntityDAOAbstract<E> { - - @Override - public void extra() throws TopiaException { - } -} Copied: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/AbstractContact2TopiaDao.java (from rev 2809, trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/Contact2DAOImpl.java) =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/AbstractContact2TopiaDao.java (rev 0) +++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/AbstractContact2TopiaDao.java 2013-10-04 12:26:57 UTC (rev 2811) @@ -0,0 +1,51 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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>. + * #L% + */ + +package org.nuiton.topiatest.deletetest; + + +import org.nuiton.topia.TopiaException; +import org.nuiton.topiatest.Company; +import org.nuiton.topiatest.Employe; + +import java.util.Set; +import java.util.TreeSet; + +/** + * + * @author desbois + */ +public class AbstractContact2TopiaDao<E extends Contact2> extends GeneratedContact2TopiaDao<E> { + + @Override + public Set<Contact2> findAllByCompany(Company company) throws TopiaException { + Set<Contact2> contacts = new TreeSet<Contact2>(); + for (Employe e : company.getEmploye()) { + contacts.addAll(e.getContacts()); + } + return contacts; + } + +} Deleted: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/Contact2DAOImpl.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/Contact2DAOImpl.java 2013-10-03 16:30:27 UTC (rev 2810) +++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/Contact2DAOImpl.java 2013-10-04 12:26:57 UTC (rev 2811) @@ -1,50 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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>. - * #L% - */ - -package org.nuiton.topiatest.deletetest; - - -import java.util.Set; -import java.util.TreeSet; -import org.nuiton.topia.TopiaException; -import org.nuiton.topiatest.Company; -import org.nuiton.topiatest.Employe; - -/** - * - * @author desbois - */ -public class Contact2DAOImpl<E extends Contact2> extends Contact2DAOAbstract<E> { - - @Override - public Set<Contact2> findAllByCompany(Company company) throws TopiaException { - Set<Contact2> contacts = new TreeSet<Contact2>(); - for (Employe e : company.getEmploye()) { - contacts.addAll(e.getContacts()); - } - return contacts; - } - -}
participants (1)
-
bleny@users.nuiton.org