r2957 - trunk/topia-templates/src/main/java/org/nuiton/topia/templates
Author: bleny Date: 2013-12-20 17:39:11 +0100 (Fri, 20 Dec 2013) New Revision: 2957 Url: http://nuiton.org/projects/topia/repository/revisions/2957 Log: fixes #2978 by adding isXXXNotEmpty and getXXXTopiaIds in generated Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java =================================================================== --- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java 2013-12-20 16:27:35 UTC (rev 2956) +++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java 2013-12-20 16:39:11 UTC (rev 2957) @@ -636,10 +636,10 @@ * @see #addMultipleRemoveOperation(ObjectModelAttribute) * @see #addMultipleClearOperation(ObjectModelAttribute, String, String) * @see #addMultipleGetOperation(ObjectModelAttribute, String) - * @see #addMultipleGetTopiaIdOperation(ObjectModelAttribute) + * @see #addMultipleGetByTopiaIdOperation(ObjectModelAttribute) * @see #addMultipleGetOperationFromEntity(ObjectModelAttribute) * @see #addMultipleSizeOperation(ObjectModelAttribute) - * @see #addMultipleIsEmptyOperation(ObjectModelAttribute) + * @see #addMultipleIsEmptyOperations(ObjectModelAttribute) */ protected void generatePropertyOperations(ObjectModelAttribute attribute) { @@ -709,7 +709,11 @@ if (TopiaGeneratorUtil.isEntity(attribute, model)) { // getXXXByTopiaId - addMultipleGetTopiaIdOperation(attribute); + addMultipleGetByTopiaIdOperation(attribute); + + // getXXXTopiaIds + addMultipleGetTopiaIdsOperation(attribute, collectionInterface, collectionImpl); + } if (attribute.hasAssociationClass()) { @@ -721,7 +725,7 @@ addMultipleSizeOperation(attribute); // isXXXEmpty - addMultipleIsEmptyOperation(attribute); + addMultipleIsEmptyOperations(attribute); } } @@ -959,7 +963,7 @@ // Interface operation ObjectModelOperation interfaceOperation = - addOperation(outputInterface, getJavaBeanMethodName("remove" , attrName), + addOperation(outputInterface, getJavaBeanMethodName("remove", attrName), void.class, ObjectModelJavaModifier.PACKAGE); ObjectModelParameter param = addParameter(interfaceOperation, attrType, attrName); @@ -1100,7 +1104,7 @@ ); } - protected void addMultipleGetTopiaIdOperation(ObjectModelAttribute attribute) { + protected void addMultipleGetByTopiaIdOperation(ObjectModelAttribute attribute) { String attrName = getPropertyName(attribute); String attrType = getPropertyType(attribute); @@ -1130,6 +1134,41 @@ ); } + protected void addMultipleGetTopiaIdsOperation(ObjectModelAttribute attribute, String collectionInterface, String collectionImpl) { + + String attrName = getPropertyName(attribute); + String attrType = getPropertyType(attribute); + + String getterName = getJavaBeanMethodName("get" , attrName); + + if (log.isDebugEnabled()) { + log.debug("Generate multiple 'getTopiaIds' operation for property : " + attrName + + " [" + attrType + "]"); + } + + // Interface operation + ObjectModelOperation interfaceOperation = + addOperation(outputInterface, getJavaBeanMethodName("get", attrName) + "TopiaIds", + collectionInterface + "<String>", ObjectModelJavaModifier.PACKAGE); + + // Implementation + ObjectModelOperation implOperation = + createImplOperation(interfaceOperation); + + setOperationBody(implOperation, "" +/*{ + <%=collectionInterface%><String> topiaIds = new <%=collectionImpl%><String>(); + <%=collectionInterface%><<%=attrType%>> tmp = <%=getterName%>(); + if (tmp != null) { + for (TopiaEntity topiaEntity : tmp) { + topiaIds.add(topiaEntity.getTopiaId()); + } + } + return topiaIds; + }*/ + ); + } + protected void addMultipleGetOperationFromEntity(ObjectModelAttribute attribute) { // reference to the real attribute name @@ -1199,7 +1238,7 @@ ); } - protected void addMultipleIsEmptyOperation(ObjectModelAttribute attribute) { + protected void addMultipleIsEmptyOperations(ObjectModelAttribute attribute) { String attrName = getPropertyName(attribute); @@ -1208,20 +1247,38 @@ } String sizeMethodName = getJavaBeanMethodName("size", attrName); - // Interface operation - ObjectModelOperation interfaceOperation = - addOperation(outputInterface, getJavaBeanMethodName("is", attrName)+ "Empty", + + // isEmpty Interface operation + String isEmptyMethodName = getJavaBeanMethodName("is", attrName) + "Empty"; + + ObjectModelOperation isEmptyInterfaceOperation = + addOperation(outputInterface, isEmptyMethodName, boolean.class, ObjectModelJavaModifier.PACKAGE); // Implementation - ObjectModelOperation implOperation = createImplOperation(interfaceOperation); + ObjectModelOperation isEmptyOperationImpl = createImplOperation(isEmptyInterfaceOperation); - setOperationBody(implOperation, "" + setOperationBody(isEmptyOperationImpl, "" /*{ int size = <%=sizeMethodName%>(); return size == 0; }*/ ); + + // isNotEmpty Interface operation + ObjectModelOperation isNotEmptyInterfaceOperation = + addOperation(outputInterface, getJavaBeanMethodName("is", attrName)+ "NotEmpty", + boolean.class, ObjectModelJavaModifier.PACKAGE); + + // Implementation + ObjectModelOperation isNotEmptyOperationImpl = createImplOperation(isNotEmptyInterfaceOperation); + + setOperationBody(isNotEmptyOperationImpl, "" +/*{ + boolean empty = <%=isEmptyMethodName%>(); + return ! empty; + }*/ + ); } // -------------------------------------------------------------------------
participants (1)
-
bleny@users.nuiton.org