Skip to content

Commit

Permalink
initial DataType support in the TAP schema
Browse files Browse the repository at this point in the history
  • Loading branch information
pahjbo committed Jan 30, 2025
1 parent df26988 commit 5c968f3
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 67 deletions.
113 changes: 113 additions & 0 deletions tools/xslt/common-binding.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,120 @@
</xsl:choose>
</xsl:function>

<!-- beginning of attribute override code for datatypes -->
<!-- IMPL this code is still template based rather than function based - it does return a new structure representing the datatypes subtrees though, so templates probably best -->
<xsl:template match="dataType" mode="attrovercols2" >
<dt v="{vf:asvodmlref(current())}" n="{name}">
<xsl:apply-templates select="(attribute|reference, vf:baseTypes(vf:asvodmlref(current()))/(attribute|reference))" mode="attrovercols2"/> <!-- this takes care of dataType inheritance should work https://hibernate.atlassian.net/browse/HHH-12790 -->
<!-- FIXME what about subtypes? -->
</dt>
</xsl:template>
<xsl:template match="attribute" mode="attrovercols2" >
<att v="{vf:asvodmlref(current())}" n="{name}">
<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}">
<xsl:attribute name="type" select="datatype/vodml-ref"/>
</ref>
</xsl:template>

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

</xsl:when>
<xsl:otherwise>
<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:attribute name="atomic" select="true()"/>
</xsl:when>
<xsl:when test="$pmap/@primitive-value-field">
<xsl:attribute name="field" select="$pmap/@primitive-value-field"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="field" select="'value'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="field" select="'value'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<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: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>




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

<xsl:function name="vf:schema-location4model" as="xsd:string">
<xsl:param name="s" as="xsd:string"/>
Expand Down
56 changes: 2 additions & 54 deletions tools/xslt/jpa.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
</xsl:when>
<xsl:when test="name($type) = 'dataType'">
<xsl:choose>
<xsl:when test="xsd:int(multiplicity/maxOccurs) = -1">
<xsl:when test="xsd:int(multiplicity/maxOccurs) = -1"> <!--TODO IMPL multiplicity > 1 being supported - but it really should not be modelled this way -->
<xsl:variable name="tableName">
<xsl:apply-templates select=".." mode="tableName"/><xsl:text>_</xsl:text><xsl:value-of select="$name"/>
</xsl:variable>
Expand Down Expand Up @@ -242,7 +242,7 @@
<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 -&#45;&#45; ',string-join($atv, ' %%%* '))" /></xsl:message>-->
<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">
Expand Down Expand Up @@ -271,58 +271,6 @@
</xsl:template>


<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: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>

<!-- do the embedded refs -->
<xsl:template match="objectType[attribute[vf:isDataType(.)]]" mode="doEmbeddedRefs">
Expand Down
84 changes: 71 additions & 13 deletions tools/xslt/vo-dml2tap.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
This will produce a tap schema representation of the data model database serialization
FIXME This is not yet complete
* no datatype mapping to columns not done
* subsetting rules not done
-->

Expand Down Expand Up @@ -61,7 +60,7 @@ FIXME This is not yet complete
<xsl:apply-templates select="objectType"/>

<xsl:apply-templates select="package"/>
<!-- TODO should do imports -->
<!-- TODO should do imports as we probably want the whole schema in one hit rather than separately for each model. -->
</tables>
</schema>
</tap:tapschemaModel>
Expand Down Expand Up @@ -157,6 +156,8 @@ FIXME This is not yet complete
</ForeignKey>

</xsl:if>
<xsl:apply-templates select="attribute[vf:isDataType(.)]" mode="dtyperef"/>

</fkeys>
</table>
</xsl:if>
Expand All @@ -171,26 +172,83 @@ FIXME This is not yet complete
<description>{description}</description>
<utype>{$vodml-ref}</utype>
<indexed>{count(constraint[ends-with(@xsi:type,':NaturalKey')])> 0}</indexed>
<principal>false</principal><!-- FIXME need a way of actually specifying this -->
<principal>false</principal><!-- TODO need a way of actually specifying this -->
<std>true</std><!--IMPL if generated from VO-DML - should be a standard -->
</column>
</xsl:template>

