The following code creates a composite id class suitable to Andromda 2 and 
Hibernate. It is outdated, still using xDoclet, but I hope it helps.



CompositeIdClass.vsl

#set($allIds = [])##lista com todas as chaves, pks dessa classe 
e de classes que vem de associações <<PrimaryKey>>

#foreach&#40;$id in $class.identifiers&#41;

#set&#40;$dummy = $allIds.add&#40;$id&#41; &#41;

#end

##

###foreach &#40; $associationEnd in $class.associationEnds &#41;

###if&#40;$associationEnd.association.hasExactStereotype&#40;"PrimaryKey"&#41;&#41;

###foreach&#40;$id in $associationEnd.otherEnd.type.identifiers&#41;

####talvez tenha que mudar o nome, conforme nome da ponta da assoc.

###set&#40;$dummy = $allIds.add&#40;$id&#41; &#41;

###end

###end

###end

##

#if&#40;$allIds.size&#40;&#41; > 1&#41;

package $class.packageName;



public class $&#123;class.name&#125;_id implements java.io.Serializable&#123;



&nbsp; &nbsp;public $&#123;class.name&#125;_id&#40;&#41;&#123;

&nbsp; &nbsp;&#125;



#set&#40;$args = ""&#41;

#foreach&#40;$att in $allIds&#41;

#set&#40;$args = "$&#123;args&#125;,$&#123;att.type.fullyQualifiedName&#125; 
$&#123;att.name&#125;"&#41;

#end

&nbsp; &nbsp;public 
$&#123;class.name&#125;_id&#40;$args.substring&#40;1&#41;&#41;&#123;

#foreach&#40;$att in $allIds&#41;

&nbsp; &nbsp;&nbsp; &nbsp;this.$&#123;att.name&#125; = $att.name;

#end

&nbsp; &nbsp;&#125;



#foreach&#40;$att in $allIds&#41;

#set&#40;$atttypename = $att.type.fullyQualifiedName&#41;



&nbsp; &nbsp;private $atttypename $att.name;

&nbsp; &nbsp;

&nbsp; &nbsp;/**

&nbsp; &nbsp;* @hibernate.property

&nbsp; &nbsp;*&nbsp; &nbsp;name="$att.name"

##me parece que o @hibernate.column não funciona direito aqui, então optei por 
usar

## o length

###set&#40;$theLength = $att.sqlType&#41;

###set&#40;$posIni = $theLength.indexOf&#40;'&#40;'&#41;&#41;

###if&#40;$posIni > -1&#41;

###set&#40;$posIni = $posIni + 1&#41;

###set&#40;$posFim = $theLength.indexOf&#40;'&#41;'&#41;&#41;

###set&#40;$theLength = $theLength.substring&#40;$posIni,$posFim&#41;&#41;

##&nbsp; &nbsp;*&nbsp; &nbsp;length="$theLength"

###end

&nbsp; &nbsp;* @hibernate.column

&nbsp; &nbsp;*&nbsp; &nbsp;name="$att.name"

&nbsp; &nbsp;*&nbsp; &nbsp;sql-type="$att.sqlType"

&nbsp; &nbsp;**/

&nbsp; &nbsp; public $atttypename 
get$&#123;str.upperCaseFirstLetter&#40;$&#123;att.name&#125;&#41;&#125;&#40;&#41;&#123;

&nbsp; &nbsp; &nbsp; &nbsp; return this.$&#123;att.name&#125;;

&nbsp; &nbsp; &#125;

&nbsp; &nbsp; 

&nbsp; &nbsp; public void 
set$&#123;str.upperCaseFirstLetter&#40;$&#123;att.name&#125;&#41;&#125;&#40;$&#123;atttypename&#125;
 $&#123;att.name&#125;&#41;&#123;

&nbsp; &nbsp; &nbsp; &nbsp; this.$&#123;att.name&#125; = $&#123;att.name&#125;;

&nbsp; &nbsp; &#125;

#end



#set&#40;$eqValue = ""&#41;

#foreach&#40;$att in $allIds&#41;

#set&#40;$eqValue = "$eqValue && &#40; this.$&#123;att.name&#125; == 
$&#123;att.name&#125; || &#40;&#40;this.$&#123;att.name&#125;!=null && 
$&#123;att.name&#125;!=null&#41; && &#40; 
this.$&#123;att.name&#125;.equals&#40;&#40;&#40;$&#123;class.name&#125;_id&#41;obj&#41;.get$&#123;str.upperCaseFirstLetter&#40;$&#123;att.name&#125;&#41;&#125;&#40;&#41;&#41;
 &#41;&#41;&#41;"&#41;

#end

&nbsp; &nbsp;public boolean equals&#40;Object obj&#41;&#123;

&nbsp; &nbsp;&nbsp; &nbsp;return $&#123;eqValue.substring&#40;4&#41;&#125;;

&nbsp; &nbsp;&#125;

&nbsp; &nbsp;

&nbsp; &nbsp;public int hashCode&#40;&#41;&#123;

&nbsp; &nbsp;&nbsp; &nbsp;return &#40;

#foreach&#40;$att in $allIds&#41;

&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;this.$&#123;att.name&#125;.toString&#40;&#41; +

#end

&nbsp; &nbsp;&nbsp; &nbsp;""&#41;.hashCode&#40;&#41;;

&nbsp; &nbsp;&#125;

&#125;

#end


_________________________________________________________
Reply to the post : http://galaxy.andromda.org/forum/viewtopic.php?p=2395#2395
Posting to http://forum.andromda.org/ is preferred over posting to the mailing 
list!


-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP, 
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
Andromda-user mailing list
Andromda-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/andromda-user

Reply via email to