Author: tchemit Date: 2013-05-29 11:21:09 +0200 (Wed, 29 May 2013) New Revision: 636 Url: http://nuiton.org/projects/sandbox/repository/revisions/636 Log: add a jpa meta transformer Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaMetaTransformer.java Modified: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml Modified: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml =================================================================== --- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml 2013-05-29 08:54:49 UTC (rev 635) +++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml 2013-05-29 09:21:09 UTC (rev 636) @@ -86,16 +86,15 @@ <phase>generate-sources</phase> <configuration> <!-- Corresponding to extracted package from zargo file --> - <fullPackagePath>com.franciaflex.magalie.persistence.entity + <fullPackagePath> + com.franciaflex.magalie.persistence.entity </fullPackagePath> <!-- defaultPackage used for generation --> <defaultPackage>com.franciaflex.magalie.persistence </defaultPackage> <templates> - org.nuiton.jpa.templates.JpaEntityTransformer, - org.nuiton.jpa.templates.JpaDaoTransformer, - org.nuiton.jpa.templates.JpaPersistenceContextTransformer, - org.nuiton.eugene.java.JavaEnumerationTransformer + org.nuiton.eugene.java.JavaEnumerationTransformer, + org.nuiton.jpa.templates.JpaMetaTransformer </templates> </configuration> <goals> Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaMetaTransformer.java =================================================================== --- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaMetaTransformer.java (rev 0) +++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaMetaTransformer.java 2013-05-29 09:21:09 UTC (rev 636) @@ -0,0 +1,115 @@ +package org.nuiton.jpa.templates; + +/* + * #%L + * Nuiton Jpa :: Temlates + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 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% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.AbstractMetaTransformer; +import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.validator.AttributeNamesValidator; +import org.nuiton.eugene.models.object.validator.ClassNamesValidator; +import org.nuiton.eugene.models.object.validator.ObjectModelValidator; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created: 20 déc. 2009 + * + * @author tchemit <chemit@codelutin.com> + * @version $Id$ + * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.jpa.templates.JpaMetaTransformer" + * @since 2.3.0 + */ +public class JpaMetaTransformer extends AbstractMetaTransformer<ObjectModel> { + + /** Logger */ + private static final Log log = LogFactory.getLog(JpaMetaTransformer.class); + + public JpaMetaTransformer() { + + setTemplateTypes( + JpaEntityTransformer.class, + JpaDaoTransformer.class, + JpaPersistenceContextTransformer.class + ); + } + + protected boolean validateModel(ObjectModel model) { + List<ObjectModelValidator> validators = new ArrayList<ObjectModelValidator>(); + + AttributeNamesValidator attrValidator = new AttributeNamesValidator( + model); + attrValidator.addNameAndReason("next", + "Le nom d'attribut \"next\" est incompatible avec HSQL"); + attrValidator.addNameAndReason("value", + "Le nom d'attribut \"value\" est incompatible avec certains SGBD"); + attrValidator.addNameAndReason("values", + "Le nom d'attribut \"values\" est incompatible avec certains SGBD"); + attrValidator.addNameAndReason("begin", + "Le nom d'attribut \"begin\" est incompatible avec certains SGBD"); + attrValidator.addNameAndReason("end", + "Le nom d'attribut \"end\" est incompatible avec certains SGBD"); + attrValidator.addNameAndReason("authorization", + "Le nom d'attribut \"authorization\" est incompatible avec certains SGBD"); + attrValidator.addNameAndReason("order", + "Le nom d'attribut \"order\" est incompatible avec certains SGBD"); + validators.add(attrValidator); + + ClassNamesValidator classValidator = new ClassNamesValidator(model); + classValidator.addNameAndReason("constraint", "Nom de classe incompatible avec certains SGBD"); + classValidator.addNameAndReason("user", "Nom de classe incompatible avec certains SGBD"); + validators.add(classValidator); + +// validators.add(new TopiaJavaValidator(model)); +// validators.add(new TopiaRelationValidator(model)); + + for (ObjectModelValidator validator : validators) { + if (!validator.validate()) { + for (String error : validator.getErrors()) { + if (log.isWarnEnabled()) { + log.warn("[VALIDATION] " + error); + } + } + } + } + + // test before all if there is some entities to generate + List<ObjectModelClass> classes = + JpaTemplatesGeneratorUtil.getEntityClasses(model, true); + + if (classes.isEmpty()) { + // no entity to generate, can stop safely + if (log.isWarnEnabled()) { + log.warn("No entity to generate, " + getClass().getName() + + " is skipped"); + } + return false; + } + return true; + } + +} Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaMetaTransformer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native