Skip to content

Commit

Permalink
move the java generation to use the new intermediate DataType column …
Browse files Browse the repository at this point in the history
…resolution format.

have changed the format a little to separate the column (c attribute) and field (f attribute).
  • Loading branch information
pahjbo committed Jan 31, 2025
1 parent 5c968f3 commit d7c01fa
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 96 deletions.
79 changes: 19 additions & 60 deletions tools/xslt/common-binding.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -669,24 +669,29 @@
</dt>
</xsl:template>
<xsl:template match="attribute" mode="attrovercols2" >
<att v="{vf:asvodmlref(current())}" n="{name}">
<att v="{vf:asvodmlref(current())}" c="{name}">
<xsl:if test="not(current()/parent::objectType)">
<xsl:attribute name="f" select="name"/>
</xsl:if>
<xsl:variable name="type" select="$models/key('ellookup',current()/datatype/vodml-ref)"/>
<xsl:attribute name="type" select="datatype/vodml-ref"/>
<xsl:apply-templates select="$type" mode="attrovercols2"/>
</att>
</xsl:template>
<xsl:template match="reference" mode="attrovercols2" >
<ref v="{vf:asvodmlref(current())}" n="{name}">
<ref v="{vf:asvodmlref(current())}" f="{name}" c="{name}">
<xsl:attribute name="type" select="datatype/vodml-ref"/>
</ref>
</xsl:template>

<xsl:template match="primitiveType" mode="attrovercols2" >
<xsl:variable name="type" select="current()/datatype/vodml-ref"/>
<xsl:choose>
<xsl:when test="extends">
<xsl:attribute name="field" select="'value'"/>
<att f="value" type="{current()/extends/vodml-ref}" extends="{true()}">
<xsl:attribute name="f" select="'value'"/>
<xsl:apply-templates select="$models/key('ellookup',current()/extends/vodml-ref)" mode="attrovercols2"/>

</att>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
Expand All @@ -697,15 +702,17 @@
<xsl:attribute name="atomic" select="true()"/>
</xsl:when>
<xsl:when test="$pmap/@primitive-value-field">
<xsl:attribute name="field" select="$pmap/@primitive-value-field"/>
<att type="{$type}">
<xsl:attribute name="f" select="$pmap/@primitive-value-field"/>
</att>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="field" select="'value'"/>
<att f="value" type="{$type}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="field" select="'value'"/>
<att f="value" type="{$type}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
Expand All @@ -714,65 +721,17 @@
<xsl:template match="enumeration" mode="attrovercols2" >
<xsl:attribute name="enumeration" select="true()"/>
<xsl:attribute name="atomic" select="true()"/>
<xsl:attribute name="field" select="'value'"/>
</xsl:template>


<!-- attrovercols templates below deprecated -->
<xsl:template match="dataType" mode="attrovercols" as="xsd:string*">
<xsl:param name="prefix" as="xsd:string"/>
<!-- <xsl:message>** attrovercolsD <xsl:value-of select="concat(name(),' ',name,' *** ',$prefix, ' refs=', string-join(vf:baseTypes(vf:asvodmlref(current()))/reference/name,','))"/></xsl:message>-->
<xsl:for-each select="(attribute, vf:baseTypes(vf:asvodmlref(current()))/attribute)"> <!-- this takes care of dataType inheritance should work https://hibernate.atlassian.net/browse/HHH-12790 -->
<xsl:variable name="type" select="$models/key('ellookup',current()/datatype/vodml-ref)"/>
<xsl:apply-templates select="$type" mode="attrovercols">
<xsl:with-param name="prefix" select="concat($prefix,'_',name)"/>
</xsl:apply-templates>
</xsl:for-each>
<xsl:attribute name="f" select="'value'"/>
</xsl:template>
<!--produces _ separated string with possible last + separated
for the type access all _ and + should be changed to .
for the column name just drop the + separated if present.
-->
<xsl:template match="primitiveType" mode="attrovercols" as="xsd:string*">
<xsl:param name="prefix" as="xsd:string"/>
<xsl:variable name="type" select="$models/key('ellookup',current()/datatype/vodml-ref)"/>
<!-- <xsl:message>** attrovercolsP <xsl:value-of select="concat(name(),' ',name,' *** ',$prefix, ' extends=',extends)"/></xsl:message>-->
<xsl:choose>
<xsl:when test="vf:hasMapping(vf:asvodmlref(current()),'java')">
<xsl:variable name="pmap" select="vf:findmapping(vf:asvodmlref(current()),'java')"/>
<xsl:choose>
<xsl:when test="$pmap/@jpa-atomic">
<xsl:value-of select="$prefix"/>
</xsl:when>
<xsl:when test="$pmap/@primitive-value-field">
<xsl:value-of select="concat($prefix,'+',$pmap/@primitive-value-field)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($prefix,'+value')"/>
</xsl:otherwise>
</xsl:choose>

