r2770 - in trunk: topia-persistence topia-persistence/src/main/java/org/nuiton/topia/generator topia-persistence/src/main/java/org/nuiton/topia/persistence topia-persistence/src/test/java/org/nuiton/topiatest/deletetest topia-persistence/src/test/xmi topia-service-migration/src/main/java/org/nuiton/topia/migration topia-service-replication/src/main/java/org/nuiton/topia/replication topia-service-replication/src/main/java/org/nuiton/topia/replication/operation topia-service-replication/src/ma
Author: tchemit Date: 2013-07-14 22:13:25 +0200 (Sun, 14 Jul 2013) New Revision: 2770 Url: http://nuiton.org/projects/topia/repository/revisions/2770 Log: fixes #2760: Remove ServiceTransformer fixes #2736: Remove code deprecated before 3.0 Removed: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java trunk/topia-service-security/src/test/java/org/nuiton/topia/TestUtils.java Modified: trunk/topia-persistence/pom.xml trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaStereoTypes.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java trunk/topia-persistence/src/test/xmi/topiatest.properties trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java trunk/topia-service-replication/src/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java trunk/topia-service-security/pom.xml Modified: trunk/topia-persistence/pom.xml =================================================================== --- trunk/topia-persistence/pom.xml 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-persistence/pom.xml 2013-07-14 20:13:25 UTC (rev 2770) @@ -56,6 +56,7 @@ <dependency> <groupId>org.nuiton.i18n</groupId> <artifactId>nuiton-i18n</artifactId> + <scope>test</scope> </dependency> <dependency> Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -1,1028 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.generator; - -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.ObjectModelModifier; -import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.eugene.models.object.ObjectModelParameter; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaDAOLegacy; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.util.StringUtil; - -import java.security.Permission; -import java.util.ArrayList; -import java.util.Arrays; -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; - - -/*{generator option: parentheses = false}*/ -/*{generator option: writeString = +}*/ - -/** - * Created: 13 déc. 2009 - * - * @author tchemit <chemit@codelutin.com> - * @version $Id: DAOAbstractTransformer.java 1960 2010-05-13 17:18:23Z tchemit$ - * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.DAOAbstractTransformer" - * @since 2.3.0 - * @deprecated 2.5.4, prefer use the transformer {@link EntityDAOTransformer} - */ -@Deprecated -public class DAOAbstractTransformer extends ObjectModelTransformerToJava { - - /** Logger. */ - private static final Log log = LogFactory.getLog( - DAOAbstractTransformer.class); - - /** TODO */ - protected Map<ObjectModelClass, Set<ObjectModelClass>> usages; - - /** - * All entities fqn of the model (used to detect if an attribute is not - * an entity). - */ - Set<String> allEntitiesFqn; - - /** - * The class of abstract dao to use. - * @since 2.5 - */ - protected Class<?> daoImplementation; - - /** - * Map of extra operations for DAO. The key of the map is the qualified - * name of the entity relative to the DAO. - */ - Map<String, Collection<ObjectModelOperation>> extraOperations = - new HashMap<String, Collection<ObjectModelOperation>>(); - - @Override - public void transformFromModel(ObjectModel model) { - - usages = TopiaGeneratorUtil.searchDirectUsages(model); - boolean extendLegacyDAO = Boolean.valueOf(model.getTagValue(TopiaTagValues.TAG_USE_LEGACY_DAO)); - if (extendLegacyDAO) { - log.warn("Using a deprecated tag value "+ - TopiaTagValues.TAG_USE_LEGACY_DAO+", prefer use the tag value "+TopiaTagValues.TAG_DAO_IMPLEMENTATION); - daoImplementation = TopiaDAOLegacy.class; - } else { - daoImplementation = TopiaGeneratorUtil.getDAOImplementation(model); - } - - List<ObjectModelClass> allEntities = TopiaGeneratorUtil.getEntityClasses(model, true); - allEntitiesFqn = new HashSet<String>(allEntities.size()); - for (ObjectModelClass entity : allEntities) { - allEntitiesFqn.add(entity.getQualifiedName()); - } - } - - @Override - public void transformFromInterface(ObjectModelInterface interfacez) { - if (!TopiaGeneratorUtil.hasDaoStereotype(interfacez)) { - return; - } - - // Extra operations from <<dao>> interfacez - collectExtraOperations(interfacez); - } - - /** - * 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). - * - * @param interfacez The interface with <<dao>> stereotype - */ - protected void collectExtraOperations(ObjectModelInterface interfacez) { - 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)) { - - // Only direct operations will be used. No need to have more - // operations. - Collection<ObjectModelOperation> operations = - interfacez.getOperations(); - - if (log.isDebugEnabled()) { - log.debug("add extra operations for DAO"); - } - - extraOperations.put(classifier.getQualifiedName(), operations); - } - } - - @Override - public void transformFromClass(ObjectModelClass clazz) { - if (!TopiaGeneratorUtil.isEntity(clazz)) { - return; - } - - String clazzName = clazz.getName(); - - ObjectModelClass result = 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(result, extendClass); - - addInterface(result, TopiaDAO.class.getName() + "<E>"); - - String prefix = getConstantPrefix(clazz, ""); - setConstantPrefix(prefix); - - // imports - - Collection<ObjectModelOperation> DAOoperations = getDAOOperations(clazz); - if (isCollectionNeeded(DAOoperations)) { - addImport(result, Collection.class); - } - if (isSetNeeded(DAOoperations)) { - addImport(result, Set.class); - } - addImport(result, List.class); - addImport(result, Arrays.class); - addImport(result, TopiaException.class); - addImport(result, TopiaContextImplementor.class); - - boolean enableSecurity = TopiaGeneratorUtil.isClassWithSecurity(clazz); - - if (enableSecurity) { - addImport(result, ArrayList.class); - addImport(result, Permission.class); - addImport(result, "org.nuiton.topia.taas.entities.TaasAuthorizationImpl"); - addImport(result, "org.nuiton.topia.taas.jaas.TaasPermission"); - addImport(result, "org.nuiton.topia.taas.TaasUtil"); - addImport(result, 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(result, - "getEntityClass", - "Class<E>", - ObjectModelJavaModifier.PUBLIC); - setOperationBody(op, "" -/*{ - return (Class<E>)<%=clazzName%>.class; - }*/ - ); - - - generateDAOOperations(result, DAOoperations); - - generateDelete(clazz, result); - - generateNaturalId(result, clazz); - - for (ObjectModelAttribute attr : clazz.getAttributes()) { - if (!attr.isNavigable()) { - continue; - } - - if (!GeneratorUtil.isNMultiplicity(attr)) { - generateNoNMultiplicity(clazzName, result, attr, false); - } else { - generateNMultiplicity(clazzName, result, attr); - } - } - - if (clazz instanceof ObjectModelAssociationClass) { - ObjectModelAssociationClass assocClass = - (ObjectModelAssociationClass) clazz; - for (ObjectModelAttribute attr : assocClass.getParticipantsAttributes()) { - if (attr != null) { - if (!GeneratorUtil.isNMultiplicity(attr)) { - generateNoNMultiplicity(clazzName, result, attr, true); - } else { - generateNMultiplicity(clazzName, result, attr); - } - } - } - } - - if (enableSecurity) { - - // getRequestPermission - - op = addOperation(result, - "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(result, clazz, - TopiaGeneratorUtil.getSecurityCreateTagValue(clazz))); - buffer.append("" -/*{ - } - if ((actions & TaasUtil.LOAD) == TaasUtil.LOAD) { -}*/ - ); - buffer.append(generateSecurity(result, clazz, - TopiaGeneratorUtil.getSecurityLoadTagValue(clazz))); - buffer.append("" -/*{ - } - if ((actions & TaasUtil.UPDATE) == TaasUtil.UPDATE) { -}*/ - ); - buffer.append(generateSecurity(result, clazz, - TopiaGeneratorUtil.getSecurityUpdateTagValue(clazz))); - buffer.append("" -/*{ - } - if ((actions & TaasUtil.DELETE) == TaasUtil.DELETE) { -}*/ - ); - buffer.append(generateSecurity(result, 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(result, - "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, "" -/*{ TopiaContextImplementor context = getContext(); - 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, result, usagesForclass); - } - - protected void generateDelete(ObjectModelClass clazz, - ObjectModelClass result) { - ObjectModelOperation op; - op = addOperation(result, "delete", "void", ObjectModelJavaModifier.PUBLIC); - addException(op, TopiaException.class); - addParameter(op, "E", "entity"); - 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%>(getContext()); -// 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); - - - body.append("" -/*{ - { - List<<%=attrType%>> list = getContext().getHibernate().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.remove<%=StringUtils.capitalize(reverseAttrName)%>(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 - builder.addImport(result, attrType); - String attrSimpleType = TopiaGeneratorUtil.getClassNameFromQualifiedName(attrType); - - body.append("" - /*{ - { - List<<%=attrSimpleType%>> list = getContext() - .getDAO(<%=attrSimpleType%>.class) - .findAllByProperties(<%=attrSimpleType%>.<%=getConstantName(reverseAttrName)%>, entity); - for (<%=attrSimpleType%> item : list) { - item.set<%=StringUtils.capitalize(reverseAttrName)%>(null); - }*/ - ); - if (attr.isAggregate()) { - body.append("" -/*{ - getContext().getDAO(<%=attrSimpleType%>.class).delete(item); - //item.delete(); -}*/ - ); - } - body.append("" -/*{ - } - } -}*/ - ); - - } - } - body.append("" -/*{ - super.delete(entity); - }*/ - ); - - setOperationBody(op, body.toString()); - } - - private 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"); - addException(operation, TopiaException.class); - 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"); - addException(operation, TopiaException.class); - 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"); - addException(operation, TopiaException.class); - 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 methodNameSuffix = StringUtils.capitalize(attrName); - String methodName; - if (TopiaGeneratorUtil.isNMultiplicity(attr)) { - methodName = "findAllContains" + methodNameSuffix; - } else { - methodName = "findAllBy" + methodNameSuffix; - } - String daoName = StringUtils.capitalize(usageSimpleType) + "DAO"; - - builder.addImport(result, usageClass.getPackageName() + '.' + daoName); - - buffer.append("" -/*{ - if (type == <%=usageSimpleType%>.class) { - <%=daoName%> dao = (<%=daoName%>) - getContext().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"); - addException(operation, TopiaException.class); - 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) { - for (ObjectModelOperation op : operations) { - - //TODO: add to transformer cloneOperation - - ObjectModelOperation op2; - op2 = addOperation(result, - op.getName(), - op.getReturnType(), - ObjectModelJavaModifier.ABSTRACT, - ObjectModelJavaModifier.fromVisibility(op.getVisibility())); - setDocumentation(op2, op.getDocumentation()); - - // parameters - - for (ObjectModelParameter param : op.getParameters()) { - ObjectModelParameter param2 = addParameter(op2, - param.getType(), param.getName()); - setDocumentation(param2, param.getDocumentation()); - } - - // exceptions - Set<String> exceptions = op.getExceptions(); - exceptions.add(TopiaException.class.getName()); - for (String exception : exceptions) { - addException(op2, exception); - } - } - } - - - 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 = attrName; - if (!isAssoc && attr.hasAssociationClass()) { - propertyName = TopiaGeneratorUtil.toLowerCaseFirstLetter( - attr.getAssociationClass().getName()) + '.' + propertyName; - } - ObjectModelOperation op; - op = addOperation(result, - "findBy" + StringUtils.capitalize(attrName), - "E", - ObjectModelJavaModifier.PUBLIC); - addException(op, TopiaException.class); - addParameter(op, attrType, "v"); - setDocumentation(op, "Retourne le premier élément trouvé ayant comme valeur pour l'attribut " + attrName + " le paramètre."); - setOperationBody(op, "" -/*{ - E result = findByProperty(<%=clazzName + "." + getConstantName(propertyName)%>, v); - return result; - }*/ - ); - - op = addOperation(result, - "findAllBy" + StringUtils.capitalize(attrName), - "List<E>", - ObjectModelJavaModifier.PUBLIC); - addException(op, TopiaException.class); - addParameter(op, attrType, "v"); - setDocumentation(op, "Retourne les éléments ayant comme valeur pour " + - "l'attribut " + attrName + " le paramètre."); - setOperationBody(op, "" -/*{ - List<E> result = findAllByProperty(<%=clazzName + "." + getConstantName(propertyName)%>, v); - return result; - }*/ - ); - - if (attr.hasAssociationClass()) { - String assocClassName = attr.getAssociationClass().getName(); - String assocClassFQN = attr.getAssociationClass().getQualifiedName(); - op = addOperation(result, - "findBy" + StringUtils.capitalize(assocClassName), - "E", - ObjectModelJavaModifier.PUBLIC); - addException(op, TopiaException.class); - addParameter(op, assocClassFQN, "value"); - setDocumentation(op, "Retourne le premier élément trouvé ayant " + - "comme valeur pour l'attribut " + - TopiaGeneratorUtil.toLowerCaseFirstLetter(assocClassName) + - " le paramètre."); - setOperationBody(op, "" -/*{ - E result = findByProperty(<%=clazzName + "." + getConstantName(TopiaGeneratorUtil.toLowerCaseFirstLetter(assocClassName))%>, value); - return result; - }*/ - ); - - op = addOperation(result, - "findAllBy" + StringUtils.capitalize(assocClassName), - "List<E>", - ObjectModelJavaModifier.PUBLIC); - addException(op, TopiaException.class); - addParameter(op, assocClassFQN, "value"); - setDocumentation(op, "Retourne les éléments ayant comme valeur pour" + - " l'attribut " + - TopiaGeneratorUtil.toLowerCaseFirstLetter(assocClassName) + - " le paramètre."); - setOperationBody(op, "" -/*{ - List<E> result = findAllByProperty(<%=clazzName + "." + getConstantName(TopiaGeneratorUtil.toLowerCaseFirstLetter(assocClassName))%>, 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, - "findContains" + StringUtils.capitalize(attrName), - "E", - ObjectModelJavaModifier.PUBLIC); - addException(op, TopiaException.class); - addParameter(op, attrType, "v"); - setDocumentation(op, "Retourne le premier élément ayant comme valeur pour" + - " l'attribut " + - TopiaGeneratorUtil.toLowerCaseFirstLetter(attrName) + - " le paramètre."); - setOperationBody(op, "" -/*{ - E result = findContains(<%=clazzName + "." + getConstantName(attrName)%>, v); - return result; - }*/ - ); - - op = addOperation(result, - "findAllContains" + StringUtils.capitalize(attrName), - "List<E>", - ObjectModelJavaModifier.PUBLIC); - addException(op, TopiaException.class); - addParameter(op, attrType, "v"); - setDocumentation(op, "Retourne les éléments ayant comme valeur pour" + - " l'attribut " + - TopiaGeneratorUtil.toLowerCaseFirstLetter(attrName) + - " le paramètre."); - setOperationBody(op, "" -/*{ - List<E> result = findAllContains(<%=clazzName + "." + getConstantName(attrName)%>, v); - return result; - }*/ - ); - } - - private boolean isCollectionNeeded( - Collection<ObjectModelOperation> operations) { - return isImportNeeded(operations, "Collection"); - } - - private boolean isSetNeeded(Collection<ObjectModelOperation> operations) { - return isImportNeeded(operations, "Set"); - } - - private boolean isImportNeeded(Collection<ObjectModelOperation> operations, - String importName) { - for (ObjectModelOperation op : operations) { - if (op.getReturnType().contains(importName)) { - return true; - } - for (ObjectModelParameter param : op.getParameters()) { - if (param.getType().contains(importName)) { - return true; - } - } - } - return false; - } - - 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); - } - } - // New method : interface dependency - Collection<ObjectModelOperation> extra = - extraOperations.get(clazz.getQualifiedName()); - - 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); - addException(findByNaturalId, TopiaException.class); - - ObjectModelOperation existByNaturalId = addOperation(result, - "existByNaturalId", "boolean", ObjectModelJavaModifier.PUBLIC); - addException(existByNaturalId, TopiaException.class); - - ObjectModelOperation create = addOperation(result, - "create", "E", ObjectModelJavaModifier.PUBLIC); - addException(create, TopiaException.class); - - // 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); - - 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%>); - }*/ - ); - } - - - } -} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -45,7 +45,6 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaDAOLegacy; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.StringUtil; @@ -124,19 +123,10 @@ } usages = TopiaGeneratorUtil.searchDirectUsages(model); - boolean extendLegacyDAO = - Boolean.valueOf(model.getTagValue(TopiaTagValues.TAG_USE_LEGACY_DAO)); - if (extendLegacyDAO) { - log.warn("Using a deprecated tag value " + - TopiaTagValues.TAG_USE_LEGACY_DAO + - ", prefer use the tag value " + - TopiaTagValues.TAG_DAO_IMPLEMENTATION); - daoImplementation = TopiaDAOLegacy.class; - } else { - daoImplementation = - TopiaGeneratorUtil.getDAOImplementation(model); - } + daoImplementation = TopiaGeneratorUtil.getDAOImplementation(model); + + // keep all classifiers on the model which are entities List<ObjectModelClass> allEntities = TopiaGeneratorUtil.getEntityClasses(model, true); Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -1,774 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.generator; - -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.ObjectModelClass; -import org.nuiton.eugene.models.object.ObjectModelInterface; -import org.nuiton.eugene.models.object.ObjectModelJavaModifier; -import org.nuiton.eugene.models.object.ObjectModelModifier; -import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.eugene.models.object.ObjectModelParameter; -import org.nuiton.i18n.I18n; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.Map; - -/*{generator option: parentheses = false}*/ - -/*{generator option: writeString = +}*/ - -/** - * This Template is used to create the skeleton of services for a final - * application which using Topia. - * <div> - * Generation from interfaces with stereotype <<service>> : - * <ul> - * <li>Service : interface of the service defined in model.</li> - * <li><p>ServiceAbstract : abstract class which contains :</p> - * <p>* treateError : abstract method used to catch all exception from a - * service method.</p> - * <p>* closeTransaction : abstract method used to finally the try/catch - * of a service method</p> - * <p>* beginTransaction : abstract method used to start the transaction - * using rootContext.</p> - * <p>* constructor with AppContextImplementor in argument</p> - * <p>* for each method : the implementation of the method (skeleton with - * try/catch and beginTransaction call to open a new TopiaContext from - * AppContextImplementor). Usage of i18n keys for error messages in - * exception.</p> - * <p>* for each method : an abstract method used to execute the business - * code of the method : need to be implemented in subclass.</p> - * </li> - * </ul> - * </div> - * <div> - * Exemple of ServiceImpl utils method implementation. (The AppException - * is considered if defined in model tagvalue "exceptionClass") : <br /> - * <pre> - * public class ServiceImpl implements ServiceAbstract { - * - * // properties for Topia configuration - * protected Properties properties; - * ... - * - * @Override - * public void treateError(TopiaContext transaction, Exception eee, - * String message, Object... args) throws AppException { - * - * // Note that the message from service doesn't directly use _() for - * // i18 messages but n_(). In this log, the _() is used to translate - * // correctly the message. But the message must be translate when - * // catching the AppException in UI. - * if (log.isErrorEnabled()) { - * log.error(_(message, args), eee); - * } - * - * // rollback of current transaction - * if (transaction != null) { - * try { - * transaction.rollbackTransaction(); - * } catch (TopiaException ex) { - * if (log.isErrorEnabled()) { - * log.error(_("app.error.context.rollback"), ex); - * } - * } - * } - * // wrapping the exception in a AppException with message and - * // arguments for i18n translation - * throw new AppException(eee, message, args); - * } - * - * @Override - * public void closeTransaction(TopiaContext transaction) { - * if (transaction != null) { - * try { - * transaction.closeContext(); - * } catch (TopiaException eee) { - * if (log.isErrorEnabled()) { - * log.error(_("app.error.context.close"), eee); - * } - * } - * } - * } - * - * @Override - * public TopiaContext beginTransaction() throws TopiaException { - * TopiaContext rootContext = null; - * try { - * // You have to manage the properties using ApplicationConfig - * // or other lib to have configuration for Topia - * rootContext = TopiaContextFactory.getContext(properties); - * - * return getTopiaRootContext().beginTransaction(); - * - * // only catch exception for rootContext - * } catch (TopiaNotFoundException eee) { - * treateError(eee, n_("app.error.context.getTopiaRootContext")); - * } - * return null; - * } - * - * // Implementation of abstract method, the interface method is - * // called 'createMyEntity(MyEntity entity)' in this case. - * @Override - * public void executeCreateMyEntity(TopiaContext transaction, - * MyEntity entity) throws TopiaException { - * - * MyEntityDAO dao = AppDAOHelper.getMyEntityDAO(transaction); - * dao.create(entity); - * // That's it, no need to manage errors or transaction, the abstract - * // service will do this job. - * } - * } - * </pre> - * <div> - * <h2>TAG_TRANSACTION</h2> - * <p>Default value : true</p> - * <p>You can use the tagValue 'transaction=false' to specify that a method - * doesn't need any TopiaContext, so no need to instantiate a new one. - * This tagValue can only be put directly in the model and not in properties - * file (because of multiple methods with same name problem).</p> - * </div> - * <div> - * <h2>TAG_ERROR_ARGS</h2> - * <p>Default value : false</p> - * <p>You can use the tagValue 'errorArgs=true' to specify that a method - * need arguments for error message. This tagValue can only be put directly - * in the model and not in properties file.</p> - * </div> - * <div> - * <h2>TAG_EXCEPTION_CLASS</h2> - * <p>Default value : null</p> - * <p>You can use the tagValue 'exceptionClass=my.exception.full.qualified.Name' - * to specify that all contract methods will throw this exception.</p> - * </div> - * <p>It is smooth, isn't it :p ?</p> - * <p> - * - * Created: 23 mars 2010 - * - * @author fdesbois <fdesbois@codelutin.com> - * @version $Id$ - * @since 2.3.1 - * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.ServiceTransformer" - */ -// TODO : may be refactor to integrate JTA or webservice or may be not in this transformer. -public class ServiceTransformer extends ObjectModelTransformerToJava { - - - private static final Log log = LogFactory.getLog(ServiceTransformer.class); - protected String modelName; - - protected String defaultPackageName; - - protected String exceptionName; - - private static final String OP_NAME_BEGIN_TRANSACTION = "beginTransaction"; - - private static final String OP_NAME_COMMIT_TRANSACTION = "commitTransaction"; - - private static final String OP_NAME_CLOSE_TRANSACTION = "closeTransaction"; - - private static final String OP_NAME_TREATE_ERROR = "treateError"; - - public static final String PARAMETER_TRANSACTION = "transaction"; - - protected String getServiceAbstractClassName(String serviceName) { - return serviceName + "Abstract"; - } - - @Override - public void transformFromModel(ObjectModel model) { - exceptionName = TopiaGeneratorUtil.getExceptionClassTagValue(model); - modelName = model.getName(); - } - - @Override - public void transformFromInterface(ObjectModelInterface input) { - if (!TopiaGeneratorUtil.hasServiceStereotype(input)) { - return; - } - - // global transaction needed (if set to false then never use transaction) - boolean needTransaction = isTransactionNeeded(input); - - ObjectModelInterface serviceContract = createServiceContract(input); - - createServiceAbstract(input, - serviceContract, - needTransaction); - } - - /** - * Create the service contract using {@code source} interface defined - * in model. - * - * @param source interface from model - * @return the ObjectModelInterface created - */ - protected ObjectModelInterface createServiceContract( - ObjectModelInterface source) { - - ObjectModelInterface serviceContract = - createInterface(source.getName(), source.getPackageName()); - - setDocumentation(serviceContract, source.getDocumentation()); - for (ObjectModelOperation op : source.getOperations()) { - ObjectModelOperation newOp = addOperation(serviceContract, - op.getName(), - op.getReturnType() - ); - setDocumentation(newOp.getReturnParameter(), - op.getReturnParameter().getDocumentation() - ); - for (ObjectModelParameter param : op.getParameters()) { - ObjectModelParameter newParam = addParameter(newOp, - param.getType(), - param.getName() - ); - setDocumentation(newParam, param.getDocumentation()); - } - for (String ex : op.getExceptions()) { - addException(newOp, ex); - } - if (exceptionName != null) { - addException(newOp, exceptionName); - } - setDocumentation(newOp, op.getDocumentation()); - } - return serviceContract; - } - - protected void createBeginTransactionMethod(ObjectModelInterface source, - ObjectModelInterface serviceContract, - ObjectModelClass serviceAbstract) { - ObjectModelOperation operation = - addOperation(serviceAbstract, OP_NAME_BEGIN_TRANSACTION, - TopiaContext.class, - ObjectModelJavaModifier.ABSTRACT, - ObjectModelJavaModifier.PROTECTED); - addException(operation, TopiaException.class); - } - - protected void createCommitTransactionMethod(ObjectModelClass serviceAbstract) { - ObjectModelOperation operation = - addOperation(serviceAbstract, - OP_NAME_COMMIT_TRANSACTION, - "void", - ObjectModelJavaModifier.PROTECTED); - addParameter(operation, TopiaContext.class, PARAMETER_TRANSACTION); - addException(operation, TopiaException.class); - setOperationBody(operation,"" -/*{ - transaction.commitTransaction(); -}*/ - ); - - } - - protected void createCloseTransactionMethod(ObjectModelInterface source, - ObjectModelInterface serviceContract, - ObjectModelClass serviceAbstract) { - ObjectModelOperation operation = - addOperation(serviceAbstract, - OP_NAME_CLOSE_TRANSACTION, - "void", - ObjectModelJavaModifier.ABSTRACT, - ObjectModelJavaModifier.PROTECTED); - addParameter(operation, TopiaContext.class, PARAMETER_TRANSACTION); - addException(operation, TopiaException.class); - } - - protected void createTreateErrorMethod(ObjectModelInterface source, - ObjectModelInterface serviceContract, - ObjectModelClass serviceAbstract, - boolean needTransaction) { - - ObjectModelOperation treateError1 = - addOperation(serviceAbstract, - OP_NAME_TREATE_ERROR, - "void", - ObjectModelJavaModifier.ABSTRACT, - ObjectModelJavaModifier.PROTECTED); - if (needTransaction) { - addParameter(treateError1, TopiaContext.class, PARAMETER_TRANSACTION); - } - addParameter(treateError1, Exception.class, "eee"); - addParameter(treateError1, String.class, "message"); - addParameter(treateError1, "Object...", "args"); - if (exceptionName != null) { - addException(treateError1, exceptionName); - } - - if (needTransaction) { - ObjectModelOperation treateError2 = - addOperation(serviceAbstract, OP_NAME_TREATE_ERROR, "void", - ObjectModelJavaModifier.PROTECTED); - addParameter(treateError2, Exception.class, "eee"); - addParameter(treateError2, String.class, "message"); - addParameter(treateError2, "Object...", "args"); - if (exceptionName != null) { - addException(treateError2, exceptionName); - } - - setOperationBody(treateError2, "" - /*{ - treateError(null, eee, message, args); - }*/ - ); - } - } - /** - * Create the service abstract for {@code serviceContract} - * using {@code source} interface defined - * in model. - * - * @param source interface from model - * @param serviceContract to implement - * @param needTransaction flag to know if service globally use transaction - */ - protected void createServiceAbstract(ObjectModelInterface source, - ObjectModelInterface serviceContract, - boolean needTransaction) { - - ObjectModelClass serviceAbstract = createAbstractClass( - getServiceAbstractClassName(serviceContract.getName()), - serviceContract.getPackageName()); - - // Imports for implementations - if (needTransaction) { - addImport(serviceAbstract, TopiaContext.class); - } - addImport(serviceAbstract, I18n.class); - - // Implements contract interface - addInterface(serviceAbstract, serviceContract.getQualifiedName()); - - // Create abstract methods - - if (needTransaction) { - createBeginTransactionMethod(source, - serviceContract, - serviceAbstract); - - createCommitTransactionMethod(serviceAbstract); - - createCloseTransactionMethod(source, - serviceContract, - serviceAbstract); - } - - createTreateErrorMethod(source, - serviceContract, - serviceAbstract, - needTransaction - ); - - // keep execute methods (we want to generate them at the top of the - // class since they are all abstract) - // Note: using a LinkedHashMap permits to keep incoming order - Map<ObjectModelOperation, ObjectModelOperation> abstractExecuteMethods = - new LinkedHashMap<ObjectModelOperation, ObjectModelOperation>(); - - // first generate the abstract execute methods - for (ObjectModelOperation operation : source.getOperations()) { - - ObjectModelOperation executeOp = createOperationExecuteAbstract( - serviceAbstract, - operation, - needTransaction - ); - - abstractExecuteMethods.put(operation , executeOp); - } - - // Then generates the real operation which boxes the execute methods - for (Map.Entry<ObjectModelOperation, ObjectModelOperation> entry : - abstractExecuteMethods.entrySet()) { - ObjectModelOperation operation = entry.getKey(); - ObjectModelOperation executeOperation = entry.getValue(); - createOperationImplementation( - serviceAbstract, - executeOperation, - operation, - source.getName(), - needTransaction - ); - } - } - - /** - * Create an operation abstract to execute in contract implementation. - * You can use tagvalues "errorArgs" (default = false) and "transaction" - * (default = true) to generate appropriate parameters. This abstract - * method will throw all exceptions (Exception.class). This is the method - * which will be implemented by the developper in service implementation - * class. - * - * @param serviceAbstract where the operation will be created - * @param source ObjectModelOperation from model - * @param needTransaction flag to know if service globally use transaction - * @return the abstract operation created - * @see #isErrorArgsNeeded(ObjectModelOperation) - * @see #isTransactionNeeded(ObjectModelOperation) - * @see #isTransactionNeeded(ObjectModelInterface) - */ - protected ObjectModelOperation createOperationExecuteAbstract( - ObjectModelClass serviceAbstract, - ObjectModelOperation source, - boolean needTransaction) { - String opName = StringUtils.capitalize(source.getName()); - - // Abstract operation to execute method content - ObjectModelOperation executeOperation = - addOperation(serviceAbstract, "execute" + opName, - source.getReturnType(), - ObjectModelJavaModifier.ABSTRACT, - ObjectModelJavaModifier.PROTECTED); - - // Throw all exception from abstract method - // They will be catched by interface method to use treateError - addException(executeOperation, Exception.class); - - if (needTransaction && isTransactionNeeded(source)) { - addParameter(executeOperation, TopiaContext.class, PARAMETER_TRANSACTION); - } - - if (isErrorArgsNeeded(source)) { - // Add errorArgs to abstract operation - addParameter(executeOperation, "java.util.List<Object>", "errorArgs"); - } - - // Copy other operation parameters - for (ObjectModelParameter param : source.getParameters()) { - addParameter(executeOperation, param.getType(), param.getName()); - } - return executeOperation; - } - - /** - * Create an operation implementation. This is the skeleton of the operation - * defined from model. This will put a try/catch block over an abstract - * method {@code abstOp}. You can use tagvalues "errorArgs" and - * "transaction" for abstract method parameters to call. If the transaction - * is needed, this will use the beginTransaction() and closeTransaction() - * methods defined in {@code serviceAbstract} class. - * - * @param serviceAbstract where the operation will be created - * @param abstOp to execute into the implementation body - * @param source ObjectModelOperation from model - * @param serviceContractName where the signature method is defined - * @param needTransaction flag to know if service globally use transaction - * @see #isErrorArgsNeeded(ObjectModelOperation) - * @see #isTransactionNeeded(ObjectModelInterface) - */ - protected void createOperationImplementation( - ObjectModelClass serviceAbstract, - ObjectModelOperation abstOp, - ObjectModelOperation source, - String serviceContractName, - boolean needTransaction) { - - // boolean to specify if the method need a transaction or not - // Default set to true but can be override by a tagvalue on the - // method - needTransaction &= isTransactionNeeded(source); - - // boolean to specify if the method need error arguments or not - // Default set to true but can be override by a tagvalue on the - // method - boolean needErrorArgs = isErrorArgsNeeded(source); - - // Implementation of interface operation - ObjectModelOperation implOp = - addOperation(serviceAbstract, - source.getName(), - source.getReturnType(), - ObjectModelJavaModifier.PUBLIC); - - addAnnotation(serviceAbstract, implOp, Override.class.getSimpleName()); - - String toStringAppend = ""; - String separatorLog = " : "; - // Copy operation parameters - for (ObjectModelParameter param : source.getParameters()) { - String paramName = param.getName(); - addParameter(implOp, param.getType(), paramName); - } - - // Use buffer for operation body - StringBuilder buffer = new StringBuilder(); - - // Abstract operation parameters - String abstName = abstOp.getName(); - String abstParams = - GeneratorUtil.getOperationParametersListName(abstOp); - - // Abstract operation return managment - String abstReturnType = ""; - String abstReturn = ""; - String finalReturn = ""; - String returnType = GeneratorUtil.getSimpleName(abstOp.getReturnType(), - true - ); - if (!returnType.equals("void")) { - abstReturnType = returnType + " result = "; - abstReturn = "return result;"; - finalReturn = "return " + - getReturnValue(abstOp.getReturnType()) + ";"; - } - - // Error key for i18n - String contract = - GeneratorUtil.toLowerCaseFirstLetter(serviceContractName); - String errorKey = StringUtils.lowerCase(modelName) + ".error." + - contract + "." + source.getName(); - - String treateErrorParams = "eee, I18n.n_(\"" + errorKey + "\")"; - - if (needErrorArgs) { - addImport(serviceAbstract, ArrayList.class); - // Init errorArgs - buffer.append("" - /*{ - List<Object> errorArgs = new ArrayList<Object>(); - }*/ ); - treateErrorParams += ", errorArgs.toArray()"; - } - - if (needTransaction) { - // Open the transaction - buffer.append("" - /*{ - TopiaContext transaction = null; - try { - transaction = beginTransaction(); - - try {}*/ - ); - // Add transaction in treateError parameters - treateErrorParams = "transaction, " + treateErrorParams; - } else { - buffer.append("" - /*{ - try { - }*/ - ); - } - String implName = StringUtils.capitalize(implOp.getName()); - String first = modelName.substring(0, 1); - - buffer.append("" - /*{ - <%=abstReturnType%><%=abstName%>(<%=abstParams%>);}*/); - - if (needTransaction && isCommit(source, model)) { - - // add the commit instruction - buffer.append("" - /*{ - commitTransaction(transaction);}*/); - - } - buffer.append("" - /*{ - <%=abstReturn%>}*/); - - if (needTransaction) { - // Finally block to close transaction - buffer.append("" - /*{ - } finally { - closeTransaction(transaction); - } - }*/ - ); - - } - // Copy exceptions - for (String ex : source.getExceptions()) { - addException(implOp, ex); - // Add catch block for known exceptions we want to throw - String exName = GeneratorUtil.getSimpleName(ex); - buffer.append("" - /*{ - } catch (<%=exName%> eee) { - throw eee; }*/); - } - if (exceptionName != null) { - addException(implOp, exceptionName); - } - - buffer.append("" - /*{ - } catch (Exception eee) { - treateError(<%=treateErrorParams%>); }*/); - - - buffer.append("" - /*{ - } - <%=finalReturn%> - }*/ - ); - - setOperationBody(implOp, buffer.toString()); - } - - /** - * boolean to specify if the method need a transaction or not. - * Default set to true but can be override using a tagvalue "transaction" - * on the method from model. - * - * @param op where the tagvalue is set - * @return {@code true} if transaction is needed - */ - protected boolean isTransactionNeeded(ObjectModelInterface op) { - boolean needTransaction = true; - - String transactionTag = TopiaGeneratorUtil.getTransactionTagValue(op); - - if (transactionTag != null) { - needTransaction = Boolean.parseBoolean(transactionTag); - } - return needTransaction; - } - - /** - * boolean to specify if the method need a transaction or not. - * Default set to true but can be override using a tagvalue "transaction" - * on the method from model. - * - * @param op where the tagvalue is set - * @return {@code true} if transaction is needed - */ - protected boolean isTransactionNeeded(ObjectModelOperation op) { - boolean needTransaction = true; - - String transactionTag = TopiaGeneratorUtil.getTransactionTagValue(op); - - if (transactionTag != null) { - needTransaction = Boolean.parseBoolean(transactionTag); - } - return needTransaction; - } - - /** - * boolean to specify if method needs a commit after the executeXXX code invoked. - * - * @param op model element where the tagvalue is set - * @param model model where to tagvalue can be also set - * @return {@code true} if a commit must be generated after the executeXXX invocation - * @see TopiaTagValues#TAG_DO_COMMIT - * @since 2.5 - */ - protected boolean isCommit(ObjectModelOperation op, ObjectModel model) { - boolean needCommit = false; - - String tagValue = TopiaGeneratorUtil.getDoCommitTagValue( - op, - model - ); - if (tagValue != null) { - needCommit = Boolean.parseBoolean(tagValue); - } - if (isVerbose()) { - log.info("commit needed for op [" + op.getName() + "] : " + needCommit); - } - return needCommit; - } - - /** - * boolean to specify if the method need error arguments or not - * Default set to false but can be override using a tagvalue "errorArgs" on - * the method from model. - * - * @param op where the tagvalue is set - * @return true if errorArgs are needed - */ - protected boolean isErrorArgsNeeded(ObjectModelOperation op) { - // - boolean needErrorArgs = false; - - String errorArgsTag = TopiaGeneratorUtil.getErrorArgsTagValue(op); - - if (errorArgsTag != null) { - needErrorArgs = Boolean.parseBoolean(errorArgsTag); - } - return needErrorArgs; - } - - /** - * This method give the return string for an operation {@code returnType}. - * This use {@link Primitive} enum to provide default values for primitive - * type. For all other object type, this method will return null. - * - * @param returnType - * @return the defaultValue of the returnType - */ - protected String getReturnValue(String returnType) { - try { - //FIXME-TC20100423 : can not deal with Object types (float != Float) - Primitive prim = - Primitive.valueOf(StringUtils.upperCase(returnType)); - return prim.getValue(); - // If not defined in Primitive enum, return null - } catch (IllegalArgumentException eee) { - return null; - } - } - - //FIXME-TC20100423 : REMOVE THIS! - protected enum Primitive { - BYTE("0"), - SHORT("0"), - INT("0"), - LONG("0"), - FLOAT("0."), - DOUBLE("0."), - CHAR("''"), - BOOLEAN("false"); - - private String value; - - Primitive(String value) { - this.value = value; - } - - public String getValue() { - return value; - } - } -} Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -25,7 +25,6 @@ package org.nuiton.topia.generator; -import java.util.LinkedHashSet; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -34,7 +33,6 @@ import org.nuiton.eugene.GeneratorUtil; import org.nuiton.eugene.ModelPropertiesUtil; import org.nuiton.eugene.java.JavaGeneratorUtil; -import org.nuiton.eugene.models.Model; import org.nuiton.eugene.models.object.ObjectModel; import org.nuiton.eugene.models.object.ObjectModelAssociationClass; import org.nuiton.eugene.models.object.ObjectModelAttribute; @@ -54,6 +52,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -168,16 +167,6 @@ } /** - * @param attr the attribute to inspece - * @return the name of the name in db of the reverse attribute - * @deprecated since 2.5, prefer use the methode {@link #getReverseDbName(ObjectModelAttribute)} - */ - @Deprecated - public static String getReverseDBName(ObjectModelAttribute attr) { - return getReverseDbName(attr); - } - - /** * Obtain the reverse db name of an attribute. * <p/> * If attribute has a specific reverse attribute, use his db name, otherwise @@ -233,29 +222,6 @@ * Cherche si le tagvalue {@link TopiaTagValues#TAG_GENERATE_OPERATOR_FOR_DAO_HELPER} a été * activé dans le model. * - * @param element l'élément à tester - * @param model le modele utilisé - * @return {@code true} si le tag value trouvé dans le modèle, {@code false} - * sinon. - * @since 2.4.1 - * @deprecated since 2.5, prefer use the method {@link #shouldGenerateStandaloneEnumForDAOHelper(ObjectModel)} - */ - @Deprecated - public static boolean shouldGnerateStandaloneEnumForDAOHelper( - ObjectModelElement element, - ObjectModel model) { - return shouldGenerateStandaloneEnumForDAOHelper(model); -// String tagValue = GeneratorUtil.findTagValue( -// TopiaTagValues.TAG_GENERATE_STANDALONE_ENUM_FOR_DAO_HELPER, element, model); -// boolean generate = GeneratorUtil.notEmpty(tagValue) && -// Boolean.valueOf(tagValue); -// return generate; - } - - /** - * Cherche si le tagvalue {@link TopiaTagValues#TAG_GENERATE_OPERATOR_FOR_DAO_HELPER} a été - * activé dans le model. - * * @param model le modele utilisé * @return {@code true} si le tag value trouvé dans le modèle, {@code false} * sinon. @@ -335,13 +301,6 @@ ObjectModel model) { String value = getNotGenerateToStringTagValue(clazz, model); return StringUtils.isEmpty(value); -// String value; -// value = model.getTagValue(TAG_NOT_GENERATE_TO_STRING); -// if (value != null && !value.trim().isEmpty()) { -// return false; -// } -// value = clazz.getTagValue(TAG_NOT_GENERATE_TO_STRING); -// return value == null || value.trim().isEmpty(); } @@ -358,25 +317,6 @@ ObjectModel model) { String value = getSortAttributeTagValue(clazz, model); return "true".equals(value); -// String value; -// value = clazz.getTagValue(TopiaTagValues.TAG_SORT_ATTRIBUTE); -// if (value == null || value.trim().isEmpty() || -// "false".equals(value.trim())) { -// return false; -// } -// if ("true".equals(value.trim())) { -// return true; -// } -// -// value = model.getTagValue(TopiaTagValues.TAG_SORT_ATTRIBUTE); -// if (value == null || value.trim().isEmpty() || -// "false".equals(value.trim())) { -// return false; -// } -// if ("true".equals(value.trim())) { -// return true; -// } -// return true; } /** @@ -425,18 +365,6 @@ } } - /** - * Cherches et renvoie le copyright a utiliser sur le model. - * - * @param model le modele utilisé - * @return le texte du copyright ou null$ - * @deprecated since 2.5 never use anywhere - */ - @Deprecated - public static String getCopyright(Model model) { - return findTagValue(TopiaTagValues.TAG_COPYRIGHT, null, model); - } - public static <Type extends ObjectModelElement> Collection<Type> getElementsWithStereotype( Collection<Type> elements, String... stereotypes) { Collection<Type> result = new ArrayList<Type>(); @@ -477,10 +405,6 @@ return attributes; } -// public static String capitalize(String s) { -// return StringUtils.capitalize(s); -// } - public static boolean isAssociationClassDoublon(ObjectModelAttribute attr) { return attr.getReverseAttribute() != null && attr.getDeclaringElement().equals( @@ -505,7 +429,7 @@ } ObjectModelClass clazz = model.getClass(type); if (isEntity(clazz)) { - //tchemit-2011-09-12 What ever abstract or not, we alwyas use an Impl + //tchemit-2011-09-12 What ever abstract or not, we always use an Impl type += "Impl"; // if (shouldBeAbstract(clazz)) { // type += "Abstract"; @@ -1168,19 +1092,6 @@ /** * Check if the given classifier has the - * {@link TopiaStereoTypes#STEREOTYPE_SERVICE} stereotype. - * - * @param classifier classifier to test - * @return {@code true} if stereotype was found, {@code false otherwise} - * @see TopiaStereoTypes#STEREOTYPE_SERVICE - * @since 2.5 - */ - public static boolean hasServiceStereotype(ObjectModelClassifier classifier) { - return classifier.hasStereotype(TopiaStereoTypes.STEREOTYPE_SERVICE); - } - - /** - * Check if the given classifier has the * {@link TopiaStereoTypes#STEREOTYPE_DAO} stereotype. * * @param classifier classifier to test @@ -1234,7 +1145,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_PERSISTENCE_TYPE} * tag value on the given classifier. - * <p/> * * @param classifier classifier to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1249,7 +1159,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_INHERITANCE_STRATEGY} * tag value on the given classifier. - * <p/> * * @param classifier classifier to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1267,7 +1176,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_DB_NAME} * tag value on the given classifier. - * <p/> * * @param element classifier to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1282,7 +1190,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_SCHEMA_NAME} * tag value on the given classifier. - * <p/> * * @param classifier classifier to seek * @param model model to seek @@ -1298,7 +1205,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_SCHEMA_NAME} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @param model model to seek @@ -1314,7 +1220,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_LENGTH} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1329,7 +1234,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_ANNOTATION} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1341,11 +1245,9 @@ return value; } - /** * Obtain the value of the {@link TopiaTagValues#TAG_ACCESS} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1360,7 +1262,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_NATURAL_ID} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1375,7 +1276,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_NATURAL_ID_MUTABLE} * tag value on the given classifier. - * <p/> * * @param classifier classifier to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1390,7 +1290,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_INVERSE} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1405,7 +1304,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_LAZY} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1420,7 +1318,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_FETCH} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1435,7 +1332,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_ORDER_BY} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1450,7 +1346,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_NOT_NULL} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1465,7 +1360,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_PROXY_INTERFACE} * tag value on the given classifier. - * <p/> * * @param classifier classifier to seek * @param model model to seek @@ -1495,7 +1389,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_SECURITY_CREATE} * tag value on the given classifier. - * <p/> * * @param classifier classifier to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1510,7 +1403,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_SECURITY_DELETE} * tag value on the given classifier. - * <p/> * * @param classifier classifier to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1525,7 +1417,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_SECURITY_LOAD} * tag value on the given classifier. - * <p/> * * @param classifier classifier to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1540,7 +1431,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_SECURITY_UPDATE} * tag value on the given classifier. - * <p/> * * @param classifier classifier to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1555,7 +1445,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_NOT_GENERATE_TO_STRING} * tag value on the given class. - * <p/> * * @param clazz class to seek * @param model model to seek @@ -1571,7 +1460,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_SORT_ATTRIBUTE} * tag value on the given classifier. - * <p/> * * @param classifier classifier to seek * @param model model to seek @@ -1587,7 +1475,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_GENERATE_STANDALONE_ENUM_FOR_DAO_HELPER} * tag value on the given model. - * <p/> * * @param model model to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1601,14 +1488,12 @@ /* Obtain the value of the {@link TopiaTagValues#TAG_GENERATE_OPERATOR_FOR_DAO_HELPER} * tag value on the given model. - * <p/> * * @param model model to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. * @see TopiaTagValues#TAG_GENERATE_OPERATOR_FOR_DAO_HELPER * @since 2.5 */ - public static String getGenerateOperatorForDAOHelperTagValue(ObjectModel model) { String value = findTagValue(TopiaTagValues.TAG_GENERATE_OPERATOR_FOR_DAO_HELPER, null, model); return value; @@ -1617,7 +1502,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_TYPE} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1632,7 +1516,6 @@ /** * Obtain the value of the {@link TopiaTagValues#TAG_SQL_TYPE} * tag value on the given attribute. - * <p/> * * @param attribute attribute to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1645,85 +1528,9 @@ } /** - * Obtain the value of the {@link TopiaTagValues#TAG_EXCEPTION_CLASS} - * tag value on the given interface. - * <p/> - * - * @param model model to seek - * @return the none empty value of the found tag value or {@code null} if not found nor empty. - * @see TopiaTagValues#TAG_EXCEPTION_CLASS - * @since 2.5 - */ - public static String getExceptionClassTagValue(ObjectModel model) { - String value = findTagValue(TopiaTagValues.TAG_EXCEPTION_CLASS, null, model); - return value; - } - - /** - * Obtain the value of the {@link TopiaTagValues#TAG_TRANSACTION} - * tag value on the given operation. - * <p/> - * - * @param operation operation to seek - * @return the none empty value of the found tag value or {@code null} if not found nor empty. - * @see TopiaTagValues#TAG_TRANSACTION - * @since 2.5 - */ - public static String getTransactionTagValue(ObjectModelOperation operation) { - String value = findTagValue(TopiaTagValues.TAG_TRANSACTION, operation, null); - return value; - } - - /** - * Obtain the value of the {@link TopiaTagValues#TAG_TRANSACTION} - * tag value on the given classifier. - * <p/> - * - * @param classifier classifier to seek - * @return the none empty value of the found tag value or {@code null} if not found nor empty. - * @see TopiaTagValues#TAG_TRANSACTION - * @since 2.5 - */ - public static String getTransactionTagValue(ObjectModelClassifier classifier) { - String value = findTagValue(TopiaTagValues.TAG_TRANSACTION, classifier, null); - return value; - } - - /** - * Obtain the value of the {@link TopiaTagValues#TAG_DO_COMMIT} - * tag value on the given operation. - * <p/> - * - * @param operation operation to seek - * @param model model to seek - * @return the none empty value of the found tag value or {@code null} if not found nor empty. - * @see TopiaTagValues#TAG_DO_COMMIT - * @since 2.5 - */ - public static String getDoCommitTagValue(ObjectModelOperation operation, ObjectModel model) { - String value = findTagValue(TopiaTagValues.TAG_DO_COMMIT, operation, model); - return value; - } - - /** - * Obtain the value of the {@link TopiaTagValues#TAG_ERROR_ARGS} - * tag value on the given operation. - * <p/> - * - * @param operation operation to seek - * @return the none empty value of the found tag value or {@code null} if not found nor empty. - * @see TopiaTagValues#TAG_ERROR_ARGS - * @since 2.5 - */ - public static String getErrorArgsTagValue(ObjectModelOperation operation) { - String value = findTagValue(TopiaTagValues.TAG_ERROR_ARGS, operation, null); - return value; - } - - /** * Obtains the value of the {@link TopiaTagValues#TAG_DAO_IMPLEMENTATION} * tag value on the given model. - * <p/> + * * @param model model to seek * @return the none empty value of the found tag value or {@code null} if not found nor empty. @@ -1741,7 +1548,7 @@ * given attribute. * * @param attribute attribute to test - * @param model model to test + * @param model model to test * @return none empty value of the found tag value or {@code null} if not found nor empty. * @see TopiaTagValues#TAG_INDEX_FOREIGN_KEYS * @since 2.6.5 Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaStereoTypes.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaStereoTypes.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaStereoTypes.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -59,17 +59,6 @@ String STEREOTYPE_DTO = "dto"; /** - * Stéréotype pour les interfaces devant être générées sous forme de - * services. - * - * @see ServiceTransformer - * @see TopiaGeneratorUtil#hasServiceStereotype(ObjectModelClassifier) - */ - @StereotypeDefinition(target = ObjectModelClassifier.class, - documentation = "To specify that a class is a Service") - String STEREOTYPE_SERVICE = "service"; - - /** * Stéréotype pour les interfaces devant être générées sous forme de DAO. * * @see TopiaGeneratorUtil#hasDaoStereotype(ObjectModelClassifier) Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -25,13 +25,11 @@ package org.nuiton.topia.generator; import org.nuiton.eugene.EugeneTagValues; -import org.nuiton.eugene.models.Model; import org.nuiton.eugene.models.object.ObjectModel; 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.ObjectModelElement; -import org.nuiton.eugene.models.object.ObjectModelOperation; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.persistence.TopiaEntityContextable; import org.nuiton.topia.persistence.TopiaEntityEnum; @@ -47,15 +45,6 @@ public interface TopiaTagValues extends EugeneTagValues { /** - * Tag pour ajouter specifier le copyright d'un fichier. - * - * @since 2.5 - * @deprecated since 2.5 only use in a deprecated method {@link TopiaGeneratorUtil#getCopyright(Model)} - */ - @Deprecated - String TAG_COPYRIGHT = "copyright"; - - /** * Tag pour le type de persistence. * * @see TopiaGeneratorUtil#getPersistenceType(ObjectModelClassifier) @@ -228,7 +217,7 @@ @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class}, documentation = "Configure the proxy interface on something else than the default implementation (null to use our default implementation, none to let hibernate deal it) (Hibernate mapping)") String TAG_PROXY_INTERFACE = "hibernateProxyInterface"; - + /** * Tag pour configurer la stategie d'heritage choisie. * <p/> @@ -236,7 +225,7 @@ * Autre valeur : * "subclass" > Single table per class hierarchy strategy * "joined-subclass" > Joined subclass strategy - * + * * @see TopiaGeneratorUtil#getPersistenceTypeTagValue(ObjectModelClassifier) * @since 3.0 */ @@ -352,18 +341,6 @@ String TAG_SQL_TYPE = "sqlType"; /** - * To use the legacy DAO generation. - * - * @see TopiaGeneratorUtil#getTypeTagValue(ObjectModelAttribute) - * @since 2.5 - * @deprecated since 2.5, prefer use the tag value - */ - @Deprecated - @TagValueDefinition(target = {ObjectModel.class}, - documentation = "Deprecated! To use the previous DAO implementation in generated DAO (use Criteria api)") - String TAG_USE_LEGACY_DAO = "useLegacyDAO"; - - /** * To specify the abstract dao to use. * <p/> * If none given, will use the {@code org.nuiton.topia.persistence.TopiaDAOImpl}. @@ -377,70 +354,13 @@ documentation = "Sets the fully qualified name of the DAO implementation to use in generated DAO (default is DAOImpl (base on TopiaQuery))") String TAG_DAO_IMPLEMENTATION = "daoImplementation"; - /** - * Tag pour specifier l'exception principale de l'application. - * Utiliser dans le ServiceTransformer ou QueryHelperTransformer pour etre - * automatiquement jeter - * depuis les methodes des services. - * - * @see ServiceTransformer - * @see QueryHelperTransformer - * @see TopiaGeneratorUtil#getExceptionClassTagValue(ObjectModel) - * @since 2.3.2 - */ - @TagValueDefinition(target = {ObjectModel.class}, - documentation = "Sets the fully qualified name of the exception to generate in Services and QueryHelper") - String TAG_EXCEPTION_CLASS = "exceptionClass"; - - // ------------------------------------------------------------------------- - // ServiceTransformer specific tag values - // ------------------------------------------------------------------------- - - /** - * Tag pour specifier si une methode a besoin d'une transaction - * (TopiaContext) ou non - * - * @see ServiceTransformer - * @see TopiaGeneratorUtil#getTransactionTagValue(ObjectModelClassifier) - * @see TopiaGeneratorUtil#getTransactionTagValue(ObjectModelOperation) - * @since 2.3.1 - */ - @TagValueDefinition(target = {ObjectModelClassifier.class, ObjectModelOperation.class}, - documentation = "Sets if an operation or a complete service required transaction (if set to true then a TopiaContext parameter will be added to methods)") - String TAG_TRANSACTION = "transaction"; - - /** - * Tag pour specifier si une methode a besoin d'un commit après son - * exécution. - * - * @see ServiceTransformer - * @see TopiaGeneratorUtil#getDoCommitTagValue(ObjectModelOperation, ObjectModel) - * @since 2.5 - */ - @TagValueDefinition(target = {ObjectModelOperation.class}, - documentation = "Sets if an operation needs a commit") - String TAG_DO_COMMIT = "doCommit"; - - /** - * Tag pour specifier si une methode de service a besoin d'arguments pour - * le message d'erreur ou non - * - * @see ServiceTransformer - * @see TopiaGeneratorUtil#getErrorArgsTagValue(ObjectModelOperation) - * @since 2.3.1 - */ - @TagValueDefinition(target = {ObjectModelOperation.class}, - documentation = "Sets if an operation required errors arguments ?") - String TAG_ERROR_ARGS = "errorArgs"; - - /** * Stéréotype pour les attributs avec multiplicité nécessitant la création d'un index. * * @see TopiaGeneratorUtil#getIndexForeignKeys(ObjectModelAttribute, ObjectModel) * @since 2.6.5 */ - @TagValueDefinition(target = {ObjectModel.class,ObjectModelAttribute.class}, + @TagValueDefinition(target = {ObjectModel.class, ObjectModelAttribute.class}, documentation = "Specifies if an nm-multiplicity attribute (or all nm-multiplicity attributes of a given model) needs an index in db (Hibernate mapping)") String TAG_INDEX_FOREIGN_KEYS = "indexForeignKeys"; Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -1,626 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -/* *##% - * ToPIA :: Persistence - * Copyright (C) 2004 - 2009 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>. - * ##%*/ - -package org.nuiton.topia.persistence; - -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Criteria; -import org.hibernate.FlushMode; -import org.hibernate.HibernateException; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.Order; -import org.hibernate.criterion.Restrictions; -import org.hibernate.metadata.ClassMetadata; -import org.nuiton.topia.TopiaException; - -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Surcharge du {@link TopiaDAOImpl} pour utiliser l'api criteria au lieu du hql - * pour tout ce qui est requétage. - * <p/> - * Created: 31 déc. 2005 13:10:34 - * - * @param <E> le type de l'entite - * @author bpoussin <poussin@codelutin.com> - * @author tchemit <chemit@codelutin.com> - * @deprecated since 2.6.12 Using the hibernate Criteria api is not a good idea as we wants to use in ToPIA next generation (version 3.0) jpa api. - */ -@Deprecated -public class TopiaDAOLegacy<E extends TopiaEntity> extends TopiaDAOImpl<E> { // TopiaDAOLegacy - - /** Logger. */ - private static Log log = LogFactory.getLog(TopiaDAOLegacy.class); - - @SuppressWarnings("unchecked") - protected E instanciateNew() throws TopiaException { - E result = newInstance(); - return result; - } - - @Override - public E create(Object... properties) throws TopiaException { - Map<String, Object> map = new HashMap<String, Object>(); - Object propertyName = null; - Object value; - try { - for (int i = 0; i < properties.length; ) { - propertyName = properties[i++]; - value = properties[i++]; - map.put((String) propertyName, value); - } - } catch (ArrayIndexOutOfBoundsException eee) { - throw new IllegalArgumentException("Wrong number of argument " - + properties.length - + ", you must have even number. Last property name read: " - + propertyName); - } catch (ClassCastException eee) { - throw new IllegalArgumentException( - "Wrong argument type, wait property name as String and have " - + propertyName.getClass().getName()); - } - - E result = create(map); - return result; - } - - @Override - public E findByPrimaryKey(Map<String, Object> keys) - throws TopiaException { - try { - // we used hibernate meta information for all persistence type - // it's more easy than create different for all persistence - ClassMetadata meta = getClassMetadata(); - if (meta.hasNaturalIdentifier()) { - E result = findByProperties(keys); - return result; - } - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - throw new TopiaException("La classe " + entityClass.getName() - + " n'a pas de cle primaire naturelle"); - - } - - @Override - public E findByPrimaryKey(Object... k) throws TopiaException { - // TODO pour une meilleur gestion des problemes a la compilation - // mettre un premier couple (propName, value) en argument ca evitera - // de pouvoir appeler cette methode sans argument - try { - ClassMetadata meta = getClassMetadata(); - if (meta.hasNaturalIdentifier()) { - int[] ikeys = meta.getNaturalIdentifierProperties(); - String[] pnames = meta.getPropertyNames(); - - Map<String, Object> keys = new HashMap<String, Object>(); - for (int ikey : ikeys) { - keys.put(pnames[ikey], k[ikey]); - } - - E result = findByProperties(keys); - return result; - } - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - throw new TopiaException("La classe " + entityClass.getName() - + " n'a pas de cle primaire naturelle"); - - } - - @Override - public E findByProperties(String propertyName, Object value, - Object... others) throws TopiaException { - Map<String, Object> properties = new HashMap<String, Object>(); - properties.put(propertyName, value); - Object name = null; - for (int i = 0; i < others.length; ) { - try { - name = others[i++]; - value = others[i++]; - properties.put((String) name, value); - } catch (ClassCastException eee) { - throw new IllegalArgumentException( - "Les noms des propriétés doivent être des chaines et non pas " - + propertyName.getClass().getName(), eee); - } catch (ArrayIndexOutOfBoundsException eee) { - throw new IllegalArgumentException( - "Le nombre d'argument n'est pas un nombre pair: " - + (others.length + 2) - + " La dernière propriété était: " + name, eee); - } - } - E result = findByProperties(properties); - return result; - } - - @Override - public List<E> findAllByProperties(String propertyName, Object value, - Object... others) throws TopiaException { - Map<String, Object> properties = new HashMap<String, Object>(); - properties.put(propertyName, value); - Object name = null; - for (int i = 0; i < others.length; ) { - try { - name = others[i++]; - value = others[i++]; - properties.put((String) name, value); - } catch (ClassCastException eee) { - throw new IllegalArgumentException( - "Les noms des propriétés doivent être des chaines et non pas " - + propertyName.getClass().getName(), eee); - } catch (ArrayIndexOutOfBoundsException eee) { - throw new IllegalArgumentException( - "Le nombre d'argument n'est pas un nombre pair: " - + (others.length + 2) - + " La dernière propriété était: " + name, eee); - } - } - List<E> result = findAllByProperties(properties); - return result; - } - -// @Override -// public E findContainsProperties(Map<String, Collection<?>> properties) -// throws TopiaException { -// List<E> results = findAllContainsProperties(properties); -// E result = null; -// if (results.size() > 0) { -// result = results.get(0); -// } -// return result; -// } -// -// @Override -// public E findContainsProperties(String propertyName, -// Collection values, Object... others) throws TopiaException { -// Map<String, Collection<?>> properties = new HashMap<String, Collection<?>>(); -// properties.put(propertyName, values); -// Object name = null; -// for (int i = 0; i < others.length;) { -// try { -// name = others[i++]; -// values = (Collection) others[i++]; -// properties.put((String) name, values); -// } catch (ClassCastException eee) { -// throw new IllegalArgumentException( -// "Les noms des propriétés doivent être des chaines et non pas " -// + propertyName.getClass().getName(), eee); -// } catch (ArrayIndexOutOfBoundsException eee) { -// throw new IllegalArgumentException( -// "Le nombre d'argument n'est pas un nombre pair: " -// + (others.length + 2) -// + " La dernière propriété était: " + name, eee); -// } -// } -// E result = findContainsProperties(properties); -// return result; -// } -// -// /** -// * Find all entities with a specific rule : -// * When the entity have a Collection type property, you want to find all entites where some values are -// * contained in the collection type property. -// * Example entity parameter : private Collection<Date> historicalDates; -// * You want some dates to be contained in historicalDates. -// * Collection<Date> myDates... -// * myDates.add(date1) ... -// * Map<String, Collection> properties = new HashMap<String,Collection>(); -// * properties.put("historicalDates",myDates); -// * findAllContainsProperties(properties); -// * @param properties -// * @return the list of entities corresponding to the request -// * @throws org.nuiton.topia.TopiaException if any pb -// */ -// @Override -// public List<E> findAllContainsProperties(Map<String, Collection<?>> properties) throws TopiaException { -// List<E> all = findAll(); -// List<E> result = new ArrayList<E>(); -// for (E e : all) { -// boolean ok = true; -// try { -// for (Entry<String, Collection<?>> kv : properties.entrySet()) { -// Collection entityValues = (Collection) PropertyUtils -// .getProperty(e, kv.getKey()); -// Collection values = kv.getValue(); -// if (!entityValues.containsAll(values)) { -// ok = false; -// break; -// } -// } -// } catch (IllegalAccessException eee) { -// ok = false; -// if (log.isWarnEnabled()) { -// log.warn( -// "Impossible d'acceder a la methode demandé pour l'obbjet " -// + e, eee); -// } -// } catch (InvocationTargetException eee) { -// ok = false; -// if (log.isWarnEnabled()) { -// log.warn( -// "Impossible d'acceder a la methode demandé pour l'obbjet " -// + e, eee); -// } -// } catch (NoSuchMethodException eee) { -// ok = false; -// if (log.isWarnEnabled()) { -// log.warn( -// "Impossible d'acceder a la methode demandé pour l'obbjet " -// + e, eee); -// } -// } -// if (ok) { -// result.add(e); -// } -// } -// return result; -// } -// -// @Override -// public List<E> findAllContainsProperties(String propertyName, -// Collection values, Object... others) throws TopiaException { -// Map<String, Collection<?>> properties = new HashMap<String, Collection<?>>(); -// properties.put(propertyName, values); -// Object name = null; -// for (int i = 0; i < others.length;) { -// try { -// name = others[i++]; -// values = (Collection) others[i++]; -// properties.put((String) name, values); -// } catch (ClassCastException eee) { -// throw new IllegalArgumentException( -// "Les noms des propriétés doivent être des chaines et non pas " -// + propertyName.getClass().getName(), eee); -// } catch (ArrayIndexOutOfBoundsException eee) { -// throw new IllegalArgumentException( -// "Le nombre d'argument n'est pas un nombre pair: " -// + (others.length + 2) -// + " La dernière propriété était: " + name, eee); -// } -// } -// List<E> result = findAllContainsProperties(properties); -// return result; -// } - - @Override - public List<E> findAllByProperty(String propertyName, Object value) - throws TopiaException { - Map<String, Object> properties = new HashMap<String, Object>(); - properties.put(propertyName, value); - List<E> result = findAllByProperties(properties); - return result; - } - - @Override - public E findByProperty(String propertyName, Object value) - throws TopiaException { - Map<String, Object> properties = new HashMap<String, Object>(); - properties.put(propertyName, value); - E result = findByProperties(properties); - return result; - } - - @Deprecated - private Criterion computeCriterions(Object... values) { - if (values == null) { - return null; - } - Criterion criterion = null; - for (Object value : values) { - criterion = or(criterion, computeCriterion(value)); - } - return criterion; - } - - @Deprecated - private Criterion computeCriterion(Object value) { - Criterion criterion = null; - SearchFields fields = entityClass.getAnnotation(SearchFields.class); - String textValue = "%" + value + "%"; - //textFields - String[] textFields = fields.txtFields(); - for (String propName : textFields) { - criterion = or(criterion, Restrictions.like(propName, textValue)); - } - //numFields - boolean isNumber = value instanceof Number; - if (value instanceof String) { - try { - Double.parseDouble((String) value); - isNumber = true; - } catch (NumberFormatException nfe) { - isNumber = false; - } - - } - if (isNumber) { - String[] numFields = fields.numFields(); - for (String propName : numFields) { - criterion = or(criterion, Restrictions.sqlRestriction(propName - + " like '" + textValue + "'")); - } - } - //boolFields - boolean isBoolean = value instanceof Boolean; - if (value instanceof String) { - isBoolean |= "true".equalsIgnoreCase((String) value) || "false" - .equalsIgnoreCase((String) value); - } - if (isBoolean) { - Boolean booleanValue; - if (value instanceof String) { - booleanValue = Boolean.valueOf((String) value); - } else { - booleanValue = (Boolean) value; - } - String[] boolFields = fields.numFields(); - for (String propName : boolFields) { - criterion = or(criterion, Restrictions.eq(propName, - booleanValue)); - } - } - //timeFields - String[] timeFields = fields.dateFields(); - for (String propName : timeFields) { - criterion = or(criterion, Restrictions.sqlRestriction(propName - + " like '" + textValue + "'")); - } - return criterion; - } - - @Deprecated - private Criterion or(Criterion crit1, Criterion crit2) { - if (crit1 == null) { - return crit2; - } - if (crit2 == null) { - return crit1; - } - return Restrictions.or(crit1, crit2); - } - - /** - * Cette methode appelle fireVetoableCreate et fireOnCreated - * Si vous la surchargé, faites attention a appeler le super - * ou a appeler vous aussi ces deux methodes. - */ - @Override - public E create(Map<String, Object> properties) throws TopiaException { - - E result = instanciateNew(); - - if (result instanceof TopiaEntityContextable) { - TopiaEntityContextable contextable = (TopiaEntityContextable)result; - contextable.setTopiaContext(getContext()); - } - - try { - for (Map.Entry<String, Object> e : properties.entrySet()) { - String propertyName = e.getKey(); - Object value = e.getValue(); - PropertyUtils.setProperty(result, propertyName, value); - } - } catch (IllegalAccessException eee) { - throw new IllegalArgumentException( - "Can't put properties on new Object", eee); - } catch (InvocationTargetException eee) { - throw new IllegalArgumentException( - "Can't put properties on new Object", eee); - } catch (NoSuchMethodException eee) { - throw new IllegalArgumentException( - "Can't put properties on new Object", eee); - } - - String topiaId = getContext().getTopiaIdFactory().newTopiaId(entityClass, result); - result.setTopiaId(topiaId); - - // on fait un save maintenant, car puisqu'on a creer l'entity au - // travers du DAO, on s'attend a l'avoir a disposition tout de - // suite pour les requetes sans avoir a faire un update dessus - getSession().save(result); - getContext().getFiresSupport().warnOnCreateEntity(result); - return result; - } - - @Override - public E findByTopiaId(String k) throws TopiaException { - return query(Restrictions.idEq(k)); - } - - @Override - public List<E> findAll() throws TopiaException { - try { - Criteria criteria = createCriteria(FlushMode.AUTO); - List<E> result = (List<E>) criteria.list(); - result = getContext().getFiresSupport().fireEntitiesLoad(context, - result); - return result; - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - } - - @Override - public List<String> findAllIds() throws TopiaException { -// List<String> findAll = context.findAll("select src.topiaId from " + entityClass.getSimpleName() + "Impl src"); - List<String> find = context.findAll("select src.topiaId from " + getEntityClass() + " src"); - return find; - } - - - @Override - public List<E> findAllWithOrder(String... propertyNames) - throws TopiaException { - try { - Criteria criteria = createCriteria(FlushMode.AUTO); - for (String propertyName : propertyNames) { - criteria.addOrder(Order.asc(propertyName)); - } - List<E> result = (List<E>) criteria.list(); - result = getContext().getFiresSupport().fireEntitiesLoad(context, - result); - return result; - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - } - - @Override - public E findByProperties(Map<String, Object> properties) - throws TopiaException { - return query(Restrictions.allEq(properties)); - } - - @Override - public List<E> findAllByProperties(Map<String, Object> properties) - throws TopiaException { - return queryAll(Restrictions.allEq(properties)); - } - - private List<E> queryAll(Criterion criterion) throws TopiaException { - try { - Criteria criteria = createCriteria(FlushMode.AUTO); - criteria.add(criterion); - List<E> result = (List<E>) criteria.list(); - result = getContext().getFiresSupport().fireEntitiesLoad(context, - result); - return result; - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - } - - private E query(Criterion criterion) throws TopiaException { - try { - Criteria criteria = createCriteria(FlushMode.AUTO); - criteria.add(criterion); - criteria.setMaxResults(1); - List<E> result = (List<E>) criteria.list(); - int sizeBefore = result != null ? result.size() : 0; - result = getContext().getFiresSupport().fireEntitiesLoad(context, - result); - int sizeAfter = result != null ? result.size() : 0; - if (sizeAfter < sizeBefore) { - if (log.isDebugEnabled()) { - log.debug((sizeBefore - sizeAfter) - + " element(s) removed. Filter entity: " - + entityClass.getName() + " - criterion: " - + criterion); - } - } - if (result != null && result.size() > 0) { - E elem = result.get(0); - return elem; - } - return null; - } catch (HibernateException eee) { - throw new TopiaException(eee); - } - } - - //FIXME : Commenté car impossible de trouver le bon Criterion - // ATTENTION ancienne methode du TopiaDAOAbstract deja presente dans le fichier - - // /* (non-Javadoc) - // * @see org.nuiton.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map) - // */ - // public E findContainsProperties(Map<String, Collection> properties) throws TopiaException { - // try { - // Criteria criteria = createCriteria(FlushMode.AUTO); - // for (Entry<String, Collection> entry : properties.entrySet()) { - // for (Object value : entry.getValue()) { - // criteria.add(Restrictions.eq(entry.getKey(), value)); - // } - // } - // criteria.setMaxResults(1); - // List<E> results = (List<E>)criteria.list(); - // if (results.size() > 0) { - // return (E)results.get(0); - // } else { - // return null; - // } - // } catch (HibernateException eee) { - // throw new TopiaException(eee); - // } - // } - // - // /* (non-Javadoc) - // * @see org.nuiton.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map) - // */ - // public List<E> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException { - // try { - // Criteria criteria = createCriteria(FlushMode.AUTO); - // for (Entry<String, Collection> entry : properties.entrySet()) { - // for (Object value : entry.getValue()) { - // criteria.add(Restrictions.eq(entry.getKey(), value)); - // } - // } - // List<E> result = (List<E>)criteria.list(); - // return result; - // } catch (HibernateException eee) { - // throw new TopiaException(eee); - // } - // } - - /** - * Renvoie un Criteria créé avec l'entityClass - * - * @param mode le FlushMode du Criteria - * @return le Criteria nouvellement créé - * @throws TopiaException if any pb - */ - private Criteria createCriteria(FlushMode mode) throws TopiaException { - Criteria criteria = getSession().createCriteria(entityClass); - criteria.setFlushMode(mode); - return criteria; - } - -} //TopiaDAOLegacy Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -46,7 +46,6 @@ import org.nuiton.topia.TopiaDatabase; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaTestDAOHelper; -import org.nuiton.topia.generator.DAOAbstractTransformer; import org.nuiton.topiatest.Personne; import org.nuiton.topiatest.PersonneDAO; @@ -126,7 +125,6 @@ * two entities have both inheritance. * * @throws TopiaException if any exception while manipulating db - * @see DAOAbstractTransformer */ @Test public void testDeleteEntityWithManyToManyRelation() throws TopiaException { Modified: trunk/topia-persistence/src/test/xmi/topiatest.properties =================================================================== --- trunk/topia-persistence/src/test/xmi/topiatest.properties 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-persistence/src/test/xmi/topiatest.properties 2013-07-14 20:13:25 UTC (rev 2770) @@ -27,11 +27,6 @@ model.tagvalue.constantPrefix=PROPERTY_ model.tagvalue.generateDTOTopiaId=true -# Do not use this tag value (deprecated since 2.5) -#model.tagvalue.useLegacyDAO=true -# Replaced by this one, which will allow us to switch to any dao implementation... -#model.tagvalue.daoImplementation=org.nuiton.topia.persistence.TopiaDAOLegacy - #org.nuiton.topiatest.Company.class.tagvalue.naturalIdMutable=false #org.nuiton.topiatest.Company.attribute.siret.tagvalue.naturalId=true #org.nuiton.topiatest.Company.attribute.name.tagvalue.naturalId=true Deleted: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -1,59 +0,0 @@ -/* - * #%L - * ToPIA :: Service Migration - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.migration; - -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.util.Version; - -import java.lang.reflect.Method; - -/** - * Default migration call back to use. - * <p/> - * Replace deprecated implementation {@code ManualMigrationCallback}. - * - * @author tchemit <chemit@codelutin.com> - * @version $Id$ - * @since 2.3.4 - * @deprecated since 2.5, use now the {@link TopiaMigrationCallbackByClass} or {@link TopiaMigrationCallbackByMethod}. - * <b>will not be replaced and remove before version {@code 2.6}</b>. - */ -@Deprecated -public abstract class TopiaMigrationCallback extends TopiaMigrationCallbackByMethod { - - @Deprecated - protected Method getMigrationMethod(Version version) throws NoSuchMethodException { - - String methodName = "migrateTo_" + version.getValidName(); - - Method m = getClass().getMethod(methodName, - TopiaContextImplementor.class, - boolean.class, - boolean.class - ); - return m; - } -} \ No newline at end of file Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -654,18 +654,6 @@ * * @param configuration the incoming hibernate configuration * @return the complete configuration usable by the service - * @deprecated since 2.5.3, prefer to use the method {@link #createHibernateConfiguration(Configuration)} - */ - @Deprecated - protected Configuration creaHibernateConfiguration(Configuration configuration) { - return createHibernateConfiguration(configuration); - } - - /** - * Creates the hibernate configuration to be used by the service. - * - * @param configuration the incoming hibernate configuration - * @return the complete configuration usable by the service * @since 2.5.3 */ protected Configuration createHibernateConfiguration(Configuration configuration) { Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -225,28 +225,6 @@ } /** - * Instantie un nouveau modèle de réplication en respectant l'ordre induit - * par les {@code contracts}. - * - * @param contracts les types d'entités - * @param topiaIds les ids à dupliquer - * @return le modèle crée mais non initialisé. - * @throws TopiaException pour toute erreur lors de la création du modèle - * @deprecated since 2.4.3, prefer use method {@link #createModel(TopiaContext, TopiaEntityEnum[], boolean, String...)} - */ - @Deprecated - public ReplicationModel createModelWithComputedOrder(TopiaEntityEnum[] contracts, - String... topiaIds) - throws TopiaException { - - ReplicationModel model; - - - model = new ReplicationModel(contracts, false, topiaIds); - return model; - } - - /** * Instantie un nouveau modèle de réplication pour toutes les entitées. * <p/> * Ici, l'ordre est toujours calculé. Deleted: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -1,265 +0,0 @@ -/* - * #%L - * ToPIA :: Service Replication - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.replication.operation; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.EntityOperator; -import org.nuiton.topia.persistence.util.TopiaEntityHelper; -import org.nuiton.topia.replication.TopiaReplicationContext; -import org.nuiton.topia.replication.TopiaReplicationOperation; -import org.nuiton.topia.replication.model.ReplicationModel; -import org.nuiton.topia.replication.model.ReplicationNode; -import org.nuiton.topia.replication.model.ReplicationOperationDef; -import org.nuiton.topia.replication.model.ReplicationOperationPhase; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -/** - * Pour attacher une association. - * <p/> - * L'opération requière 2 ou 3 paramètres : - * <ul> - * <li>{@code parameters[0]} : le nom de l'association à traiter</li> - * <li>{@code parameters[1]} : un drapeau pour savoir si on est sur le reverse - * de l'association</li> - * <li>{@code parameters[2]} : le noeud source de l'association - * (uniquement utilisé si on est sur le reverse d'une association)</li> - * </ul> - * <p/> - * Deux cas peuvent se produire : - * <p/> - * - le noeud de l'operation est la source de l'association, dans ce cas la - * {@code entities} contient les entites sources de l'association et on - * retrouve les entites associes a partir du type de l'association - * <p/> - * Ce premier cas est verifie quand {@code reverse} (le second parametre) est - * à {@code false}. - * <p/> - * - le noeud de l'operation est la cible de l'association, dans ce cas la - * {@code entities} contient les entities associées (cibles) de - * l'assocation et on retrouve les entities a partir d'un troisieme parametre - * qui donne le node source de l'association. - * <p/> - * Note : cette operation est interne, et n'est pas creable par l'utilisateur - * via la methode {@link #register(ReplicationModel, ReplicationNode, - * ReplicationOperationPhase, Object...)}. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.2.0 - * @deprecated since 2.5.2, this operation will be removed in version 2.6 and - * will not be replaced : prefer use the {@link AttachLink} instead. - */ -@Deprecated -public class AttachAssociation implements TopiaReplicationOperation { - - /** Logger */ - private static final Log log = LogFactory.getLog(AttachAssociation.class); - - @Override - public void register(ReplicationModel model, - ReplicationNode ownerNode, - ReplicationOperationPhase phase, - Object... parameters) { - -// throw new UnsupportedOperationException( -// _("topia.replication.error.operation.uncreatable", getClass())); - } - - @Override - public void run(TopiaReplicationContext replicationContext, - ReplicationOperationDef operationDef, - TopiaContextImplementor srcCtxt, - TopiaContextImplementor dstCtxt, - List<? extends TopiaEntity> entities) throws TopiaException { - - String name = (String) operationDef.getParameters()[0]; - Boolean reverse = (Boolean) operationDef.getParameters()[1]; - - if (log.isDebugEnabled()) { - log.debug("currentNode : " + operationDef.getNode() + - ", association name : " + name + " reverse ? " + reverse); - } - - ReplicationNode ownerNode; - ReplicationNode cibleNode; - - EntityOperator<? super TopiaEntity> ownerOperator; - - // contient la liste des ids d'association autorisees ici - List<String> associationsId; - - // contient la liste des ids des entite source de l'association - List<String> ownerIds; - if (reverse) { - - // on est en mode reverse, i.e : - // - le noeud courant est la cible - // - le noeud cible est passe en parametre - // - nodeEntities contient les entities sources - - ownerNode = (ReplicationNode) operationDef.getParameters()[2]; - ownerOperator = ownerNode.getOperator(); - - cibleNode = operationDef.getNode(); - - ownerIds = TopiaEntityHelper.getTopiaIdList(entities); - associationsId = replicationContext.getEntityIds(cibleNode); - - } else { - - // on est en mode non reverse, i.e : - // - le noeud courant est la source - // - le noeud cible est deduit de l'association sur le noeud source - // - nodeEntities contient les entities cibles - - ownerNode = operationDef.getNode(); - ownerOperator = ownerNode.getOperator(); - - cibleNode = ownerNode.getAssociations().get(name); - - ownerIds = replicationContext.getEntityIds(cibleNode); - associationsId = TopiaEntityHelper.getTopiaIdList(entities); - } - - if (ownerIds == null || ownerIds.isEmpty()) { - // pas de donnees a traiter - log.info("Nothing to attach..."); - return; - } - - // contient la liste des entites sources de l'association - List<? extends TopiaEntity> ownerEntities; - - // on recharge obligatoirement les donnees sources car elles ont pu etre - // modifiees (dettachement d'association ou autres) - // ils nous faut les entites telles qu'elles sont en base source - - ownerEntities = TopiaEntityHelper.getEntitiesList( - srcCtxt, - ownerIds.toArray(new String[ownerIds.size()]) - ); - - boolean shouldCommit = false; - - if (log.isInfoEnabled()) { - log.info("ownerNode : " + ownerNode + " , targetNode : " + - cibleNode + ", association : " + name); - } - if (log.isDebugEnabled()) { - log.debug("owner ids : " + ownerIds); - log.debug("association ids : " + associationsId); - } - - for (TopiaEntity src : ownerEntities) { - - // les association cibles connues pour l'entite sur la base source - Collection<?> targetEntities = - (Collection<?>) ownerOperator.get(name, src); - - if (targetEntities == null || targetEntities.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("no association '" + name + "' attached to " + - src); - } - // pas de donnees dans l'association - continue; - } - if (log.isDebugEnabled()) { - log.debug("will try to attach " + targetEntities.size() + - " association(s) '" + name + "' to " + src); - } - - // l'entite repliquee a laquelle on veut attacher l'association - - TopiaEntity dst = dstCtxt.findByTopiaId(src.getTopiaId()); - - // les association cibles connues pour l'entite sur la base - // destination - Collection<?> dstTargetEntities = (Collection<?>) - ownerOperator.get(name, dst); - - // les ids des entities deja associees - List<String> dstTargetAssociationsId = - dstTargetEntities == null ? - Collections.<String>emptyList() : - TopiaEntityHelper.getTopiaIdList( - (List<? extends TopiaEntity>) dstTargetEntities); - - boolean shouldUpdate = false; - for (Object a : targetEntities) { - - TopiaEntity assosiationSrc = (TopiaEntity) a; - - // on verifie que l'association doit etre rattachee - if (associationsId.contains(assosiationSrc.getTopiaId())) { - if (dstTargetAssociationsId.contains( - assosiationSrc.getTopiaId())) { - // deja attache - if (log.isDebugEnabled()) { - log.debug("already attached association '" + name + - "' : " + assosiationSrc); - } - continue; - - } - - // la donnees doit etre attachee - - TopiaEntity assosiationDst = - dstCtxt.findByTopiaId(assosiationSrc.getTopiaId()); - ownerOperator.addChild(name, dst, assosiationDst); - if (log.isDebugEnabled()) { - log.debug("will attach association '" + name + "' : " + - assosiationDst); - } - shouldUpdate = true; - } - - } - - if (shouldUpdate) { - if (log.isTraceEnabled()) { - log.trace("will update " + dst.getTopiaId()); - } - //FIXME: on ne peut pas updater l'objet car l'objet peut rentre - // en conflit dans la session hibernate - // cela fonctionne sans faire d'update (heureusement...) - //dst.update(); - shouldCommit = true; - } - } - - if (shouldCommit) { - dstCtxt.commitTransaction(); - } - } -} Modified: trunk/topia-service-replication/src/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation =================================================================== --- trunk/topia-service-replication/src/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-service-replication/src/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation 2013-07-14 20:13:25 UTC (rev 2770) @@ -3,6 +3,5 @@ # org.nuiton.topia.replication.operation.AttachLink org.nuiton.topia.replication.operation.LoadLink -org.nuiton.topia.replication.operation.AttachAssociation org.nuiton.topia.replication.operation.DettachAssociation org.nuiton.topia.replication.operation.Duplicate 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-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -585,36 +585,6 @@ } } - @Deprecated - protected void createUnsupportedBeforeOperation(TopiaEntityEnum contract, - TopiaEntity entity, - Class<? extends TopiaReplicationOperation> operationClass, - Object... parameters) throws Exception { - - getLog().info("entity " + entity.getTopiaId()); - prepareModel(entity.getTopiaId()); - - getModelBuilder().addBeforeOperation(model, contract, operationClass, parameters); - // on ne doit pas avoir le droit de creer cette operation - fail(); - } - - @Deprecated - protected void createUnsupportedAfterOperation( - TopiaEntityEnum contract, - TopiaEntity entity, - Class<? extends TopiaReplicationOperation> operationClass, - Object... parameters) throws Exception { - - getLog().info("entity " + entity.getTopiaId()); - prepareModel(entity.getTopiaId()); -// model = service.createModel(getContracts()); -// model.detectDirectDependencies(); - getModelBuilder().addAfterOperation(model, contract, operationClass, parameters); - // on ne doit pas avoir le droit de creer cette operation - fail(); - } - protected void createSupportedBeforeOperation(TopiaEntityEnum contract, TopiaEntity entity, Class<? extends TopiaReplicationOperation> operationClass, 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-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -41,7 +41,6 @@ import org.nuiton.topia.persistence.TopiaEntityEnum; import org.nuiton.topia.persistence.util.TopiaEntityIdsMap; import org.nuiton.topia.replication.model.ReplicationModel; -import org.nuiton.topia.replication.operation.AttachAssociation; import org.nuiton.topia.replication.operation.DettachAssociation; import org.nuiton.topia.replication.operation.Duplicate; import org.nuiton.topia.replication.operation.FakeOperation; @@ -143,7 +142,6 @@ getOperation(UncreatableOperation.class, true); getOperation(FakeOperation.class, true); getOperation(Duplicate.class, true); - getOperation(AttachAssociation.class, true); getOperation(DettachAssociation.class, true); } Modified: trunk/topia-service-security/pom.xml =================================================================== --- trunk/topia-service-security/pom.xml 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-service-security/pom.xml 2013-07-14 20:13:25 UTC (rev 2770) @@ -58,11 +58,6 @@ </dependency> <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-utils</artifactId> - </dependency> - - <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> @@ -83,11 +78,6 @@ </dependency> <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - - <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> </dependency> Deleted: trunk/topia-service-security/src/test/java/org/nuiton/topia/TestUtils.java =================================================================== --- trunk/topia-service-security/src/test/java/org/nuiton/topia/TestUtils.java 2013-07-14 19:41:45 UTC (rev 2769) +++ trunk/topia-service-security/src/test/java/org/nuiton/topia/TestUtils.java 2013-07-14 20:13:25 UTC (rev 2770) @@ -1,93 +0,0 @@ -/* - * #%L - * ToPIA :: Service Security - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia; - -import org.apache.commons.io.FileUtils; -import org.nuiton.util.FileUtil; - -import java.io.File; -import java.io.IOException; - -/** - * Une classe pour avoir des choses utiles pour tous les tests. - * - * @author Chatellier Eric - * <p/> - * Last update : $Date$ - * @deprecated since 2.5, everything usefull already exists in the class {@link TestHelper} from {@code topia-persistence module}. - */ -@Deprecated -public abstract class TestUtils { - - protected static File basedir; - - protected static File targetdir; - - protected static File dirDatabase; - - public static File getBasedir() { - if (basedir == null) { - String base = System.getProperty("basedir"); - if (base == null || base.isEmpty()) { - base = new File("").getAbsolutePath(); - } - basedir = new File(base); - System.out.println("basedir for test " + basedir); - } - return basedir; - } - - public static File getTargetdir() { - if (targetdir == null) { - targetdir = new File(getBasedir(), "target"); - System.out.println("targetdir for test " + targetdir); - } - return targetdir; - } - - /** - * Create a temp dir and init isis with that temp dir as database. - * - * @throws Exception - */ - public static void init() throws Exception { - - File mavenTestDir = new File(getTargetdir() + File.separator + "surefire-workdir"); - dirDatabase = FileUtil.createTempDirectory("topia-test", "", mavenTestDir); - } - - public static File getDirDatabase() { - return dirDatabase; - } - - /** Delete created temp directory. */ - public static void clean() throws IOException { - if (dirDatabase != null) { - FileUtils.deleteDirectory(dirDatabase); - dirDatabase = null; - } - } -}
participants (1)
-
tchemit@users.nuiton.org