This is an automated email from the git hooks/post-receive script. New commit to branch feature/3452 in repository topia. See http://git.nuiton.org/topia.git commit f72b535f3ff8fc84f0cbe8dbe0c1b9634d0bd68d Author: Brendan Le Ny <bleny@codelutin.com> Date: Mon Feb 2 12:39:20 2015 +0100 For each entity of the model, generate a indexes.ddl file (refs #3452) --- .../topia/templates/IndexesDdlGenerator.java | 126 +++++++++++++++++++++ .../topia/templates/TopiaMetaTransformer.java | 3 +- 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/topia-templates/src/main/java/org/nuiton/topia/templates/IndexesDdlGenerator.java b/topia-templates/src/main/java/org/nuiton/topia/templates/IndexesDdlGenerator.java new file mode 100644 index 0000000..17e2289 --- /dev/null +++ b/topia-templates/src/main/java/org/nuiton/topia/templates/IndexesDdlGenerator.java @@ -0,0 +1,126 @@ +package org.nuiton.topia.templates; + +/* + * #%L + * ToPIA :: Templates + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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.lang3.StringUtils; +import org.nuiton.eugene.GeneratorUtil; +import org.nuiton.eugene.models.object.ObjectModelAttribute; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelGenerator; +import org.nuiton.eugene.models.object.ObjectModelPackage; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; + +/*{generator option: parentheses = true}*/ +/*{generator option: writeString = output.write}*/ + +/** + * Generate files with CREATE INDEX statements + * + * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.templates.IndexesDdlGenerator" + */ +public class IndexesDdlGenerator extends ObjectModelGenerator { + + protected TopiaTemplateHelper templateHelper; + + protected TopiaTagValues topiaTagValues; + + @Override + public String getFilenameForClass(ObjectModelClass clazz) { + if (templateHelper == null) { + templateHelper = new TopiaTemplateHelper(model); + } + return clazz.getQualifiedName().replace('.', File.separatorChar) + "-indexes.ddl"; + } + + @Override + public void generateFromClass(Writer output, + ObjectModelClass input) throws IOException { + + if (templateHelper == null) { + templateHelper = new TopiaTemplateHelper(model); + } + if (topiaTagValues == null) { + topiaTagValues = templateHelper.getTopiaTagValues(); + } + + for (ObjectModelAttribute attribute : input.getAttributes()) { + if (!attribute.isNavigable() || + attribute.hasAssociationClass() || + !GeneratorUtil.isNMultiplicity(attribute) || + attribute.getClassifier() == null || + !templateHelper.isEntity(attribute.getClassifier()) || + templateHelper.isAbstract(attribute.getClassifier()) + ) { + + // skip for this case (not a nm-multiplicity attribute) + continue; + } + + ObjectModelPackage aPackage = model.getPackage(input); + + boolean indexForeignKeys = + topiaTagValues.getIndexForeignKeysTagValue(attribute, aPackage, model); + + if (!indexForeignKeys) { + + // no index to put of the attribute. + continue; + } + + // add database-object to create and drop index + + String tableName; + String indexName = "idx_" + input.getName() + "_" + attribute.getName(); + String propertyName; + + + if (GeneratorUtil.isNMultiplicity(attribute.getReverseMaxMultiplicity())) { + + // many to many + tableName = templateHelper.getManyToManyTableName(attribute); + propertyName = templateHelper.getDbName(attribute.getReverseAttribute()); + } else { + + // one to many + tableName =templateHelper.getDbName(attribute.getClassifier()); + propertyName = templateHelper.getDbName(attribute.getReverseAttribute()); + } + + // add schema if exist (http://nuiton.org/issues/2052) + String schema = topiaTagValues.getDbSchemaNameTagValue(input, model); + if (StringUtils.isNotEmpty(schema)) { + tableName = schema + "." + tableName; + } +/*{ +CREATE INDEX <%=indexName%> ON <%=tableName%>(<%=propertyName%>); +}*/ + + } + } + +} diff --git a/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetaTransformer.java b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetaTransformer.java index 4da8fcd..9e4ac16 100644 --- a/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetaTransformer.java +++ b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetaTransformer.java @@ -69,7 +69,8 @@ public class TopiaMetaTransformer extends AbstractMetaTransformer<ObjectModel> { EntityDaoTransformer.class, EntityEnumTransformer.class, ApplicationContextTransformer.class, - PersistenceContextTransformer.class + PersistenceContextTransformer.class, + IndexesDdlGenerator.class ); } -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.