Index: ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/GeneratorEntityServicesJava.java diff -u ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/GeneratorEntityServicesJava.java:1.5 ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/GeneratorEntityServicesJava.java:1.6 --- ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/GeneratorEntityServicesJava.java:1.5 Mon Jun 28 23:04:22 2004 +++ ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/GeneratorEntityServicesJava.java Tue Jun 29 10:23:26 2004 @@ -32,16 +32,14 @@ Util.getClassShortName(classComposite) + Util.toUpperCaseFirstLetter(attributeKeyName) ; primaryKeyAsParam += fieldName; primaryKeyNotNull += fieldName +" != null"; -/*{ -<%=ident%> <%=attributeKeyType%> <%=fieldName%>= (<%=attributeKeyType%>) context.get("<%=fieldName%>"); +/*{<%=ident%> <%=attributeKeyType%> <%=fieldName%>= (<%=attributeKeyType%>) context.get("<%=fieldName%>"); }*/ if (j <%=classCompositeName%> <%=Util.toLowerCaseFirstLetter(classCompositeName)%> = null; +/*{<%=ident%> <%=classCompositeName%> <%=Util.toLowerCaseFirstLetter(classCompositeName)%> = null; <%=ident%> if (<%=primaryKeyNotNull%> ){ <%=ident%> <%=Util.toLowerCaseFirstLetter(classCompositeName)%> = new <%=classCompositeName%>(delegator, <%=primaryKeyAsParam%>); <%=ident%> } @@ -60,16 +58,14 @@ String attributeKeyType = (String) listPrimaryKey.getType().get(j); primaryKeyAsParam = primaryKeyAsParam + attributeKeyName; primaryKeyNotNull = primaryKeyNotNull + attributeKeyName +" != null"; -/*{ -<%=ident%> <%=attributeKeyType%> <%=attributeKeyName%> = (<%=attributeKeyType%>) context.get("<%=attributeKeyName%>"); +/*{<%=ident%> <%=attributeKeyType%> <%=attributeKeyName%> = (<%=attributeKeyType%>) context.get("<%=attributeKeyName%>"); }*/ if (j if (<%=primaryKeyNotNull%> ){ +/*{<%=ident%> if (<%=primaryKeyNotNull%> ){ <%=ident%> <%=entityName%> <%=Util.toLowerCaseFirstLetter(entityName)%> = new <%=entityName%>(delegator, <%=primaryKeyAsParam%>); }*/ @@ -92,8 +88,7 @@ String subpackageName = (String)nameMap.get("subpackageName"); String entityName = clazz.getName(); -/*{ -// +/*{// // Copyright (c) 2004 Olivier Heintz - olivier.heintz@nereide.biz // Copyright (c) 2004 Nereide - www.nereide.biz // Copyright (c) 2004 Neogia - www.neogia.org @@ -113,7 +108,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // @author Olivier.Heintz@nereide.biz -// @version $Revision: 1.5 $ +// @version $Revision: 1.6 $ // @since 3.1 // // This file has been generated, and will be re-generated, @@ -179,8 +174,7 @@ // code generation for retreiving objetc generateRetreiveObject(output, clazz, AttrComposite, ident); // -/*{ - if (actionForm.equals("add") ){ +/*{ if (actionForm.equals("add") ){ if (<%=Util.toLowerCaseFirstLetter(entityName)%>.isAlreadyPersistant() ){ return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonIdAlreadyExist", locale)); } @@ -191,24 +185,25 @@ if (! Util.isPrimaryKey(attribute) ){ if (attribute.referenceClassifier() ){ if (attribute.getMaxMultiplicity() == 1){ - Map relationKeyName = Util.getRelationOneFieldName(model, attribute); - List listName = (List) relationKeyName.get("listName"); - ObjectModelClass classAssociated = (ObjectModelClass) ((Map) relationKeyName ).get("clazzAssociated"); - String primaryKeyAsParam = "", primaryKeyNotNull = ""; - for(Iterator iterList=listName.iterator(); iterList.hasNext(); ){ - Map fieldNameMap = (Map) iterList.next(); - String fieldName = (String) fieldNameMap.get("fieldName"); - primaryKeyAsParam += fieldName + ( iterList.hasNext() ? ", " : " " ); - primaryKeyNotNull += fieldName + ( iterList.hasNext() ? " != null && " : " != null " ); - String fieldType = (String) fieldNameMap.get("fieldType"); -/*{ - - <%=fieldType%> <%=fieldName%> = (<%=fieldType%>) context.get("<%=fieldName%>"); + if (! (attribute.getReverseAttribute() != null && attribute.getReverseAttribute().isComposite() ) ){ // so this attribute is in the primaryKey so already defined + Map relationKeyName = Util.getRelationOneFieldName(model, attribute, clazz); + List listName = (List) relationKeyName.get("listName"); + ObjectModelClass classAssociated = (ObjectModelClass) ((Map) relationKeyName ).get("clazzAssociated"); + String primaryKeyAsParam = "", primaryKeyNotNull = ""; +/*{ +}*/ + for(Iterator iterList=listName.iterator(); iterList.hasNext(); ){ + Map fieldNameMap = (Map) iterList.next(); + String fieldName = (String) fieldNameMap.get("fieldName"); + primaryKeyAsParam += fieldName + ( iterList.hasNext() ? ", " : " " ); + primaryKeyNotNull += fieldName + ( iterList.hasNext() ? " != null && " : " != null " ); + String fieldType = (String) fieldNameMap.get("fieldType"); +/*{ <%=fieldType%> <%=fieldName%> = (<%=fieldType%>) context.get("<%=fieldName%>"); }*/ - } -/*{ - if (<%=primaryKeyNotNull%> ) <%=Util.toLowerCaseFirstLetter(entityName)%>.set<%=classAssociated.getName()%>(<%=primaryKeyAsParam%>); + } +/*{ if (<%=primaryKeyNotNull%> ) <%=Util.toLowerCaseFirstLetter(entityName)%>.set<%=classAssociated.getName()%>(<%=primaryKeyAsParam%>); }*/ + } }else{ // TODO : methode get add remove for item of the list } @@ -216,7 +211,6 @@ String attOfbizJavaType = Util.getOfbizJavaType(attribute); String attributeName = attribute.getName(); /*{ - <%=attOfbizJavaType%> <%=attributeName%> = (<%=attOfbizJavaType%>) context.get("<%=attributeName%>"); if (<%=attributeName%> != null ) <%=Util.toLowerCaseFirstLetter(entityName)%>.set<%=Util.toUpperCaseFirstLetter(attributeName)%>(<%=attributeName%>); }*/ @@ -224,7 +218,6 @@ } } /*{ - if (<%=Util.toLowerCaseFirstLetter(entityName)%>.store() ) result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); else return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonDatabaseProblem", locale)); } @@ -249,8 +242,7 @@ }*/ ident = " "; generateRetreiveObject(output, clazz, AttrComposite, ident); -/*{ - if (! <%=Util.toLowerCaseFirstLetter(entityName)%>.isAlreadyPersistant() ){ +/*{ if (! <%=Util.toLowerCaseFirstLetter(entityName)%>.isAlreadyPersistant() ){ return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonIdDoesNotExist", locale)); } if (<%=Util.toLowerCaseFirstLetter(entityName)%>.remove() ) result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); Index: ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/GeneratorEntityObjectJava.java diff -u ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/GeneratorEntityObjectJava.java:1.6 ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/GeneratorEntityObjectJava.java:1.7 --- ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/GeneratorEntityObjectJava.java:1.6 Sat Jun 26 17:18:33 2004 +++ ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/GeneratorEntityObjectJava.java Tue Jun 29 10:23:26 2004 @@ -27,8 +27,7 @@ String entityName = clazz.getName(); String varEntityName = Util.toLowerCaseFirstLetter(entityName); -/*{ -// +/*{// // Copyright (c) 2004 Olivier Heintz - olivier.heintz@nereide.biz // Copyright (c) 2004 Nereide - www.nereide.biz // Copyright (c) 2004 Neogia - www.neogia.org @@ -48,7 +47,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // @author Olivier.Heintz@nereide.biz -// @version $Revision: 1.6 $ +// @version $Revision: 1.7 $ // @since 3.1 // // This file has been generated, and will be re-generated, @@ -84,8 +83,7 @@ if (AttrComposite != null){ classComposite = (ObjectModelClass) AttrComposite.getDeclaringElement(); String classCompositeName = classComposite.getName(); -/*{ - protected <%=classCompositeName%> <%=Util.toLowerCaseFirstLetter(classCompositeName)%>; +/*{ protected <%=classCompositeName%> <%=Util.toLowerCaseFirstLetter(classCompositeName)%>; }*/ } @@ -101,8 +99,7 @@ primaryKeyAsParam = primaryKeyAsParam + attributeKeyType + " " + attributeKeyName; primaryKeyAsMap = primaryKeyAsMap + "\"" + attributeKeyName +"\", " + attributeKeyName; primaryKeyNotNull += attributeKeyName + " != null"; -/*{ - protected <%=attributeKeyType%> <%=attributeKeyName%>; +/*{ protected <%=attributeKeyType%> <%=attributeKeyName%>; }*/ if (j(GenericValue <%=varEntityName%>){ if (<%=varEntityName%> != null ){ @@ -124,8 +120,7 @@ }*/ if (AttrComposite != null ){ String fieldCompositeName = Util.toLowerCaseFirstLetter(classComposite.getName()); -/*{ - this.<%=fieldCompositeName%> = <%=fieldCompositeName%>; +/*{ this.<%=fieldCompositeName%> = <%=fieldCompositeName%>; }*/ String pKeyCompositeNotNull = "", pKeyCompositeAsMap=""; ListPkAttribute listPKeyComposite = new ListPkAttribute(model, classComposite, false); @@ -138,33 +133,27 @@ String fieldName = prefixFieldName +Util.toUpperCaseFirstLetter(attributeKeyName); pKeyCompositeNotNull += fieldName + " != null && "; pKeyCompositeAsMap += "\"" + fieldName +"\", " + fieldName +", " ; -/*{ - <%=attributeKeyType%> <%=fieldName%> = null; +/*{ <%=attributeKeyType%> <%=fieldName%> = null; }*/ } primaryKeyNotNull = pKeyCompositeNotNull + primaryKeyNotNull; primaryKeyAsMap = pKeyCompositeAsMap + primaryKeyAsMap; -/*{ - if (<%=fieldCompositeName%> != null ){ +/*{ if (<%=fieldCompositeName%> != null ){ }*/ for (int j=0; j = <%=fieldCompositeName%>.get<%=Util.toUpperCaseFirstLetter(attributeKeyName)%>(); +/*{ <%=fieldName%> = <%=fieldCompositeName%>.get<%=Util.toUpperCaseFirstLetter(attributeKeyName)%>(); }*/ } -/*{ - } +/*{ } }*/ } for(int j=0; j = <%=(String) listPrimaryKey.getName().get(j)%>; +/*{ this.<%=(String) listPrimaryKey.getName().get(j)%> = <%=(String) listPrimaryKey.getName().get(j)%>; }*/ } -/*{ - try { +/*{ try { if (<%=primaryKeyNotNull%>) { this.<%=Util.toLowerCaseFirstLetter(entityName)%> = delegator.findByPrimaryKey("<%=entityName%>",UtilMisc.toMap(<%=primaryKeyAsMap%>) ); if (! exist() ){ @@ -195,7 +184,6 @@ }*/ for(int j=0; j get<%=Util.toUpperCaseFirstLetter((String) listPrimaryKey.getName().get(j) )%>(){ if (exist() ) return <%=(String) listPrimaryKey.getName().get(j)%>; return null; @@ -207,11 +195,11 @@ if (! Util.isPrimaryKey(attribute) ){ if (attribute.referenceClassifier() ){ if (attribute.getMaxMultiplicity() == 1){ - Map relationKeyName = Util.getRelationOneFieldName(model, attribute); + Map relationKeyName = Util.getRelationOneFieldName(model, attribute, clazz); List listName = (List) relationKeyName.get("listName"); ObjectModelClass classAssociated = (ObjectModelClass) ((Map) relationKeyName ).get("clazzAssociated"); primaryKeyAsParam=""; - ListPkAttribute listPrimaryKeyAssoc = new ListPkAttribute(model, classAssociated, false); + ListPkAttribute listPrimaryKeyAssoc = new ListPkAttribute(model, classAssociated, false, clazz); for(int j=0; j get<%=classAssociated.getName()%>(){ public GenericValue get<%=classAssociated.getName()%>(){ if (exist() ) try { @@ -240,19 +228,16 @@ Map fieldNameMap = (Map) iterList.next(); String fieldName = (String) fieldNameMap.get("fieldName"); String relFieldName = (String) fieldNameMap.get("relFieldName"); -/*{ - <%=Util.toLowerCaseFirstLetter(entityName)%>.put("<%=fieldName%>", _<%=relFieldName%>); +/*{ <%=Util.toLowerCaseFirstLetter(entityName)%>.put("<%=fieldName%>", _<%=relFieldName%>); }*/ } -/*{ - } +/*{ } return; } }*/ }else{ // association with MaxMultiplicity > 1 String associationEntityName = Util.toUpperCaseFirstLetter(attribute.getName() ); /*{ - public List get<%=associationEntityName%>s(){ if (exist() ) { try { @@ -271,7 +256,6 @@ } else { // it's a standard attribute String attOfbizJavaType = Util.getOfbizJavaType(attribute); /*{ - public <%=attOfbizJavaType%> get<%=Util.toUpperCaseFirstLetter(attribute.getName() )%>(){ if (exist() ) return (<%=attOfbizJavaType%>) <%=Util.toLowerCaseFirstLetter(entityName)%>.get("<%=attribute.getName()%>"); return null; @@ -285,8 +269,7 @@ } } } // TODO : add some controle or actions in the remove method when there are association -/*{ - public boolean store(){ +/*{ public boolean store(){ if (exist() ){ try { if (alreadyPersistant) <%=Util.toLowerCaseFirstLetter(entityName)%>.store(); Index: ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/Util.java diff -u ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/Util.java:1.23 ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/Util.java:1.24 --- ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/Util.java:1.23 Mon Jun 28 23:04:22 2004 +++ ofbiz-neogia-generators/src/java/org/nereide/ofbiz/neogia/generators/Util.java Tue Jun 29 10:23:26 2004 @@ -28,9 +28,9 @@ * Copyright Code Lutin * Copyright Nereide * Copyright Neogia -* @version $Revision: 1.23 $ +* @version $Revision: 1.24 $ * -* Last update : $Date: 2004/06/28 23:04:22 $ +* Last update : $Date: 2004/06/29 10:23:26 $ * by : $Author: holivier $ */ package org.nereide.ofbiz.neogia.generators; @@ -383,14 +383,14 @@ * It's use for defining relation in entitymodel * @param model * @param attribute + * @param _classOrigin to be able to test for not retreiving primaryKey when they coming from _classOrigin. * @return a Map with two key
    *
  • "clazzAssociated" : the class associated (the reference classifier or associationClass). *
  • "listName" : a list of map, in each map three key "fieldName", "relFieldName" and "fieldType" (OfbizJavaType). *
*/ - public static Map getRelationOneFieldName(ObjectModel model, ObjectModelAttribute attribute){ + public static Map getRelationOneFieldName(ObjectModel model, ObjectModelAttribute attribute, ObjectModelClass _classOrigin){ List relationOneFieldNames = new ArrayList(); - List listPrimaryKeyName = new ArrayList(), listPrimaryKeyType = new ArrayList(); ObjectModelClass clazzAssociated; // test if there are an association class for this atribute String prefix=null; @@ -406,11 +406,11 @@ clazzAssociated = (ObjectModelClass) attribute.getClassifier(); if (attribute.getMaxMultiplicity() == 1){ - Util.getListPrimaryKeyAttr(model, clazzAssociated, listPrimaryKeyName, listPrimaryKeyType, false); - for(int i=0; i