<xsl:template match="attribute[vf:isDataType(.)]" mode="defn" >
<xsl:variable name="vodml-ref" select="vf:asvodmlref(current())"/>
<!-- FIXME need to deal with datatypes properly -->

<xsl:variable name="atv">
<xsl:apply-templates select="current()" mode="attrovercols2"/>
</xsl:variable>
<!-- <xsl:message>**** <xsl:copy-of select="$atv" copy-namespaces="no"/></xsl:message>-->

<xsl:apply-templates select="$atv" mode="dtypeexpandcols"/>

</xsl:template>
<xsl:template match="attribute[vf:isDataType(.)]" mode="dtyperef" >
<xsl:variable name="atv">
<xsl:apply-templates select="current()" mode="attrovercols2"/>
</xsl:variable>
<xsl:apply-templates select="$atv" mode="dtypeexpandrefs"/>
</xsl:template>

<!-- note that these templates are matching on the construct created by the attrovercols2 mode on attributes -->
<xsl:template match="att[not(*)]" mode="dtypeexpandcols">
<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>{vf:tapcolumnName($vodml-ref)}</column_name>
<xsl:comment>attribute of {vf:typeRole(datatype/vodml-ref)} {datatype/vodml-ref}</xsl:comment>
<datatype>DATATYPE</datatype>
<description>{description}</description>
<utype>{$vodml-ref}</utype>
<indexed>{count(constraint[ends-with(@xsi:type,':NaturalKey')])> 0}</indexed>
<principal>false</principal><!-- FIXME need a way of actually specifying this -->
<column_name><xsl:value-of select="string-join(current()/ancestor-or-self::att/@n,'_')"/></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 -->
<utype>{$top-vodml-ref}</utype>
<indexed>{count($top-el/constraint[ends-with(@xsi:type,':NaturalKey')])> 0}</indexed>
<principal>false</principal><!-- TODO need a way of actually specifying this -->
<std>true</std><!--IMPL if generated from VO-DML - should be a standard -->
</column>
</xsl:template>

<xsl:template match="ref" mode="dtypeexpandcols">
<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>
<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 -->
<utype>{@v}</utype>
<indexed>true</indexed>
<principal>false</principal><!-- TODO need a way of actually specifying this -->
<std>true</std><!--IMPL if generated from VO-DML - should be a standard -->
</column>
</xsl:template>

<xsl:template match="ref" mode="dtypeexpandrefs">
<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)"/>
<ForeignKey>
<xsl:variable name="vodml-ref" select="vf:asvodmlref(current())"/>
<key_id>{vf:tapFkeyID($top-vodml-ref)}</key_id>
<xsl:comment>reference to {@type}</xsl:comment>

<description>{$top-el/description}</description>
<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>
<target_column>{vf:tapTargetColumnName(@type)}</target_column>
</FKColumn>
</columns>
<target_table>{vf:rdbTableName(@type)}</target_table>
</ForeignKey>
</xsl:template>




<xsl:template match="reference" mode="defn">
<column>
<xsl:variable name="vodml-ref" select="vf:asvodmlref(current())"/>
Expand All @@ -200,7 +258,7 @@ FIXME This is not yet complete
<description>{description}</description>
<utype>{$vodml-ref}</utype>
<indexed>false</indexed><!-- IMPL or true?! -->
<principal>false</principal><!-- FIXME need a way of actually specifying this -->
<principal>false</principal><!-- TODO need a way of actually specifying this -->
<std>true</std><!--IMPL if generated from VO-DML - should be a standard -->
</column>
</xsl:template>
Expand Down Expand Up @@ -255,7 +313,7 @@ FIXME This is not yet complete
<description>foreign key column for {$vodml-ref} composition of {datatype/vodml-ref}</description>
<utype>{$vodml-ref}</utype>
<indexed>false</indexed><!-- IMPL or true?! -->
<principal>false</principal><!-- FIXME need a way of actually specifying this -->
<principal>false</principal><!-- TODO need a way of actually specifying this -->
<std>true</std><!--IMPL if generated from VO-DML - should be a standard -->
</column>
</xsl:if>
Expand Down

0 comments on commit 5c968f3

Please sign in to comment.