Author: bleny Date: 2013-10-17 18:14:18 +0200 (Thu, 17 Oct 2013) New Revision: 2846 Url: http://nuiton.org/projects/topia/repository/revisions/2846 Log: refs #2086 rename DAO to Dao to prevent confusing names Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java Removed: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/LegacyEntityDAOTransformer.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -212,7 +212,7 @@ checkClosed(); Class<E> entityClass = getTopiaIdFactory().getClassName(topiaId); - TopiaDAO<E> dao = getDAO(entityClass); + TopiaDAO<E> dao = getDao(entityClass); E result = dao.findByTopiaId(topiaId); return result; } @@ -223,7 +223,7 @@ String topiaId = entity.getTopiaId(); Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(topiaId); - TopiaDAO<TopiaEntity> dao = getDAO(entityClass); + TopiaDAO<TopiaEntity> dao = getDao(entityClass); dao.update(entity); } @@ -234,8 +234,8 @@ } @Override - public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) { - Preconditions.checkArgument(entityClass != null, "The method 'getDAO' requires a non null 'entityClass' parameter"); + public <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityClass) { + Preconditions.checkArgument(entityClass != null, "The method 'getDao' requires a non null 'entityClass' parameter"); SessionFactory hibernateFactory = hibernateSupport.getHibernateFactory(); if (hibernateFactory.getClassMetadata(entityClass) == null && @@ -291,8 +291,8 @@ } @Override - public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass, Class<D> daoClass) { - return (D) getDAO(entityClass); + public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDao(Class<E> entityClass, Class<D> daoClass) { + return (D) getDao(entityClass); } @Override Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -1,54 +0,0 @@ -package org.nuiton.topia; - -/* - * #%L - * ToPIA :: Persistence - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 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.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; - -/** - * @author bleny - */ -public interface TopiaDAOSupplier { - - /** - * Get DAO for specified class. If Specialized DAO exists then it returned - * otherwize TopiaDAO<entityClass> is returned - * - * @param entityClass type of entity - * @return the expected dao - */ - <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass); - - /** - * Get DAO for specified class. If Specialized DAO exists then it returned - * otherwize TopiaDAO<entityClass> is returned - * - * @param entityClass type of entity - * @param daoClass the concrete dao class to use - * @return the expected dao - */ - <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass, Class<D> daoClass); - -} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java (from rev 2845, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -0,0 +1,54 @@ +package org.nuiton.topia; + +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 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.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.TopiaEntity; + +/** + * @author bleny + */ +public interface TopiaDaoSupplier { + + /** + * Get DAO for specified class. If Specialized DAO exists then it returned + * otherwize TopiaDAO<entityClass> is returned + * + * @param entityClass type of entity + * @return the expected dao + */ + <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityClass); + + /** + * Get DAO for specified class. If Specialized DAO exists then it returned + * otherwize TopiaDAO<entityClass> is returned + * + * @param entityClass type of entity + * @param daoClass the concrete dao class to use + * @return the expected dao + */ + <E extends TopiaEntity, D extends TopiaDAO<E>> D getDao(Class<E> entityClass, Class<D> daoClass); + +} 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-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -38,7 +38,7 @@ * @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/framework/AbstractTopiaContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -707,12 +707,12 @@ /* -------------------- CHILD CONTEXT AND DAOS --------------------------*/ @Override - public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) + public <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityClass) throws TopiaException { if (entityClass == null) { throw new IllegalArgumentException( String.format("The method '%1$s' requires a non null parameter '%2$s'.", - "entityClass", "getDAO")); + "entityClass", "getDao")); } if (equals(getRootContext())) { throw new TopiaException( @@ -761,9 +761,9 @@ @SuppressWarnings({"unchecked"}) @Override - public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass, + public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDao(Class<E> entityClass, Class<D> daoClass) throws TopiaException { - return (D) getDAO(entityClass); + return (D) getDao(entityClass); } @Override @@ -983,7 +983,7 @@ "findByTopiaId")); Class<E> entityClass = getTopiaIdFactory().getClassName(id); - TopiaDAO<E> dao = getDAO(entityClass); + TopiaDAO<E> dao = getDao(entityClass); E result = dao.findByTopiaId(id); return result; } @@ -1612,7 +1612,7 @@ String id = entity.getTopiaId(); Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(id); - TopiaDAO<TopiaEntity> dao = getDAO(entityClass); + TopiaDAO<TopiaEntity> dao = getDao(entityClass); dao.update(entity); } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -146,7 +146,7 @@ * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext} */ @Deprecated - <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) + <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityClass) throws TopiaException; /** @@ -161,7 +161,7 @@ * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext} */ @Deprecated - <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass, Class<D> daoClass) + <E extends TopiaEntity, D extends TopiaDAO<E>> D getDao(Class<E> entityClass, Class<D> daoClass) throws TopiaException; /** Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -47,7 +47,7 @@ import org.hibernate.event.spi.PreUpdateEventListener; import org.hibernate.event.spi.SaveOrUpdateEvent; import org.hibernate.event.spi.SaveOrUpdateEventListener; -import org.nuiton.topia.TopiaDAOSupplier; +import org.nuiton.topia.TopiaDaoSupplier; import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.AbstractTopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; @@ -116,7 +116,7 @@ } private void attachContext(Object entity, - TopiaDAOSupplier daoSupplier) { + TopiaDaoSupplier daoSupplier) { if (entity instanceof TopiaEntityContextable) { TopiaEntityContextable topiaEntityContextable = (TopiaEntityContextable) entity; if (topiaEntityContextable.getTopiaDAOSupplier() == null) { @@ -184,11 +184,11 @@ public void onPostLoad(PostLoadEvent event) { // TopiaContextImplementor context = getContext(rootContext, event // .getSession()); - TopiaDAOSupplier daoSupplier = null; // TODO brendan 30/09/13 Implment + TopiaDaoSupplier daoSupplier = null; // TODO brendan 30/09/13 Implment if (daoSupplier != null && event.getEntity() instanceof TopiaEntity) { attachContext(event.getEntity(), daoSupplier); TopiaEntity entity = (TopiaEntity) event.getEntity(); - AbstractTopiaDAO<? extends TopiaEntity> dao = (AbstractTopiaDAO) daoSupplier.getDAO(entity.getClass()); + AbstractTopiaDAO<? extends TopiaEntity> dao = (AbstractTopiaDAO) daoSupplier.getDao(entity.getClass()); dao.getTopiaFiresSupport().fireOnPostLoad(dao, (TopiaEntity) event.getEntity(), new Object[]{}); } } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -39,7 +39,7 @@ import org.nuiton.eugene.models.object.xml.ObjectModelAttributeImpl; import org.nuiton.eugene.models.object.xml.ObjectModelEnumerationImpl; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaDAOSupplier; +import org.nuiton.topia.TopiaDaoSupplier; import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; @@ -184,12 +184,12 @@ // specialized getXXXDao method op = addOperation(daoHelper, "get" + daoClazzName, clazz.getPackageName() + '.' + daoClazzName, ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC); - addParameter(op, TopiaDAOSupplier.class, "supplier"); + addParameter(op, TopiaDaoSupplier.class, "supplier"); addImport(daoHelper, clazz); addException(op, TopiaException.class); setOperationBody(op, "" /*{ - <%=daoClazzName%> result = supplier.getDAO(<%=clazzName%>.class, <%=daoClazzName%>.class); + <%=daoClazzName%> result = supplier.getDao(<%=clazzName%>.class, <%=daoClazzName%>.class); return result; }*/ ); @@ -197,26 +197,26 @@ } // generic getDao method - op = addOperation(daoHelper, "getDAO", "<T extends TopiaEntity, D extends TopiaDAO<? super T>> D", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC); + op = addOperation(daoHelper, "getDao", "<T extends TopiaEntity, D extends TopiaDAO<? super T>> D", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC); addParameter(op, TopiaContext.class, "context"); addParameter(op, "Class<T>", "klass"); addException(op, TopiaException.class); setOperationBody(op, "" /*{ <%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(klass); - D dao = (D) context.getDAO(constant.getContract()); + D dao = (D) context.getDao(constant.getContract()); return dao; }*/ ); - op = addOperation(daoHelper, "getDAO", "<T extends TopiaEntity, D extends TopiaDAO<? super T>> D", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC); + op = addOperation(daoHelper, "getDao", "<T extends TopiaEntity, D extends TopiaDAO<? super T>> D", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC); addParameter(op, TopiaContext.class, "context"); addParameter(op, "T", "entity"); addException(op, TopiaException.class); setOperationBody(op, "" /*{ <%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(entity); - D dao = (D) context.getDAO(constant.getContract()); + D dao = (D) context.getDao(constant.getContract()); return dao; }*/ ); Deleted: 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-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -1,1113 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2011 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.topia.generator; - -/*{generator option: parentheses = false}*/ -/*{generator option: writeString = +}*/ - -import com.google.common.collect.Sets; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.eugene.GeneratorUtil; -import org.nuiton.eugene.java.JavaGeneratorUtil; -import org.nuiton.eugene.java.ObjectModelTransformerToJava; -import org.nuiton.eugene.models.object.ObjectModel; -import org.nuiton.eugene.models.object.ObjectModelAssociationClass; -import org.nuiton.eugene.models.object.ObjectModelAttribute; -import org.nuiton.eugene.models.object.ObjectModelClass; -import org.nuiton.eugene.models.object.ObjectModelClassifier; -import org.nuiton.eugene.models.object.ObjectModelDependency; -import org.nuiton.eugene.models.object.ObjectModelInterface; -import org.nuiton.eugene.models.object.ObjectModelJavaModifier; -import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -/** - * To generate all <code>DAO</code> related classes for a given entity. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.5.4 - * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityDAOTransformer" - */ -public class EntityDAOTransformer extends ObjectModelTransformerToJava { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(EntityDAOTransformer.class); - - /** - * map of direct usages (values) for each entity (key). - * <p/> - * This map is used to generate the findUsages methods for DAOAbstract. - */ - protected Map<ObjectModelClass, Set<ObjectModelClass>> usages; - - /** - * All entities fqn of the model (used to detect if an attribute is not - * an entity). - */ - protected Set<String> allEntitiesFqn; - - /** - * The class of abstract dao to use. - * @since 2.5 - */ - protected Class<?> daoImplementation; - - protected String entityEnumName; - - protected String entityEnumPackage; - - /** - * Map of extra operations for DAO. The key of the map is the qualified - * name of the entity relative to the DAO. - */ - protected Map<String, Collection<ObjectModelOperation>> extraOperations = - new HashMap<String, Collection<ObjectModelOperation>>(); - - @Override - public void transformFromModel(ObjectModel model) { - - boolean generateStandaloneEnum = - TopiaGeneratorUtil.shouldGenerateStandaloneEnumForDAOHelper(model); - String modelName = model.getName(); - - entityEnumName = modelName + "EntityEnum"; - - String packageName = - getOutputProperties().getProperty(PROP_DEFAULT_PACKAGE); - - if (generateStandaloneEnum) { - entityEnumPackage = packageName + "." + entityEnumName; - } else { - String daoHelperClazzName = modelName + "DAOHelper"; - entityEnumPackage = packageName + "." + daoHelperClazzName + "." + entityEnumName; - } - - usages = TopiaGeneratorUtil.searchDirectUsages(model); - - daoImplementation = TopiaGeneratorUtil.getDAOImplementation(model); - - - // keep all classifiers on the model which are entities - List<ObjectModelClass> allEntities = - TopiaGeneratorUtil.getEntityClasses(model, true); - allEntitiesFqn = new HashSet<String>(allEntities.size()); - for (ObjectModelClass entity : allEntities) { - String fqn = entity.getQualifiedName(); - allEntitiesFqn.add(fqn); - Collection<ObjectModelOperation> daoOperations = - new HashSet<ObjectModelOperation>(); - for (ObjectModelOperation op : entity.getOperations()) { - if (TopiaGeneratorUtil.hasDaoStereotype(op)) { - daoOperations.add(op); - } - } - - if (daoOperations.isEmpty()) { - - // found some dao operations - extraOperations.put(fqn, daoOperations); - } - } - } - - @Override - public void transformFromInterface(ObjectModelInterface interfacez) { - if (!TopiaGeneratorUtil.hasDaoStereotype(interfacez)) { - return; - } - - /** - * EVO #636 : Manage extra operations for DAO from "dao" dependency - * between an interface with stereotype <<dao>> (dependency client) and - * a class with stereotype <<entity>> (dependency supplier). - */ - - ObjectModelDependency dependency = - interfacez.getDependency(TopiaGeneratorUtil.DEPENDENCIES_DAO); - - if (dependency == null) { - if (log.isWarnEnabled()) { - log.warn("Could not find dependency " + - TopiaGeneratorUtil.DEPENDENCIES_DAO + - " but DAO stereotype was placed on the interface " + - interfacez.getName()); - } - return; - } - - ObjectModelClassifier classifier = dependency.getSupplier(); - - if (!TopiaGeneratorUtil.isEntity(classifier)) { - - // dependency supplier is not an entity... - if (log.isWarnEnabled()) { - log.warn("Dependency supplier " + - classifier.getQualifiedName() + - " is not an entity."); - } - return; - } - - // keep only direct operations - Collection<ObjectModelOperation> operations = - interfacez.getOperations(); - - if (CollectionUtils.isEmpty(operations)) { - - // no operations on interface, this is not normal - if (log.isWarnEnabled()) { - log.warn("No operation found on interface with DAO " + - "stereotype "+classifier.getQualifiedName()); - } - return; - } - if (log.isDebugEnabled()) { - log.debug("add "+operations.size()+" extra operation(s) for DAO"); - } - - extraOperations.put(classifier.getQualifiedName(), operations); - } - - @Override - public void transformFromClass(ObjectModelClass clazz) { - if (!TopiaGeneratorUtil.isEntity(clazz)) { - // not an entity - return; - } - String clazzName = clazz.getName(); - String clazzFQN = clazz.getQualifiedName(); - - if (isGenerateGeneratedDao(clazz)) { - generateGeneratedDao(clazz, clazzName, clazzFQN); - } - - if (isGenerateAbstractDao(clazz)) { - generateAbstractDao(clazz, clazzName, clazzFQN); - } - - if (isGenerateLegacyDao(clazz)) { - generateLegacyDao(clazz, clazzName, clazzFQN); - } - - if (isGenerateConcreteDao(clazz)) { - generateConcreteDao(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 isGenerateConcreteDao(ObjectModelClass input) { - - String daoConcreteFqn = TopiaGeneratorUtil.getConcreteDaoFqn(input); - - if (isInClassPath(daoConcreteFqn)) { - - // already in class-path - return false; - } - - // can safely generate the dao impl - return true; - } - - protected boolean isGenerateGeneratedDao(ObjectModelClass input) { - - String daoGeneratedFqn = TopiaGeneratorUtil.getGeneratedDaoFqn(input); - - if (isInClassPath(daoGeneratedFqn)) { - - // already in class-path - return false; - } - - // can safely generate the dao impl - return true; - - } - - protected boolean isGenerateAbstractDao(ObjectModelClass input) { - - String fqn = TopiaGeneratorUtil.getAbstractDaoFqn(input); - - if (isInClassPath(fqn)) { - - // already in class-path - return false; - } - - Collection<ObjectModelOperation> moreOperations = - extraOperations.get(input.getQualifiedName()); - - if (CollectionUtils.isNotEmpty(moreOperations)) { - - // no user operations, can not generate it - return false; - } - - // can safely generate the dao impl - return true; - - } - - 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, TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">"); - } - - 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()); - - 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>"); - } - } - - protected void generateGeneratedDao(ObjectModelClass clazz, - String clazzName, - String clazzFQN) { - ObjectModelClass daoAbstractClass = createAbstractClass(TopiaGeneratorUtil.getGeneratedDaoName(clazz) + "<E extends " + clazzName + '>', - clazz.getPackageName()); - - // super class - - String superClassName = null; - for (ObjectModelClass parent : clazz.getSuperclasses()) { - if (TopiaGeneratorUtil.isEntity(parent)) { - superClassName = TopiaGeneratorUtil.getAbstractDaoFqn(parent) + "<E>"; - // in java no multi-inheritance - break; - } - } - if (superClassName == null) { - superClassName = daoImplementation.getName() + "<E>"; - } - if (log.isDebugEnabled()) { - log.debug("super class = " + superClassName); - } - setSuperClass(daoAbstractClass, superClassName); - - String prefix = getConstantPrefix(clazz, ""); - setConstantPrefix(prefix); - - // imports - - Collection<ObjectModelOperation> DAOoperations = - getDAOOperations(clazz); - - if (TopiaGeneratorUtil.isCollectionNeeded(DAOoperations)) { - addImport(daoAbstractClass, Collection.class); - } - if (TopiaGeneratorUtil.isSetNeeded(DAOoperations)) { - addImport(daoAbstractClass, Set.class); - } - addImport(daoAbstractClass, List.class); - addImport(daoAbstractClass, TopiaException.class); - - ObjectModelOperation op; - - // getEntityClass - - op = addOperation(daoAbstractClass, - "getEntityClass", - "Class<E>", - ObjectModelJavaModifier.PUBLIC); - addAnnotation(daoAbstractClass, op,Override.class); - setOperationBody(op, "" -/*{ - return (Class<E>) <%=clazzName%>.class; - }*/ - ); - - // getTopiaEntityEnum - addImport(daoAbstractClass, entityEnumPackage); - op = addOperation(daoAbstractClass, - "getTopiaEntityEnum", - entityEnumName, - ObjectModelJavaModifier.PUBLIC); - addAnnotation(daoAbstractClass, op,Override.class); - setOperationBody(op, "" -/*{ - return <%=entityEnumName%>.<%=clazzName%>; - }*/ - ); - - generateDAOOperations(daoAbstractClass, DAOoperations); - - generateDelete(clazz, daoAbstractClass); - - generateNaturalId(daoAbstractClass, clazz); - - generateNotNull(daoAbstractClass, clazz); - - for (ObjectModelAttribute attr : clazz.getAttributes()) { - if (!attr.isNavigable()) { - continue; - } - - if (!GeneratorUtil.isNMultiplicity(attr)) { - generateNoNMultiplicity(clazzName, daoAbstractClass, attr, false); - } else { - generateNMultiplicity(clazzName, daoAbstractClass, attr); - } - } - - if (clazz instanceof ObjectModelAssociationClass) { - ObjectModelAssociationClass assocClass = - (ObjectModelAssociationClass) clazz; - for (ObjectModelAttribute attr : assocClass.getParticipantsAttributes()) { - if (attr != null) { - if (!GeneratorUtil.isNMultiplicity(attr)) { - generateNoNMultiplicity(clazzName, daoAbstractClass, attr, true); - } else { - generateNMultiplicity(clazzName, daoAbstractClass, attr); - } - } - } - } - - Set<ObjectModelClass> usagesForclass = usages.get(clazz); - generateFindUsages(clazz, daoAbstractClass, usagesForclass); - } - - protected void generateDelete(ObjectModelClass clazz, - ObjectModelClass result) { - - StringBuilder body = new StringBuilder(); - String modelName = StringUtils.capitalize(model.getName()); - String providerFQN = getOutputProperties().getProperty( - PROP_DEFAULT_PACKAGE) + '.' + modelName + - "DAOHelper.getImplementationClass"; - - for (ObjectModelAttribute attr : clazz.getAttributes()) { - - String attrType = GeneratorUtil.getSimpleName(attr.getType()); - - String reverseAttrName = attr.getReverseAttributeName(); - ObjectModelAttribute reverse = attr.getReverseAttribute(); - if (attr.hasAssociationClass() || - reverse == null || !reverse.isNavigable()) { - - // never treate a non reverse and navigable attribute - // never treate an association class attribute - continue; - } - - // at this point we are sure to have a attribute which is - // - reverse - // - navigable - // - not from an association class - if (!allEntitiesFqn.contains(attr.getType())) { - - // this attribute is not from an entity, don't treate it - if (log.isDebugEnabled()) { - log.debug("[" + result.getName() + "] Skip attribute [" + - attr.getName() + "] with type " + attr.getType()); - } - continue; - } - - // At this point, the attribute type is a entity - if (GeneratorUtil.isNMultiplicity(attr) && - GeneratorUtil.isNMultiplicity(reverse)) { - // On doit absolument supprimer pour les relations many-to-many - // le this de la collection de l'autre cote - - String attrDBName = TopiaGeneratorUtil.getDbName(attr); - String attrClassifierDBName = TopiaGeneratorUtil.getDbName(attr.getClassifier()); - String attrJoinTableName = TopiaGeneratorUtil.getManyToManyTableName(attr); - String attrReverseDBName = TopiaGeneratorUtil.getReverseDbName(attr); - - //FIXME_-FC-20100413 Use a TopiaQuery (use HQLin elements) -// // Add DAOHelper -// String daoHelper = modelName + "DAOHelper"; -// String daoHelperFQN = getOutputProperties(). -// getProperty(PROP_DEFAULT_PACKAGE) + '.' + daoHelper; -// addImport(result, daoHelperFQN); -// -// // Add import for TopiaQuery -// addImport(result, TopiaQuery.class); -// -// // Entity DAO and reversePropertyName -// String entityDAO = attrType + "DAO"; -// String reverseAttrNameProperty = -// attrType + "." + getConstantName(reverseAttrName); -// -// -// <%=entityDAO%> dao = <%=daoHelper%>.get<%=entityDAO%>(getTopiaContext()); -// TopiaQuery query = dao.createQuery("B"). -// addFrom(entity.getClass(), "A"). -// add("A", entity). -// addInElements("A", "B." + <%=reverseAttrNameProperty%>); -// -// System.out.println("Query : " + query); -// List<<%=attrType%>> list = dao.findAllByQuery(query); - - String removeName = getJavaBeanMethodName("remove", reverseAttrName); - body.append("" -/*{ - { - List<<%=attrType%>> list = topiaHibernateSupport.getHibernateSession().createSQLQuery( - "SELECT main.topiaid " + - "from <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " + - "where main.topiaid=secondary.<%=attrDBName%>" + - " and secondary.<%=attrReverseDBName%>='" + entity.getTopiaId() + "'") - .addEntity("main", <%=providerFQN%>(<%=attrType%>.class)).list(); - - for (<%=attrType%> item : list) { - item.<%=removeName%>(entity); - } - } -}*/ - ); - } else if (!GeneratorUtil.isNMultiplicity(reverse)) { - // On doit mettre a null les attributs qui ont cet objet sur les - // autres entites en one-to-* - // TODO peut-etre qu'hibernate est capable de faire ca tout seul ? - // 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); - - body.append("" - /*{ - { - List<<%=attrSimpleType%>> list = topiaDAOSupplier - .getDAO(<%=attrSimpleType%>.class, <%=attrConcreteDaoClassName%>.class) - .forProperties(<%=attrSimpleType%>.<%=getConstantName(reverseAttrName)%>, entity).findAll(); - for (<%=attrSimpleType%> item : list) { - - // sletellier : Set null only if target is concerned by deletion - if (entity.equals(item.<%=getName%>())) { - item.<%=setName%>(null); - } - }*/ - ); - if (attr.isAggregate()) { - body.append("" -/*{ - topiaDAOSupplier.getDAO(<%=attrSimpleType%>.class).delete(item); -}*/ - ); - } - body.append("" -/*{ - } - } -}*/ - ); - - } - } - - if (body.length()>0) { - // something specific was done, need to generate the method - ObjectModelOperation op; - op = addOperation(result, "delete", "void", ObjectModelJavaModifier.PUBLIC); - addAnnotation(result, op,Override.class); - addParameter(op, "E", "entity"); - body.append("" -/*{ - super.delete(entity); - }*/ - ); - setOperationBody(op, body.toString()); - } - - - - } - - protected void generateFindUsages(ObjectModelClass clazz, - ObjectModelClass result, - Set<ObjectModelClass> usagesForclass) { - - builder.addImport(result, LinkedList.class.getName()); - builder.addImport(result, Map.class.getName()); - builder.addImport(result, HashMap.class.getName()); - builder.addImport(result, TopiaEntity.class.getName()); - - if (clazz instanceof ObjectModelAssociationClass || - usagesForclass.isEmpty()) { - // not for an association class - // just let a null method - ObjectModelOperation operation; - operation = addOperation(result, - "findUsages", - "<U extends TopiaEntity> List<U>", - ObjectModelJavaModifier.PUBLIC); - - addParameter(operation, "Class<U>", "type"); - addParameter(operation, "E", "entity"); - addAnnotation(result, operation, Override.class); - setOperationBody(operation, "" -/*{ - return new LinkedList<U>(); - }*/ - ); - - operation = addOperation(result, - "findAllUsages", - "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>", - ObjectModelJavaModifier.PUBLIC); - - addParameter(operation, "E", "entity"); - addAnnotation(result, operation, Override.class); - setOperationBody(operation, "" -/*{ - return new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>(); - }*/ - ); - - return; - } - List<ObjectModelClass> allEntities; - Map<String, ObjectModelClass> allEntitiesByFQN; - - allEntities = TopiaGeneratorUtil.getEntityClasses(model, true); - allEntitiesByFQN = new TreeMap<String, ObjectModelClass>(); - - // prepare usages map and fill allEntitiesByFQN map - for (ObjectModelClass klass : allEntities) { - allEntitiesByFQN.put(klass.getQualifiedName(), klass); - } - - ObjectModelOperation operation; - operation = addOperation(result, - "findUsages", - "<U extends TopiaEntity> List<U>", - ObjectModelJavaModifier.PUBLIC); - - addParameter(operation, "Class<U>", "type"); - addParameter(operation, "E", "entity"); - addAnnotation(result, operation, Override.class); - StringBuilder buffer = new StringBuilder(300); - buffer.append("" -/*{ - List<?> result = new LinkedList(); - List tmp; -}*/ - ); - - for (ObjectModelClass usageClass : usagesForclass) { - String usageType = usageClass.getQualifiedName(); - builder.addImport(result, usageType); - String usageSimpleType = - TopiaGeneratorUtil.getClassNameFromQualifiedName(usageType); - String usageSimplePropertyMethod = "findAllBy" + usageSimpleType; - String usageCollectionPropertyMethod = "findAllContaining" + usageSimpleType; - for (ObjectModelAttribute attr : usageClass.getAttributes()) { - if (!attr.isNavigable()) { - // skip this case - continue; - } - String type; - String attrName = attr.getName(); - if (attr.hasAssociationClass()) { - //FIXME-TC20100224 dont known how to do this ? - continue; -// type = attr.getAssociationClass().getQualifiedName(); -// //FIXME-TC20100224 : this is crazy ??? must find the good name -// // Perhaps need to make different cases? -// attrName = attrName + "_" + TopiaGeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName()); - } else { - type = attr.getType(); - } - if (!allEntitiesByFQN.containsKey(type)) { - // not a entity, can skip for this attribute - continue; - } - ObjectModelClass targetEntity = allEntitiesByFQN.get(type); -// if (!type.equals(clazz.getQualifiedName())) { - if (!targetEntity.equals(clazz)) { - // not a good attribute reference - continue; - } - // found something to seek - - String methodName; - if (TopiaGeneratorUtil.isNMultiplicity(attr)) { - methodName = getJavaBeanMethodName("findAllContains", attrName); - } else { - methodName = getJavaBeanMethodName("findAllBy", attrName); - } - String daoName = StringUtils.capitalize(usageSimpleType) + "DAO"; - - builder.addImport(result, usageClass.getPackageName() + '.' + daoName); - - buffer.append("" -/*{ - if (type == <%=usageSimpleType%>.class) { - <%=daoName%> dao = (<%=daoName%>) - topiaDAOSupplier.getDAO(<%=usageSimpleType%>.class); - tmp = dao.<%=methodName%>(entity); - result.addAll(tmp); - } -}*/ - ); - } - } - - buffer.append("" -/*{ - return (List<U>) result; - }*/ - ); - setOperationBody(operation, buffer.toString()); - - operation = addOperation(result, - "findAllUsages", - "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>", - ObjectModelJavaModifier.PUBLIC); - - addParameter(operation, "E", "entity"); - addAnnotation(result, operation, Override.class); - - buffer = new StringBuilder(300); - buffer.append("" -/*{ - Map<Class<? extends TopiaEntity>,List<? extends TopiaEntity>> result; - result = new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>(<%=usagesForclass.size()%>); - - List<? extends TopiaEntity> list; -}*/ - ); - for (ObjectModelClass usageClass : usagesForclass) { - - String fqn = usageClass.getName(); - buffer.append("" -/*{ - list = findUsages(<%=fqn%>.class, entity); - if (!list.isEmpty()) { - result.put(<%=fqn%>.class, list); - } -}*/ - ); - - } - buffer.append("" -/*{ - return result; - }*/ - ); - - setOperationBody(operation, buffer.toString()); - } - - /** - * Generation of DAO operations signatures from class. These operations are - * abstract and identified by <<dao>> stereotype in the model. The - * developper must defined these methods in the DAOImpl associated to this - * DAOAbstract. - * - * @param result clazz where to add operations - * @param operations operations to generate - * @deprecated will be removed ASAP in topia 3.0 - */ - @Deprecated - protected void generateDAOOperations(ObjectModelClass result, - Collection<ObjectModelOperation> - operations) { - if (CollectionUtils.isEmpty(operations)) { - - // no extra operations to generate - return; - } - - for (ObjectModelOperation op : operations) { - - Set<String> exceptions = op.getExceptions(); - cloneOperation(op, - result, - true, - ObjectModelJavaModifier.ABSTRACT, - ObjectModelJavaModifier.fromVisibility(op.getVisibility()) - ); - } - } - - - protected void generateNoNMultiplicity(String clazzName, - ObjectModelClass result, - ObjectModelAttribute attr, - boolean isAssoc) { - String attrName = attr.getName(); - String attrType = attr.getType(); - String propertyName = clazzName + "." + getConstantName(attrName); - - String attrTypeForGeneric; - if (JavaGeneratorUtil.isPrimitiveType(attrType)) { - attrTypeForGeneric = TopiaGeneratorUtil.getClassForPrimitiveType(attr); - } else { - attrTypeForGeneric = attrType; - } - - if (!isAssoc && attr.hasAssociationClass()) { - String assocClassName = attr.getAssociationClass().getName(); - String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); - // It is about transitivity : use the property to access the - // associationClass + '.' + the property to access the expected - // attribute - // <class>.<attrAssoc> + '.' + <assocClass>.<attr> - propertyName = - clazzName + '.' + getConstantName(assocAttrName) + - " + '.' + " + - assocClassName + '.' + getConstantName(attrName); - } - - ObjectModelOperation op; - op = addOperation(result, - getJavaBeanMethodName("for", attrName, "In"), - "TopiaQueryBuilderRunQueryStep<E>", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, "Iterable<" + attrTypeForGeneric + ">", "v"); - setOperationBody(op, "" -/*{ - TopiaQueryBuilderRunQueryStep<E> result = forIn(<%=propertyName%>, (Iterable) v); - return result; - }*/ - ); - - op = addOperation(result, - getJavaBeanMethodName("for", attrName, "Equals"), - "TopiaQueryBuilderRunQueryStep<E>", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrType, "v"); - setOperationBody(op, "" -/*{ - TopiaQueryBuilderRunQueryStep<E> result = forEquals(<%=propertyName%>, v); - return result; - }*/ - ); - - String methodToDelegateName = op.getName(); - - op = addOperation(result, - getJavaBeanMethodName("findBy", attrName), - "E", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrType, "v"); - setOperationBody(op, "" -/*{ - return <%=methodToDelegateName%>(v).findAnyOrNull(); - }*/ - ); - - addAnnotation(result, op, Deprecated.class); - - op = addOperation(result, - getJavaBeanMethodName("findAllBy", attrName), - "List<E>", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrType, "v"); - setOperationBody(op, "" -/*{ - return <%=methodToDelegateName%>(v).findAll(); - }*/ - ); - - addAnnotation(result, op, Deprecated.class); - - if (!isAssoc && attr.hasAssociationClass()) { - String assocClassName = attr.getAssociationClass().getName(); - String assocClassFQN = attr.getAssociationClass().getQualifiedName(); - String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); - String assocPropertyConstantName = getConstantName(assocAttrName); - op = addOperation(result, - getJavaBeanMethodName("findBy", assocClassName), - "E", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, assocClassFQN, "value"); - setOperationBody(op, "" -/*{ - E result = findByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value); - return result; - }*/ - ); - - op = addOperation(result, - getJavaBeanMethodName("findAllBy", assocClassName), - "List<E>", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, assocClassFQN, "value"); - setOperationBody(op, "" -/*{ - List<E> result = findAllByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value); - return result; - }*/ - ); - } - } - - protected void generateNMultiplicity(String clazzName, - ObjectModelClass result, - ObjectModelAttribute attr) { - String attrName = attr.getName(); - String attrType = attr.getType(); - if (attr.hasAssociationClass()) { - // do nothing for association class, too complex... - return; - } - ObjectModelOperation op; - - op = addOperation(result, - getJavaBeanMethodName("for", attrName, "Contains"), - "TopiaQueryBuilderRunQueryStep<E>", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrType, "v"); - setOperationBody(op, "" -/*{ - return forContains(<%=clazzName + "." + getConstantName(attrName)%>, v); - }*/ - ); - - String methodToDelegateName = op.getName(); - - op = addOperation(result, - getJavaBeanMethodName("findContains", attrName), - "E", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrType, "v"); - setOperationBody(op, "" -/*{ - return <%=methodToDelegateName%>(v).findAnyOrNull(); - }*/ - ); - - addAnnotation(result, op, Deprecated.class); - - op = addOperation(result, - getJavaBeanMethodName("findAllContains", attrName), - "List<E>", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrType, "v"); - setOperationBody(op, "" -/*{ - return <%=methodToDelegateName%>(v).findAll(); - }*/ - ); - - addAnnotation(result, op, Deprecated.class); - - } - - - /** - * Obtain business operations of the DAO. - * - * This operations can not be generated, but must be written by developper. - * - * @param clazz the clazz to test. - * @return collections of extra operations, or empty collection if none found. - */ - public Collection<ObjectModelOperation> getDAOOperations( - ObjectModelClass clazz) { - -// // Note : this collection will contains extra operations for DAO. -// // Overriding existing generated methods is not managed yet -// Collection<ObjectModelOperation> results = -// new ArrayList<ObjectModelOperation>(); - -// // This code will be deprecated -// for (ObjectModelOperation op : clazz.getOperations()) { -// if (TopiaGeneratorUtil.hasDaoStereotype(op)) { -// results.add(op); -// } -// } - - if (log.isWarnEnabled()) { - log.warn("dao contract in model will not be supported in topia 3.0"); - } - Collection<ObjectModelOperation> extra = - extraOperations.get(clazz.getQualifiedName()); - return extra; -// if (extra != null) { -// for (ObjectModelOperation op : extra) { -// results.add(op); -// } -// } - -// return results; - } - - private void generateNaturalId(ObjectModelClass result, - ObjectModelClass clazz) { - Set<ObjectModelAttribute> props = - TopiaGeneratorUtil.getNaturalIdAttributes(clazz); - - if (!props.isEmpty()) { - - if (log.isDebugEnabled()) { - log.debug("generateNaturalId for " + props); - } - ObjectModelOperation findByNaturalId = addOperation(result, - "findByNaturalId", "E", ObjectModelJavaModifier.PUBLIC); - - ObjectModelOperation existByNaturalId = addOperation(result, - "existByNaturalId", "boolean", ObjectModelJavaModifier.PUBLIC); - - ObjectModelOperation createByNaturalId = addOperation(result, - "createByNaturalId", "E", ObjectModelJavaModifier.PUBLIC); - - Set<String> properties = Sets.newLinkedHashSet(); - String clazzName = clazz.getName(); - - for (ObjectModelAttribute attr : props) { - - String propName = attr.getName(); - String type = attr.getType(); - - addParameter(findByNaturalId, type, propName); - addParameter(existByNaturalId, type, propName); - addParameter(createByNaturalId, type, propName); - - String property = clazzName + '.' + getConstantName(propName) + ", " + propName; - properties.add(property); - - } - - String arguments = StringUtils.join(properties, ", "); - - setOperationBody(findByNaturalId, "" -/*{ - return forProperties(<%=arguments%>).findUnique(); - }*/ - ); - - setOperationBody(existByNaturalId, "" -/*{ - return forProperties(<%=arguments%>).exists(); - }*/ - ); - - setOperationBody(createByNaturalId, "" -/*{ - return create(<%=arguments%>); - }*/ - ); - } - } - - protected void generateNotNull(ObjectModelClass result, - ObjectModelClass clazz) { - - Set<ObjectModelAttribute> props = - TopiaGeneratorUtil.getNotNullAttributes(clazz); - - if (!props.isEmpty()) { - - if (log.isDebugEnabled()) { - log.debug("generateNotNull for " + props); - } - - ObjectModelOperation createByNotNull = addOperation(result, - "createByNotNull", "E", ObjectModelJavaModifier.PUBLIC); - - String createProperties = ""; -// String params = ""; - String clazzName = clazz.getName(); - for (ObjectModelAttribute attr : props) { - String propName = attr.getName(); - // add property as param in both methods - addParameter(createByNotNull, attr.getType(), propName); - - createProperties += - ", " + clazzName + '.' + getConstantName(propName) + - ", " + propName; - //params += ", " + propName; - } - createProperties = createProperties.substring(2); - //params = params.substring(2); - - setOperationBody(createByNotNull, "" -/*{ - return create(<%=createProperties%>); - }*/ - ); - } - } -} Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java (from rev 2845, trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java) =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -0,0 +1,1113 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2011 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.topia.generator; + +/*{generator option: parentheses = false}*/ +/*{generator option: writeString = +}*/ + +import com.google.common.collect.Sets; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.GeneratorUtil; +import org.nuiton.eugene.java.JavaGeneratorUtil; +import org.nuiton.eugene.java.ObjectModelTransformerToJava; +import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.ObjectModelAssociationClass; +import org.nuiton.eugene.models.object.ObjectModelAttribute; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelClassifier; +import org.nuiton.eugene.models.object.ObjectModelDependency; +import org.nuiton.eugene.models.object.ObjectModelInterface; +import org.nuiton.eugene.models.object.ObjectModelJavaModifier; +import org.nuiton.eugene.models.object.ObjectModelOperation; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +/** + * To generate all <code>DAO</code> related classes for a given entity. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.5.4 + * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityDaoTransformer" + */ +public class EntityDaoTransformer extends ObjectModelTransformerToJava { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(EntityDaoTransformer.class); + + /** + * map of direct usages (values) for each entity (key). + * <p/> + * This map is used to generate the findUsages methods for DAOAbstract. + */ + protected Map<ObjectModelClass, Set<ObjectModelClass>> usages; + + /** + * All entities fqn of the model (used to detect if an attribute is not + * an entity). + */ + protected Set<String> allEntitiesFqn; + + /** + * The class of abstract dao to use. + * @since 2.5 + */ + protected Class<?> daoImplementation; + + protected String entityEnumName; + + protected String entityEnumPackage; + + /** + * Map of extra operations for DAO. The key of the map is the qualified + * name of the entity relative to the DAO. + */ + protected Map<String, Collection<ObjectModelOperation>> extraOperations = + new HashMap<String, Collection<ObjectModelOperation>>(); + + @Override + public void transformFromModel(ObjectModel model) { + + boolean generateStandaloneEnum = + TopiaGeneratorUtil.shouldGenerateStandaloneEnumForDAOHelper(model); + String modelName = model.getName(); + + entityEnumName = modelName + "EntityEnum"; + + String packageName = + getOutputProperties().getProperty(PROP_DEFAULT_PACKAGE); + + if (generateStandaloneEnum) { + entityEnumPackage = packageName + "." + entityEnumName; + } else { + String daoHelperClazzName = modelName + "DAOHelper"; + entityEnumPackage = packageName + "." + daoHelperClazzName + "." + entityEnumName; + } + + usages = TopiaGeneratorUtil.searchDirectUsages(model); + + daoImplementation = TopiaGeneratorUtil.getDAOImplementation(model); + + + // keep all classifiers on the model which are entities + List<ObjectModelClass> allEntities = + TopiaGeneratorUtil.getEntityClasses(model, true); + allEntitiesFqn = new HashSet<String>(allEntities.size()); + for (ObjectModelClass entity : allEntities) { + String fqn = entity.getQualifiedName(); + allEntitiesFqn.add(fqn); + Collection<ObjectModelOperation> daoOperations = + new HashSet<ObjectModelOperation>(); + for (ObjectModelOperation op : entity.getOperations()) { + if (TopiaGeneratorUtil.hasDaoStereotype(op)) { + daoOperations.add(op); + } + } + + if (daoOperations.isEmpty()) { + + // found some dao operations + extraOperations.put(fqn, daoOperations); + } + } + } + + @Override + public void transformFromInterface(ObjectModelInterface interfacez) { + if (!TopiaGeneratorUtil.hasDaoStereotype(interfacez)) { + return; + } + + /** + * EVO #636 : Manage extra operations for DAO from "dao" dependency + * between an interface with stereotype <<dao>> (dependency client) and + * a class with stereotype <<entity>> (dependency supplier). + */ + + ObjectModelDependency dependency = + interfacez.getDependency(TopiaGeneratorUtil.DEPENDENCIES_DAO); + + if (dependency == null) { + if (log.isWarnEnabled()) { + log.warn("Could not find dependency " + + TopiaGeneratorUtil.DEPENDENCIES_DAO + + " but DAO stereotype was placed on the interface " + + interfacez.getName()); + } + return; + } + + ObjectModelClassifier classifier = dependency.getSupplier(); + + if (!TopiaGeneratorUtil.isEntity(classifier)) { + + // dependency supplier is not an entity... + if (log.isWarnEnabled()) { + log.warn("Dependency supplier " + + classifier.getQualifiedName() + + " is not an entity."); + } + return; + } + + // keep only direct operations + Collection<ObjectModelOperation> operations = + interfacez.getOperations(); + + if (CollectionUtils.isEmpty(operations)) { + + // no operations on interface, this is not normal + if (log.isWarnEnabled()) { + log.warn("No operation found on interface with DAO " + + "stereotype "+classifier.getQualifiedName()); + } + return; + } + if (log.isDebugEnabled()) { + log.debug("add "+operations.size()+" extra operation(s) for DAO"); + } + + extraOperations.put(classifier.getQualifiedName(), operations); + } + + @Override + public void transformFromClass(ObjectModelClass clazz) { + if (!TopiaGeneratorUtil.isEntity(clazz)) { + // not an entity + return; + } + String clazzName = clazz.getName(); + String clazzFQN = clazz.getQualifiedName(); + + if (isGenerateGeneratedDao(clazz)) { + generateGeneratedDao(clazz, clazzName, clazzFQN); + } + + if (isGenerateAbstractDao(clazz)) { + generateAbstractDao(clazz, clazzName, clazzFQN); + } + + if (isGenerateLegacyDao(clazz)) { + generateLegacyDao(clazz, clazzName, clazzFQN); + } + + if (isGenerateConcreteDao(clazz)) { + generateConcreteDao(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 isGenerateConcreteDao(ObjectModelClass input) { + + String daoConcreteFqn = TopiaGeneratorUtil.getConcreteDaoFqn(input); + + if (isInClassPath(daoConcreteFqn)) { + + // already in class-path + return false; + } + + // can safely generate the dao impl + return true; + } + + protected boolean isGenerateGeneratedDao(ObjectModelClass input) { + + String daoGeneratedFqn = TopiaGeneratorUtil.getGeneratedDaoFqn(input); + + if (isInClassPath(daoGeneratedFqn)) { + + // already in class-path + return false; + } + + // can safely generate the dao impl + return true; + + } + + protected boolean isGenerateAbstractDao(ObjectModelClass input) { + + String fqn = TopiaGeneratorUtil.getAbstractDaoFqn(input); + + if (isInClassPath(fqn)) { + + // already in class-path + return false; + } + + Collection<ObjectModelOperation> moreOperations = + extraOperations.get(input.getQualifiedName()); + + if (CollectionUtils.isNotEmpty(moreOperations)) { + + // no user operations, can not generate it + return false; + } + + // can safely generate the dao impl + return true; + + } + + 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, TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">"); + } + + 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()); + + 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>"); + } + } + + protected void generateGeneratedDao(ObjectModelClass clazz, + String clazzName, + String clazzFQN) { + ObjectModelClass daoAbstractClass = createAbstractClass(TopiaGeneratorUtil.getGeneratedDaoName(clazz) + "<E extends " + clazzName + '>', + clazz.getPackageName()); + + // super class + + String superClassName = null; + for (ObjectModelClass parent : clazz.getSuperclasses()) { + if (TopiaGeneratorUtil.isEntity(parent)) { + superClassName = TopiaGeneratorUtil.getAbstractDaoFqn(parent) + "<E>"; + // in java no multi-inheritance + break; + } + } + if (superClassName == null) { + superClassName = daoImplementation.getName() + "<E>"; + } + if (log.isDebugEnabled()) { + log.debug("super class = " + superClassName); + } + setSuperClass(daoAbstractClass, superClassName); + + String prefix = getConstantPrefix(clazz, ""); + setConstantPrefix(prefix); + + // imports + + Collection<ObjectModelOperation> DAOoperations = + getDAOOperations(clazz); + + if (TopiaGeneratorUtil.isCollectionNeeded(DAOoperations)) { + addImport(daoAbstractClass, Collection.class); + } + if (TopiaGeneratorUtil.isSetNeeded(DAOoperations)) { + addImport(daoAbstractClass, Set.class); + } + addImport(daoAbstractClass, List.class); + addImport(daoAbstractClass, TopiaException.class); + + ObjectModelOperation op; + + // getEntityClass + + op = addOperation(daoAbstractClass, + "getEntityClass", + "Class<E>", + ObjectModelJavaModifier.PUBLIC); + addAnnotation(daoAbstractClass, op,Override.class); + setOperationBody(op, "" +/*{ + return (Class<E>) <%=clazzName%>.class; + }*/ + ); + + // getTopiaEntityEnum + addImport(daoAbstractClass, entityEnumPackage); + op = addOperation(daoAbstractClass, + "getTopiaEntityEnum", + entityEnumName, + ObjectModelJavaModifier.PUBLIC); + addAnnotation(daoAbstractClass, op,Override.class); + setOperationBody(op, "" +/*{ + return <%=entityEnumName%>.<%=clazzName%>; + }*/ + ); + + generateDAOOperations(daoAbstractClass, DAOoperations); + + generateDelete(clazz, daoAbstractClass); + + generateNaturalId(daoAbstractClass, clazz); + + generateNotNull(daoAbstractClass, clazz); + + for (ObjectModelAttribute attr : clazz.getAttributes()) { + if (!attr.isNavigable()) { + continue; + } + + if (!GeneratorUtil.isNMultiplicity(attr)) { + generateNoNMultiplicity(clazzName, daoAbstractClass, attr, false); + } else { + generateNMultiplicity(clazzName, daoAbstractClass, attr); + } + } + + if (clazz instanceof ObjectModelAssociationClass) { + ObjectModelAssociationClass assocClass = + (ObjectModelAssociationClass) clazz; + for (ObjectModelAttribute attr : assocClass.getParticipantsAttributes()) { + if (attr != null) { + if (!GeneratorUtil.isNMultiplicity(attr)) { + generateNoNMultiplicity(clazzName, daoAbstractClass, attr, true); + } else { + generateNMultiplicity(clazzName, daoAbstractClass, attr); + } + } + } + } + + Set<ObjectModelClass> usagesForclass = usages.get(clazz); + generateFindUsages(clazz, daoAbstractClass, usagesForclass); + } + + protected void generateDelete(ObjectModelClass clazz, + ObjectModelClass result) { + + StringBuilder body = new StringBuilder(); + String modelName = StringUtils.capitalize(model.getName()); + String providerFQN = getOutputProperties().getProperty( + PROP_DEFAULT_PACKAGE) + '.' + modelName + + "DAOHelper.getImplementationClass"; + + for (ObjectModelAttribute attr : clazz.getAttributes()) { + + String attrType = GeneratorUtil.getSimpleName(attr.getType()); + + String reverseAttrName = attr.getReverseAttributeName(); + ObjectModelAttribute reverse = attr.getReverseAttribute(); + if (attr.hasAssociationClass() || + reverse == null || !reverse.isNavigable()) { + + // never treate a non reverse and navigable attribute + // never treate an association class attribute + continue; + } + + // at this point we are sure to have a attribute which is + // - reverse + // - navigable + // - not from an association class + if (!allEntitiesFqn.contains(attr.getType())) { + + // this attribute is not from an entity, don't treate it + if (log.isDebugEnabled()) { + log.debug("[" + result.getName() + "] Skip attribute [" + + attr.getName() + "] with type " + attr.getType()); + } + continue; + } + + // At this point, the attribute type is a entity + if (GeneratorUtil.isNMultiplicity(attr) && + GeneratorUtil.isNMultiplicity(reverse)) { + // On doit absolument supprimer pour les relations many-to-many + // le this de la collection de l'autre cote + + String attrDBName = TopiaGeneratorUtil.getDbName(attr); + String attrClassifierDBName = TopiaGeneratorUtil.getDbName(attr.getClassifier()); + String attrJoinTableName = TopiaGeneratorUtil.getManyToManyTableName(attr); + String attrReverseDBName = TopiaGeneratorUtil.getReverseDbName(attr); + + //FIXME_-FC-20100413 Use a TopiaQuery (use HQLin elements) +// // Add DAOHelper +// String daoHelper = modelName + "DAOHelper"; +// String daoHelperFQN = getOutputProperties(). +// getProperty(PROP_DEFAULT_PACKAGE) + '.' + daoHelper; +// addImport(result, daoHelperFQN); +// +// // Add import for TopiaQuery +// addImport(result, TopiaQuery.class); +// +// // Entity DAO and reversePropertyName +// String entityDAO = attrType + "DAO"; +// String reverseAttrNameProperty = +// attrType + "." + getConstantName(reverseAttrName); +// +// +// <%=entityDAO%> dao = <%=daoHelper%>.get<%=entityDAO%>(getTopiaContext()); +// TopiaQuery query = dao.createQuery("B"). +// addFrom(entity.getClass(), "A"). +// add("A", entity). +// addInElements("A", "B." + <%=reverseAttrNameProperty%>); +// +// System.out.println("Query : " + query); +// List<<%=attrType%>> list = dao.findAllByQuery(query); + + String removeName = getJavaBeanMethodName("remove", reverseAttrName); + body.append("" +/*{ + { + List<<%=attrType%>> list = topiaHibernateSupport.getHibernateSession().createSQLQuery( + "SELECT main.topiaid " + + "from <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " + + "where main.topiaid=secondary.<%=attrDBName%>" + + " and secondary.<%=attrReverseDBName%>='" + entity.getTopiaId() + "'") + .addEntity("main", <%=providerFQN%>(<%=attrType%>.class)).list(); + + for (<%=attrType%> item : list) { + item.<%=removeName%>(entity); + } + } +}*/ + ); + } else if (!GeneratorUtil.isNMultiplicity(reverse)) { + // On doit mettre a null les attributs qui ont cet objet sur les + // autres entites en one-to-* + // TODO peut-etre qu'hibernate est capable de faire ca tout seul ? + // 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); + + body.append("" + /*{ + { + List<<%=attrSimpleType%>> list = topiaDaoSupplier + .getDao(<%=attrSimpleType%>.class, <%=attrConcreteDaoClassName%>.class) + .forProperties(<%=attrSimpleType%>.<%=getConstantName(reverseAttrName)%>, entity).findAll(); + for (<%=attrSimpleType%> item : list) { + + // sletellier : Set null only if target is concerned by deletion + if (entity.equals(item.<%=getName%>())) { + item.<%=setName%>(null); + } + }*/ + ); + if (attr.isAggregate()) { + body.append("" +/*{ + topiaDaoSupplier.getDao(<%=attrSimpleType%>.class).delete(item); +}*/ + ); + } + body.append("" +/*{ + } + } +}*/ + ); + + } + } + + if (body.length()>0) { + // something specific was done, need to generate the method + ObjectModelOperation op; + op = addOperation(result, "delete", "void", ObjectModelJavaModifier.PUBLIC); + addAnnotation(result, op,Override.class); + addParameter(op, "E", "entity"); + body.append("" +/*{ + super.delete(entity); + }*/ + ); + setOperationBody(op, body.toString()); + } + + + + } + + protected void generateFindUsages(ObjectModelClass clazz, + ObjectModelClass result, + Set<ObjectModelClass> usagesForclass) { + + builder.addImport(result, LinkedList.class.getName()); + builder.addImport(result, Map.class.getName()); + builder.addImport(result, HashMap.class.getName()); + builder.addImport(result, TopiaEntity.class.getName()); + + if (clazz instanceof ObjectModelAssociationClass || + usagesForclass.isEmpty()) { + // not for an association class + // just let a null method + ObjectModelOperation operation; + operation = addOperation(result, + "findUsages", + "<U extends TopiaEntity> List<U>", + ObjectModelJavaModifier.PUBLIC); + + addParameter(operation, "Class<U>", "type"); + addParameter(operation, "E", "entity"); + addAnnotation(result, operation, Override.class); + setOperationBody(operation, "" +/*{ + return new LinkedList<U>(); + }*/ + ); + + operation = addOperation(result, + "findAllUsages", + "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>", + ObjectModelJavaModifier.PUBLIC); + + addParameter(operation, "E", "entity"); + addAnnotation(result, operation, Override.class); + setOperationBody(operation, "" +/*{ + return new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>(); + }*/ + ); + + return; + } + List<ObjectModelClass> allEntities; + Map<String, ObjectModelClass> allEntitiesByFQN; + + allEntities = TopiaGeneratorUtil.getEntityClasses(model, true); + allEntitiesByFQN = new TreeMap<String, ObjectModelClass>(); + + // prepare usages map and fill allEntitiesByFQN map + for (ObjectModelClass klass : allEntities) { + allEntitiesByFQN.put(klass.getQualifiedName(), klass); + } + + ObjectModelOperation operation; + operation = addOperation(result, + "findUsages", + "<U extends TopiaEntity> List<U>", + ObjectModelJavaModifier.PUBLIC); + + addParameter(operation, "Class<U>", "type"); + addParameter(operation, "E", "entity"); + addAnnotation(result, operation, Override.class); + StringBuilder buffer = new StringBuilder(300); + buffer.append("" +/*{ + List<?> result = new LinkedList(); + List tmp; +}*/ + ); + + for (ObjectModelClass usageClass : usagesForclass) { + String usageType = usageClass.getQualifiedName(); + builder.addImport(result, usageType); + String usageSimpleType = + TopiaGeneratorUtil.getClassNameFromQualifiedName(usageType); + String usageSimplePropertyMethod = "findAllBy" + usageSimpleType; + String usageCollectionPropertyMethod = "findAllContaining" + usageSimpleType; + for (ObjectModelAttribute attr : usageClass.getAttributes()) { + if (!attr.isNavigable()) { + // skip this case + continue; + } + String type; + String attrName = attr.getName(); + if (attr.hasAssociationClass()) { + //FIXME-TC20100224 dont known how to do this ? + continue; +// type = attr.getAssociationClass().getQualifiedName(); +// //FIXME-TC20100224 : this is crazy ??? must find the good name +// // Perhaps need to make different cases? +// attrName = attrName + "_" + TopiaGeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName()); + } else { + type = attr.getType(); + } + if (!allEntitiesByFQN.containsKey(type)) { + // not a entity, can skip for this attribute + continue; + } + ObjectModelClass targetEntity = allEntitiesByFQN.get(type); +// if (!type.equals(clazz.getQualifiedName())) { + if (!targetEntity.equals(clazz)) { + // not a good attribute reference + continue; + } + // found something to seek + + String methodName; + if (TopiaGeneratorUtil.isNMultiplicity(attr)) { + methodName = getJavaBeanMethodName("findAllContains", attrName); + } else { + methodName = getJavaBeanMethodName("findAllBy", attrName); + } + String daoName = StringUtils.capitalize(usageSimpleType) + "DAO"; + + builder.addImport(result, usageClass.getPackageName() + '.' + daoName); + + buffer.append("" +/*{ + if (type == <%=usageSimpleType%>.class) { + <%=daoName%> dao = (<%=daoName%>) + topiaDaoSupplier.getDao(<%=usageSimpleType%>.class); + tmp = dao.<%=methodName%>(entity); + result.addAll(tmp); + } +}*/ + ); + } + } + + buffer.append("" +/*{ + return (List<U>) result; + }*/ + ); + setOperationBody(operation, buffer.toString()); + + operation = addOperation(result, + "findAllUsages", + "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>", + ObjectModelJavaModifier.PUBLIC); + + addParameter(operation, "E", "entity"); + addAnnotation(result, operation, Override.class); + + buffer = new StringBuilder(300); + buffer.append("" +/*{ + Map<Class<? extends TopiaEntity>,List<? extends TopiaEntity>> result; + result = new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>(<%=usagesForclass.size()%>); + + List<? extends TopiaEntity> list; +}*/ + ); + for (ObjectModelClass usageClass : usagesForclass) { + + String fqn = usageClass.getName(); + buffer.append("" +/*{ + list = findUsages(<%=fqn%>.class, entity); + if (!list.isEmpty()) { + result.put(<%=fqn%>.class, list); + } +}*/ + ); + + } + buffer.append("" +/*{ + return result; + }*/ + ); + + setOperationBody(operation, buffer.toString()); + } + + /** + * Generation of DAO operations signatures from class. These operations are + * abstract and identified by <<dao>> stereotype in the model. The + * developper must defined these methods in the DAOImpl associated to this + * DAOAbstract. + * + * @param result clazz where to add operations + * @param operations operations to generate + * @deprecated will be removed ASAP in topia 3.0 + */ + @Deprecated + protected void generateDAOOperations(ObjectModelClass result, + Collection<ObjectModelOperation> + operations) { + if (CollectionUtils.isEmpty(operations)) { + + // no extra operations to generate + return; + } + + for (ObjectModelOperation op : operations) { + + Set<String> exceptions = op.getExceptions(); + cloneOperation(op, + result, + true, + ObjectModelJavaModifier.ABSTRACT, + ObjectModelJavaModifier.fromVisibility(op.getVisibility()) + ); + } + } + + + protected void generateNoNMultiplicity(String clazzName, + ObjectModelClass result, + ObjectModelAttribute attr, + boolean isAssoc) { + String attrName = attr.getName(); + String attrType = attr.getType(); + String propertyName = clazzName + "." + getConstantName(attrName); + + String attrTypeForGeneric; + if (JavaGeneratorUtil.isPrimitiveType(attrType)) { + attrTypeForGeneric = TopiaGeneratorUtil.getClassForPrimitiveType(attr); + } else { + attrTypeForGeneric = attrType; + } + + if (!isAssoc && attr.hasAssociationClass()) { + String assocClassName = attr.getAssociationClass().getName(); + String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); + // It is about transitivity : use the property to access the + // associationClass + '.' + the property to access the expected + // attribute + // <class>.<attrAssoc> + '.' + <assocClass>.<attr> + propertyName = + clazzName + '.' + getConstantName(assocAttrName) + + " + '.' + " + + assocClassName + '.' + getConstantName(attrName); + } + + ObjectModelOperation op; + op = addOperation(result, + getJavaBeanMethodName("for", attrName, "In"), + "TopiaQueryBuilderRunQueryStep<E>", + ObjectModelJavaModifier.PUBLIC); + addParameter(op, "Iterable<" + attrTypeForGeneric + ">", "v"); + setOperationBody(op, "" +/*{ + TopiaQueryBuilderRunQueryStep<E> result = forIn(<%=propertyName%>, (Iterable) v); + return result; + }*/ + ); + + op = addOperation(result, + getJavaBeanMethodName("for", attrName, "Equals"), + "TopiaQueryBuilderRunQueryStep<E>", + ObjectModelJavaModifier.PUBLIC); + addParameter(op, attrType, "v"); + setOperationBody(op, "" +/*{ + TopiaQueryBuilderRunQueryStep<E> result = forEquals(<%=propertyName%>, v); + return result; + }*/ + ); + + String methodToDelegateName = op.getName(); + + op = addOperation(result, + getJavaBeanMethodName("findBy", attrName), + "E", + ObjectModelJavaModifier.PUBLIC); + addParameter(op, attrType, "v"); + setOperationBody(op, "" +/*{ + return <%=methodToDelegateName%>(v).findAnyOrNull(); + }*/ + ); + + addAnnotation(result, op, Deprecated.class); + + op = addOperation(result, + getJavaBeanMethodName("findAllBy", attrName), + "List<E>", + ObjectModelJavaModifier.PUBLIC); + addParameter(op, attrType, "v"); + setOperationBody(op, "" +/*{ + return <%=methodToDelegateName%>(v).findAll(); + }*/ + ); + + addAnnotation(result, op, Deprecated.class); + + if (!isAssoc && attr.hasAssociationClass()) { + String assocClassName = attr.getAssociationClass().getName(); + String assocClassFQN = attr.getAssociationClass().getQualifiedName(); + String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); + String assocPropertyConstantName = getConstantName(assocAttrName); + op = addOperation(result, + getJavaBeanMethodName("findBy", assocClassName), + "E", + ObjectModelJavaModifier.PUBLIC); + addParameter(op, assocClassFQN, "value"); + setOperationBody(op, "" +/*{ + E result = findByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value); + return result; + }*/ + ); + + op = addOperation(result, + getJavaBeanMethodName("findAllBy", assocClassName), + "List<E>", + ObjectModelJavaModifier.PUBLIC); + addParameter(op, assocClassFQN, "value"); + setOperationBody(op, "" +/*{ + List<E> result = findAllByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value); + return result; + }*/ + ); + } + } + + protected void generateNMultiplicity(String clazzName, + ObjectModelClass result, + ObjectModelAttribute attr) { + String attrName = attr.getName(); + String attrType = attr.getType(); + if (attr.hasAssociationClass()) { + // do nothing for association class, too complex... + return; + } + ObjectModelOperation op; + + op = addOperation(result, + getJavaBeanMethodName("for", attrName, "Contains"), + "TopiaQueryBuilderRunQueryStep<E>", + ObjectModelJavaModifier.PUBLIC); + addParameter(op, attrType, "v"); + setOperationBody(op, "" +/*{ + return forContains(<%=clazzName + "." + getConstantName(attrName)%>, v); + }*/ + ); + + String methodToDelegateName = op.getName(); + + op = addOperation(result, + getJavaBeanMethodName("findContains", attrName), + "E", + ObjectModelJavaModifier.PUBLIC); + addParameter(op, attrType, "v"); + setOperationBody(op, "" +/*{ + return <%=methodToDelegateName%>(v).findAnyOrNull(); + }*/ + ); + + addAnnotation(result, op, Deprecated.class); + + op = addOperation(result, + getJavaBeanMethodName("findAllContains", attrName), + "List<E>", + ObjectModelJavaModifier.PUBLIC); + addParameter(op, attrType, "v"); + setOperationBody(op, "" +/*{ + return <%=methodToDelegateName%>(v).findAll(); + }*/ + ); + + addAnnotation(result, op, Deprecated.class); + + } + + + /** + * Obtain business operations of the DAO. + * + * This operations can not be generated, but must be written by developper. + * + * @param clazz the clazz to test. + * @return collections of extra operations, or empty collection if none found. + */ + public Collection<ObjectModelOperation> getDAOOperations( + ObjectModelClass clazz) { + +// // Note : this collection will contains extra operations for DAO. +// // Overriding existing generated methods is not managed yet +// Collection<ObjectModelOperation> results = +// new ArrayList<ObjectModelOperation>(); + +// // This code will be deprecated +// for (ObjectModelOperation op : clazz.getOperations()) { +// if (TopiaGeneratorUtil.hasDaoStereotype(op)) { +// results.add(op); +// } +// } + + if (log.isWarnEnabled()) { + log.warn("dao contract in model will not be supported in topia 3.0"); + } + Collection<ObjectModelOperation> extra = + extraOperations.get(clazz.getQualifiedName()); + return extra; +// if (extra != null) { +// for (ObjectModelOperation op : extra) { +// results.add(op); +// } +// } + +// return results; + } + + private void generateNaturalId(ObjectModelClass result, + ObjectModelClass clazz) { + Set<ObjectModelAttribute> props = + TopiaGeneratorUtil.getNaturalIdAttributes(clazz); + + if (!props.isEmpty()) { + + if (log.isDebugEnabled()) { + log.debug("generateNaturalId for " + props); + } + ObjectModelOperation findByNaturalId = addOperation(result, + "findByNaturalId", "E", ObjectModelJavaModifier.PUBLIC); + + ObjectModelOperation existByNaturalId = addOperation(result, + "existByNaturalId", "boolean", ObjectModelJavaModifier.PUBLIC); + + ObjectModelOperation createByNaturalId = addOperation(result, + "createByNaturalId", "E", ObjectModelJavaModifier.PUBLIC); + + Set<String> properties = Sets.newLinkedHashSet(); + String clazzName = clazz.getName(); + + for (ObjectModelAttribute attr : props) { + + String propName = attr.getName(); + String type = attr.getType(); + + addParameter(findByNaturalId, type, propName); + addParameter(existByNaturalId, type, propName); + addParameter(createByNaturalId, type, propName); + + String property = clazzName + '.' + getConstantName(propName) + ", " + propName; + properties.add(property); + + } + + String arguments = StringUtils.join(properties, ", "); + + setOperationBody(findByNaturalId, "" +/*{ + return forProperties(<%=arguments%>).findUnique(); + }*/ + ); + + setOperationBody(existByNaturalId, "" +/*{ + return forProperties(<%=arguments%>).exists(); + }*/ + ); + + setOperationBody(createByNaturalId, "" +/*{ + return create(<%=arguments%>); + }*/ + ); + } + } + + protected void generateNotNull(ObjectModelClass result, + ObjectModelClass clazz) { + + Set<ObjectModelAttribute> props = + TopiaGeneratorUtil.getNotNullAttributes(clazz); + + if (!props.isEmpty()) { + + if (log.isDebugEnabled()) { + log.debug("generateNotNull for " + props); + } + + ObjectModelOperation createByNotNull = addOperation(result, + "createByNotNull", "E", ObjectModelJavaModifier.PUBLIC); + + String createProperties = ""; +// String params = ""; + String clazzName = clazz.getName(); + for (ObjectModelAttribute attr : props) { + String propName = attr.getName(); + // add property as param in both methods + addParameter(createByNotNull, attr.getType(), propName); + + createProperties += + ", " + clazzName + '.' + getConstantName(propName) + + ", " + propName; + //params += ", " + propName; + } + createProperties = createProperties.substring(2); + //params = params.substring(2); + + setOperationBody(createByNotNull, "" +/*{ + return create(<%=createProperties%>); + }*/ + ); + } + } +} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -39,7 +39,7 @@ import org.nuiton.eugene.models.object.ObjectModelModifier; import org.nuiton.eugene.models.object.ObjectModelOperation; import org.nuiton.eugene.models.object.ObjectModelParameter; -import org.nuiton.topia.TopiaDAOSupplier; +import org.nuiton.topia.TopiaDaoSupplier; import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.EntityVisitor; import org.nuiton.topia.persistence.TopiaEntity; @@ -338,24 +338,24 @@ if (TopiaGeneratorUtil.isContextable(input)) { - addImport(outputAbstract, TopiaDAOSupplier.class); + addImport(outputAbstract, TopiaDaoSupplier.class); // topiaContext attribute ObjectModelAttribute topiaContextAttribute = addAttribute( - outputAbstract, "topiaDAOSupplier", TopiaDAOSupplier.class, null, + outputAbstract, "topiaDaoSupplier", TopiaDaoSupplier.class, null, ObjectModelJavaModifier.PROTECTED, ObjectModelJavaModifier.TRANSIENT); setDocumentation(topiaContextAttribute, "TopiaDAO instance associated with the current \n" + "instance. For internal usage only"); ObjectModelOperation op = addOperation(outputAbstract, - "getTopiaDAOSupplier", TopiaDAOSupplier.class, + "getTopiaDAOSupplier", TopiaDaoSupplier.class, ObjectModelJavaModifier.PUBLIC); setDocumentation(op,"@since 3.0"); addAnnotation(outputAbstract, op, Override.class); setOperationBody(op, "" /*{ - return topiaDAOSupplier; + return topiaDaoSupplier; }*/ ); @@ -363,7 +363,7 @@ "setTopiaDAOSupplier", "void", ObjectModelJavaModifier.PUBLIC); addException(op, TopiaException.class); - addParameter(op, TopiaDAOSupplier.class, "topiaDAOSupplier"); + addParameter(op, TopiaDaoSupplier.class, "topiaDaoSupplier"); setDocumentation(op, // "@param context The context to set.\n" + // "@throws TopiaException if trying to replace a context\n" + @@ -371,8 +371,8 @@ addAnnotation(outputAbstract, op, Override.class); setOperationBody(op, "" /*{ - if (this.topiaDAOSupplier == null) { - this.topiaDAOSupplier = topiaDAOSupplier; + if (this.topiaDaoSupplier == null) { + this.topiaDaoSupplier = topiaDaoSupplier; // } else { // throw new TopiaException("TopiaContext replacement is forbidden"); } @@ -386,7 +386,7 @@ addAnnotation(outputAbstract, op, Override.class); setOperationBody(op, "" /*{ - getTopiaDAOSupplier().getDAO(<%=input.getName()%>.class).update(this); + getTopiaDAOSupplier().getDao(<%=input.getName()%>.class).update(this); }*/ ); @@ -396,7 +396,7 @@ addAnnotation(outputAbstract, op, Override.class); setOperationBody(op, "" /*{ - getTopiaDAOSupplier().getDAO(<%=input.getName()%>.class).delete(this); + getTopiaDAOSupplier().getDao(<%=input.getName()%>.class).delete(this); }*/ ); } @@ -1407,7 +1407,7 @@ body.append("" /*{ { - org.nuiton.topia.persistence.TopiaDAO<<%=assocClassFQN%>> dao = getTopiaContext().getDAO(<%=assocClassFQN%>.class); + org.nuiton.topia.persistence.TopiaDAO<<%=assocClassFQN%>> dao = getTopiaContext().getDao(<%=assocClassFQN%>.class); List<<%=assocClassFQN%>> findAllByProperties = dao.findAllByProperties("<%=reverseAttrName%>", this); if (findAllByProperties != null) { tmp.addAll(findAllByProperties); Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/LegacyEntityDAOTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/LegacyEntityDAOTransformer.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/LegacyEntityDAOTransformer.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -1,1204 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2011 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.topia.generator; - -/*{generator option: parentheses = false}*/ -/*{generator option: writeString = +}*/ - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.eugene.GeneratorUtil; -import org.nuiton.eugene.java.ObjectModelTransformerToJava; -import org.nuiton.eugene.models.object.ObjectModel; -import org.nuiton.eugene.models.object.ObjectModelAssociationClass; -import org.nuiton.eugene.models.object.ObjectModelAttribute; -import org.nuiton.eugene.models.object.ObjectModelClass; -import org.nuiton.eugene.models.object.ObjectModelClassifier; -import org.nuiton.eugene.models.object.ObjectModelDependency; -import org.nuiton.eugene.models.object.ObjectModelInterface; -import org.nuiton.eugene.models.object.ObjectModelJavaModifier; -import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.util.StringUtil; - -import java.security.Permission; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * To generate all <code>DAO</code> related classes for a given entity. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.5.4 - * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityDAOTransformer" - */ -public class LegacyEntityDAOTransformer extends ObjectModelTransformerToJava { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(EntityDAOTransformer.class); - - /** - * map of direct usages (values) for each entity (key). - * <p/> - * This map is used to generate the findUsages methods for DAOAbstract. - */ - protected Map<ObjectModelClass, Set<ObjectModelClass>> usages; - - /** - * All entities fqn of the model (used to detect if an attribute is not - * an entity). - */ - protected Set<String> allEntitiesFqn; - - /** - * The class of abstract dao to use. - * @since 2.5 - */ - protected Class<?> daoImplementation; - - protected String entityEnumName; - - protected String entityEnumPackage; - - /** - * Map of extra operations for DAO. The key of the map is the qualified - * name of the entity relative to the DAO. - */ - protected Map<String, Collection<ObjectModelOperation>> extraOperations = - new HashMap<String, Collection<ObjectModelOperation>>(); - - @Override - public void transformFromModel(ObjectModel model) { - - boolean generateStandaloneEnum = - TopiaGeneratorUtil.shouldGenerateStandaloneEnumForDAOHelper(model); - String modelName = model.getName(); - - entityEnumName = modelName + "EntityEnum"; - - String packageName = - getOutputProperties().getProperty(PROP_DEFAULT_PACKAGE); - - if (generateStandaloneEnum) { - entityEnumPackage = packageName + "." + entityEnumName; - } else { - String daoHelperClazzName = modelName + "DAOHelper"; - entityEnumPackage = packageName + "." + daoHelperClazzName + "." + entityEnumName; - } - - usages = TopiaGeneratorUtil.searchDirectUsages(model); - - daoImplementation = TopiaGeneratorUtil.getDAOImplementation(model); - - - // keep all classifiers on the model which are entities - List<ObjectModelClass> allEntities = - TopiaGeneratorUtil.getEntityClasses(model, true); - allEntitiesFqn = new HashSet<String>(allEntities.size()); - for (ObjectModelClass entity : allEntities) { - String fqn = entity.getQualifiedName(); - allEntitiesFqn.add(fqn); - Collection<ObjectModelOperation> daoOperations = - new HashSet<ObjectModelOperation>(); - for (ObjectModelOperation op : entity.getOperations()) { - if (TopiaGeneratorUtil.hasDaoStereotype(op)) { - daoOperations.add(op); - } - } - - if (daoOperations.isEmpty()) { - - // found some dao operations - extraOperations.put(fqn, daoOperations); - } - } - } - - @Override - public void transformFromInterface(ObjectModelInterface interfacez) { - if (!TopiaGeneratorUtil.hasDaoStereotype(interfacez)) { - return; - } - - /** - * EVO #636 : Manage extra operations for DAO from "dao" dependency - * between an interface with stereotype <<dao>> (dependency client) and - * a class with stereotype <<entity>> (dependency supplier). - */ - - ObjectModelDependency dependency = - interfacez.getDependency(TopiaGeneratorUtil.DEPENDENCIES_DAO); - - if (dependency == null) { - if (log.isWarnEnabled()) { - log.warn("Could not find dependency " + - TopiaGeneratorUtil.DEPENDENCIES_DAO + - " but DAO stereotype was placed on the interface " + - interfacez.getName()); - } - return; - } - - ObjectModelClassifier classifier = dependency.getSupplier(); - - if (!TopiaGeneratorUtil.isEntity(classifier)) { - - // dependency supplier is not an entity... - if (log.isWarnEnabled()) { - log.warn("Dependency supplier " + - classifier.getQualifiedName() + - " is not an entity."); - } - return; - } - - // keep only direct operations - Collection<ObjectModelOperation> operations = - interfacez.getOperations(); - - if (CollectionUtils.isEmpty(operations)) { - - // no operations on interface, this is not normal - if (log.isWarnEnabled()) { - log.warn("No operation found on interface with DAO " + - "stereotype "+classifier.getQualifiedName()); - } - return; - } - if (log.isDebugEnabled()) { - log.debug("add "+operations.size()+" extra operation(s) for DAO"); - } - - extraOperations.put(classifier.getQualifiedName(), operations); - } - - @Override - public void transformFromClass(ObjectModelClass clazz) { - if (!TopiaGeneratorUtil.isEntity(clazz)) { - // not an entity - return; - } - String clazzName = clazz.getName(); - String clazzFQN = clazz.getQualifiedName(); - - if (isGenerateDAO(clazz)) { - - // generate DAO - generateDAOClass(clazz, clazzName, clazzFQN); - - } - if (isGenerateImpl(clazz)) { - - // generate DAOImpl - generateDAOImpl(clazz, clazzName, clazzFQN); - } - - if (isGenerateDAOAbstract(clazz)) { - - // generate DAOAbstract - generateDAOAbstract(clazz, clazzName, clazzFQN); - } - } - - protected boolean isGenerateDAO(ObjectModelClass input) { - - String fqn = input.getQualifiedName() + "DAO"; - - if (isInClassPath(fqn)) { - - // already in class-path - return false; - } - - // can safely generate the dao impl - return true; - } - - protected boolean isGenerateDAOAbstract(ObjectModelClass input) { - - String fqn = input.getQualifiedName() + "DAOAbstract"; - - if (isInClassPath(fqn)) { - - // already in class-path - return false; - } - - // can safely generate the dao impl - return true; - } - - protected boolean isGenerateImpl(ObjectModelClass input) { - - String fqn = input.getQualifiedName() + "DAOImpl"; - - if (isInClassPath(fqn)) { - - // already in class-path - return false; - } - - Collection<ObjectModelOperation> moreOperations = - extraOperations.get(input.getQualifiedName()); - - if (CollectionUtils.isNotEmpty(moreOperations)) { - - // no user operations, can 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()); - 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 + ">"); - } - - protected void generateDAOImpl(ObjectModelClass clazz, - String clazzName, - String clazzFQN) { - - Collection<ObjectModelOperation> moreOperations = - extraOperations.get(clazz.getQualifiedName()); - - if (CollectionUtils.isEmpty(moreOperations)) { - - // no business dao found, can safely generate the daoImpl class - - ObjectModelClass daoImplClass = createClass(clazzName + "DAOImpl<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>"); - } - } - - protected void generateDAOAbstract(ObjectModelClass clazz, - String clazzName, - String clazzFQN) { - ObjectModelClass daoAbstractClass = createAbstractClass( - clazzName + "DAOAbstract<E extends " + clazzName + '>', - clazz.getPackageName()); - - // super class - - String extendClass = ""; - for (ObjectModelClass parent : clazz.getSuperclasses()) { - extendClass = parent.getQualifiedName(); - if (TopiaGeneratorUtil.isEntity(parent)) { - extendClass += "DAOImpl<E>"; - // in java no multi-inheritance - break; - } - } - if (extendClass.length() == 0) { - extendClass = daoImplementation.getName() + "<E>"; - } - if (log.isDebugEnabled()) { - log.debug("super class = " + extendClass); - } - setSuperClass(daoAbstractClass, extendClass); - - String prefix = getConstantPrefix(clazz, ""); - setConstantPrefix(prefix); - - // imports - - Collection<ObjectModelOperation> DAOoperations = - getDAOOperations(clazz); - - if (TopiaGeneratorUtil.isCollectionNeeded(DAOoperations)) { - addImport(daoAbstractClass, Collection.class); - } - if (TopiaGeneratorUtil.isSetNeeded(DAOoperations)) { - addImport(daoAbstractClass, Set.class); - } - addImport(daoAbstractClass, List.class); - addImport(daoAbstractClass, TopiaException.class); - - boolean enableSecurity = TopiaGeneratorUtil.isClassWithSecurity(clazz); - - if (enableSecurity) { - addImport(daoAbstractClass, ArrayList.class); - addImport(daoAbstractClass, Permission.class); - addImport(daoAbstractClass, "org.nuiton.topia.taas.entities.TaasAuthorizationImpl"); - addImport(daoAbstractClass, "org.nuiton.topia.taas.jaas.TaasPermission"); - addImport(daoAbstractClass, "org.nuiton.topia.taas.TaasUtil"); - addImport(daoAbstractClass, TopiaDAO.class); - - //FIXME : how to do static imports ? -//import static org.nuiton.topia.taas.TaasUtil.CREATE; -//import static org.nuiton.topia.taas.TaasUtil.DELETE; -//import static org.nuiton.topia.taas.TaasUtil.LOAD; -//import static org.nuiton.topia.taas.TaasUtil.UPDATE; - } - - ObjectModelOperation op; - - // getEntityClass - - op = addOperation(daoAbstractClass, - "getEntityClass", - "Class<E>", - ObjectModelJavaModifier.PUBLIC); - addAnnotation(daoAbstractClass, op,Override.class); - setOperationBody(op, "" -/*{ - return (Class<E>)<%=clazzName%>.class; - }*/ - ); - - // getTopiaEntityEnum - addImport(daoAbstractClass, entityEnumPackage); - op = addOperation(daoAbstractClass, - "getTopiaEntityEnum", - entityEnumName, - ObjectModelJavaModifier.PUBLIC); - addAnnotation(daoAbstractClass, op,Override.class); - setOperationBody(op, "" -/*{ - return <%=entityEnumName%>.<%=clazzName%>; - }*/ - ); - - generateDAOOperations(daoAbstractClass, DAOoperations); - - generateDelete(clazz, daoAbstractClass); - - generateNaturalId(daoAbstractClass, clazz); - - generateNotNull(daoAbstractClass, clazz); - - for (ObjectModelAttribute attr : clazz.getAttributes()) { - if (!attr.isNavigable()) { - continue; - } - - if (!GeneratorUtil.isNMultiplicity(attr)) { - generateNoNMultiplicity(clazzName, daoAbstractClass, attr, false); - } else { - generateNMultiplicity(clazzName, daoAbstractClass, attr); - } - } - - if (clazz instanceof ObjectModelAssociationClass) { - ObjectModelAssociationClass assocClass = - (ObjectModelAssociationClass) clazz; - for (ObjectModelAttribute attr : assocClass.getParticipantsAttributes()) { - if (attr != null) { - if (!GeneratorUtil.isNMultiplicity(attr)) { - generateNoNMultiplicity(clazzName, daoAbstractClass, attr, true); - } else { - generateNMultiplicity(clazzName, daoAbstractClass, attr); - } - } - } - } - - if (enableSecurity) { - - // getRequestPermission - - op = addOperation(daoAbstractClass, - "getRequestPermission", - "List<Permission>", - ObjectModelJavaModifier.PUBLIC); -// setDocumentation(op, "Retourne les permissions a verifier pour " + -// "l'acces a l'entite pour le service Taas"); - addException(op, TopiaException.class); - addParameter(op, String.class, "topiaId"); - addParameter(op, int.class, "actions"); - StringBuilder buffer = new StringBuilder(); - buffer.append("" -/*{ - List<Permission> resultPermissions = new ArrayList<Permission>(); - if ((actions & TaasUtil.CREATE) == TaasUtil.CREATE) { -}*/ - ); - buffer.append(generateSecurity(daoAbstractClass, clazz, - TopiaGeneratorUtil.getSecurityCreateTagValue(clazz))); - buffer.append("" -/*{ - } - if ((actions & TaasUtil.LOAD) == TaasUtil.LOAD) { -}*/ - ); - buffer.append(generateSecurity(daoAbstractClass, clazz, - TopiaGeneratorUtil.getSecurityLoadTagValue(clazz))); - buffer.append("" -/*{ - } - if ((actions & TaasUtil.UPDATE) == TaasUtil.UPDATE) { -}*/ - ); - buffer.append(generateSecurity(daoAbstractClass, clazz, - TopiaGeneratorUtil.getSecurityUpdateTagValue(clazz))); - buffer.append("" -/*{ - } - if ((actions & TaasUtil.DELETE) == TaasUtil.DELETE) { -}*/ - ); - buffer.append(generateSecurity(daoAbstractClass, clazz, - TopiaGeneratorUtil.getSecurityDeleteTagValue(clazz))); - buffer.append("" -/*{ - } - return resultPermissions; - }*/ - ); - - setOperationBody(op, buffer.toString()); - - // THIMEL : Le code suivant doit pouvoir être déplacé dans DAODelegator ? - - // getRequestPermission - - - op = addOperation(daoAbstractClass, - "getRequestPermission", - "List<Permission>", - ObjectModelJavaModifier.PROTECTED); - addParameter(op, String.class, "topiaId"); - addParameter(op, int.class, "actions"); - addParameter(op, String.class, "query"); - addParameter(op, Class.class, "daoClass"); - addException(op, TopiaException.class); -// setDocumentation(op, "Retourne les permissions a verifier pour " + -// "l'acces a l'entite pour le service Taas"); - setOperationBody(op, "" -/*{ TopiaContext context = getTopiaContext(); - List<String> result = context.findAll(query, "id", topiaId); - - List<Permission> resultPermissions = new ArrayList<Permission>(); - for (String topiaIdPermission : result) { - TopiaDAO dao = context.getDAO(daoClass); - List<Permission> permissions = dao.getRequestPermission(topiaIdPermission, actions); - if(permissions != null) { - resultPermissions.addAll(permissions); - } else { - TaasPermission permission = new TaasPermission(topiaIdPermission, actions); - resultPermissions.add(permission); - } - } - return resultPermissions; - }*/ - ); - } - - Set<ObjectModelClass> usagesForclass = usages.get(clazz); - generateFindUsages(clazz, daoAbstractClass, usagesForclass); - } - - protected void generateDelete(ObjectModelClass clazz, - ObjectModelClass result) { - - StringBuilder body = new StringBuilder(); - String modelName = StringUtils.capitalize(model.getName()); - String providerFQN = getOutputProperties().getProperty( - PROP_DEFAULT_PACKAGE) + '.' + modelName + - "DAOHelper.getImplementationClass"; - - for (ObjectModelAttribute attr : clazz.getAttributes()) { - - String attrType = GeneratorUtil.getSimpleName(attr.getType()); - - String reverseAttrName = attr.getReverseAttributeName(); - ObjectModelAttribute reverse = attr.getReverseAttribute(); - if (attr.hasAssociationClass() || - reverse == null || !reverse.isNavigable()) { - - // never treate a non reverse and navigable attribute - // never treate an association class attribute - continue; - } - - // at this point we are sure to have a attribute which is - // - reverse - // - navigable - // - not from an association class - if (!allEntitiesFqn.contains(attr.getType())) { - - // this attribute is not from an entity, don't treate it - if (log.isDebugEnabled()) { - log.debug("[" + result.getName() + "] Skip attribute [" + - attr.getName() + "] with type " + attr.getType()); - } - continue; - } - - // At this point, the attribute type is a entity - if (GeneratorUtil.isNMultiplicity(attr) && - GeneratorUtil.isNMultiplicity(reverse)) { - // On doit absolument supprimer pour les relations many-to-many - // le this de la collection de l'autre cote - - String attrDBName = TopiaGeneratorUtil.getDbName(attr); - String attrClassifierDBName = TopiaGeneratorUtil.getDbName(attr.getClassifier()); - String attrJoinTableName = TopiaGeneratorUtil.getManyToManyTableName(attr); - String attrReverseDBName = TopiaGeneratorUtil.getReverseDbName(attr); - - //FIXME_-FC-20100413 Use a TopiaQuery (use HQLin elements) -// // Add DAOHelper -// String daoHelper = modelName + "DAOHelper"; -// String daoHelperFQN = getOutputProperties(). -// getProperty(PROP_DEFAULT_PACKAGE) + '.' + daoHelper; -// addImport(result, daoHelperFQN); -// -// // Add import for TopiaQuery -// addImport(result, TopiaQuery.class); -// -// // Entity DAO and reversePropertyName -// String entityDAO = attrType + "DAO"; -// String reverseAttrNameProperty = -// attrType + "." + getConstantName(reverseAttrName); -// -// -// <%=entityDAO%> dao = <%=daoHelper%>.get<%=entityDAO%>(getTopiaContext()); -// TopiaQuery query = dao.createQuery("B"). -// addFrom(entity.getClass(), "A"). -// add("A", entity). -// addInElements("A", "B." + <%=reverseAttrNameProperty%>); -// -// System.out.println("Query : " + query); -// List<<%=attrType%>> list = dao.findAllByQuery(query); - - String removeName = getJavaBeanMethodName("remove", reverseAttrName); - body.append("" -/*{ - { - List<<%=attrType%>> list = getTopiaContext().getHibernateSession().createSQLQuery( - "SELECT main.topiaid " + - "from <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " + - "where main.topiaid=secondary.<%=attrDBName%>" + - " and secondary.<%=attrReverseDBName%>='" + entity.getTopiaId() + "'") - .addEntity("main", <%=providerFQN%>(<%=attrType%>.class)).list(); - - for (<%=attrType%> item : list) { - item.<%=removeName%>(entity); - } - } -}*/ - ); - } else if (!GeneratorUtil.isNMultiplicity(reverse)) { - // On doit mettre a null les attributs qui ont cet objet sur les - // autres entites en one-to-* - // TODO peut-etre qu'hibernate est capable de faire ca tout seul ? - // THIMEL: J'ai remplacé reverse.getName() par reverseAttrName sans certitude - addImport(result, attrType); - String attrSimpleType = TopiaGeneratorUtil.getClassNameFromQualifiedName(attrType); - String getName = getJavaBeanMethodName("get", reverseAttrName); - String setName = getJavaBeanMethodName("set", reverseAttrName); - - body.append("" - /*{ - { - List<<%=attrSimpleType%>> list = topiaDAOSupplier - .getDAO(<%=attrSimpleType%>.class) - .findAllByProperties(<%=attrSimpleType%>.<%=getConstantName(reverseAttrName)%>, entity); - for (<%=attrSimpleType%> item : list) { - - // sletellier : Set null only if target is concerned by deletion - if (entity.equals(item.<%=getName%>())) { - item.<%=setName%>(null); - } - }*/ - ); - if (attr.isAggregate()) { - body.append("" -/*{ - topiaDAOSupplier.getDAO(<%=attrSimpleType%>.class).delete(item); -}*/ - ); - } - body.append("" -/*{ - } - } -}*/ - ); - - } - } - - if (body.length()>0) { - // something specific was done, need to generate the method - ObjectModelOperation op; - op = addOperation(result, "delete", "void", ObjectModelJavaModifier.PUBLIC); - addAnnotation(result, op,Override.class); - addParameter(op, "E", "entity"); - body.append("" -/*{ - super.delete(entity); - }*/ - ); - setOperationBody(op, body.toString()); - } - - - - } - - protected void generateFindUsages(ObjectModelClass clazz, - ObjectModelClass result, - Set<ObjectModelClass> usagesForclass) { - - builder.addImport(result, ArrayList.class.getName()); - builder.addImport(result, Map.class.getName()); - builder.addImport(result, HashMap.class.getName()); - builder.addImport(result, TopiaEntity.class.getName()); - - if (clazz instanceof ObjectModelAssociationClass || - usagesForclass.isEmpty()) { - // not for an association class - // just let a null method - ObjectModelOperation operation; - operation = addOperation(result, - "findUsages", - "<U extends TopiaEntity> List<U>", - ObjectModelJavaModifier.PUBLIC); - - addParameter(operation, "Class<U>", "type"); - addParameter(operation, "E", "entity"); - addAnnotation(result, operation, Override.class); - setOperationBody(operation, "" -/*{ - return new ArrayList<U>(); - }*/ - ); - - operation = addOperation(result, - "findAllUsages", - "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>", - ObjectModelJavaModifier.PUBLIC); - - addParameter(operation, "E", "entity"); - addAnnotation(result, operation, Override.class); - setOperationBody(operation, "" -/*{ - return new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>(); - }*/ - ); - - return; - } - List<ObjectModelClass> allEntities; - Map<String, ObjectModelClass> allEntitiesByFQN; - - allEntities = TopiaGeneratorUtil.getEntityClasses(model, true); - allEntitiesByFQN = new TreeMap<String, ObjectModelClass>(); - - // prepare usages map and fill allEntitiesByFQN map - for (ObjectModelClass klass : allEntities) { - allEntitiesByFQN.put(klass.getQualifiedName(), klass); - } - - ObjectModelOperation operation; - operation = addOperation(result, - "findUsages", - "<U extends TopiaEntity> List<U>", - ObjectModelJavaModifier.PUBLIC); - - addParameter(operation, "Class<U>", "type"); - addParameter(operation, "E", "entity"); - addAnnotation(result, operation, Override.class); - StringBuilder buffer = new StringBuilder(300); - buffer.append("" -/*{ - List<?> result = new ArrayList(); - List tmp; -}*/ - ); - - for (ObjectModelClass usageClass : usagesForclass) { - String usageType = usageClass.getQualifiedName(); - builder.addImport(result, usageType); - String usageSimpleType = - TopiaGeneratorUtil.getClassNameFromQualifiedName(usageType); - String usageSimplePropertyMethod = "findAllBy" + usageSimpleType; - String usageCollectionPropertyMethod = "findAllContaining" + usageSimpleType; - for (ObjectModelAttribute attr : usageClass.getAttributes()) { - if (!attr.isNavigable()) { - // skip this case - continue; - } - String type; - String attrName = attr.getName(); - if (attr.hasAssociationClass()) { - //FIXME-TC20100224 dont known how to do this ? - continue; -// type = attr.getAssociationClass().getQualifiedName(); -// //FIXME-TC20100224 : this is crazy ??? must find the good name -// // Perhaps need to make different cases? -// attrName = attrName + "_" + TopiaGeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName()); - } else { - type = attr.getType(); - } - if (!allEntitiesByFQN.containsKey(type)) { - // not a entity, can skip for this attribute - continue; - } - ObjectModelClass targetEntity = allEntitiesByFQN.get(type); -// if (!type.equals(clazz.getQualifiedName())) { - if (!targetEntity.equals(clazz)) { - // not a good attribute reference - continue; - } - // found something to seek - - String methodName; - if (TopiaGeneratorUtil.isNMultiplicity(attr)) { - methodName = getJavaBeanMethodName("findAllContains", attrName); - } else { - methodName = getJavaBeanMethodName("findAllBy", attrName); - } - String daoName = StringUtils.capitalize(usageSimpleType) + "DAO"; - - builder.addImport(result, usageClass.getPackageName() + '.' + daoName); - - buffer.append("" -/*{ - if (type == <%=usageSimpleType%>.class) { - <%=daoName%> dao = (<%=daoName%>) - topiaDAOSupplier.getDAO(<%=usageSimpleType%>.class); - tmp = dao.<%=methodName%>(entity); - result.addAll(tmp); - } -}*/ - ); - } - } - - buffer.append("" -/*{ - return (List<U>) result; - }*/ - ); - setOperationBody(operation, buffer.toString()); - - operation = addOperation(result, - "findAllUsages", - "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>", - ObjectModelJavaModifier.PUBLIC); - - addParameter(operation, "E", "entity"); - addAnnotation(result, operation, Override.class); - - buffer = new StringBuilder(300); - buffer.append("" -/*{ - Map<Class<? extends TopiaEntity>,List<? extends TopiaEntity>> result; - result = new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>(<%=usagesForclass.size()%>); - - List<? extends TopiaEntity> list; -}*/ - ); - for (ObjectModelClass usageClass : usagesForclass) { - - String fqn = usageClass.getName(); - buffer.append("" -/*{ - list = findUsages(<%=fqn%>.class, entity); - if (!list.isEmpty()) { - result.put(<%=fqn%>.class, list); - } -}*/ - ); - - } - buffer.append("" -/*{ - return result; - }*/ - ); - - setOperationBody(operation, buffer.toString()); - } - - /** - * Generation of DAO operations signatures from class. These operations are - * abstract and identified by <<dao>> stereotype in the model. The - * developper must defined these methods in the DAOImpl associated to this - * DAOAbstract. - * - * @param result clazz where to add operations - * @param operations operations to generate - */ - private void generateDAOOperations(ObjectModelClass result, - Collection<ObjectModelOperation> - operations) { - if (CollectionUtils.isEmpty(operations)) { - - // no extra operations to generate - return; - } - - for (ObjectModelOperation op : operations) { - - Set<String> exceptions = op.getExceptions(); - cloneOperation(op, - result, - true, - ObjectModelJavaModifier.ABSTRACT, - ObjectModelJavaModifier.fromVisibility(op.getVisibility()) - ); - } - } - - - - - private String generateSecurity(ObjectModelClass result, - ObjectModelClass clazz, - String tagValue) { - StringBuilder buffer = new StringBuilder(); - - if (StringUtils.isNotEmpty(tagValue)) { - String security = tagValue; - Pattern propertiesPattern = Pattern - .compile("((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)attribute\\.(?:([_a-z0-9][_a-zA-Z0-9]*))#(?:(create|load|update|delete))"); - String[] valuesSecurity = security.split(":"); - - for (String valueSecurity : valuesSecurity) { - Matcher matcher = propertiesPattern.matcher(valueSecurity); - matcher.find(); - // className is fully qualified name of class - String className = matcher.group(1); - className = StringUtil.substring(className, 0, -1); // remove ended - // . - // target is class, attribute or operation - String attributeName = matcher.group(2); - String actions = matcher.group(3).toUpperCase(); - - String query = ""; - String daoClass = ""; - if (className.equals(clazz.getQualifiedName())) { - query = "select " + attributeName + ".topiaId from " + clazz.getQualifiedName() + " where topiaId = :id"; - daoClass = clazz.getAttribute(attributeName).getClassifier().getQualifiedName(); - } else { - query = "select at.topiaId from " + className + " at inner join at." + attributeName + " cl where cl.topiaId = :id"; - daoClass = className; - } - buffer.append("" -/*{ - resultPermissions.addAll(getRequestPermission(topiaId, - <%=actions%>, - "<%=query%>", - <%=daoClass%>.class)); -}*/ - ); - } - } else { - buffer.append("" -/*{ return null; - }*/ - ); - } - return buffer.toString(); - } - - protected void generateNoNMultiplicity(String clazzName, - ObjectModelClass result, - ObjectModelAttribute attr, - boolean isAssoc) { - String attrName = attr.getName(); - String attrType = attr.getType(); - String propertyName = clazzName + "." + getConstantName(attrName); - if (!isAssoc && attr.hasAssociationClass()) { - String assocClassName = attr.getAssociationClass().getName(); - String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); - // It is about transitivity : use the property to access the - // associationClass + '.' + the property to access the expected - // attribute - // <class>.<attrAssoc> + '.' + <assocClass>.<attr> - propertyName = - clazzName + '.' + getConstantName(assocAttrName) + - " + '.' + " + - assocClassName + '.' + getConstantName(attrName); - } - - ObjectModelOperation op; - op = addOperation(result, - getJavaBeanMethodName("findBy", attrName), - "E", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrType, "v"); - setOperationBody(op, "" -/*{ - E result = findByProperty(<%=propertyName%>, v); - return result; - }*/ - ); - - op = addOperation(result, - getJavaBeanMethodName("findAllBy", attrName), - "List<E>", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrType, "v"); - setOperationBody(op, "" -/*{ - List<E> result = findAllByProperty(<%=propertyName%>, v); - return result; - }*/ - ); - - if (!isAssoc && attr.hasAssociationClass()) { - String assocClassName = attr.getAssociationClass().getName(); - String assocClassFQN = attr.getAssociationClass().getQualifiedName(); - String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); - String assocPropertyConstantName = getConstantName(assocAttrName); - op = addOperation(result, - getJavaBeanMethodName("findBy", assocClassName), - "E", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, assocClassFQN, "value"); - setOperationBody(op, "" -/*{ - E result = findByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value); - return result; - }*/ - ); - - op = addOperation(result, - getJavaBeanMethodName("findAllBy", assocClassName), - "List<E>", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, assocClassFQN, "value"); - setOperationBody(op, "" -/*{ - List<E> result = findAllByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value); - return result; - }*/ - ); - } - } - - protected void generateNMultiplicity(String clazzName, - ObjectModelClass result, - ObjectModelAttribute attr) { - String attrName = attr.getName(); - String attrType = attr.getType(); - if (attr.hasAssociationClass()) { - // do nothing for association class, too complex... - return; - } - ObjectModelOperation op; - // Since 2.4 do nothing, findContains and findAllContains are not generated anymore - op = addOperation(result, - getJavaBeanMethodName("findContains", attrName), - "E", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrType, "v"); - setOperationBody(op, "" -/*{ - E result = findContains(<%=clazzName + "." + getConstantName(attrName)%>, v); - return result; - }*/ - ); - - op = addOperation(result, - getJavaBeanMethodName("findAllContains", attrName), - "List<E>", - ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrType, "v"); - setOperationBody(op, "" -/*{ - List<E> result = findAllContains(<%=clazzName + "." + getConstantName(attrName)%>, v); - return result; - }*/ - ); - } - - - /** - * Obtain business operations of the DAO. - * - * This operations can not be generated, but must be written by developper. - * - * @param clazz the clazz to test. - * @return collections of extra operations, or empty collection if none found. - */ - public Collection<ObjectModelOperation> getDAOOperations( - ObjectModelClass clazz) { - -// // Note : this collection will contains extra operations for DAO. -// // Overriding existing generated methods is not managed yet -// Collection<ObjectModelOperation> results = -// new ArrayList<ObjectModelOperation>(); - -// // This code will be deprecated -// for (ObjectModelOperation op : clazz.getOperations()) { -// if (TopiaGeneratorUtil.hasDaoStereotype(op)) { -// results.add(op); -// } -// } - Collection<ObjectModelOperation> extra = - extraOperations.get(clazz.getQualifiedName()); - return extra; -// if (extra != null) { -// for (ObjectModelOperation op : extra) { -// results.add(op); -// } -// } - -// return results; - } - - private void generateNaturalId(ObjectModelClass result, - ObjectModelClass clazz) { - Set<ObjectModelAttribute> props = - TopiaGeneratorUtil.getNaturalIdAttributes(clazz); - - if (!props.isEmpty()) { - - if (log.isDebugEnabled()) { - log.debug("generateNaturalId for " + props); - } - ObjectModelOperation findByNaturalId = addOperation(result, - "findByNaturalId", "E", ObjectModelJavaModifier.PUBLIC); - - ObjectModelOperation existByNaturalId = addOperation(result, - "existByNaturalId", "boolean", ObjectModelJavaModifier.PUBLIC); - - // TODO sletellier 20120406 : remove method on 3.0 - ObjectModelOperation create = addOperation(result, - "create", "E", ObjectModelJavaModifier.PUBLIC); - - // sletellier : mark as Deprecated (http://nuiton.org/issues/2051) - setDocumentation(create, "@deprecated since 2.6.10, prefer use {@link #createByNaturalId}\n"); - addAnnotation(result, create, "Deprecated"); - - ObjectModelOperation createByNaturalId = addOperation(result, - "createByNaturalId", "E", ObjectModelJavaModifier.PUBLIC); - - // used for calling findByProperties in findByNaturalId - String searchProperties = ""; - // used for calling findByNaturalId in existByNaturalId -// String params = ""; - String clazzName = clazz.getName(); - for (ObjectModelAttribute attr : props) { - String propName = attr.getName(); - // add property as param in both methods - addParameter(findByNaturalId, attr.getType(), propName); - addParameter(existByNaturalId, attr.getType(), propName); - addParameter(create, attr.getType(), propName); - addParameter(createByNaturalId, attr.getType(), propName); - - searchProperties += - ", " + clazzName + '.' + getConstantName(propName) + - ", " + propName; - //params += ", " + propName; - } - searchProperties = searchProperties.substring(2); - //params = params.substring(2); - - setOperationBody(findByNaturalId, "" -/*{ - return findByProperties(<%=searchProperties%>); - }*/ - ); - - setOperationBody(existByNaturalId, "" -/*{ - return existByProperties(<%=searchProperties%>); - }*/ - ); - - setOperationBody(create, "" -/*{ - return create(<%=searchProperties%>); - }*/ - ); - - setOperationBody(createByNaturalId, "" -/*{ - return create(<%=searchProperties%>); - }*/ - ); - } - } - - private void generateNotNull(ObjectModelClass result, - ObjectModelClass clazz) { - - Set<ObjectModelAttribute> props = - TopiaGeneratorUtil.getNotNullAttributes(clazz); - - if (!props.isEmpty()) { - - if (log.isDebugEnabled()) { - log.debug("generateNotNull for " + props); - } - - ObjectModelOperation createByNotNull = addOperation(result, - "createByNotNull", "E", ObjectModelJavaModifier.PUBLIC); - - String createProperties = ""; -// String params = ""; - String clazzName = clazz.getName(); - for (ObjectModelAttribute attr : props) { - String propName = attr.getName(); - // add property as param in both methods - addParameter(createByNotNull, attr.getType(), propName); - - createProperties += - ", " + clazzName + '.' + getConstantName(propName) + - ", " + propName; - //params += ", " + propName; - } - createProperties = createProperties.substring(2); - //params = params.substring(2); - - setOperationBody(createByNotNull, "" -/*{ - return create(<%=createProperties%>); - }*/ - ); - } - } -} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -186,7 +186,7 @@ addImport(output, clazz); setOperationBody(op, "" /*{ - <%=daoClazzName%> result = getDAO(<%=clazzName%>.class, <%=daoClazzName%>.class); + <%=daoClazzName%> result = getDao(<%=clazzName%>.class, <%=daoClazzName%>.class); return result; }*/ ); Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -64,7 +64,7 @@ ApplicationContextTransformer.class, PersistenceContextTransformer.class, EntityTransformer.class, - EntityDAOTransformer.class, + EntityDaoTransformer.class, // DAOTransformer.class, // DAOImplTransformer.class, // DAOAbstractTransformer.class, Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -48,7 +48,7 @@ import org.hibernate.HibernateException; import org.hibernate.metadata.ClassMetadata; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaDAOSupplier; +import org.nuiton.topia.TopiaDaoSupplier; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaHibernateSupport; import org.nuiton.topia.TopiaJpaSupport; @@ -109,7 +109,7 @@ protected TopiaFiresSupport topiaFiresSupport; - protected TopiaDAOSupplier topiaDAOSupplier; + protected TopiaDaoSupplier topiaDaoSupplier; public abstract TopiaEntityEnum getTopiaEntityEnum(); @@ -180,7 +180,7 @@ TopiaListenableSupport topiaListenableSupport, TopiaIdFactory topiaIdFactory, TopiaFiresSupport topiaFiresSupport, - TopiaDAOSupplier topiaDAOSupplier) { + TopiaDaoSupplier topiaDaoSupplier) { log.debug("init dao for " + getEntityClass()); this.topiaHibernateSupport = topiaHibernateSupport; this.topiaJpaSupport = topiaJpaSupport; @@ -188,7 +188,7 @@ this.topiaListenableSupport = topiaListenableSupport; this.topiaIdFactory = topiaIdFactory; this.topiaFiresSupport = topiaFiresSupport; - this.topiaDAOSupplier = topiaDAOSupplier; + this.topiaDaoSupplier = topiaDaoSupplier; } public TopiaFiresSupport getTopiaFiresSupport() { @@ -270,7 +270,7 @@ if (entity instanceof TopiaEntityContextable) { TopiaEntityContextable contextable = (TopiaEntityContextable) entity; - contextable.setTopiaDAOSupplier(this.topiaDAOSupplier); + contextable.setTopiaDAOSupplier(this.topiaDaoSupplier); } // save entity Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -41,7 +41,6 @@ import org.nuiton.topia.event.TopiaEntityListener; import org.nuiton.topia.event.TopiaEntityVetoable; import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.generator.EntityDAOTransformer; import org.nuiton.topia.persistence.pager.TopiaPagerBean; import java.security.Permission; @@ -53,7 +52,7 @@ * create, delete, update or find entities. * <p/> * This interface is implemented by {@link TopiaDAOImpl} overridden by generation - * from {@link EntityDAOTransformer}. + * from {@link org.nuiton.topia.generator.EntityDaoTransformer}. * <p/> * * @param <E> the entity type managed by the dao Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -208,7 +208,7 @@ if (fireSupport == null) { if (this instanceof TopiaEntityContextable) { TopiaEntityContextable contextable = (TopiaEntityContextable) this; - AbstractTopiaDAO topiaDAO = (AbstractTopiaDAO)contextable.getTopiaDAOSupplier().getDAO(getClass()); + AbstractTopiaDAO topiaDAO = (AbstractTopiaDAO)contextable.getTopiaDAOSupplier().getDao(getClass()); fireSupport = topiaDAO.getTopiaFiresSupport(); } } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -26,7 +26,7 @@ package org.nuiton.topia.persistence; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaDAOSupplier; +import org.nuiton.topia.TopiaDaoSupplier; /** * {@link TopiaEntity} with {@link TopiaContext} support (injected by @@ -50,8 +50,8 @@ */ void delete(); - void setTopiaDAOSupplier(TopiaDAOSupplier topiaDAO); + void setTopiaDAOSupplier(TopiaDaoSupplier topiaDAO); - TopiaDAOSupplier getTopiaDAOSupplier(); + TopiaDaoSupplier getTopiaDAOSupplier(); } Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -229,7 +229,7 @@ // on recupere pour chaque type tous les ids des entites a repliquer data = new TopiaEntityIdsMap(); for (TopiaEntityEnum e : replicationModel.getContracts()) { - List<String> ids = srcCtxt.getDAO(e.getContract()).findAllIds(); + List<String> ids = srcCtxt.getDao(e.getContract()).findAllIds(); data.put(e.getContract(), ids); } } else { Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -106,7 +106,7 @@ Class<? extends TopiaEntity> entityClass = operationDef.getEntityType(); TopiaDAO<TopiaEntity> dao = - (TopiaDAO<TopiaEntity>) dstCtxt.getDAO(entityClass); + (TopiaDAO<TopiaEntity>) dstCtxt.getDao(entityClass); List<String> allIds = dao.findAllIds(); try { Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -484,8 +484,8 @@ if (getLog().isDebugEnabled()) { getLog().debug("verify for contract " + c); } - TopiaDAO<? extends TopiaEntity> daoSrc = ctxt.getDAO(c.getContract()); - TopiaDAO<? extends TopiaEntity> daoDst = ctxt2.getDAO(c.getContract()); + TopiaDAO<? extends TopiaEntity> daoSrc = ctxt.getDao(c.getContract()); + TopiaDAO<? extends TopiaEntity> daoDst = ctxt2.getDao(c.getContract()); long nbSrc = daoSrc.count(); long nbDst = daoDst.count(); assertEquals("le nombres d'entites de type " + c + " devrait etre " + nbSrc + " mais est " + nbDst, nbSrc, nbDst); Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -277,13 +277,13 @@ TopiaContextImplementor tx = (TopiaContextImplementor) context.beginTransaction(); - person = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding master"); - race = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race I"); - pet = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race); + person = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding master"); + race = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race I"); + pet = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race); - person2 = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding II master"); - pet2 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding II"); - race2 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race II"); + person2 = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding II master"); + pet2 = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding II"); + race2 = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race II"); tx.commitTransaction(); tx.closeContext(); Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -236,16 +236,16 @@ TopiaContextImplementor tx = (TopiaContextImplementor) context.beginTransaction(); - person = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding master"); - race = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race I"); - pet = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race); + person = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding master"); + race = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race I"); + pet = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race); - person2 = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding II master"); - pet2 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding II"); - race2 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race II"); + person2 = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding II master"); + pet2 = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding II"); + race2 = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race II"); - race3 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race III"); - pet3 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding III", Pet.PROPERTY_RACE, race3); + race3 = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race III"); + pet3 = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding III", Pet.PROPERTY_RACE, race3); tx.commitTransaction(); tx.closeContext(); Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2013-10-15 15:08:16 UTC (rev 2845) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2013-10-17 16:14:18 UTC (rev 2846) @@ -395,16 +395,16 @@ TopiaContextImplementor tx = (TopiaContextImplementor) context.beginTransaction(); - person = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding master"); - race = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race I"); - pet = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race); + person = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding master"); + race = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race I"); + pet = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race); - person2 = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding II master"); - pet2 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding II"); - race2 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race II"); + person2 = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding II master"); + pet2 = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding II"); + race2 = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race II"); - race3 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race III"); - pet3 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding III", Pet.PROPERTY_RACE, race3); + race3 = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race III"); + pet3 = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding III", Pet.PROPERTY_RACE, race3); tx.commitTransaction(); tx.closeContext();