</xsl:when>
<xsl:when test="extends">
<xsl:apply-templates select="$models/key('ellookup',current()/extends/vodml-ref)" mode="attrovercols">
<xsl:with-param name="prefix" select="concat($prefix,'_value')"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$prefix"/> <!--this is the old primitive case -->
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template match="enumeration" mode="attrovercols" as="xsd:string*">
<xsl:param name="prefix" as="xsd:string"/>
<xsl:value-of select="$prefix"/>
<xsl:template match="constraint[ends-with(@xsi:type,':SubsettedRole')]" mode="attrovercols2">
<att c="{tokenize(role/vodml-ref,'\.')[last()]}">
<xsl:apply-templates select="$models/key('ellookup',current()/datatype/vodml-ref)" mode="attrovercols2"/>
</att>
</xsl:template>




<!-- end of attribute override code for datatypes -->

<xsl:function name="vf:schema-location4model" as="xsd:string">
Expand Down
48 changes: 17 additions & 31 deletions tools/xslt/jpa.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<!ENTITY cr "<xsl:text>
</xsl:text>">
<!ENTITY bl "<xsl:text> </xsl:text>">
<!ENTITY bl "<xsl:text> </xsl:text>">
]>

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
Expand Down Expand Up @@ -210,8 +209,6 @@
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="doEmbeddedJPA">
<xsl:with-param name="name" select="$name"/>
<xsl:with-param name="type" select="$type"/>
<xsl:with-param name="nillable" >
<xsl:choose>
<xsl:when test="$isRdbSingleInheritance">true</xsl:when><!--IMPL perhaps this is too simplistic -->
Expand All @@ -232,47 +229,36 @@
</xsl:template>

<xsl:template name="doEmbeddedJPA">
<xsl:param name="name"/>
<xsl:param name="type"/>
<xsl:param name="nillable"/>
@jakarta.persistence.Embedded
<xsl:if test="current()/parent::objectType">
<xsl:variable name="attovers" as="xsd:string*">
<!-- IMPL - this code is a bit ugly - is attempting to deal with the case where a dataType has a dataType member (quite frequent as base model has quantities)
it probably can be refactored to be a bit more recursive -->
<xsl:variable name="atv" as="xsd:string*">
<xsl:apply-templates select="$models/key('ellookup',current()/datatype/vodml-ref)" mode="attrovercols"><xsl:with-param name="prefix" select="$name"/></xsl:apply-templates>
</xsl:variable>
<xsl:message><xsl:value-of select="concat('***',$name,'-',$type/name, ' ', name,' overrides --- ',string-join($atv, ' %%%* '))" /></xsl:message>
<xsl:for-each select="$atv">
<xsl:variable name="tmp"> <!-- just to make formatting easier (otherwise each bit is a string seqmnent, and a lot of quotes!) -->
<xsl:variable name="attsubst">
<xsl:value-of select="string-join(tokenize(.,'_|\+')[position() != 1],'.')"/>
</xsl:variable>
<xsl:variable name="colsubs">
<xsl:choose>
<xsl:when test="contains(.,'+')">
<xsl:value-of select="substring-before(.,'+')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>

