From: Vance K. <va...@us...> - 2006-02-06 03:04:14
|
User: vancek Date: 06/02/05 19:04:06 Modified: andromda-ejb3/src/main/resources/templates/ejb3 EntityEmbeddable.vsl Log: renamed @EmbeddableSuperclass to @MappedSuperclass removed access type for @MappedSuperclass and @Entity - figured out automatically moved generator properties from @Id to @GeneratedValue added @SequenceGenerator and fixed @TableGenerator properties removed type property from @Lob - determined from attribute type moved fetch property from @Lob to @Basic added @Temporal annotation to entity attribute getter added @Enumerated annotation to entity attribute getter fixed inheritance discriminator annotations, @Inheritance, @DiscriminatorColumn and @DiscriminatorValue (new) renamed @EntityListener to @EntityListeners when defining attributes, use instanceAttributes only, not allInstanceAttributes (excludes inherited isntance atts) added @JoinColumns if composite PK present on Many-To-One and One-To-One relationships added @JoinTable on owning side of Many-To-Many relationship removed entity business operations - only exist in impl class Revision Changes Path 1.14 +88 -48 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.13 retrieving revision 1.14 diff -u -w -r1.13 -r1.14 --- EntityEmbeddable.vsl 1 Feb 2006 08:38:44 -0000 1.13 +++ EntityEmbeddable.vsl 6 Feb 2006 03:04:06 -0000 1.14 @@ -19,10 +19,10 @@ #set ($identifier = $entity.identifiers.iterator().next()) /** - * Autogenerated POJO EJB#if (!$entity.requiresGeneralizationMapping || $entity.embeddableSuperclass) embeddable super#end class for ${entity.entityName} containing the + * Autogenerated POJO EJB#if (!$entity.requiresGeneralizationMapping || $entity.embeddableSuperclass) embeddable/mapped super#end class for ${entity.entityName} containing the * bulk of the entity implementation. * - * This is#if (!$entity.requiresGeneralizationMapping || $entity.embeddableSuperclass) an embeddable super class and#end autogenerated by AndroMDA using the EJB3 + * This is#if (!$entity.requiresGeneralizationMapping || $entity.embeddableSuperclass) an embeddable/mapped super class and#end autogenerated by AndroMDA using the EJB3 * cartridge. * * DO NOT MODIFY this class. @@ -31,11 +31,9 @@ * */ #if (!$entity.requiresGeneralizationMapping || $entity.embeddableSuperclass) -...@ja...rsistence.EmbeddableSuperclass#if ($entity.accessType)(access = javax.persistence.AccessType.${entity.accessType})#end - +...@ja...ppedSuperclass #else -...@ja...rsistence.Entity#if ($entity.accessType)(access = javax.persistence.AccessType.${entity.accessType})#end - +...@ja...rsistence.Entity #end ## ## Include the Table annotation for a base class in single table inheritence hierarchy @@ -48,20 +46,25 @@ @javax.persistence.Table(name = "${entity.tableName}") #end #if ($entity.requiresGeneralizationMapping && $entity.listenerEnabled) -...@ja...rsistence.EntityListener(${entity.fullyQualifiedEntityListenerName}.class) +...@ja...rsistence.EntityListeners({${entity.fullyQualifiedEntityListenerName}.class}) #end +## ## Only include the inheritance related annotations for inheritance mapping ## that doesn't involve embeddable superclass hierarchy. +## #if ($entity.requiresSpecializationMapping && !$entity.embeddableSuperclass) -...@ja...heritance(strategy = javax.persistence.InheritanceType.${entity.inheritanceStrategy}, discriminatorType = javax.persistence.DiscriminatorType.${entity.discriminatorType}#if ($entity.discriminatorValue), discriminatorValue = "${entity.discriminatorValue}"#end) +...@ja...heritance(strategy = javax.persistence.InheritanceType.${entity.inheritanceStrategy}) #**##if ($entity.inheritanceSingleTable || $entity.inheritanceJoined) -...@ja...rsistence.DiscriminatorColumn(name = "${entity.discriminatorColumn}"#if ($entity.discriminatorColumnDefinition), columnDefinition = "${entity.discriminatorColumnDefinition}"#end#if ($entity.discriminatorLength > 0), length = ${entity.discriminatorLength}#end) +#* *##set ($argExists = false) +...@ja...rsistence.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) +...@ja...rsistence.DiscriminatorValue("${entity.discriminatorValue}") #**##end #elseif ($entity.requiresGeneralizationMapping && !$entity.embeddableSuperclassGeneralizationExists) -## Only include the inheritance annotation for subclasses if the super class +## +## Only include the DiscriminatorValue annotation for subclasses if the super class ## is NOT an embeddable superclass. -...@ja...heritance#if ($entity.discriminatorValue)(discriminatorValue = "${entity.discriminatorValue}")#end - +## +...@ja...rsistence.DiscriminatorValue("${entity.discriminatorValue}") #end public#if (!$entity.requiresGeneralizationMapping && !$entity.embeddableSuperclass) abstract class ${entity.entityEmbeddableName}#else class ${entity.entityName}#end @@ -82,7 +85,10 @@ public static final $constant.type.fullyQualifiedName $constant.name = $constant.defaultValue; #**##end #end -#set ($attributes = $entity.allInstanceAttributes) +## +## Only declase instance attributes that are NOT inherited +## +#set ($attributes = $entity.instanceAttributes) #if (!$attributes.empty) // ----------- Attribute Definitions ------------ @@ -277,10 +283,15 @@ * @return $attribute.type.fullyQualifiedName The value of ${attribute.name} */ #* *##if ($attribute.identifier) -#* *##if ($attribute.sequenceGeneratorType || $attribute.tableGeneratorType) - @javax.persistence.TableGenerator(name = "${attribute.generatorName}"#if ($attribute.sequenceGeneratorType), sequenceName = "${attribute.generatorSourceName}"#elseif ($attribute.tableGeneratorType), tableName = "${attribute.generatorSourceName}"#end,#if ($attribute.tableGeneratorType) pkColumnValue = "${attribute.generatorPkColumnValue}",#end#if ($attribute.sequenceGeneratorType) initialValue = ${attribute.generatorInitialValue},#end allocationSize = ${attribute.generatorAllocationSize}) + @javax.persistence.Id +#* *##if ($attribute.sequenceGeneratorType) + @javax.persistence.SequenceGenerator(name = "${attribute.generatorName}"#if ($attribute.sequenceGeneratorType), sequenceName = "${attribute.generatorSourceName}"#end#if ($attribute.sequenceGeneratorType), initialValue = ${attribute.generatorInitialValue}#end#if ($attribute.generatorAllocationSize), allocationSize = ${attribute.generatorAllocationSize}#end) +#* *##elseif ($attribute.tableGeneratorType) + @javax.persistence.TableGenerator(name = "${attribute.generatorName}"#if ($attribute.tableGeneratorType), table = "${attribute.generatorSourceName}"#end#if ($attribute.generatorPkColumnValue), pkColumnValue = "${attribute.generatorPkColumnValue}"#end#if ($attribute.generatorInitialValue), initialValue = ${attribute.generatorInitialValue}#end#if ($attribute.generatorAllocationSize), allocationSize = ${attribute.generatorAllocationSize}#end) +#* *##end +#* *##if (!$attribute.generatorTypeNone) + @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.${attribute.generatorType}#if ($attribute.sequenceGeneratorType || $attribute.tableGeneratorType), generator = "${attribute.generatorName}"#end) #* *##end - @javax.persistence.Id(generate = javax.persistence.GeneratorType.${attribute.generatorType}#if ($attribute.sequenceGeneratorType || $attribute.tableGeneratorType), generator = "${attribute.generatorName}"#end) #* *##end #* *##if ($attribute.version) @javax.persistence.Version @@ -288,15 +299,30 @@ #* *##if ($attribute.transient) @javax.persistence.Transient #* *##end -#* *##if ($attribute.lobType) -## LOB type is specified - also sepcify FetchType if set to EAGER since default fetch type for LOB annotation is LAZY - @javax.persistence.Lob(type = javax.persistence.LobType.${attribute.lobType}#if ($attribute.eager), fetch = javax.persistence.FetchType.EAGER#end) +#* *##if ($attribute.lob) +## +## Add if LOB type is specified - do not set LOB type as of PFD Spec - inferred from type. +## Also sepcify Fetch type in Basic annotation if set to EAGER since +## default fetch type for LOB annotation is LAZY. +## + @javax.persistence.Lob +#* *##if ($attribute.eager) + @javax.persistence.Basic(fetch = javax.persistence.FetchType.EAGER) +#* *##end #* *##end @javax.persistence.Column(name = "${attribute.columnName}"#if ($attribute.unique), unique = ${attribute.unique}#end#if (!$attribute.columnNullable), nullable = ${attribute.columnNullable}#end#if ($attribute.columnLength), length = ${attribute.columnLength}#end#if ($attribute.columnDefinition), columnDefinition = "${attribute.columnDefinition}"#end#if ($attribute.columnPrecision), precision = ${attribute.columnPrecision}#end#if ($attribute.columnScale), scale = ${attribute.columnScale}#end) +#* *##if (!$attribute.lob && $attribute.lazy) +## ## Only add the fetch type property for LAZY hints - default is EAGER -#* *##if ($attribute.lazy) +## @javax.persistence.Basic(fetch = javax.persistence.FetchType.LAZY) #* *##end +#* *##if ($stringUtils.isNotBlank($attribute.temporalType)) + @javax.persistence.Temporal(javax.persistence.TemporalType.${attribute.temporalType}) +#* *##end +#* *##if ($stringUtils.isNotBlank($attribute.enumerationType)) + @javax.persistence.Enumerated(${attribute.enumerationType}) +#* *##end public ${attribute.type.fullyQualifiedName} ${attribute.getterName}() { return $attribute.name; @@ -338,7 +364,22 @@ */ #* *##set ($argExists = false) @javax.persistence.ManyToOne(#if (!$target.optional)optional = false#set ($argExists = true)#end#if ($target.cascadeType)#if ($argExists), #end#**#cascade = {${target.cascadeType}}#set ($argExists = true)#end#if ($target.lazy)#if ($argExists), #end#**#fetch = javax.persistence.FetchType.LAZY#end) +## +## Add the JoinColumns annotation if the target entity has a composite primary key +## Otherwise add the JoinColumn annotation. +## +#* *##if (!$target.type.compositePrimaryKeyPresent) @javax.persistence.JoinColumn(name = "$stringUtils.upperCase(${target.name})"#if ($associationEnd.columnDefinition), columnDefinition = "${associationEnd.columnDefinition}"#end) +#* *##else +#* *##set ($identifiers = $target.type.getIdentifiers()) + @javax.persistence.JoinColumns + ({ +#* *##foreach ($attribute in $identifiers) + @javax.persistence.JoinColumn(name = "$stringUtils.upperCase(${target.name})_${attribute.columnName}", referencedColumnName = "${attribute.columnName}")#if($velocityCount != $identifiers.size()),#end + +#* *##end + }) +#* *##end public $target.getterSetterTypeName ${target.getterName}() { return this.${target.name}; @@ -408,7 +449,22 @@ #* *##set ($argExists = false) @javax.persistence.OneToOne(#if($associationEnd.owning)#if (!$target.optional)optional = false#set ($argExists = true)#end#end#if ($target.cascadeType)#if ($argExists), #end#**#cascade = {${target.cascadeType}}#set ($argExists = true)#end#if(!$associationEnd.owning)#if ($argExists), #end#**#mappedBy = "${associationEnd.name}"#set ($argExists = true)#end#if ($target.lazy)#if ($argExists), #end#**#fetch = javax.persistence.FetchType.LAZY#end) #* *##if($associationEnd.owning) +## +## Add the JoinColumns annotation if the target entity has a composite primary key +## Otherwise add the JoinColumn annotation. +## +#* *##if (!$target.type.compositePrimaryKeyPresent) @javax.persistence.JoinColumn(name = "$stringUtils.upperCase(${target.name})"#if ($associationEnd.columnDefinition), columnDefinition = "${associationEnd.columnDefinition}"#end) +#* *##else +#* *##set ($identifiers = $target.type.getIdentifiers()) + @javax.persistence.JoinColumns + ({ +#* *##foreach ($attribute in $identifiers) + @javax.persistence.JoinColumn(name = "$stringUtils.upperCase(${target.name})_${attribute.columnName}", referencedColumnName = "${attribute.columnName}")#if($velocityCount != $identifiers.size()),#end + +#* *##end + }) +#* *##end #* *##end public $target.getterSetterTypeName ${target.getterName}() { @@ -441,8 +497,18 @@ #* *##set ($argExists = false) @javax.persistence.ManyToMany(#if ($target.cascadeType)cascade = {${target.cascadeType}}#set ($argExists = true)#end#if(!$associationEnd.owning)#if ($argExists), #end#**#mappedBy = "${associationEnd.name}"#set ($argExists = true)#end#if ($target.eager)#if ($argExists), #end#**#fetch = javax.persistence.FetchType.EAGER#end) ## Use Aggregation and Composition to determine owning side -#* *##if(($associationEnd.owning) && ${associationEnd.association.tableName}) - @javax.persistence.JoinTable(table = @javax.persistence.Table(name = "${associationEnd.association.tableName}")) +#* *##if (${associationEnd.association.tableName}) +#* *##if($associationEnd.owning) +## +## Add the JoinTable annotation on the owning side +## + @javax.persistence.JoinTable + ( + name = "${associationEnd.association.tableName}", + joinColumns = {#set ($identifiers = $entity.getIdentifiers())#foreach ($attribute in $identifiers)@javax.persistence.JoinColumn(name = "${attribute.columnName}")#if($velocityCount != $identifiers.size()), #end#end#**#}, + inverseJoinColumns = {#set ($identifiers = $target.type.getIdentifiers())#foreach ($attribute in $identifiers)@javax.persistence.JoinColumn(name = "${attribute.columnName}")#if($velocityCount != $identifiers.size()), #end#end#**#} + ) +#* *##end #* *##end #* *##if ($target.hasTaggedValue("@andromda.persistence.orderBy")) #* *##if ($stringUtils.isNotEmpty(${target.orderByClause})) @@ -576,30 +642,4 @@ #**##end #end -#set ($businessOperations = $entity.businessOperations) -#if (!$businessOperations.empty) - - // --------------- Entity Methods ----------------- - -## -## Method with a static modifier will be defined in the inheriting subclass -## -#**##foreach ($operation in $businessOperations) -#* *##if (!$operation.static) -#* *##set ($signature = $operation.signature) -#* *##set ($visibility = $operation.visibility.toString()) -#* *##set ($returnType = $operation.returnType.fullyQualifiedName) - /** -$operation.getDocumentation(" * ") - */ -#* *##if ($operation.exceptionsPresent) - $visibility abstract $returnType $signature - throws $operation.exceptionList; -#* *##else - $visibility abstract $returnType $signature; -#* *##end - -#* *##end -#**##end -#end } \ No newline at end of file |