From: Vance K. <va...@us...> - 2006-04-26 15:17:40
|
User: vancek Date: 06/04/26 08:16:52 Modified: andromda-ejb3/src/main/resources/templates/ejb3 EntityEmbeddable.vsl Log: extensive refactoring to avoid generating the entity impl src if no business operations are modelled. eliminate static finders from entity class -> finders reside in DAO only, inline with spring cartridge. added NamedQueries and NamedQuery annotations for pre-configured queries. Revision Changes Path 1.25 +52 -147 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.24 retrieving revision 1.25 diff -u -w -r1.24 -r1.25 --- EntityEmbeddable.vsl 24 Apr 2006 02:26:51 -0000 1.24 +++ EntityEmbeddable.vsl 26 Apr 2006 15:16:51 -0000 1.25 @@ -1,5 +1,8 @@ // license-header java merge-point -/* Autogenerated by AndroMDA (Entity.vsl) - do not edit */ +// +// Attention: Generated code! Do not modify by hand! +// Generated by: EntityEmbeddable.vsl in andromda-ejb3-cartridge. +// #if ($stringUtils.isNotBlank($entity.packageName)) package $entity.packageName; #end @@ -11,7 +14,7 @@ ## 2. an abstract class ## ## -#if (!$entity.requiresGeneralizationMapping && !$entity.embeddableSuperclass) +#if ($entity.entityImplementationRequired) #**##set ($generatedFile = "${stringUtils.replace($entity.fullyQualifiedEntityEmbeddableName,'.','/')}.java") #else #**##set ($generatedFile = "${stringUtils.replace($entity.fullyQualifiedEntityName,'.','/')}.java") @@ -19,10 +22,10 @@ #set ($identifier = $entity.identifiers.iterator().next()) /** - * Autogenerated POJO EJB#if (!$entity.requiresGeneralizationMapping || $entity.embeddableSuperclass) embeddable/mapped super#end class for ${entity.entityName} containing the + * Autogenerated POJO EJB#if ($entity.entityImplementationRequired) mapped super#end class for ${entity.entityName} containing the * bulk of the entity implementation. * - * This is#if (!$entity.requiresGeneralizationMapping || $entity.embeddableSuperclass) an embeddable/mapped super class and#end autogenerated by AndroMDA using the EJB3 + * This is#if ($entity.entityImplementationRequired) a mapped super class and#end autogenerated by AndroMDA using the EJB3 * cartridge. * * DO NOT MODIFY this class. @@ -30,29 +33,33 @@ $entity.getDocumentation(" * ") * */ -#if (!$entity.requiresGeneralizationMapping || $entity.embeddableSuperclass) +## +## Only set the Entity annotation if it is explicity defined as an embeddable super class +## or business operations exist(implementation is required). +## +#if ($entity.entityImplementationRequired) @javax.persistence.MappedSuperclass #else @javax.persistence.Entity -#end ## ## Include the Table annotation for a base class in single table inheritence hierarchy ## but not in the subclasses. Include in all classes for joined and table per class ## inheritance hierarchies. +## ## If a class is manually specified as an embeddable superclass, add ## the Table annotation to the subclass, not to the base superclass. ## -#if ($entity.requiresGeneralizationMapping && ($entity.embeddableSuperclassGeneralizationExists || $entity.inheritanceTablePerClass || $entity.inheritanceJoined)) +#**##if (!$entity.entityImplementationRequired && (($entity.requiresSpecializationMapping && !$entity.embeddableSuperclass) || ($entity.requiresGeneralizationMapping && ($entity.embeddableSuperclassGeneralizationExists || $entity.inheritanceTablePerClass || $entity.inheritanceJoined)))) @javax.persistence.Table(name = "${entity.tableName}") -#end -#if ($entity.requiresGeneralizationMapping && $entity.listenerEnabled) +#**##end +#**##if ($entity.listenerEnabled) @javax.persistence.EntityListeners({${entity.fullyQualifiedEntityListenerName}.class}) -#end +#**##end ## ## Only include the inheritance related annotations for inheritance mapping ## that doesn't involve embeddable superclass hierarchy. ## -#if ($entity.requiresSpecializationMapping && !$entity.embeddableSuperclass) +#**##if ($entity.requiresSpecializationMapping && !$entity.embeddableSuperclass) @javax.persistence.Inheritance(strategy = javax.persistence.InheritanceType.${entity.inheritanceStrategy}) ## ## Discriminator components only apply to single table mapping strategy @@ -62,17 +69,37 @@ @javax.persistence.DiscriminatorColumn(#if ($entity.discriminatorColumn)name = "${entity.discriminatorColumn}"#set ($argExists = true)#end#if ($entity.discriminatorType)#if ($argExists), #end#**#discriminatorType = javax.persistence.DiscriminatorType.${entity.discriminatorType}#set ($argExists = true)#end#if ($entity.discriminatorColumnDefinition)#if ($argExists), #end#**#columnDefinition = "${entity.discriminatorColumnDefinition}"#set ($argExists = true)#end#if ($entity.discriminatorLength > 0)#if ($argExists), #end#**#length = ${entity.discriminatorLength}#end) @javax.persistence.DiscriminatorValue("${entity.discriminatorValue}") #**##end -#elseif ($entity.requiresGeneralizationMapping && !$entity.embeddableSuperclassGeneralizationExists) +#**##elseif ($entity.requiresGeneralizationMapping && $entity.inheritanceSingleTable) ## -## Only include the DiscriminatorValue annotation for subclasses if the super class -## is NOT an embeddable superclass. +## Only include the DiscriminatorValue annotation for subclasses if +## the inheritance strategy is single table mapping strategy. ## @javax.persistence.DiscriminatorValue("${entity.discriminatorValue}") -#end -#if ($entity.cacheEnabled) +#**##end +#**##if ($entity.cacheEnabled) @org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.${entity.cacheType}) +#**##end +#**##set ($finders = $entity.getQueryOperations(false)) +#**##if (!$finders.empty) +...@ja...dQueries +({ +#* *##if ($entity.genericFinders) + @javax.persistence.NamedQuery(name = "${entity.name}.findAll", query = "select $stringUtils.uncapitalize(${entity.name}) from ${entity.name} AS $stringUtils.uncapitalize(${entity.name})")#if (!$finders.empty),#end + +#* *##end +#* *##foreach ($finder in $finders) + @javax.persistence.NamedQuery(name = "${entity.name}.${finder.name}", query = "${finder.query}")#if($velocityCount != $finders.size()), #end + +#* *##end +}) +#**##else +#* *##if ($entity.genericFinders) +...@ja...dQuery(name = "${entity.name}.findAll", query = "select $stringUtils.uncapitalize(${entity.name}) from ${entity.name} AS $stringUtils.uncapitalize(${entity.name})")#if (!$finders.empty),#end + +#* *##end +#**##end #end -public#if (!$entity.requiresGeneralizationMapping && !$entity.embeddableSuperclass) abstract class ${entity.entityEmbeddableName}#else class ${entity.entityName}#end +public#if ($entity.entityImplementationRequired) abstract class ${entity.entityEmbeddableName}#else class ${entity.entityName}#end #if($entity.generalization) extends ${entity.generalization.fullyQualifiedName} @@ -167,7 +194,7 @@ /** * Default empty constructor */ - public #if (!$entity.requiresGeneralizationMapping && !$entity.embeddableSuperclass)${entity.entityEmbeddableName}#else${entity.entityName}#end() + public #if ($entity.entityImplementationRequired)${entity.entityEmbeddableName}#else${entity.entityName}#end() { // default null constructor } @@ -186,7 +213,7 @@ * @param $attribute.name Value for the ${attribute.name} property #**##end */ - public #if (!$entity.requiresGeneralizationMapping && !$entity.embeddableSuperclass)${entity.entityEmbeddableName}#else${entity.entityName}#end($entity.getAttributesAsList($allAttributes, true, true, false)) + public #if ($entity.entityImplementationRequired)${entity.entityEmbeddableName}#else${entity.entityName}#end($entity.getAttributesAsList($allAttributes, true, true, false)) { #**##if(!$inheritedAttributes.empty) super($entity.getAttributesAsList($inheritedAttributes, false, true, false)); @@ -210,7 +237,7 @@ * @param $relation.otherEnd.name Value for the ${relation.otherEnd.name} relation role #* *##end */ - public #if (!$entity.requiresGeneralizationMapping && !$entity.embeddableSuperclass)${entity.entityEmbeddableName}#else${entity.entityName}#end($entity.getAttributesAsList($allAttributes, true, true, false)#if(!$allAttributes.empty), #end#foreach ($relation in $relations)${relation.otherEnd.getterSetterTypeName} $relation.otherEnd.name#if($velocityCount != $relations.size()), #end#end) + public #if ($entity.entityImplementationRequired)${entity.entityEmbeddableName}#else${entity.entityName}#end($entity.getAttributesAsList($allAttributes, true, true, false)#if(!$allAttributes.empty), #end#foreach ($relation in $relations)${relation.otherEnd.getterSetterTypeName} $relation.otherEnd.name#if($velocityCount != $relations.size()), #end#end) { #* *##foreach ($attribute in $transform.filterUpdatableAttributes($instanceAttributes, $entity.compositePrimaryKeyPresent)) ${attribute.setterName}(${attribute.name}); @@ -233,7 +260,7 @@ * @param $attribute Value for the $attribute property #**##end */ - public #if (!$entity.requiresGeneralizationMapping && !$entity.embeddableSuperclass)${entity.entityEmbeddableName}#else${entity.entityName}#end(${operation.typedArgumentList}) + public #if ($entity.entityImplementationRequired)${entity.entityEmbeddableName}#else${entity.entityName}#end(${operation.typedArgumentList}) { #**##foreach($attribute in $opArguments) this.${attribute} = $attribute; @@ -247,7 +274,7 @@ * * @param pk Composite primary key */ - public #if (!$entity.requiresGeneralizationMapping && !$entity.embeddableSuperclass)${entity.entityEmbeddableName}#else${entity.entityName}#end(${entity.fullyQualifiedEntityCompositePrimaryKeyName} pk) + public #if ($entity.entityImplementationRequired)${entity.entityEmbeddableName}#else${entity.entityName}#end(${entity.fullyQualifiedEntityCompositePrimaryKeyName} pk) { this.pk = pk; } @@ -670,126 +697,4 @@ #* *##end #**##end #end -#if ($entity.genericFinders) - - // ----------- 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. -## -## Only render if the findAll finder hasn't been modelled. -## -#**##if ((($entity.inheritanceSingleTable && !$entity.requiresGeneralizationMapping) || !$entity.inheritanceSingleTable) && !$entity.finderFindAllExists) - /** - * Returns the collection of all ${entity.name}s. - * - * @param em javax.persistence.EntityManager - * @return all available ${entity.name} objects - */ -## -## 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.name} AS $stringUtils.uncapitalize(${entity.name})").getResultList(); - } - -#**##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. -## -## Only render if the findAll finder hasn't been modelled. -## -#**##if (!$entity.compositePrimaryKeyPresent && !$entity.requiresGeneralizationMapping && !$entity.finderFindByPrimaryKeyExists) -#* *##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 - /** - * Returns the ${entity.name} matching the identifier. - * - * @param em javax.persistence.EntityManager - * @param ${identifierName} the primary key - * @return the ${entity.name} object matching the primary key - */ - public static ${entity.fullyQualifiedEntityName} findByPrimaryKey(javax.persistence.EntityManager em, ${identifierType} ${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) - - // -------- User Defined Finder Methods ------------ - -#**##foreach ($finder in $finders) -#* *##set ($returnType = $finder.returnType.fullyQualifiedName) -#* *##set ($parameterList = $finder.typedArgumentList) -#* *##if ($finder.arguments.empty) -#* *##set ($parameters = "javax.persistence.EntityManager em") -#* *##else -#* *##set ($parameters = "javax.persistence.EntityManager em, ${parameterList}") -#* *##end - /** - * Finder method for ${entity.name} entity using a query. -$finder.getDocumentation(" * ") - * - * @param em javax.persistence.EntityManager -#* *##foreach ($parameter in $finder.arguments) - * @param $parameter.type.fullyQualifiedName ${parameter.name} -#* *##end - * @return $returnType - */ - $finder.visibility static $returnType#if ($finder.returnType.collectionType || $finder.returnType.listType || $finder.returnType.setType || $finder.returnType.mapType)<${entity.name}>#end ${finder.name}($parameters) - { - javax.persistence.Query query = em.createQuery("$finder.query"); -#* *##foreach ($parameter in $finder.arguments) -#* *##set ($index = $velocityCount - 1) -#* *##if ($parameter.firstResult) - query.setFirstResult(${parameter.name}); -#* *##elseif ($parameter.maxResults) - query.setMaxResults(${parameter.name}); -#* *##else -## -## Find the attribute matching the parameter name -## If the parameter type is an enum: -## If -## -#* *##if ($finder.useNamedParameters) - query.setParameter("${parameter.name}",#if ($parameter.type.primitive) new ${parameter.type.wrapperName}(${parameter.name})#else ${parameter.name}#if ($parameter.enumerationTypeOrdinal).ordinal()#elseif ($parameter.enumerationTypeString).name()#end#end#if ($parameter.temporalType), javax.persistence.TemporalType.${parameter.temporalType}#end); -#* *##else - query.setParameter(${index},#if ($parameter.type.primitive) new ${parameter.type.wrapperName}(${parameter.name})#else ${parameter.name}#if ($parameter.enumerationTypeOrdinal).ordinal()#elseif ($parameter.enumerationTypeString).name()#end#end#if ($parameter.temporalType), javax.persistence.TemporalType.${parameter.temporalType}#end); -#* *##end -#* *##end -#* *##end -#* *##if ($finder.useQueryCache && !$entity.useDefaultCacheRegion) - query.setHint("org.hibernate.cacheRegion", "/${entity.fullyQualifiedNamePath}_${finder.name}"); -#* *##end -#* *##if ($stringUtils.equalsIgnoreCase($returnType, "void")) - query.executeUpdate(); -#* *##elseif ($finder.returnType.primitive) - return (($finder.returnType.wrapperName)query.getSingleResult()).${returnType}Value(); -#* *##elseif (!$finder.returnType.collectionType) - return ($returnType)query.getSingleResult(); -#* *##else - return query.getResultList(); -#* *##end - } - -#**##end -#end } \ No newline at end of file |