r1427 - in topia/trunk/topia-persistence: . src/main/java/org/codelutin/topia/generator
Author: tchemit Date: 2009-04-18 15:15:00 +0000 (Sat, 18 Apr 2009) New Revision: 1427 Removed: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityProviderGenerator.java Modified: topia/trunk/topia-persistence/changelog.txt topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java Log: - suppression generateurs deprecies - fix bug dans BeanGenerator quand pas d'association Modified: topia/trunk/topia-persistence/changelog.txt =================================================================== --- topia/trunk/topia-persistence/changelog.txt 2009-04-18 07:42:19 UTC (rev 1426) +++ topia/trunk/topia-persistence/changelog.txt 2009-04-18 15:15:00 UTC (rev 1427) @@ -1,5 +1,6 @@ 2.1.4 xxxx 200903xx -* 20090418 [chemit] - add a BeanGenerator +* 20090418 [chemit] - suppress deprecated generators + - add a BeanGenerator - add methods isXXXEmpty on association in generated entities * 20090317 [chatellier] Change tagValue from "orderBy" to "order-by" Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java 2009-04-18 07:42:19 UTC (rev 1426) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java 2009-04-18 15:15:00 UTC (rev 1427) @@ -214,10 +214,7 @@ } if (!multipleAttr.isEmpty()) { /*{ - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - pcs.firePropertyChange(propertyName, oldValue, newValue); - } - + protected <T> T getChild(Collection<T> childs, int index) { if (childs != null) { int i = 0; @@ -245,6 +242,10 @@ } /*{ + protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + pcs.firePropertyChange(propertyName, oldValue, newValue); + } + } //<%=clazz.getName()%> }*/ } Deleted: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2009-04-18 07:42:19 UTC (rev 1426) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2009-04-18 15:15:00 UTC (rev 1427) @@ -1,316 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 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>. ##%*/ - -/******************************************************************************* - * EntityProviderGenerator.java - * - */ - -package org.codelutin.topia.generator; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.generator.Generator; -import org.codelutin.generator.GeneratorUtil; -import org.codelutin.generator.ObjectModelGenerator; -import org.codelutin.generator.models.object.ObjectModel; -import org.codelutin.generator.models.object.ObjectModelClass; - -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.util.Iterator; -import java.util.List; - -/** - * Ce generateur permet d'avoir une énumeration sur les entités du model. - * <p/> - * Chaque entité est associée à un {@link org.codelutin.topia.persistence.TopiaEntityEnumEntry}. - * - * @author chemit - * @see org.codelutin.topia.persistence.TopiaEntityEnumEntry - */ -@Deprecated -public class EntityEnumGenerator extends ObjectModelGenerator { - - private static Log log = LogFactory.getLog(EntityEnumGenerator.class); - - public EntityEnumGenerator() { - super(); - } - - public EntityEnumGenerator(Generator parent) { - super(parent); - } - - @Override - public String getFilenameForModel(ObjectModel model) { - - String modelName = GeneratorUtil.capitalize(model.getName()); - - return (getProperty("defaultPackage") + ".").replace('.', - File.separatorChar) - + modelName + "EntityEnum.java"; - } - - @Override - public void generateFromModel(Writer output, ObjectModel model) - throws IOException { - String copyright = TopiaGeneratorUtil.getCopyright(model); - String modelName = GeneratorUtil.capitalize(model.getName()); - String className = modelName + "EntityEnum"; - if (log.isDebugEnabled()) { - log.debug("generating " + className); - } - if (TopiaGeneratorUtil.notEmpty(copyright)) { -/*{<%=copyright%> -}*/ - } -/*{package <%=getProperty("defaultPackage")%>; - -import java.util.Map; -import java.util.List; -import java.util.Collection; - -import org.codelutin.topia.TopiaContext; -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.persistence.TopiaDAO; -import org.codelutin.topia.persistence.TopiaEntity; -import org.codelutin.topia.persistence.TopiaEntityEnumEntry; - -/** - @deprecated <%=className%> will be removed in future ToPIA version - *) -@SuppressWarnings({"unchecked"}) -public enum <%=className%> { -}*/ - List<ObjectModelClass> classes = TopiaGeneratorUtil.getEntityClasses(model, true); - if (classes.isEmpty()) { -/*{ - TopiaEntity(TopiaEntity.class); -}*/ - } else { - for (Iterator<ObjectModelClass> i = classes.iterator(); i.hasNext();) { - ObjectModelClass clazz = i.next(); - String clazzName = clazz.getName(); - String clazzFQN = clazz.getQualifiedName(); - boolean hasNext = i.hasNext(); - if (log.isDebugEnabled()) { - log.debug("generating entry " + clazzFQN + " (hasNext:" + hasNext + ")"); - } -/*{ <%=clazzName%>(<%=clazzFQN%>.class)<%=(hasNext?",":";")%> -}*/ - } - } -/*{ - private TopiaEntityEnumEntry<TopiaEntity> entry; - - <%=className%>(Class<? extends TopiaEntity> contractClass) { - entry = new TopiaEntityEnumEntry(contractClass); - } - - public <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry() { - return (TopiaEntityEnumEntry<T>)entry; - } - - public static <%=className%> valueOf(TopiaEntity entity) { - return valueOf(entity.getClass()); - } - - public static <%=className%> valueOf(Class<?> klass) { - if (klass.isInterface()) { - return <%=modelName%>EntityEnum.valueOf(klass.getSimpleName()); - } - for (<%=className%> entityEnum : <%=className%>.values()) { - if (entityEnum.entry.getContractClass().isAssignableFrom(klass)) { - return entityEnum; - } - } - throw new IllegalArgumentException("no entity defined for the class " + klass + " in : " + java.util.Arrays.toString(<%=className%>.values())); - } - - public static <T extends TopiaEntity> Class<T> getContractClass(Class<T> klass) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.getContractClass(); - } - - public static <T extends TopiaEntity> Class<T> getImplementationClass(Class<T> klass) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.getImplementationClass(); - } - - public static Class<? extends TopiaEntity>[] getContractClasses() { - <%=className%>[] values = <%=className%>.values(); - Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length); - for (int i = 0; i < values.length; i++) { - result[i] = values[i].entry.getContractClass(); - } - return result; - } - - public static Class<? extends TopiaEntity>[] getImplementationClasses() { - <%=className%>[] values = <%=className%>.values(); - Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length); - for (int i = 0; i < values.length; i++) { - result[i] = values[i].entry.getImplementationClass(); - } - return result; - } - - public static String getImplementationClassesAsString() { - StringBuilder buffer = new StringBuilder(); - for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) { - buffer.append(',').append(aClass.getName()); - } - return buffer.substring(1); - } - - public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(T entity) { - <%=className%> e = <%=className%>.valueOf(entity); - return (TopiaEntityEnumEntry<T>)e.entry; - } - - public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(Class<T> klass) { - <%=className%> e = <%=className%>.valueOf(klass); - return (TopiaEntityEnumEntry<T>)e.entry; - } - - public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(String constantName) { - <%=className%> e = <%=className%>.valueOf(constantName); - return (TopiaEntityEnumEntry<T>)e.entry; - } - - public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(TopiaContext ctxt, Class<T> klass) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return (D) entry.getDAO(ctxt); - } - - public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(TopiaContext ctxt, T entity) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(entity); - return (D) entry.getDAO(ctxt); - } - - public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.create(ctxt); - } - - public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass, Object... properties) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.create(ctxt, properties); - } - - public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.create(ctxt, properties); - } - - public static <T extends TopiaEntity> T update(TopiaContext ctxt, T entity) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(entity); - return entry.update(entity, ctxt); - } - - public static <T extends TopiaEntity> void delete(TopiaContext ctxt, T entity) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(entity); - entry.delete(entity, ctxt); - } - - public static <T extends TopiaEntity> int size(TopiaContext ctxt, Class<T> klass) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.size(ctxt); - } - - public static <T extends TopiaEntity> List<T> findAll(TopiaContext ctxt, Class<T> klass) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findAll(ctxt); - } - - public static <T extends TopiaEntity> List<T> findAllWithOrder(TopiaContext ctxt, Class<T> klass,String... propertyNames) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findAllWithOrder(ctxt, propertyNames); - } - - public static <T extends TopiaEntity> T findByTopiaId(TopiaContext ctxt, Class<T> klass,String topiaId) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findByTopiaId(topiaId,ctxt); - } - - public static <T extends TopiaEntity> T findByPrimaryKey(TopiaContext ctxt, Class<T> klass, Map<String, Object> keys) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findByPrimaryKey(ctxt, keys); - } - - public static <T extends TopiaEntity> T findByPrimaryKey(TopiaContext ctxt, Class<T> klass, Object... k) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findByPrimaryKey(ctxt, k); - } - - public static <T extends TopiaEntity> T findByProperty(TopiaContext ctxt, Class<T> klass, String propertyName, Object value) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findByProperty(ctxt, propertyName, value); - } - - public static <T extends TopiaEntity> T findByProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Object value, Object... others) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findByProperties(ctxt, propertyName, value, others); - } - - public static <T extends TopiaEntity> T findByProperties(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findByProperties(ctxt, properties); - } - - public static <T extends TopiaEntity> List<T> findAllByProperty(TopiaContext ctxt, Class<T> klass, String propertyName, Object value) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findAllByProperty(ctxt, propertyName, value); - } - - public static <T extends TopiaEntity> List<T> findAllByProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Object value, Object... others) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findAllByProperties(ctxt, propertyName, value, others); - } - - public static <T extends TopiaEntity> List<T> findAllByProperties(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findAllByProperties(ctxt, properties); - } - - public static <T extends TopiaEntity> T findContainsProperties(TopiaContext ctxt, Class<T> klass, Map<String, Collection> properties) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findContainsProperties(ctxt, properties); - } - - public static <T extends TopiaEntity> T findContainsProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Collection values, Object... others) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findContainsProperties(ctxt, propertyName, values, others); - } - - public static <T extends TopiaEntity> List<T> findAllContainsProperties(TopiaContext ctxt, Class<T> klass, Map<String, Collection> properties) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findAllContainsProperties(ctxt, properties); - } - - public static <T extends TopiaEntity> List<T> findAllContainsProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Collection values, Object... others) throws TopiaException { - TopiaEntityEnumEntry<T> entry = getEntry(klass); - return entry.findAllContainsProperties(ctxt, propertyName, values, others); - } - -} //<%=className%> -}*/ - } - -} // EntityEnumGenerator Deleted: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityProviderGenerator.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityProviderGenerator.java 2009-04-18 07:42:19 UTC (rev 1426) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityProviderGenerator.java 2009-04-18 15:15:00 UTC (rev 1427) @@ -1,151 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 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>. ##%*/ - -/******************************************************************************* - * EntityProviderGenerator.java - * - */ - -package org.codelutin.topia.generator; - -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.util.Iterator; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.generator.Generator; -import org.codelutin.generator.GeneratorUtil; -import org.codelutin.generator.ObjectModelGenerator; -import org.codelutin.generator.models.object.ObjectModel; -import org.codelutin.generator.models.object.ObjectModelClass; - -/** - * Ce generateur permet d'avoir les implantations des entites concretes a partir des - * interfaces des entites de maniere dynamique (i.e qu'on n'aura pas dans cette classe - * les classes desces implantations) : ceci permet la modularite. - * - * @author chemit - * - * @see Deprecated you should prefer use the {@link EntityEnumGenerator} - */ -@Deprecated -public class EntityProviderGenerator extends ObjectModelGenerator { - - private Log log = LogFactory.getLog(EntityProviderGenerator.class); - - public EntityProviderGenerator() { - super(); - } - - public EntityProviderGenerator(Generator parent) { - super(parent); - } - - @Override - public String getFilenameForModel(ObjectModel model) { - - String modelName = GeneratorUtil.capitalize(model.getName()); - - return (getProperty("defaultPackage") + ".").replace('.', - File.separatorChar) - + modelName + "EntityProvider.java"; - } - - @Override - public void generateFromModel(Writer output, ObjectModel model) - throws IOException { - String copyright = TopiaGeneratorUtil.getCopyright(model); - if (TopiaGeneratorUtil.notEmpty(copyright)) { -/*{<%=copyright%> -}*/ - } - String modelName = GeneratorUtil.capitalize(model.getName()); - String clazzName = modelName + "EntityProvider"; - -/*{package <%=getProperty("defaultPackage")%>; - -import org.codelutin.topia.persistence.TopiaEntity; -import java.util.Map; -import java.util.HashMap; - -/** - * <%=clazzName%> - * - * @deprecated <%=clazzName%> will be removed in future ToPIA version - *) -@SuppressWarnings({"unchecked"}) -public class <%=clazzName%> { - - protected static Map<Class<? extends TopiaEntity>, Class<? extends TopiaEntity>> cache; - -}*/ - List<ObjectModelClass> classes = TopiaGeneratorUtil.getEntityClasses(model, true); - if (classes.isEmpty()) { -/*{ - protected static Class<? extends TopiaEntity>[] entitiesClass = new Class[]{}; -}*/ - } else { -/*{ - protected static Class<? extends TopiaEntity>[] entitiesClass = new Class[]{ -}*/ - } - for (Iterator<ObjectModelClass> i=classes.iterator(); i.hasNext();) { - ObjectModelClass clazz = i.next(); - String clazzFQN = clazz.getQualifiedName(); -/*{ <%=clazzFQN%>.class<%=(i.hasNext()?", ":"\n};")%> -}*/ - } -/*{ - public static <E extends TopiaEntity> Class<E> getImpl(Class<E> klazz) { - return (Class<E>) getCache().get(klazz); - } - - public static Map<Class<? extends TopiaEntity>, Class<? extends TopiaEntity>> getCache() { - if (cache == null) { - initCache(); - } - return cache; - } - - private static void initCache() { - Map<Class<? extends TopiaEntity>, Class<? extends TopiaEntity>> cache = new HashMap<Class<? extends TopiaEntity>, Class<? extends TopiaEntity>>(); - for (Class<? extends TopiaEntity> entitiesClas : entitiesClass) { - String implFQN = entitiesClas.getName() + "Impl"; - try { - Class<? extends TopiaEntity> impl = (Class<? extends TopiaEntity>) Class.forName(implFQN); - cache.put(entitiesClas, impl); - } catch (ClassNotFoundException e) { - throw new RuntimeException("could not find entity implementation class " + implFQN); - } - } - <%=clazzName%>.cache = java.util.Collections.unmodifiableMap(cache); - } - - /** - * should have no instance - *) - protected <%=clazzName%>() { - } - -} //<%=clazzName%> -}*/ - } - -} // EntityPoviderGenerator Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java 2009-04-18 07:42:19 UTC (rev 1426) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java 2009-04-18 15:15:00 UTC (rev 1427) @@ -69,8 +69,6 @@ DAOImplGenerator.class, DAOAbstractGenerator.class, - EntityProviderGenerator.class, - EntityEnumGenerator.class, DAOHelperGenerator.class)); protected boolean validateModel(ObjectModel model) {
participants (1)
-
tchemit@users.labs.libre-entreprise.org