From: Vance K. <va...@us...> - 2006-07-01 10:13:03
|
User: vancek Date: 06/07/01 03:13:01 Modified: andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades EJB3AssociationEndFacadeLogicImpl.java andromda-ejb3/src/main/resources/templates/ejb3 GlobalMacros.vm EntityCompositePK.vsl Entity.vsl EntityEmbeddable.vsl andromda-ejb3/src/main/resources/META-INF/andromda profile.xml andromda-ejb3/src/main/uml EJB3MetafacadeModel.xml.zip Log: fix JIRA EJB-36 entities and composite PK implement Comparable and implement compareTo @Sort only set if collection interface is SortedSet Revision Changes Path 1.12 +47 -22 cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3AssociationEndFacadeLogicImpl.java Index: EJB3AssociationEndFacadeLogicImpl.java =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3AssociationEndFacadeLogicImpl.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -w -r1.11 -r1.12 --- EJB3AssociationEndFacadeLogicImpl.java 26 Jun 2006 14:40:34 -0000 1.11 +++ EJB3AssociationEndFacadeLogicImpl.java 1 Jul 2006 10:13:00 -0000 1.12 @@ -139,7 +139,7 @@ /** * Value for collections */ - private static final String COLLECTION_TYPE_COLLECTION = "collection"; + private static final String COLLECTION_TYPE_COLLECTION = "bag"; /** * Stores the valid collection types @@ -225,6 +225,10 @@ { getterSetterTypeName = mappings.getTo(UMLProfile.LIST_TYPE_NAME); } + else if (this.isCollection()) + { + getterSetterTypeName = mappings.getTo(UMLProfile.COLLECTION_TYPE_NAME); + } } else { @@ -581,7 +585,36 @@ } /** - * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleGetCollectionTypeImplementation() + * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic# + * handleGetCollectionTypeImplemenationClass() + */ + protected String handleGetCollectionTypeImplemenationClass() + { + String collectionTypeImplementationClass = null; + if (this.isMany()) + { + if (this.isSet()) + { + collectionTypeImplementationClass = String.valueOf( + this.getConfiguredProperty(SET_TYPE_IMPLEMENTATION)); + } + else if (this.isMap()) + { + collectionTypeImplementationClass = String.valueOf( + this.getConfiguredProperty(MAP_TYPE_IMPLEMENTATION)); + } + else if (this.isList() || this.isCollection()) + { + collectionTypeImplementationClass = String.valueOf( + this.getConfiguredProperty(LIST_TYPE_IMPLEMENTATION)); + } + } + return collectionTypeImplementationClass; + } + + /** + * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic# + * handleGetCollectionTypeImplementation() */ protected String handleGetCollectionTypeImplementation() { @@ -589,7 +622,8 @@ } /** - * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleGetCollectionTypeImplementation(java.lang.String) + * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic# + * handleGetCollectionTypeImplementation(java.lang.String) */ protected String handleGetCollectionTypeImplementation(String arg) { @@ -597,18 +631,7 @@ if (this.isMany()) { implementation.append("new "); - if (this.isSet()) - { - implementation.append(this.getConfiguredProperty(SET_TYPE_IMPLEMENTATION)); - } - else if (this.isMap()) - { - implementation.append(this.getConfiguredProperty(MAP_TYPE_IMPLEMENTATION)); - } - else if (this.isList() || this.isCollection()) - { - implementation.append(this.getConfiguredProperty(LIST_TYPE_IMPLEMENTATION)); - } + implementation.append(this.getCollectionTypeImplemenationClass()); // set this association end's type as a template parameter if required if (Boolean.valueOf(String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.ENABLE_TEMPLATING))) @@ -872,7 +895,8 @@ } /** - * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleGetDefaultCollectionInterface() + * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic# + * handleGetDefaultCollectionInterface() */ protected String handleGetDefaultCollectionInterface() { @@ -880,15 +904,16 @@ } /** - * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleIsDefaultCollectionInterfaceSortedSet() + * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic# + * handleIsCollectionInterfaceSortedSet() */ - protected boolean handleIsDefaultCollectionInterfaceSortedSet() + protected boolean handleIsCollectionInterfaceSortedSet() { - boolean isDefaultSortedSet = false; - if (StringUtils.equals(this.getDefaultCollectionInterface(), EJB3Globals.COLLECTION_INTERFACE_SORTED_SET)) + boolean isInterfaceSortedSet = false; + if (this.getGetterSetterTypeName().startsWith(EJB3Globals.COLLECTION_INTERFACE_SORTED_SET)) { - isDefaultSortedSet = true; + isInterfaceSortedSet = true; } - return isDefaultSortedSet; + return isInterfaceSortedSet; } } \ No newline at end of file 1.3 +57 -1 cartridges/andromda-ejb3/src/main/resources/templates/ejb3/GlobalMacros.vm Index: GlobalMacros.vm =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/main/resources/templates/ejb3/GlobalMacros.vm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- GlobalMacros.vm 1 Jun 2006 14:40:46 -0000 1.2 +++ GlobalMacros.vm 1 Jul 2006 10:13:01 -0000 1.3 @@ -7,6 +7,12 @@ ## identifier, must call accessor on PK object. ## #macro (renderEqualsMethod $class $className $attributeSet) + /** + * Indicates if the argument is of the same type and all values are equal. + * + * @param object The target object to compare with + * @return boolean True if both objects a 'equal' + */ public boolean equals(Object object) { #**##if ($attributeSet.empty) @@ -53,6 +59,11 @@ ## identifier, must call accessor on PK object. ## #macro (renderHashCodeMethod $class $attributeSet) + /** + * Returns a hash code value for the object + * + * @return int The hash code value + */ public int hashCode() { #**##if ($attributeSet.empty) @@ -89,6 +100,11 @@ ## identifier, must call accessor on PK object. ## #macro (renderToStringMethod $class $className $attributeSet) + /** + * Returns a String representation of the object + * + * @return String Textual representation of the object displaying name/value pairs for all attributes + */ public String toString() { #**##if ($attributeSet.empty) @@ -103,7 +119,7 @@ #* *##foreach ($attribute in $attributeSet) #* *##set ($attrType = $attribute.type) sb.append("${sep}#if ($class.compositePrimaryKeyPresent && $attribute.identifier)pk.#end${attribute.name}: "); - sb.append(#if ($class.compositePrimaryKeyPresent && $attribute.identifier)this.getPk().#end${attribute.getterName}()); + sb.append(#if ($class.compositePrimaryKeyPresent && $attribute.identifier)this.getPk().#end${attribute.getterName}()#if ($attribute.containsEmbeddedObject).toString()#end); #* *##set( $sep = ", " ) #* *##end## foreach sb.append(")"); @@ -111,3 +127,43 @@ #**##end## $attributeSet.empty } #end +## +## This macro will render the compareTo(Object o) method +## This is required since each entity implements Comparable<T> +## +#macro (renderCompareToMethod $class $className $identifiers) + /** + * @see java.lang.Comparable#compareTo(T) + */ + public int compareTo($className o) + { + int cmp = 0; +#**##if ($identifiers.size() > 1) + if (this.getPk() != null) + { + cmp = this.getPk().compareTo(o.getPk()); + } +#**##else +#* *##set ($identifier = $identifiers.iterator().next()) + if (this.${identifier.getterName}() != null) + { + cmp = this.${identifier.getterName}().compareTo(o.${identifier.getterName}()); + } +#**##end +#**##set ($attributes = $class.attributes) +#**##if (!$attributes.empty) + else + { +#* *##foreach ($attribute in $attributes) +#* *##if (!$attribute.type.primitive && !$attribute.type.arrayType && !$attribute.lob && !$attribute.identifier && !$attribute.containsEmbeddedObject) + if (this.${attribute.getterName}() != null) + { + cmp = (cmp != 0 ? cmp : this.${attribute.getterName}().compareTo(o.${attribute.getterName}())); + } +#* *##end +#* *##end + } +#**##end + return cmp; + } +#end 1.2 +29 -1 cartridges/andromda-ejb3/src/main/resources/templates/ejb3/EntityCompositePK.vsl Index: EntityCompositePK.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/main/resources/templates/ejb3/EntityCompositePK.vsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- EntityCompositePK.vsl 18 Jan 2006 08:46:04 -0000 1.1 +++ EntityCompositePK.vsl 1 Jul 2006 10:13:01 -0000 1.2 @@ -10,7 +10,8 @@ $entity.getDocumentation(" * ") */ @javax.persistence.Embeddable -public class ${entity.entityCompositePrimaryKeyName} implements java.io.Serializable +public class ${entity.entityCompositePrimaryKeyName} + implements java.io.Serializable, Comparable<${entity.entityCompositePrimaryKeyName}> { private static final long serialVersionUID = 1L; @@ -104,4 +105,31 @@ #**##end #end } + + /** + * @see java.lang.Comparable#compareTo(T) + */ + public int compareTo(${entity.entityCompositePrimaryKeyName} o) + { + int cmp = 0; +#set ($identifiers = $class.identifiers) +#if (!$identifiers.empty) +#**##foreach ($identifier in $identifiers) +#* *##if (!$identifier.type.primitive && !$identifier.type.arrayType && !$identifier.lob && !$identifier.containsEmbeddedObject) +#* *##if ($velocityCount == 1) + if (this.${identifier.getterName}() != null) + { + cmp = this.${identifier.getterName}().compareTo(o.${identifier.getterName}()); + } +#* *##else + if (this.${identifier.getterName}() != null) + { + cmp = (cmp != 0 ? cmp : this.${identifier.getterName}().compareTo(o.${identifier.getterName}())); + } +#* *##end +#* *##end +#**##end +#end + return cmp; + } } \ No newline at end of file 1.20 +2 -1 cartridges/andromda-ejb3/src/main/resources/templates/ejb3/Entity.vsl Index: Entity.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/main/resources/templates/ejb3/Entity.vsl,v retrieving revision 1.19 retrieving revision 1.20 diff -u -w -r1.19 -r1.20 --- Entity.vsl 14 Jun 2006 04:55:20 -0000 1.19 +++ Entity.vsl 1 Jul 2006 10:13:01 -0000 1.20 @@ -65,7 +65,7 @@ #end public#if ($entity.abstract) abstract#end class ${entity.entityName} extends ${entity.fullyQualifiedEntityEmbeddableName} - implements java.io.Serializable + implements java.io.Serializable, Comparable<${entity.entityName}> { /** @@ -198,4 +198,5 @@ #* *##end #**##end #end +#renderCompareToMethod($entity $entity.entityName $entity.identifiers) } \ No newline at end of file 1.37 +11 -19 cartridges/andromda-ejb3/src/main/resources/templates/ejb3/EntityEmbeddable.vsl Index: EntityEmbeddable.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/main/resources/templates/ejb3/EntityEmbeddable.vsl,v retrieving revision 1.36 retrieving revision 1.37 diff -u -w -r1.36 -r1.37 --- EntityEmbeddable.vsl 27 Jun 2006 05:20:29 -0000 1.36 +++ EntityEmbeddable.vsl 1 Jul 2006 10:13:01 -0000 1.37 @@ -121,10 +121,15 @@ extends ${entity.generalization.fullyQualifiedName} #**##end #end - implements java.io.Serializable +## +## Do not implement Comparable for (implicit or explicitly defined) mapped superclass +## or for a subclass in an inheritance hierarchy. +## + implements java.io.Serializable#if (!$entity.entityImplementationRequired && !$entity.embeddableSuperclass && !$entity.requiresGeneralizationMapping), Comparable<${entity.entityName}>#end## no newline #if (!$entity.interfaceAbstractions.empty) , $entity.implementedInterfaceList #end + { private static final long serialVersionUID = ${entity.serialVersionUID}L; @@ -598,7 +603,7 @@ #* *##if ($target.associationCacheEnabled) @org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.${target.cacheType}) #* *##end -#* *##if ($target.defaultCollectionInterfaceSortedSet) +#* *##if ($target.collectionInterfaceSortedSet) @org.hibernate.annotations.Sort(type = org.hibernate.annotations.SortType.NATURAL) #* *##end #* *##end @@ -716,7 +721,7 @@ #* *##if ($target.associationCacheEnabled) @org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.${target.cacheType}) #* *##end -#* *##if ($target.defaultCollectionInterfaceSortedSet) +#* *##if ($target.collectionInterfaceSortedSet) @org.hibernate.annotations.Sort(type = org.hibernate.annotations.SortType.NATURAL) #* *##end #* *##end @@ -784,26 +789,13 @@ #else #**##set ($entityName = $entity.entityName) #end - /** - * Indicates if the argument is of the same type and all values are equal. - * - * @param object The target object to compare with - * @return boolean True if both objects a 'equal' - */ #renderEqualsMethod($entity $entityName $entity.identifiers) - /** - * Returns a hash code value for the object - * - * @return int The hash code value - */ #renderHashCodeMethod($entity $entity.identifiers) - /** - * Returns a String representation of the object - * - * @return String Textual representation of the object displaying name/value pairs for all attributes - */ #renderToStringMethod($entity $entityName $entity.attributes) +#if (!$entity.entityImplementationRequired && !$entity.embeddableSuperclass && !$entity.requiresGeneralizationMapping) +#renderCompareToMethod($entity $entityName $entity.identifiers) +#end } \ No newline at end of file 1.32 +1 -0 cartridges/andromda-ejb3/src/main/resources/META-INF/andromda/profile.xml Index: profile.xml =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/main/resources/META-INF/andromda/profile.xml,v retrieving revision 1.31 retrieving revision 1.32 diff -u -w -r1.31 -r1.32 --- profile.xml 26 Jun 2006 06:56:51 -0000 1.31 +++ profile.xml 1 Jul 2006 10:13:01 -0000 1.32 @@ -913,6 +913,7 @@ <value>set</value> <value>map</value> <value>list</value> + <value>bag</value> </allowedValues> </element> <element name="ASSOCIATION_INDEX"> 1.43 +220 -235 cartridges/andromda-ejb3/src/main/uml/EJB3MetafacadeModel.xml.zip <<Binary file>> |