telosystools

Open full view…

Is there a trick to generate @OneToOne relationship with Telosys tools

abu0khalique
Fri, 23 Oct 2015 19:19:00 GMT

I am trying to work with @OneToOne relationship where I do not need to manually edit dbrep file. Is there a way to do that.

abu0khalique
Mon, 26 Oct 2015 18:08:12 GMT

This is what we end up doing. ( I know it can be improved) Assume you have following tables PERSON [ id, name ........] HOUSE[id, owner_id, .......] CAR[id, owner_id, ......... What we did is modified velocity template to create @OneToOne relationship First we declare a map of entities (entity name) which will have one to one relationship in entity with link vm template, ## Map and List for OneToOne relationship #set( $mapOneToOneEntity = {"Person" : ["House", "Car"] , "House" : ["Person"], "Car" : ["Person"]}) ## Now get the list out of the map that will be used to map OneToONe relationship #set( $listOneToOneEntity = [] ) ##initialize #if ($mapOneToOneEntity.containsKey($entity.name)) #set( $listOneToOneEntity = ${mapOneToOneEntity.get($entity.name)} ) #end Now edit link field creation with this //---------------------------------------------------------------------- // ENTITY LINKS ( RELATIONSHIP ) //---------------------------------------------------------------------- ## #foreach( $link in $entity.links ) #foreach( $link in $entity.selectedLinks ) ## $linkAnnotationPrint will be annotation for link #set( $linkAnnotationPrint = $jpa.linkAnnotations(4, $link, $allMappedFields) ) ## linkFieldTypePrint is field type #set( $linkFieldTypePrint = $link.formattedFieldType(0) ) ## $linkFieldNamePrint is private field name for link #set( $linkFieldNamePrint = $link.formattedFieldName(0) ) ## we are trying to figure out @OneToOne relationship #if ( $listOneToOneEntity.contains($link.fieldType) && $link.isCardinalityManyToOne() ) #set( $linkAnnotationPrint = $linkAnnotationPrint.replace("@ManyToOne", "@OneToOne") ) #elseif ( $listOneToOneEntity.contains($link.formattedFieldName(0).replace("list Of", "")) && $link.isCardinalityOneToMany() ) ## transforming listOf to entity #set( $linkAnnotationPrint = $linkAnnotationPrint.replace("@OneToMany", "@OneToOne") ) #set( $linkFieldTypePrint = $link.formattedFieldName(0).replace("listOf", "") ) #set( $linkFieldNamePrint = $linkFieldTypePrint.substring(0,1).toLowerCase()+$linkFieldTypePrint.s ubstring(1) ) #end ${linkAnnotationPrint} private $linkFieldTypePrint $linkFieldNamePrint; #end Now edit link getters and setter with this //---------------------------------------------------------------------- // GETTERS & SETTERS FOR LINKS //---------------------------------------------------------------------- ## #foreach( $link in $entity.selectedLinks ) #foreach( $link in $entity.links ) ## $linkSetterPrint for setter method #set( $linkSetterPrint = $link.setter ) ## $linkGetterPrint for gettter method #set( $linkGetterPrint = $link.getter ) ## linkFieldTypePrint is field type #set( $linkFieldTypePrint = $link.formattedFieldType(0) ) ## $linkFieldNamePrint is private field name for link #set( $linkFieldNamePrint = $link.formattedFieldName(0) ) #if ( $listOneToOneEntity.contains($link.formattedFieldName(0).replace("list Of", "")) && $link.isCardinalityOneToMany() ) ## transforming listOf to entity for getter and setter #set( $linkFieldTypePrint = $link.formattedFieldName(0).replace("listOf", "") ) #set( $linkFieldNamePrint = $linkFieldTypePrint.substring(0,1).toLowerCase()+$linkFieldTypePrint.s ubstring(1) ) #set( $linkSetterPrint = $link.setter.substring(0,3)+$linkFieldTypePrint ) #set( $linkGetterPrint = $link.getter.substring(0,3)+$linkFieldTypePrint ) #end #if ( $link.setter ) public void $linkSetterPrint( $linkFieldTypePrint $linkFieldNamePrint ) { this.$linkFieldNamePrint = $linkFieldNamePrint; } #end #if ( $link.getter ) public $linkFieldTypePrint $linkGetterPrint() { return this.$linkFieldNamePrint; } #end #end

Telosys Team
Wed, 25 Nov 2015 10:10:45 GMT

You just have to change the cardinality in the model Select "Links between entities" Choose the link with the "Many To One" cardinality you want to change Click "Edit" Change the cardinality form "Many To One" to "One To One" The both sides are now "One To One" ( owning side and inserse side ) Save the model Re-generate your classes