</xsl:variable>
@jakarta.persistence.AttributeOverride(name="<xsl:value-of select='$attsubst'/>", column = @jakarta.persistence.Column(name="<xsl:value-of select='$colsubs'/>", nullable = <xsl:value-of select='$nillable'/> ))
</xsl:variable>
<xsl:value-of select="$tmp"/>
</xsl:for-each>
-->
<xsl:variable name="atv">
<xsl:apply-templates select="current()" mode="attrovercols2"/>
</xsl:variable>
<!-- <xsl:message>*** <xsl:value-of select="vf:asvodmlref(current())"/> -&#45;&#45; <xsl:copy-of select="$atv" copy-namespaces="no"/></xsl:message>-->
<xsl:apply-templates select="$atv" mode="doAttributeOverride">
<xsl:with-param name="nillable" select="$nillable"/>
</xsl:apply-templates>
</xsl:variable>
@jakarta.persistence.AttributeOverrides( {
<xsl:value-of select="string-join($attovers,concat(',',$cr))"/>
})
</xsl:if>
</xsl:template>
<xsl:template match="att[not(*)]" mode="doAttributeOverride">
<xsl:param name="nillable"/>

<xsl:sequence select="concat('@jakarta.persistence.AttributeOverride(name=',$dq, string-join(current()/ancestor-or-self::att/@f,'.'),$dq,
', column = @jakarta.persistence.Column(name=',$dq,string-join(current()/ancestor-or-self::att/@c,'_'),$dq,
',nullable = ',$nillable,' ))')"/>
</xsl:template>



<!-- do the embedded refs -->
<!-- do the embedded refs -->
<xsl:template match="objectType[attribute[vf:isDataType(.)]]" mode="doEmbeddedRefs">
<xsl:variable name="attovers" as="xsd:string*">
<xsl:for-each select="attribute[vf:isDataType(.)]">
Expand Down
2 changes: 0 additions & 2 deletions tools/xslt/vo-dml2java.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,6 @@ package <xsl:value-of select="$path"/>;

<xsl:if test="$do_jpa">
<xsl:call-template name="doEmbeddedJPA">
<xsl:with-param name="name" select="$name"/>
<xsl:with-param name="type" select="$models/key('ellookup',current()/datatype/vodml-ref)"/>
<xsl:with-param name="nillable" >true</xsl:with-param><!--TODO think if it is possible to do better with nillable value-->
</xsl:call-template>

Expand Down
6 changes: 3 additions & 3 deletions tools/xslt/vo-dml2tap.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ FIXME This is not yet complete
<xsl:variable name="top-vodml-ref" select="ancestor-or-self::dt[last()]/@v"/>
<xsl:variable name="top-el" select="$models/key('ellookup',$top-vodml-ref)"/>
<column>
<column_name><xsl:value-of select="string-join(current()/ancestor-or-self::att/@n,'_')"/></column_name>
<column_name><xsl:value-of select="string-join(current()/ancestor-or-self::att/@c,'_')"/></column_name>
<xsl:comment>attribute from dtype</xsl:comment>
<datatype>{vf:rdbTapType(@type)}</datatype>
<description>{$top-el/description}</description><!-- TODO would perhaps like to include datatype description too -->
Expand All @@ -215,7 +215,7 @@ FIXME This is not yet complete
<xsl:variable name="top-vodml-ref" select="ancestor-or-self::dt[last()]/@v"/>
<xsl:variable name="top-el" select="$models/key('ellookup',$top-vodml-ref)"/>
<column>
<column_name><xsl:value-of select="string-join(current()/(ancestor-or-self::att|ancestor-or-self::ref)/@n,'_')"/></column_name>
<column_name><xsl:value-of select="string-join(current()/(ancestor-or-self::att|ancestor-or-self::ref)/@c,'_')"/></column_name>
<xsl:comment>reference from datatype</xsl:comment>
<datatype>{vf:rdbKeyType(@type)}</datatype>
<description>{$top-el/description}</description><!-- TODO would perhaps like to include datatype description too -->
Expand All @@ -238,7 +238,7 @@ FIXME This is not yet complete
<utype>{$top-vodml-ref}</utype>
<columns>
<FKColumn>
<from_column><xsl:value-of select="string-join(current()/(ancestor-or-self::att|ancestor-or-self::ref)/@n,'_')"/></from_column>
<from_column><xsl:value-of select="string-join(current()/(ancestor-or-self::att|ancestor-or-self::ref)/@c,'_')"/></from_column>
<target_column>{vf:tapTargetColumnName(@type)}</target_column>
</FKColumn>
</columns>
Expand Down

0 comments on commit d7c01fa

Please sign in to comment.