From: Vance K. <va...@us...> - 2006-01-18 08:48:48
|
User: vancek Date: 06/01/18 00:48:42 Modified: andromda-ejb3/src/main/resources/templates/ejb3 EntityEmbeddable.vsl Log: introduced composite primary key, fixed findByPrimaryKey for non-primitive types Revision Changes Path 1.2 +89 -29 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.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- EntityEmbeddable.vsl 17 Jan 2006 04:11:21 -0000 1.1 +++ EntityEmbeddable.vsl 18 Jan 2006 08:48:42 -0000 1.2 @@ -55,9 +55,20 @@ // ----------- Attribute Definitions ------------ +#if ($entity.compositePrimaryKeyPresent) + private ${entity.fullyQualifiedEntityCompositePrimaryKeyName} pk; +#end +## Only include identifier attributes if a composite primary key is NOT present #**##foreach ($attribute in $attributes) +#* *##if ($entity.compositePrimaryKeyPresent && $attribute.identifier) +#* *##set ($doAttribute = false) +#* *##else +#* *##set ($doAttribute = true) +#* *##end +#* *##if ($doAttribute) private $attribute.type.fullyQualifiedName $attribute.name; #**##end +#**##end #end #set ($entityRelations = $entity.allEntityRelations) #if (!$entityRelations.empty) @@ -87,22 +98,21 @@ #set ($allAttributes = $transform.filterByVisibility($entity.allInstanceAttributes, "public")) #set ($inheritedAttributes = $transform.filterByVisibility($entity.inheritedInstanceAttributes, "public")) #set ($instanceAttributes = $transform.filterByVisibility($entity.instanceAttributes, "public")) - /** * Implementation for the main constructor with all POJO attributes. * This method sets all POJO fields defined in this class to the * values provided by the parameters. * -#foreach($attribute in $transform.filterUpdatableAttributes($allAttributes)) +#foreach($attribute in $transform.filterUpdatableAttributes($allAttributes, $entity.compositePrimaryKeyPresent)) * @param $attribute.name Value for the ${attribute.name} property #end */ - public ${entity.entityEmbeddableName}($entity.getAttributesAsList($allAttributes, true, true)) + public ${entity.entityEmbeddableName}($entity.getAttributesAsList($allAttributes, true, true, false)) { #if(!$inheritedAttributes.empty) - super($entity.getAttributesAsList($inheritedAttributes, false, true)); + super($entity.getAttributesAsList($inheritedAttributes, false, true, false)); #end -#foreach ($attribute in $transform.filterUpdatableAttributes($instanceAttributes)) +#foreach ($attribute in $transform.filterUpdatableAttributes($instanceAttributes, $entity.compositePrimaryKeyPresent)) ${attribute.setterName}(${attribute.name}); #end } @@ -119,10 +129,10 @@ * @param $relation.otherEnd.name Value for the ${relation.otherEnd.name} relation role #* *##end */ - public ${entity.entityEmbeddableName}($entity.getAttributesAsList($allAttributes, true, true)#if(!$allAttributes.empty), #end#foreach ($relation in $relations)#if ($relation.one2Many || $relation.many2Many)${relation.relationType}<${relation.otherEnd.type.name}> $relation.otherEnd.name#else${relation.relationType} $relation.otherEnd.name#end#if($velocityCount != $relations.size()), #end#end) + public ${entity.entityEmbeddableName}($entity.getAttributesAsList($allAttributes, true, true, false)#if(!$allAttributes.empty), #end#foreach ($relation in $relations)#if ($relation.one2Many || $relation.many2Many)${relation.relationType}<${relation.otherEnd.type.name}> $relation.otherEnd.name#else${relation.relationType} $relation.otherEnd.name#end#if($velocityCount != $relations.size()), #end#end) { // Call suitable class constructor - this($entity.getAttributesAsList($allAttributes, false, true)); + this($entity.getAttributesAsList($allAttributes, false, true, false)); // Set the CMR relations #* *##foreach ($relation in $relations) @@ -147,6 +157,19 @@ this.${attribute} = $attribute; #**##end } + +#end +#if ($entity.compositePrimaryKeyPresent) + /** + * Constructor with composite primary key arg only + * + * @param pk Composite primary key + */ + public ${entity.entityEmbeddableName}(${entity.fullyQualifiedEntityCompositePrimaryKeyName} pk) + { + this.pk = pk; + } + #end #if (!$constants.empty) @@ -161,13 +184,47 @@ { return $constant.name; } + #**##end #end +#if ($entity.compositePrimaryKeyPresent) + + // ----- Composite PK Accessors ------ + + /** + * Return the composite primary key for ${entity.entityName} + * + * @return The composite primary key + */ + @javax.persistence.EmbeddedId + public ${entity.fullyQualifiedEntityCompositePrimaryKeyName} getPk() + { + return this.pk; + } + + /** + * Set the composite primary key for ${entity.entityName} + * + * @param pk The composite primary key + */ + public void setPk(${entity.fullyQualifiedEntityCompositePrimaryKeyName} pk) + { + this.pk = pk; + } + +#end #if (!$attributes.empty) // -------- Attribute Accessors ---------- #**##foreach ($attribute in $entity.attributes) +## Only include accessors for identifier attributes if entity does not have a composite primary key +#* *##if ($entity.compositePrimaryKeyPresent && $attribute.identifier) +#* *##set ($doAttributeAccessors = false) +#* *##else +#* *##set ($doAttributeAccessors = true) +#* *##end +#* *##if ($doAttributeAccessors) #* *##set ($visibility = $attribute.visibility) /** * Get the $attribute.name property. @@ -211,6 +268,7 @@ } #**##end +#**##end #end // ------------- Relations ------------------ @@ -363,11 +421,12 @@ { return em.createQuery("FROM ${entity.tableName} AS $stringUtils.uncapitalize(${entity.name})").getResultList(); } - -#**##foreach ($attribute in $entity.attributes) -#* *##if ($attribute.identifier) +#**##if (!$entity.compositePrimaryKeyPresent) +#**##foreach ($attribute in $entity.getIdentifiers(false)) #* *##set ($identifierName = $attribute.name) #* *##set ($identifierType = $attribute.type.fullyQualifiedName) +#* *##set ($identifierTypePrimitive = $attribute.type.primitive) +#* *##if ($attribute.type.primitive) #* *##set ($identifierTypeWrapperName = $attribute.type.wrapperName) #* *##end #**##end @@ -380,9 +439,10 @@ */ public static ${entity.fullyQualifiedEntityName} findByPrimaryKey(javax.persistence.EntityManager em, ${identifierType} ${identifierName}) { -## Identifier will always be a primitive type - return em.find(${entity.fullyQualifiedEntityName}.class, new ${identifierTypeWrapperName}(${identifierName})); +## If the identifier is a primitive type, use the wrapper class + return em.find(${entity.fullyQualifiedEntityName}.class,#if ($identifierTypePrimitive) new ${identifierTypeWrapperName}(${identifierName})#else ${identifierName}#end); } +#**##end #end #set ($finders = $entity.getQueryOperations(true)) #if (!$finders.empty) |