Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
July 2013
- 6 participants
- 62 discussions
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(a)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(a)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(a)codelutin.com>
- * @author tchemit <chemit(a)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(a)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(a)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;
- }
- }
-}
1
0
r2769 - in trunk: . topia-persistence topia-persistence/src/main/java/org/nuiton/topia topia-persistence/src/main/java/org/nuiton/topia/event topia-persistence/src/main/java/org/nuiton/topia/framework topia-persistence/src/site/rst/user topia-persistence/src/test/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 14 Jul '13
by tchemit@users.nuiton.org 14 Jul '13
14 Jul '13
Author: tchemit
Date: 2013-07-14 21:41:45 +0200 (Sun, 14 Jul 2013)
New Revision: 2769
Url: http://nuiton.org/projects/topia/repository/revisions/2769
Log:
refs #2088: remove i18n from ToPIA
refs #2748: Improve TopiaContext if necessary (add a dropSchema operation + event on listener for this too)
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextAdapter.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
trunk/topia-persistence/src/site/rst/user/start_using_api.rst
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/pom.xml 2013-07-14 19:41:45 UTC (rev 2769)
@@ -61,6 +61,7 @@
<!-- libs version -->
<eugeneVersion>2.6.4-SNAPSHOT</eugeneVersion>
<nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
+ <nuitonI18nVersion>2.5.1</nuitonI18nVersion>
<processorPluginVersion>1.3</processorPluginVersion>
<xmlrpcVersion>3.1.2</xmlrpcVersion>
<hibernateVersion>4.2.2.Final</hibernateVersion>
@@ -118,6 +119,12 @@
</dependency>
<dependency>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>nuiton-i18n</artifactId>
+ <version>${nuitonI18nVersion}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernateVersion}</version>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/pom.xml 2013-07-14 19:41:45 UTC (rev 2769)
@@ -54,6 +54,11 @@
</dependency>
<dependency>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>nuiton-i18n</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.nuiton.eugene</groupId>
<artifactId>eugene</artifactId>
</dependency>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -141,6 +141,14 @@
void updateSchema() throws TopiaException;
/**
+ * Permet de supprimer le schema de la base de données.
+ *
+ * @throws TopiaException if any exception
+ * @since 3.0
+ */
+ void dropSchema() throws TopiaException;
+
+ /**
* Return a new context containing his own transaction.
*
* @return new context with transaction
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextAdapter.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextAdapter.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextAdapter.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -34,7 +34,16 @@
* @since 2.3.4
*/
public class TopiaContextAdapter implements TopiaContextListener {
+
@Override
+ public void preDropSchema(TopiaContextEvent event) {
+ }
+
+ @Override
+ public void postDropSchema(TopiaContextEvent event) {
+ }
+
+ @Override
public void preCreateSchema(TopiaContextEvent event) {
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -34,7 +34,7 @@
* <ul>
* <li>createSchema</li>
* <li>updateSchema</li>
- * <li>...</li>
+ * <li>...</li>
* </ul>
*
* @author chatellier <chatellier(a)codelutin.com>
@@ -43,9 +43,25 @@
public interface TopiaContextListener extends EventListener {
/**
+ * Called before dropSchema call
+ *
+ * @param event event
+ * @since 3.0
+ */
+ void preDropSchema(TopiaContextEvent event);
+
+ /**
+ * Called after dropSchema call
+ *
+ * @param event event
+ * @since 3.0
+ */
+ void postDropSchema(TopiaContextEvent event);
+
+ /**
* Called before createSchema call
*
- * @param event evet
+ * @param event event
*/
void preCreateSchema(TopiaContextEvent event);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -86,8 +86,6 @@
import java.util.WeakHashMap;
import java.util.zip.GZIPInputStream;
-import static org.nuiton.i18n.I18n._;
-
/**
* Le TopiaContextImpl est le point d'entre pour acceder aux donnees. Il est
* configurer par un fichier de propriete
@@ -259,15 +257,15 @@
TopiaService service = (TopiaService) newInstance;
if (key.equals("topia.service." + service.getServiceName())) {
result.put(service.getServiceName(), service);
- log.info(_("topia.persistence.service.loaded",
+ log.info(String.format("Service '%1$s' loaded (implementation %2$s)",
key, classService));
} else {
- log.warn(_("topia.persistence.warn.service.not.loaded",
+ log.warn(String.format("The service with key '%1$s' has a different name '%2$s'! (service not activated)",
key, service.getServiceName()));
}
} catch (Throwable eee) {
String message =
- _("topia.persistence.error.service.unknown",
+ String.format("The service %1$s of type %2$s was not found.",
key, classService);
if (log.isDebugEnabled()) {
log.debug(message, eee);
@@ -283,7 +281,7 @@
protected void preInitServices(Map<String, TopiaService> services) {
for (TopiaService service : services.values()) {
if (!service.preInit(this)) {
- log.warn(_("topia.persistence.warn.service.not.preInit",
+ log.warn(String.format("The service named '%1$s' could not be post-initialized (service not activated)",
service.getServiceName()));
}
}
@@ -292,7 +290,7 @@
protected void postInitServices(Map<String, TopiaService> services) {
for (TopiaService service : services.values()) {
if (!service.postInit(this)) {
- log.warn(_("topia.persistence.warn.service.not.postInit",
+ log.warn(String.format("The service named '%1$s' could not be pre-initialized (service not activated)",
service.getServiceName()));
}
}
@@ -357,13 +355,13 @@
result = (E) getService(name);
} catch (Exception eee) {
throw new TopiaNotFoundException(
- _("topia.persistence.error.service.not.retreaved",
+ String.format("Could not retreave service %1$s for following reason: %2$s",
interfaceService, getProperExceptionMessage(eee)),
eee);
}
if (result == null) {
throw new TopiaNotFoundException(
- _("topia.persistence.error.service.not.found",
+ String.format("The service %1$s was not found.",
interfaceService));
}
return result;
@@ -377,7 +375,7 @@
String name = getServiceName(interfaceService);
result = serviceEnabled(name);
} catch (Exception eee) {
- String message = _("topia.persistence.warn.service.not.found",
+ String message = String.format("The service named '%1$s' could not be found for following reason: %2$s",
interfaceService, getProperExceptionMessage(eee));
if (log.isDebugEnabled()) {
log.debug(message, eee);
@@ -479,7 +477,7 @@
getFiresSupport().firePostCreateSchema(this);
} catch (HibernateException eee) {
throw new TopiaException(
- _("topia.persistence.error.create.schema",
+ String.format("Could not create schema for reason: %s",
eee.getMessage()), eee);
}
}
@@ -491,7 +489,7 @@
execute(true, false, false, true);
} catch (HibernateException eee) {
throw new TopiaException(
- _("topia.persistence.error.create.schema",
+ String.format("Could not show create schema for reason: %s",
eee.getMessage()), eee);
}
}
@@ -509,16 +507,32 @@
getFiresSupport().firePostUpdateSchema(this);
} catch (HibernateException eee) {
throw new TopiaException(
- _("topia.persistence.error.update.schema",
+ String.format("Could not update schema for reason: %s",
eee.getMessage()), eee);
}
}
@Override
+ public void dropSchema() throws TopiaException {
+ try {
+ boolean showSchema = false;
+ if (log.isDebugEnabled()) {
+ showSchema = true;
+ }
+ getFiresSupport().firePreCreateSchema(this);
+ new SchemaExport(getHibernateConfiguration()).execute(showSchema, true, true, false);
+ getFiresSupport().firePostCreateSchema(this);
+ } catch (HibernateException eee) {
+ throw new TopiaException(
+ String.format("Could not drop schema for reason: %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ @Override
public Session getHibernate() throws TopiaException {
if (hibernate == null) {
- throw new TopiaException(
- _("topia.persistence.error.no.hibernate.session"));
+ throw new TopiaException("No hibernate session");
}
return hibernate;
}
@@ -1209,8 +1223,8 @@
getFiresSupport().firePostRestoreSchema(this);
} catch (Exception eee) {
throw new TopiaException(String.format(
- "An error occurs while restore operation: %1$s",
- sql, eee.getMessage()), eee);
+ String.format("An error occurs while restore operation: %1$s : %2$s",
+ sql, eee.getMessage())), eee);
}
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -838,6 +838,47 @@
}
/**
+ * Notify topia context listeners for drop schema pre operation
+ *
+ * @param context topia context
+ * @since 3.0
+ */
+ public void firePreDropSchema(TopiaContext context) {
+ if (log.isDebugEnabled()) {
+ log.debug("firePreDropSchema");
+ }
+ TopiaContextEvent event = new TopiaContextEvent(context);
+ for (TopiaContextListener topiaContextListener : topiaContextListeners) {
+ try {
+ topiaContextListener.preDropSchema(event);
+ } catch (Exception eee) {
+ throw new TopiaVetoException(eee);
+ }
+ }
+ }
+
+ /**
+ * Notify topia context listeners for drop schema post operation
+ *
+ * @param context topia context
+ * @since 3.0
+ */
+ public void firePostDropSchema(TopiaContext context) {
+ if (log.isDebugEnabled()) {
+ log.debug("firePostDropSchema");
+ }
+ TopiaContextEvent event = new TopiaContextEvent(context);
+ for (TopiaContextListener topiaContextListener : topiaContextListeners) {
+ try {
+ topiaContextListener.postDropSchema(event);
+ } catch (Exception eee) {
+ throw new TopiaVetoException(eee);
+ }
+ }
+ }
+
+
+ /**
* Notify entities listeners for load operation
*
* @param <E> type of entities
Modified: trunk/topia-persistence/src/site/rst/user/start_using_api.rst
===================================================================
--- trunk/topia-persistence/src/site/rst/user/start_using_api.rst 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/site/rst/user/start_using_api.rst 2013-07-14 19:41:45 UTC (rev 2769)
@@ -150,45 +150,6 @@
Suppression d'une entité.
-Configuration I18n
-------------------
-
-ToPIA contient une internationnalisation des messages utilisateurs (logs).
-Il est préférable d'initialiser I18n pour accélérer la recherche des messages.
-
-Au démarrage de l'application ::
-
- I18nInitializer i18nInitializer = new DefaultI18nInitializer("library-bundle");
- I18n.init(i18nInitializer, new Locale("fr", "FR"));
-
-Configuration maven ::
-
- <!-- Plugin i18n pour gérer le bundle de messages -->
- <plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <version>${nuitonI18nVersion}</version>
- <executions>
- <!-- Cette exécution permet de rassembler tous les messages i18n
- dans un seul 'properties bundle' nommé library-bundle
- -->
- <execution>
- <id>make-bundle</id>
- <configuration>
- <bundleOutputName>library-bundle</bundleOutputName>
- </configuration>
- <goals>
- <goal>bundle</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
-Vous pourrez également utiliser `nuiton-i18n`_ pour l'internationnalisation de
-votre application.
-
-.. _nuiton-i18n: http://maven-site.nuiton.org/i18n/
-
Exemple complet
---------------
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -34,7 +34,6 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.nuiton.i18n.I18n;
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaNotFoundException;
@@ -45,7 +44,6 @@
import java.io.File;
import java.util.HashMap;
-import java.util.Locale;
import java.util.Map;
import java.util.Properties;
@@ -68,7 +66,6 @@
public static void setUpClass() throws Exception {
testBasedir = TopiaDatabase.getTestSpecificDirectory(TopiaContextImplTest.class, "dummy");
- I18n.init(null, Locale.FRENCH);
}
@Before
1
0
14 Jul '13
Author: tchemit
Date: 2013-07-14 21:40:12 +0200 (Sun, 14 Jul 2013)
New Revision: 2768
Url: http://nuiton.org/projects/topia/repository/revisions/2768
Log:
refs #2088: remove i18n from ToPIA
optimize dependencies
Modified:
trunk/topia-service-migration/pom.xml
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java
trunk/topia-service-security/pom.xml
trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java
Modified: trunk/topia-service-migration/pom.xml
===================================================================
--- trunk/topia-service-migration/pom.xml 2013-07-14 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-migration/pom.xml 2013-07-14 19:40:12 UTC (rev 2768)
@@ -70,6 +70,11 @@
</dependency>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
Modified: 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 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java 2013-07-14 19:40:12 UTC (rev 2768)
@@ -43,8 +43,6 @@
import java.util.Collections;
import java.util.List;
-import static org.nuiton.i18n.I18n._;
-
/**
* Pour attacher une association.
* <p/>
@@ -154,8 +152,7 @@
if (ownerIds == null || ownerIds.isEmpty()) {
// pas de donnees a traiter
- log.info(_("topia.replication.attachAssociation.nothing.to.do",
- ownerOperator));
+ log.info("Nothing to attach...");
return;
}
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 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2013-07-14 19:40:12 UTC (rev 2768)
@@ -27,7 +27,6 @@
import org.apache.commons.logging.Log;
import org.junit.Assert;
-import org.nuiton.i18n.I18n;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaContextImplementor;
@@ -49,7 +48,6 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
import java.util.Set;
/**
@@ -92,8 +90,6 @@
if (!init) {
- I18n.setDefaultLocale(Locale.FRANCE);
-
try {
context = createDb("source");
} catch (Exception e) {
@@ -620,9 +616,9 @@
}
protected void createSupportedBeforeOperation(TopiaEntityEnum contract,
- TopiaEntity entity,
- Class<? extends TopiaReplicationOperation> operationClass,
- Object... parameters) throws Exception {
+ TopiaEntity entity,
+ Class<? extends TopiaReplicationOperation> operationClass,
+ Object... parameters) throws Exception {
getLog().info("entity " + entity.getTopiaId());
prepareModel(entity.getTopiaId());
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java 2013-07-14 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java 2013-07-14 19:40:12 UTC (rev 2768)
@@ -37,8 +37,6 @@
import java.util.List;
-import static org.nuiton.i18n.I18n._;
-
/**
* @author tchemit <chemit(a)codelutin.com>
* @since 2.2.0
@@ -52,7 +50,8 @@
Object... parameters) {
throw new UnsupportedOperationException(
- _("topia.replication.error.operation.uncreatable", getClass()));
+ String.format("The operation %1$s is internal and can not be added using the api.",
+ getClass()));
}
@Override
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2013-07-14 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-security/pom.xml 2013-07-14 19:40:12 UTC (rev 2768)
@@ -68,6 +68,11 @@
</dependency>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
Modified: trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java
===================================================================
--- trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java 2013-07-14 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java 2013-07-14 19:40:12 UTC (rev 2768)
@@ -34,7 +34,6 @@
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
-import org.nuiton.i18n.I18n;
import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaContextFactory;
@@ -68,7 +67,6 @@
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.List;
-import java.util.Locale;
import java.util.Properties;
import static org.nuiton.topia.security.util.TopiaSecurityUtil.LOAD;
@@ -84,7 +82,7 @@
private static final Log log = LogFactory.getLog(TopiaSecurityTest.class);
- protected String dbPath;
+ protected String dbPath;
protected TopiaContext context;
@@ -106,7 +104,6 @@
@BeforeClass
public static void init() throws Exception {
- I18n.init(null, Locale.FRANCE);
tesDir = TestHelper.getTestBasedir(TopiaSecurityTest.class);
}
@@ -301,6 +298,7 @@
context.closeContext();
}
}
+
@Test
public void testLoginThimel() throws Exception {
/* Authentification de l'utilisateur Thimel */
1
0
r2767 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence
by tchemit@users.nuiton.org 14 Jul '13
by tchemit@users.nuiton.org 14 Jul '13
14 Jul '13
Author: tchemit
Date: 2013-07-14 08:57:56 +0200 (Sun, 14 Jul 2013)
New Revision: 2767
Url: http://nuiton.org/projects/topia/repository/revisions/2767
Log:
refs #2751: Improve TopiaDAO create methods (test if id is not blanck instead of just not null)
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-07-14 06:57:07 UTC (rev 2766)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-07-14 06:57:56 UTC (rev 2767)
@@ -317,7 +317,7 @@
try {
// first set topiaId
- if (entity.getTopiaId() == null) {
+ if (StringUtils.isBlank(entity.getTopiaId())) {
// only set id if not already on
String topiaId = getContext().getTopiaIdFactory().newTopiaId(entityClass, entity);
1
0
r2766 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 14 Jul '13
by tchemit@users.nuiton.org 14 Jul '13
14 Jul '13
Author: tchemit
Date: 2013-07-14 08:57:07 +0200 (Sun, 14 Jul 2013)
New Revision: 2766
Url: http://nuiton.org/projects/topia/repository/revisions/2766
Log:
refs #552: Clean api
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java 2013-07-13 22:05:49 UTC (rev 2765)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java 2013-07-14 06:57:07 UTC (rev 2766)
@@ -31,7 +31,9 @@
*
* @author fdesbois <fdesbois(a)codelutin.com>
* @version $Id$
+ * @deprecated since 3.0
*/
+@Deprecated
public interface EntityFilter {
String PROPERTY_START_INDEX = "startIndex";
1
0
Author: tchemit
Date: 2013-07-14 00:05:49 +0200 (Sun, 14 Jul 2013)
New Revision: 2765
Url: http://nuiton.org/projects/topia/repository/revisions/2765
Log:
fixes #2088: remove i18n from ToPIA
Removed:
trunk/topia-persistence/src/main/resources/i18n/
trunk/topia-service-migration/src/main/resources/i18n/
trunk/topia-service-replication/src/main/resources/i18n/
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java
trunk/topia-service-migration/pom.xml
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
trunk/topia-service-replication/pom.xml
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java
trunk/topia-service-security/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/pom.xml 2013-07-13 22:05:49 UTC (rev 2765)
@@ -62,16 +62,12 @@
<eugeneVersion>2.6.4-SNAPSHOT</eugeneVersion>
<nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
<processorPluginVersion>1.3</processorPluginVersion>
- <nuitonI18nVersion>2.5.1</nuitonI18nVersion>
<xmlrpcVersion>3.1.2</xmlrpcVersion>
<hibernateVersion>4.2.2.Final</hibernateVersion>
<sl4jVersion>1.7.5</sl4jVersion>
<h2Version>1.3.172</h2Version>
<hamcrestVersion>1.3</hamcrestVersion>
- <!-- i18n configuration -->
- <i18n.bundles>fr_FR,en_GB,es_ES</i18n.bundles>
-
</properties>
<!-- ************************************************************* -->
@@ -122,12 +118,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>nuiton-i18n</artifactId>
- <version>${nuitonI18nVersion}</version>
- </dependency>
-
- <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernateVersion}</version>
@@ -398,12 +388,6 @@
</plugin>
<plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <version>${nuitonI18nVersion}</version>
- </plugin>
-
- <plugin>
<artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-persistence/pom.xml 2013-07-13 22:05:49 UTC (rev 2765)
@@ -54,11 +54,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>nuiton-i18n</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.nuiton.eugene</groupId>
<artifactId>eugene</artifactId>
</dependency>
@@ -188,32 +183,6 @@
<artifactId>processor-maven-plugin</artifactId>
</plugin>
- <plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>parserJava</goal>
- <goal>gen</goal>
- </goals>
- <!-- restrict parsing beacause this is expensive -->
- <!-- if you want to parse more, add your package in includes -->
- <configuration>
- <treateDefaultEntry>false</treateDefaultEntry>
- <entries>
- <entry>
- <basedir>${maven.src.dir}/main/java</basedir>
- <includes>
- <include>org/nuiton/topia/framework/*.java</include>
- </includes>
- </entry>
- </entries>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
<!-- expose new plexus components -->
<plugin>
<groupId>org.codehaus.plexus</groupId>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -618,7 +618,7 @@
log.debug("Class " + classname + " not found");
}
throw new TopiaNotFoundException(
- _("topia.persistence.error.class.not.found",
+ String.format("Persistence class %1$s not found",
classname));
}
persistenceClasses.add(clazz);
@@ -671,12 +671,12 @@
throws TopiaException {
if (entityClass == null) {
throw new IllegalArgumentException(
- _("topia.persistence.error.null.param",
+ String.format("The method '%1$s' requires a non null parameter '%2$s'.",
"entityClass", "getDAO"));
}
if (equals(getRootContext())) {
throw new TopiaException(
- _("topia.persistence.error.rootContext.access"));
+ "You are on root context, you MUST open a transaction to perform any database access.");
}
if (getHibernateFactory().getClassMetadata(entityClass) == null &&
getHibernateFactory().getClassMetadata(
@@ -684,10 +684,10 @@
getHibernateFactory().getClassMetadata(
entityClass.getName() + "Abstract") == null) {
- log.info(_("topia.persistence.supported.classes.for.context",
+ log.info(String.format("List of supported persistence classes: %1$s",
getHibernateFactory().getAllClassMetadata().keySet()));
throw new TopiaException(
- _("topia.persistence.error.unsupported.class",
+ String.format("The following entity type %1$s is not managed by this context, you probably forgot to declare it.",
entityClass.getName()));
}
@@ -724,7 +724,7 @@
@Override
public TopiaContext beginTransaction() throws TopiaException {
- checkClosed(_("topia.persistence.error.context.is.closed"));
+ checkClosed("Context is closed, no operation is possible.");
TopiaContextImpl result = new TopiaContextImpl(this);
SessionFactory factory = getHibernateFactory();
@@ -758,7 +758,7 @@
}
throw new TopiaException(
- _("topia.persistence.error.open.transaction.failed",
+ String.format("An error occurs while asking a new transaction: %1$s",
eee.getMessage()),
eee);
}
@@ -774,10 +774,10 @@
@Override
public void commitTransaction() throws TopiaException {
if (equals(getRootContext())) {
- throw new TopiaException(_("topia.persistence.error.unsupported.operation.on.root.context",
+ throw new TopiaException(String.format("Unsupported operation %s on root context",
"commit"));
}
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"commit"));
try {
@@ -804,7 +804,7 @@
// hibernate = getHibernateFactory().openSession();
// hibernate.setFlushMode(FlushMode.NEVER);
} catch (Exception eee) {
- throw new TopiaException(_("topia.persistence.error.on.commit",
+ throw new TopiaException(String.format("An error occurs while commit operation: %1$s",
eee.getMessage()), eee);
}
}
@@ -812,10 +812,10 @@
@Override
public void rollbackTransaction() throws TopiaException {
if (equals(getRootContext())) {
- throw new TopiaException(_("topia.persistence.error.unsupported.operation.on.root.context",
+ throw new TopiaException(String.format("Unsupported operation %s on root context",
"rollback"));
}
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"rollback"));
try {
// for (TopiaDAO<? extends TopiaEntity> dao : daoCache.values()) {
@@ -842,7 +842,7 @@
} catch (HibernateException eee) {
throw new TopiaException(
- _("topia.persistence.error.on.rollback",
+ String.format("An error occurs while rollback operation: %1$s",
eee.getMessage()), eee);
}
}
@@ -850,7 +850,7 @@
@Override
public void closeContext() throws TopiaException {
// Throw exception if context is already closed
- checkClosed(_("topia.persistence.error.context.already.closed"));
+ checkClosed("Context was already closed");
// FD-20100421 : Ano #546 : no need to copy childContext, the
// {@link #getChildContext()} provides a thread-safe copy to iterate
@@ -926,7 +926,7 @@
@Override
public <E extends TopiaEntity> E findByTopiaId(String id) throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"findById"));
Class<E> entityClass = getTopiaIdFactory().getClassName(id);
@@ -937,7 +937,7 @@
@Override
public <E> List<E> findAll(String hql, Object... args) throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"findAll"));
try {
@@ -961,7 +961,7 @@
result = firesSupport.fireEntitiesLoad(this, result);
return result;
} catch (HibernateException eee) {
- throw new TopiaException(_("topia.persistence.error.on.query",
+ throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
hql, eee.getMessage()), eee);
}
}
@@ -969,7 +969,7 @@
@Override
public <E> List<E> find(String hql, int startIndex, int endIndex, Object... args)
throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"find"));
try {
@@ -995,7 +995,7 @@
result = firesSupport.fireEntitiesLoad(this, result);
return result;
} catch (HibernateException eee) {
- throw new TopiaException(_("topia.persistence.error.on.query",
+ throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
hql, eee.getMessage()), eee);
}
}
@@ -1003,7 +1003,7 @@
@Override
public <E> E findUnique(String hql, Object... paramNamesAndValues)
throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"findUnique"));
List<E> results = find(hql, 0, 1, paramNamesAndValues);
@@ -1033,7 +1033,7 @@
*/
@Override
public int execute(String hql, Object... args) throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"find"));
try {
@@ -1044,14 +1044,14 @@
int result = query.executeUpdate();
return result;
} catch (HibernateException eee) {
- throw new TopiaException(_("topia.persistence.error.on.query",
+ throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
hql, eee.getMessage()), eee);
}
}
@Override
public void add(TopiaEntity e) throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"add"));
String id = e.getTopiaId();
@@ -1063,17 +1063,16 @@
@Override
public void replicate(TopiaContext dstCtxt, Object... entityAndCondition)
throws TopiaException, IllegalArgumentException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicate"));
TopiaContextImpl dstContextImpl = (TopiaContextImpl) dstCtxt;
dstContextImpl.checkClosed(
- _("topia.persistence.error.unsupported.operation.on.closed.context",
+ String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicate"));
if (getRootContext().equals(dstContextImpl.getRootContext())) {
- throw new IllegalArgumentException(
- _("topia.persistence.error.replicate.on.same.context"));
+ throw new IllegalArgumentException("Can not do a replication operation on same database.");
}
String[] queries = buildQueries(entityAndCondition);
@@ -1091,7 +1090,7 @@
}
}
} catch (HibernateException eee) {
- throw new TopiaException(_("topia.persistence.error.on.replicate",
+ throw new TopiaException(String.format("An error occurs while a replication operation: %s",
eee.getMessage()), eee);
}
}
@@ -1100,16 +1099,15 @@
public <T extends TopiaEntity> void replicateEntity(TopiaContext dstCtxt,
T entity)
throws TopiaException, IllegalArgumentException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntity"));
TopiaContextImpl dstContextImpl = (TopiaContextImpl) dstCtxt;
- dstContextImpl.checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ dstContextImpl.checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntity"));
if (getRootContext().equals(dstContextImpl.getRootContext())) {
- throw new IllegalArgumentException(_(
- "topia.persistence.error.replicate.on.same.context"));
+ throw new IllegalArgumentException("Can not do a replication operation on same database.");
}
replicate0(dstContextImpl, entity);
}
@@ -1118,15 +1116,15 @@
public <T extends TopiaEntity> void replicateEntities(TopiaContext dstCtxt,
List<T> entities)
throws TopiaException, IllegalArgumentException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntities"));
TopiaContextImpl dstContextImpl = (TopiaContextImpl) dstCtxt;
- dstContextImpl.checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ dstContextImpl.checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntities"));
if (getRootContext().equals(dstContextImpl.getRootContext())) {
- throw new IllegalArgumentException(_("topia.persistence.error.replicate.on.same.context"));
+ throw new IllegalArgumentException("Can not do a replication operation on same database.");
}
replicate0(dstContextImpl, entities.toArray());
}
@@ -1147,7 +1145,7 @@
*/
@Override
public void backup(File file, boolean compress) throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"backup"));
try {
String options = "";
@@ -1160,8 +1158,8 @@
query.list();
} catch (Exception eee) {
- throw new TopiaException(_(
- "topia.persistence.error.on.backup",
+ throw new TopiaException(String.format(
+ "An error occurs while backup operation: %1$s",
eee.getMessage()), eee);
}
}
@@ -1177,7 +1175,7 @@
public void restore(File file) throws TopiaException {
// send event
getFiresSupport().firePreRestoreSchema(this);
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"restore"));
String sql = null;
@@ -1210,8 +1208,8 @@
// send event AFTER restore
getFiresSupport().firePostRestoreSchema(this);
} catch (Exception eee) {
- throw new TopiaException(_(
- "topia.persistence.error.on.restore",
+ throw new TopiaException(String.format(
+ "An error occurs while restore operation: %1$s",
sql, eee.getMessage()), eee);
}
}
@@ -1237,7 +1235,7 @@
root.finalize();
} catch (Throwable eee) {
throw new TopiaException(
- _("topia.persistence.error.on.clear", eee.getMessage()), eee);
+ String.format("Error %s on clear operation", eee.getMessage()), eee);
}
}
@@ -1259,7 +1257,7 @@
@Override
public boolean isSchemaExist(Class<?> clazz)
throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntity"));
boolean result = TopiaUtil.isSchemaExist(this, clazz.getName());
return result;
@@ -1452,7 +1450,7 @@
}
} catch (HibernateException eee) {
- throw new TopiaException(_("topia.persistence.error.on.replicate",
+ throw new TopiaException(String.format("An error occurs while a replication operation : %s",
eee.getMessage()), eee);
}
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -25,7 +25,7 @@
package org.nuiton.topia.persistence.util;
-import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.TopiaContext;
@@ -57,8 +57,6 @@
import java.util.SortedMap;
import java.util.TreeMap;
-import static org.nuiton.i18n.I18n._;
-
/**
* Une classe avec des méthodes utiles sur les entités.
*
@@ -109,10 +107,8 @@
TopiaDAO<E> dao, String topiaId) throws TopiaException,
IllegalArgumentException {
E entity = dao.findByTopiaId(topiaId);
- if (entity == null) {
- throw new IllegalArgumentException(
- "could not find entity with topiaId " + topiaId);
- }
+ Preconditions.checkArgument(entity != null,
+ "could not find entity with topiaId " + topiaId);
return entity;
}
@@ -150,14 +146,9 @@
public static <E extends TopiaEntity> void checkNotNullAndExistingEntity(
String paramName, E bean) throws IllegalStateException,
NullPointerException {
- if (bean == null) {
- throw new NullPointerException(paramName + " can not be null");
- }
- if (bean.getTopiaId() == null) {
- // can not create bean here
- throw new IllegalStateException(
- "can not create " + bean.getClass() + " here...");
- }
+ Preconditions.checkNotNull(bean, paramName + " can not be null");
+ Preconditions.checkState(bean.getTopiaId() != null,
+ "can not create " + bean.getClass() + " here...");
}
/**
@@ -172,14 +163,9 @@
public static <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(
String paramName, E bean) throws NullPointerException,
IllegalStateException {
- if (bean == null) {
- throw new NullPointerException(paramName + " can not be null");
- }
- if (bean.getTopiaId() != null) {
- // can not create bean here
- throw new IllegalStateException(
- "can not update " + bean.getClass() + " here...");
- }
+ Preconditions.checkNotNull(bean, paramName + " can not be null");
+ Preconditions.checkState(bean.getTopiaId() == null,
+ "can not update " + bean.getClass() + " here...");
}
/**
@@ -197,15 +183,9 @@
TopiaContext topiaContext,
URI resource) throws IOException,
TopiaException, NullPointerException {
- if (dbDirectory == null) {
- throw new NullPointerException("dbDirectory can not be null");
- }
- if (topiaContext == null) {
- throw new NullPointerException("topiaContext can not be null");
- }
- if (resource == null) {
- throw new NullPointerException("resource can not be null");
- }
+ Preconditions.checkNotNull(dbDirectory, dbDirectory + " can not be null");
+ Preconditions.checkNotNull(topiaContext, topiaContext + " can not be null");
+ Preconditions.checkNotNull(resource, resource + " can not be null");
File databaseDump;
if (resource.isOpaque()) {
@@ -265,12 +245,9 @@
public static void saveDB(
File gzipFile, TopiaContext topiaContext)
throws TopiaException, IOException, NullPointerException {
- if (gzipFile == null) {
- throw new NullPointerException("gzipFile can not be null");
- }
- if (topiaContext == null) {
- throw new NullPointerException("topiaContext can not be null");
- }
+ Preconditions.checkNotNull(gzipFile, gzipFile + " can not be null");
+ Preconditions.checkNotNull(topiaContext, topiaContext + " can not be null");
+
if (!gzipFile.getParentFile().exists()) {
if (!gzipFile.getParentFile().mkdirs()) {
throw new IOException("could not create directory " +
@@ -674,7 +651,9 @@
List<String> ids = Arrays.asList(expressions);
/** le dictionnaire des références détectées indexées par leur type */
- SortedMap<TopiaEntity, List<TopiaEntityRef>> refs;{
+ SortedMap<TopiaEntity, List<TopiaEntityRef>> refs;
+
+ {
refs = new TreeMap<TopiaEntity, List<TopiaEntityRef>>(
getTopiaIdComparator());
}
@@ -1145,11 +1124,8 @@
public static void checkNotNull(String methodName,
String parameterName,
Object value) {
- if (value == null) {
- throw new NullPointerException(
- _("topia.persistence.error.null.param",
- methodName, parameterName));
- }
+ Preconditions.checkNotNull(value,
+ String.format("The method '%1$s' requires a non null parameter '%2$s'.", methodName, parameterName));
}
public static void checkParameters(Class<?>[] paramsType,
@@ -1161,10 +1137,7 @@
}
public static void checkSize(int size, Object[] params) {
- if (params.length != size) {
- throw new IllegalArgumentException(
- _("topia.persistence.error.invalid.size", size, params.length));
- }
+ Preconditions.checkArgument(params.length == size, String.format("Invalid parameters size. Expected:%d but was:%d", size, params.length));
}
public static void checkType(Class<?>[] paramsType,
@@ -1172,17 +1145,11 @@
Object[] params) {
Class<?> requiredType = paramsType[index];
Object value = params[index];
- if (value == null) {
- throw new IllegalArgumentException(
- _("topia.persistence.error.null.param.in.array", index));
- }
- Class<?> foundType = value.getClass();
+ Preconditions.checkArgument(value != null, String.format("The parameter at index %d must not be null", index));
- if (!requiredType.isAssignableFrom(foundType)) {
- throw new IllegalArgumentException(
- _("topia.persistence.error.invalid.type.in.array",
- index, requiredType, foundType));
- }
+ Class<?> foundType = value.getClass();
+ Preconditions.checkArgument(requiredType.isAssignableFrom(foundType), String.format("The parameter at index %d is not the expected type. Expected:%s but was:%s",
+ index, requiredType, foundType));
}
/**
Modified: trunk/topia-service-migration/pom.xml
===================================================================
--- trunk/topia-service-migration/pom.xml 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-migration/pom.xml 2013-07-13 22:05:49 UTC (rev 2765)
@@ -65,11 +65,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>nuiton-i18n</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
@@ -129,19 +124,6 @@
<plugins>
- <plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>parserJava</goal>
- <goal>gen</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
</plugins>
</build>
</project>
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -38,8 +38,6 @@
import java.sql.SQLException;
import java.util.List;
-import static org.nuiton.i18n.I18n._;
-
/**
* Abstract migration callback.
*
@@ -115,7 +113,7 @@
try {
- log.info(_("topia.migration.start.migrate", v));
+ log.info(String.format("Start migration to version %s", v));
migrateForVersion(v, tx, showSql, showProgression);
@@ -124,7 +122,7 @@
} catch (Exception eee) {
// en cas d'erreur
- log.error("Migration impossible de la base", eee);
+ log.error("Could not migrate database", eee);
// rollback du travail en cours
tx.rollbackTransaction();
// propagation de l'erreur
@@ -168,7 +166,7 @@
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.start.sqls", sqls.length));
+ log.info(String.format("Will execute %1$s requests...", sqls.length));
}
if (showSql) {
StringBuilder buffer = new StringBuilder();
@@ -196,7 +194,7 @@
String message = "";
if (showProgression) {
- message = _("topia.migration.start.sql", index, max);
+ message = String.format("Executing request [%1$-4s/%2$-4s]", index, max);
}
if (showSql) {
message += "\n" + sql;
@@ -214,7 +212,7 @@
}
if (log.isDebugEnabled()) {
String message;
- message = _("topia.migration.end.sql", index, max, StringUtil.convertTime(System.nanoTime() - t0));
+ message = String.format("Request [%1$-4s/%2$-4s] executed in %3$s.", index, max, StringUtil.convertTime(System.nanoTime() - t0));
log.debug(message);
}
}
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-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -25,6 +25,7 @@
package org.nuiton.topia.migration;
+import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -51,8 +52,6 @@
import java.util.SortedSet;
import java.util.TreeSet;
-import static org.nuiton.i18n.I18n._;
-
/**
* Le moteur de migration proposé par topia. Il est basé sur un {@link AbstractTopiaMigrationCallback}
* qui donne la version de l'application, les version de mises à jour disponibles.
@@ -278,9 +277,9 @@
boolean complete = migrateSchema();
if (!complete) {
if (log.isErrorEnabled()) {
- log.error(_("topia.migration.migration.incomplete"));
+ log.error("Database migration not succesfully ended!");
}
- throw new TopiaException(_("topia.migration.migration.incomplete"));
+ throw new TopiaException("Database migration not succesfully ended!");
}
}
@@ -297,9 +296,9 @@
Version version = callback.getApplicationVersion();
- log.info(_("topia.migration.start.migration",
- version.getVersion(),
- dbVersion.getVersion())
+ log.info(String.format("Starting Topia Migration Service - Application version \\: %1$s, Database version \\: %2$s",
+ version.getVersion(),
+ dbVersion.getVersion())
);
if (log.isDebugEnabled()) {
@@ -317,7 +316,7 @@
if (versionTableExist && dbVersion.equals(version)) {
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.skip.migration.db.is.up.to.date"));
+ log.info("Database is up to date, no migration needed.");
}
// la base est a jour
return true;
@@ -325,7 +324,7 @@
// Aucune version existante, la base de données est vierge
if (versionTableExist && dbNotVersioned && migrateOnInit) {
- log.info(_("topia.migration.skip.migration.db.is.empty"));
+ log.info("Database is empty, no migration needed.");
// la base est vierge, aucune migration nécessaire
// mise à jour de la table tmsversion
saveApplicationVersion();
@@ -337,7 +336,7 @@
// on a trouvee une table depreciee tmsVersion avec la bonne version de base
// il suffit donc d'enregister la version dans la nouvelle table
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.skip.migration.db.is.up.to.date"));
+ log.info("Database is up to date, no migration needed.");
}
// la base est a jour mais il faut migrer la table
saveApplicationVersion();
@@ -348,7 +347,7 @@
new TreeSet<Version>(new VersionComparator());
allVersions.addAll(Arrays.asList(callback.getAvailableVersions()));
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.available.versions", allVersions));
+ log.info(String.format("Available versions: %1$s", allVersions));
}
// tell if migration is needed
@@ -367,11 +366,11 @@
if (versionsToApply.isEmpty()) {
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.skip.migration.no.version.to.apply"));
+ log.info("No version to apply, no migration needed.");
}
} else {
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.migrate.versions", versionsToApply));
+ log.info(String.format("Versions to apply: %1$s", versionsToApply));
}
// perform the migration
@@ -457,14 +456,14 @@
TMSVersionDAO.deleteAll(tx);
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.saving.db.version", version));
+ log.info(String.format("Saving new database version: %1$s", version));
}
// create new version and store it in table
TMSVersion tmsVersion =
TMSVersionDAO.create(tx, version.getVersion());
if (log.isDebugEnabled()) {
- log.debug("Created version : " + tmsVersion.getVersion());
+ log.debug("Created version: " + tmsVersion.getVersion());
}
tx.commitTransaction();
@@ -572,7 +571,7 @@
if (v != null) {
if (log.isDebugEnabled()) {
- log.debug("Legacy : " + _("topia.migration.detected.db.version", v));
+ log.debug(String.format("Legacy : detected database version: %1$s", v));
}
}
}
@@ -585,9 +584,9 @@
// etre detenu en local
v = Version.VZERO;
dbNotVersioned = true;
- log.info(_("topia.migration.db.not.versionned"));
+ log.info("Database version not found, so database schema is considered as V0");
} else {
- log.info(_("topia.migration.detected.db.version", v));
+ log.info(String.format("detected database version: %1$s", v));
}
dbVersion = v;
versionDetected = true;
@@ -642,16 +641,12 @@
protected String getSafeParameter(Properties config, String key) {
String value = config.getProperty(key, null);
- if (StringUtils.isEmpty(value)) {
- throw new IllegalStateException("'" + key + "' not set.");
- }
+ Preconditions.checkState(StringUtils.isNotEmpty(value), "'" + key + "' not set.");
return value;
}
protected void checkInit() {
- if (!init) {
- throw new IllegalStateException("le service n'est pas initialisé!");
- }
+ Preconditions.checkState(init, "Service was not initialized!");
}
/**
Modified: trunk/topia-service-replication/pom.xml
===================================================================
--- trunk/topia-service-replication/pom.xml 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-replication/pom.xml 2013-07-13 22:05:49 UTC (rev 2765)
@@ -60,11 +60,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>nuiton-i18n</artifactId>
- </dependency>
-
- <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
@@ -118,18 +113,6 @@
<build>
<plugins>
- <plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>parserJava</goal>
- <goal>gen</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
@@ -207,7 +190,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
- <version>2.4</version>
+ <version>${coberturaPluginVersion}</version>
</plugin>
</plugins>
</reporting>
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-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -38,8 +38,6 @@
import java.util.Arrays;
import java.util.Set;
-import static org.nuiton.i18n.I18n._;
-
/**
* Builder of {@link ReplicationModel}.
*
@@ -128,7 +126,7 @@
if (operation == null) {
throw new IllegalArgumentException(
- _("topia.replication.error.unkown.operation",
+ String.format("The operation %1$s is unknown, known operations are: %2$s",
operationClass.getSimpleName(),
Arrays.toString(getOperationProvider().getOperations()))
);
@@ -137,7 +135,7 @@
ReplicationNode node = model.getNode(type);
if (node == null) {
throw new IllegalArgumentException(
- _("topia.replication.error.unkown.owner.node",
+ String.format("The target node (of type %1$s) for operation %2$s is unknown, known nodes are: %3$s",
type,
operationClass.getSimpleName(),
model.getNodes())
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -44,8 +44,6 @@
import java.util.Collections;
import java.util.List;
-import static org.nuiton.i18n.I18n._;
-
/**
* Pour attacher une association.
* <p/>
@@ -132,8 +130,7 @@
if (ownerIds == null || ownerIds.isEmpty()) {
// pas de donnees a traiter
- log.info(_("topia.replication.attachAssociation.nothing.to.do",
- ownerOperator));
+ log.info("Nothing to attach...");
return;
}
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -41,8 +41,6 @@
import java.util.List;
-import static org.nuiton.i18n.I18n._;
-
/**
* Pour charger une association sur le noeud de l'operation.
* <p/>
@@ -84,8 +82,8 @@
if (!ownerNode.equals(operationDef.getNode())) {
throw new IllegalStateException(
- _("topia.replication.error.operation.loadLink.illegalSource",
- operationDef.getNode(), ownerNode));
+ String.format("The source node of loading association requires the node %1$s, but was %2$s.",
+ operationDef.getNode(), ownerNode));
}
if (log.isDebugEnabled()) {
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-security/pom.xml 2013-07-13 22:05:49 UTC (rev 2765)
@@ -63,11 +63,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>nuiton-i18n</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
1
0
r2764 - in trunk: topia-persistence/src/main/java/org/nuiton/topia/framework topia-persistence/src/test/java/org/nuiton/topia/framework topia-service-migration/src/main/java/org/nuiton/topia/migration
by tchemit@users.nuiton.org 13 Jul '13
by tchemit@users.nuiton.org 13 Jul '13
13 Jul '13
Author: tchemit
Date: 2013-07-13 23:18:30 +0200 (Sat, 13 Jul 2013)
New Revision: 2764
Url: http://nuiton.org/projects/topia/repository/revisions/2764
Log:
fixes #2759: Fix back behaviour before version 2.8 around TopiaUtil.isSchemaExist
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java 2013-07-13 21:09:40 UTC (rev 2763)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java 2013-07-13 21:18:30 UTC (rev 2764)
@@ -24,10 +24,12 @@
*/
package org.nuiton.topia.framework;
+import com.google.common.base.Supplier;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.Dialect;
+import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.service.ServiceRegistry;
@@ -42,6 +44,8 @@
import org.nuiton.util.RecursiveProperties;
import org.nuiton.util.Resource;
+import java.io.Closeable;
+import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.SQLException;
@@ -164,11 +168,16 @@
public static boolean isSchemaExist(TopiaContext tx,
String entityName) {
+ TopiaContextImplementor txi = (TopiaContextImplementor) tx;
+
+ ConnectionProviderSupplier connectionProviderSupplier =
+ new ConnectionProviderSupplier(((SessionFactoryImplementor) txi.getHibernateFactory()).getServiceRegistry());
+
boolean exist = false;
try {
- TopiaContextImplementor txi = (TopiaContextImplementor) tx;
+
Configuration configuration = txi.getHibernateConfiguration();
PersistentClass classMapping =
configuration.getClassMapping(entityName);
@@ -190,7 +199,7 @@
}
ConnectionProvider connectionProvider =
- getConnectionProvider(configuration);
+ connectionProviderSupplier.get();
Dialect dialect = Dialect.getDialect(configuration.getProperties());
@@ -198,7 +207,7 @@
try {
connection = connectionProvider.getConnection();
- DatabaseMetadata meta = new DatabaseMetadata(connection, dialect);
+ DatabaseMetadata meta = new DatabaseMetadata(connection, dialect, configuration);
TableMetadata tmd = meta.getTableMetadata(
testTable.getName(), testTable.getSchema(),
@@ -209,9 +218,7 @@
exist = true;
}
} finally {
- if (connection != null) {
- connection.close();
- }
+ connectionProvider.closeConnection(connection);
}
} catch (SQLException e) {
@@ -234,6 +241,9 @@
public static boolean isSchemaExist(Configuration configuration,
String entityName) {
+ ConnectionProviderSupplier connectionProviderSupplier =
+ new ConnectionProviderSupplier(configuration);
+
boolean exist = false;
try {
@@ -257,7 +267,7 @@
}
ConnectionProvider connectionProvider =
- getConnectionProvider(configuration);
+ connectionProviderSupplier.get();
Dialect dialect = Dialect.getDialect(configuration.getProperties());
@@ -265,7 +275,7 @@
try {
connection = connectionProvider.getConnection();
- DatabaseMetadata meta = new DatabaseMetadata(connection, dialect);
+ DatabaseMetadata meta = new DatabaseMetadata(connection, dialect, configuration);
TableMetadata tmd = meta.getTableMetadata(
testTable.getName(), testTable.getSchema(),
@@ -276,15 +286,20 @@
exist = true;
}
} finally {
- if (connection != null) {
- connection.close();
- }
+ connectionProvider.closeConnection(connection);
}
} catch (SQLException e) {
log.error("Cant connect to database", e);
}
+ // close connectionProviderSupplier
+ try {
+ connectionProviderSupplier.close();
+ } catch (IOException e) {
+ log.error("Cant close connection provider", e);
+ }
+
return exist;
}
@@ -299,10 +314,13 @@
*/
public static boolean isSchemaEmpty(Configuration configuration) {
+ ConnectionProviderSupplier connectionProviderSupplier =
+ new ConnectionProviderSupplier(configuration);
+
try {
ConnectionProvider connectionProvider =
- getConnectionProvider(configuration);
+ connectionProviderSupplier.get();
Dialect dialect = Dialect.getDialect(configuration.getProperties());
@@ -344,18 +362,109 @@
}
} finally {
- if (connection != null) {
- connection.close();
+ connectionProvider.closeConnection(connection);
+ }
+
+ } catch (SQLException e) {
+ log.error("Cant connect to database", e);
+ }
+
+ // close connectionProviderSupplier
+ try {
+ connectionProviderSupplier.close();
+ } catch (IOException e) {
+ log.error("Cant close connection provider", e);
+ }
+
+ return true;
+ }
+
+ /**
+ * Test if the db associated to the given {@code configuration} contaisn any of
+ * the dealed entities.
+ *
+ * @param tx topia context
+ * @return {@code true} if there is no schema for any of the dealed entities,
+ * {@code false} otherwise.
+ * @since 2.5.3
+ */
+ public static boolean isSchemaEmpty(TopiaContext tx) {
+
+
+ TopiaContextImplementor txi = (TopiaContextImplementor) tx;
+
+ Configuration configuration = txi.getHibernateConfiguration();
+
+ ConnectionProviderSupplier connectionProviderSupplier =
+ new ConnectionProviderSupplier(((SessionFactoryImplementor) txi.getHibernateFactory()).getServiceRegistry());
+
+ try {
+
+ ConnectionProvider connectionProvider =
+ connectionProviderSupplier.get();
+
+ Dialect dialect = Dialect.getDialect(configuration.getProperties());
+
+ Connection connection = null;
+ try {
+ connection = connectionProvider.getConnection();
+
+ DatabaseMetadata meta = new DatabaseMetadata(connection, dialect, configuration);
+
+ Iterator<?> itr = configuration.getClassMappings();
+ while (itr.hasNext()) {
+ PersistentClass classMapping = (PersistentClass) itr.next();
+ Table testTable = classMapping.getTable();
+
+ if (testTable == null) {
+ throw new IllegalArgumentException(
+ "could not find entity with name " +
+ classMapping.getClassName());
+ }
+
+
+ TableMetadata tmd = meta.getTableMetadata(
+ testTable.getName(), testTable.getSchema(),
+ testTable.getCatalog(), testTable.isQuoted());
+
+ if (tmd != null) {
+ //table exist
+
+ if (log.isDebugEnabled()) {
+ log.debug("Existing table found " +
+ testTable.getName() + " for entity " +
+ classMapping.getClassName() +
+ ", db is not empty.");
+ }
+
+ return false;
+ }
}
+
+ } finally {
+ connectionProvider.closeConnection(connection);
}
} catch (SQLException e) {
log.error("Cant connect to database", e);
}
+ // close connectionProviderSupplier
+ try {
+ connectionProviderSupplier.close();
+ } catch (IOException e) {
+ log.error("Cant close connection provider", e);
+ }
+
return true;
}
+ /**
+ * @param configuration
+ * @return
+ * @deprecated since 3.0, will be remove soon, do not use it, prefer use {@link ConnectionProviderSupplier}.
+ */
+ @Deprecated
protected static ConnectionProvider getConnectionProvider(Configuration configuration) {
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(
configuration.getProperties()).buildServiceRegistry();
@@ -371,4 +480,39 @@
public static String getSchemaName(Configuration config) {
return config.getProperty(TopiaContextFactory.CONFIG_DEFAULT_SCHEMA);
}
+
+ public static class ConnectionProviderSupplier implements Supplier<ConnectionProvider>, Closeable {
+
+ protected ServiceRegistry serviceRegistry;
+
+ protected ConnectionProvider connectionProvider;
+
+ protected final boolean inlineRegistry;
+
+ public ConnectionProviderSupplier(ServiceRegistry serviceRegistry) {
+ inlineRegistry = false;
+ this.serviceRegistry = serviceRegistry;
+ }
+
+ public ConnectionProviderSupplier(Configuration configuration) {
+ inlineRegistry = true;
+ this.serviceRegistry = new ServiceRegistryBuilder().applySettings(
+ configuration.getProperties()).buildServiceRegistry();
+ }
+
+ @Override
+ public ConnectionProvider get() {
+ if (connectionProvider == null) {
+ connectionProvider = serviceRegistry.getService(ConnectionProvider.class);
+ }
+ return connectionProvider;
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (inlineRegistry) {
+ ServiceRegistryBuilder.destroy(serviceRegistry);
+ }
+ }
+ }
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2013-07-13 21:09:40 UTC (rev 2763)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2013-07-13 21:18:30 UTC (rev 2764)
@@ -103,7 +103,7 @@
// FIXME echatellier 20130315 ce test fail depuis probablement a cause
// de hibernate.hbm2ddl.auto=update, à confirmer...
- assertFalse(actual);
+ assertTrue(actual);
TopiaContext tx = rootContext.beginTransaction();
tx.createSchema();
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-13 21:09:40 UTC (rev 2763)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-07-13 21:18:30 UTC (rev 2764)
@@ -608,10 +608,10 @@
try {
boolean result;
// get db real hibernate configuration
- Configuration rootConfiguration =
- rootContext.getHibernateConfiguration();
+// Configuration rootConfiguration =
+// rootContext.getHibernateConfiguration();
- result = TopiaUtil.isSchemaEmpty(rootConfiguration);
+ result = TopiaUtil.isSchemaEmpty(rootContext);
return result;
} catch (TopiaNotFoundException e) {
throw new RuntimeException(e);
1
0
r2763 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by tchemit@users.nuiton.org 13 Jul '13
by tchemit@users.nuiton.org 13 Jul '13
13 Jul '13
Author: tchemit
Date: 2013-07-13 23:09:40 +0200 (Sat, 13 Jul 2013)
New Revision: 2763
Url: http://nuiton.org/projects/topia/repository/revisions/2763
Log:
fixes #2341: Add warning about 'analyze' keyword
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java 2013-07-13 21:08:38 UTC (rev 2762)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java 2013-07-13 21:09:40 UTC (rev 2763)
@@ -76,6 +76,8 @@
AttributeNamesValidator attrValidator = new AttributeNamesValidator(
model);
+ attrValidator.addNameAndReason("analyze",
+ "Le nom d'attribut \"analyze\" est incompatible avec certains SGBD");
attrValidator.addNameAndReason("next",
"Le nom d'attribut \"next\" est incompatible avec HSQL");
attrValidator.addNameAndReason("value",
1
0
r2762 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 13 Jul '13
by tchemit@users.nuiton.org 13 Jul '13
13 Jul '13
Author: tchemit
Date: 2013-07-13 23:08:38 +0200 (Sat, 13 Jul 2013)
New Revision: 2762
Url: http://nuiton.org/projects/topia/repository/revisions/2762
Log:
fixes #2758: Improved TopiaConnectionProvider
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaConnectionProvider.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaConnectionProvider.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaConnectionProvider.java 2013-07-13 21:07:58 UTC (rev 2761)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaConnectionProvider.java 2013-07-13 21:08:38 UTC (rev 2762)
@@ -24,6 +24,18 @@
*/
package org.nuiton.topia.framework;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.HibernateException;
+import org.hibernate.cfg.Environment;
+import org.hibernate.internal.util.ReflectHelper;
+import org.hibernate.internal.util.config.ConfigurationHelper;
+import org.hibernate.service.UnknownUnwrapTypeException;
+import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
+import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
+import org.hibernate.service.spi.Configurable;
+import org.hibernate.service.spi.Stoppable;
+
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@@ -32,15 +44,6 @@
import java.util.Map;
import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.HibernateException;
-import org.hibernate.cfg.Environment;
-import org.hibernate.internal.util.ReflectHelper;
-import org.hibernate.internal.util.config.ConfigurationHelper;
-import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
-import org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
-
/**
* Customized connection provider.
* <p/>
@@ -62,22 +65,24 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.5.3
*/
-public class TopiaConnectionProvider extends DriverManagerConnectionProviderImpl {
+public class TopiaConnectionProvider implements ConnectionProvider, Configurable, Stoppable {//}, ServiceRegistryAwareService {
/** Logger. */
private static final Log log =
LogFactory.getLog(TopiaConnectionProvider.class);
+ private static final long serialVersionUID = -8190835231054317644L;
+
/**
* JDBC url of connection.
* <p/>
* This is a mandatory hibernate configuration vi the property
* {@link Environment#URL}.
*/
- private String url;
+ protected String url;
/** All grabbed connection properties */
- private Properties connectionProps;
+ protected Properties connectionProps;
/**
* Sql isolation level to use in connection.
@@ -86,7 +91,7 @@
*
* @see Connection#getTransactionIsolation()
*/
- private Integer isolation;
+ protected Integer isolation;
/**
* auto commit connection state.
@@ -95,7 +100,7 @@
*
* @see Connection#getAutoCommit()
*/
- private boolean autocommit;
+ protected boolean autocommit;
/**
* Size of connection pool.
@@ -103,18 +108,22 @@
* By default use {@code 20}, can be specify by using the hibernate
* configuration property {@link Environment#POOL_SIZE}.
*/
- private int poolSize;
+ protected int poolSize;
+ private boolean stopped;
+
/** Our pool of connections which are not closed and availables. */
- private final List<Connection> pool;
+ protected final List<Connection> pool;
+// protected ServiceRegistryImplementor serviceRegistry;
+
public TopiaConnectionProvider() {
pool = new ArrayList<Connection>();
}
@Override
public void configure(Map configurationValues) throws HibernateException {
- String driverClass = (String)configurationValues.get(Environment.DRIVER);
+ String driverClass = (String) configurationValues.get(Environment.DRIVER);
poolSize = ConfigurationHelper.getInt(Environment.POOL_SIZE, configurationValues, 20); //default pool size 20
if (log.isDebugEnabled()) {
@@ -129,7 +138,7 @@
if (isolation != null) {
if (log.isDebugEnabled()) {
log.debug("JDBC isolation level: " +
- Environment.isolationLevelToString(isolation));
+ Environment.isolationLevelToString(isolation));
}
}
@@ -154,7 +163,7 @@
}
}
- url = (String)configurationValues.get(Environment.URL);
+ url = (String) configurationValues.get(Environment.URL);
if (url == null) {
String msg = "JDBC URL was not specified by property " +
Environment.URL;
@@ -175,7 +184,7 @@
log.debug("connection properties: " + connectionProps);
} else if (log.isDebugEnabled()) {
log.debug("connection properties: " +
- ConfigurationHelper.maskOut(connectionProps, "password"));
+ ConfigurationHelper.maskOut(connectionProps, "password"));
}
}
@@ -272,8 +281,10 @@
@Override
protected void finalize() throws Throwable {
+ if (!stopped) {
+ stop();
+ }
super.finalize();
- stop();
}
@Override
@@ -293,7 +304,7 @@
}
}
pool.clear();
-
+ stopped = true;
}
@Override
@@ -325,4 +336,25 @@
return autocommit;
}
+// @Override
+// public void injectServices(ServiceRegistryImplementor serviceRegistry) {
+// this.serviceRegistry = serviceRegistry;
+// }
+
+ @Override
+ public boolean isUnwrappableAs(Class unwrapType) {
+ return ConnectionProvider.class.equals(unwrapType) ||
+ getClass().isAssignableFrom(unwrapType);
+ }
+
+ @Override
+ @SuppressWarnings({"unchecked"})
+ public <T> T unwrap(Class<T> unwrapType) {
+ if (ConnectionProvider.class.equals(unwrapType) ||
+ getClass().isAssignableFrom(unwrapType)) {
+ return (T) this;
+ } else {
+ throw new UnknownUnwrapTypeException(unwrapType);
+ }
+ }
}
1
0
r2761 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 13 Jul '13
by tchemit@users.nuiton.org 13 Jul '13
13 Jul '13
Author: tchemit
Date: 2013-07-13 23:07:58 +0200 (Sat, 13 Jul 2013)
New Revision: 2761
Url: http://nuiton.org/projects/topia/repository/revisions/2761
Log:
fixes #2757: ConnectionProvider is not closed when closing root context
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-13 13:16:04 UTC (rev 2760)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-13 21:07:58 UTC (rev 2761)
@@ -43,6 +43,8 @@
import org.hibernate.jdbc.Work;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
+import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
+import org.hibernate.service.spi.Stoppable;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.nuiton.topia.TopiaContext;
@@ -873,6 +875,12 @@
} else {
if (hibernateFactory != null) {
hibernateFactory.close();
+ // close connection provider if possible (http://nuiton.org/issues/2757)
+ ConnectionProvider service = ((SessionFactoryImplementor) hibernateFactory).getServiceRegistry().getService(ConnectionProvider.class);
+ if (service instanceof Stoppable) {
+ Stoppable stoppable = (Stoppable) service;
+ stoppable.stop();
+ }
closed = true;
TopiaContextFactory.removeContext(this);
log.debug("TopiaContext removed");
1
0