From: Vance K. <va...@us...> - 2006-01-19 06:48:46
|
User: vancek Date: 06/01/18 22:48:40 Modified: andromda-ejb3/src/main/resources/templates/ejb3 EntityEmbeddable.vsl Log: based on the entity inheritance hierarchy: adjust generatedFile switch EmbeddableSuperclass / Entity annotations switch class/consturctor names accordingly include generic finders accordingly Revision Changes Path 1.3 +53 -20 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.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- EntityEmbeddable.vsl 18 Jan 2006 08:48:42 -0000 1.2 +++ EntityEmbeddable.vsl 19 Jan 2006 06:48:40 -0000 1.3 @@ -3,14 +3,26 @@ #if ($stringUtils.isNotBlank($entity.packageName)) package $entity.packageName; #end -#set ($generatedFile = "${stringUtils.replace($entity.fullyQualifiedEntityEmbeddableName,'.','/')}.java") +## +## If the entity is in the middle of an inheritance hierarchy +## it cannot be: +## +## 1. an embeddable superclass +## 2. an abstract class +## +## +#if (!$entity.requiresGeneralizationMapping) +#**##set ($generatedFile = "${stringUtils.replace($entity.fullyQualifiedEntityEmbeddableName,'.','/')}.java") +#else +#**##set ($generatedFile = "${stringUtils.replace($entity.fullyQualifiedEntityName,'.','/')}.java") +#end #set ($identifier = $entity.identifiers.iterator().next()) /** - * Autogenerated POJO EJB3 super class for ${entity.entityName} containing the + * Autogenerated POJO EJB #if (!$entity.requiresGeneralizationMapping) super#end class for ${entity.entityName} containing the * bulk of the entity implementation. * - * This is an embeddable super class and autogenerated by AndroMDA using the EJB3 + * This is#if (!$entity.requiresGeneralizationMapping) an embeddable super class and#end autogenerated by AndroMDA using the EJB3 * cartridge. * * DO NOT MODIFY this class. @@ -18,11 +30,19 @@ $entity.getDocumentation(" * ") * */ - +#if (!$entity.requiresGeneralizationMapping) @javax.persistence.EmbeddableSuperclass#if ($entity.accessType)(access = javax.persistence.AccessType.${entity.accessType})#end +#else +...@ja...rsistence.Entity#if ($entity.accessType)(access = javax.persistence.AccessType.${entity.accessType})#end + +#end @javax.persistence.EntityListener(${entity.fullyQualifiedEntityListenerName}.class) +## Include the Table annotation for a base class in inheritence hierarchy +## if but not the inheriting classes. +#if (!$entity.requiresGeneralizationMapping) @javax.persistence.Table(name = "${entity.tableName}") +#end #if ($entity.requiresSpecializationMapping) @javax.persistence.Inheritance(strategy = javax.persistence.InheritanceType.${entity.inheritanceStrategy}, discriminatorType = javax.persistence.DiscriminatorType.${entity.discriminatorType}#if ($entity.discriminatorValue), discriminatorValue = "${entity.discriminatorValue}"#end) #**##if ($entity.inheritanceSingleTable || $entity.inheritanceJoined) @@ -32,7 +52,8 @@ @javax.persistence.Inheritance#if ($entity.discriminatorValue)(discriminatorValue = "${entity.discriminatorValue}")#end #end -public abstract class ${entity.entityEmbeddableName} +public#if (!$entity.requiresGeneralizationMapping) abstract class ${entity.entityEmbeddableName}#else class ${entity.entityName}#end + #if($entity.generalization) extends ${entity.generalization.fullyQualifiedName} #end @@ -89,7 +110,7 @@ /** * Default empty constructor */ - public ${entity.entityEmbeddableName}() + public #if (!$entity.requiresGeneralizationMapping)${entity.entityEmbeddableName}#else${entity.entityName}#end() { // default null constructor } @@ -107,7 +128,7 @@ * @param $attribute.name Value for the ${attribute.name} property #end */ - public ${entity.entityEmbeddableName}($entity.getAttributesAsList($allAttributes, true, true, false)) + public #if (!$entity.requiresGeneralizationMapping)${entity.entityEmbeddableName}#else${entity.entityName}#end($entity.getAttributesAsList($allAttributes, true, true, false)) { #if(!$inheritedAttributes.empty) super($entity.getAttributesAsList($inheritedAttributes, false, true, false)); @@ -129,7 +150,7 @@ * @param $relation.otherEnd.name Value for the ${relation.otherEnd.name} relation role #* *##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) + public #if (!$entity.requiresGeneralizationMapping)${entity.entityEmbeddableName}#else${entity.entityName}#end($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, false)); @@ -151,7 +172,7 @@ * @param $attribute Value for the $attribute property #**##end */ - public ${entity.entityEmbeddableName}(${operation.typedArgumentList}) + public #if (!$entity.requiresGeneralizationMapping)${entity.entityEmbeddableName}#else${entity.entityName}#end(${operation.typedArgumentList}) { #**##foreach($attribute in $opArguments) this.${attribute} = $attribute; @@ -165,7 +186,7 @@ * * @param pk Composite primary key */ - public ${entity.entityEmbeddableName}(${entity.fullyQualifiedEntityCompositePrimaryKeyName} pk) + public #if (!$entity.requiresGeneralizationMapping)${entity.entityEmbeddableName}#else${entity.entityName}#end(${entity.fullyQualifiedEntityCompositePrimaryKeyName} pk) { this.pk = pk; } @@ -411,17 +432,29 @@ // ----------- Generic Finder Methods -------------- +## Do not include the findAll finder for inheriting classes when the +## inheritance strategy is single table. This is defined in the base +## class. +#**##if (($entity.inheritanceSingleTable && !$entity.requiresGeneralizationMapping) || !$entity.inheritanceSingleTable) /** * Returns the collection of all ${entity.name}s. * * @param em javax.persistence.EntityManager * @return all available ${entity.name} objects */ - public static java.util.Collection<${entity.name}> findAll(javax.persistence.EntityManager em) +## For inheriting classes, replace findAll with findAll${entity.name}s + public static java.util.Collection<${entity.name}> findAll#if ($entity.requiresGeneralizationMapping)$stringUtils.capitalize(${entity.name})s#end(javax.persistence.EntityManager em) { return em.createQuery("FROM ${entity.tableName} AS $stringUtils.uncapitalize(${entity.name})").getResultList(); } -#**##if (!$entity.compositePrimaryKeyPresent) +#**##end +## Only include the findByPrimaryKey method if not an inheriting class. +## Classes that inherit from a base class use the primary key identifier +## of the base class. The inheritence relationship is reflected in the +## queries, so queries based on the base/root class are polymorphic. +## Do not include the findByPrimaryKey if this bean has a composite +## primary key class. +#**##if (!$entity.compositePrimaryKeyPresent && !$entity.requiresGeneralizationMapping) #**##foreach ($attribute in $entity.getIdentifiers(false)) #* *##set ($identifierName = $attribute.name) #* *##set ($identifierType = $attribute.type.fullyQualifiedName) |