Skip to content

Commit

Permalink
extract the reference attribute overrides to @AssociationOverrides
Browse files Browse the repository at this point in the history
as they should have been all along
  • Loading branch information
pahjbo committed Nov 28, 2024
1 parent 2e688ef commit 2309548
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 9 deletions.
16 changes: 14 additions & 2 deletions models/sample/test/like_coords.vo-dml.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<title></title>
<author>Arnold Rots, Mark Cresitello-Dittmar, Omar Laurino</author>
<version>1.0</version>
<lastModified>2024-07-04T20:32:17Z</lastModified>
<lastModified>2024-11-28T11:52:20Z</lastModified>
<import>
<name>ivoa</name>
<version>1.0</version>
<version>1.0</version>
<url>IVOA-v1.0.vo-dml.xml</url>
<documentationURL>not known</documentationURL>
</import>
Expand Down Expand Up @@ -1039,5 +1039,17 @@
<maxOccurs>1</maxOccurs>
</multiplicity>
</attribute>
<attribute>
<vodml-id>AnObject.time</vodml-id>
<name>time</name>
<description>The time</description>
<datatype>
<vodml-ref>coords:MJD</vodml-ref>
</datatype>
<multiplicity>
<minOccurs>1</minOccurs>
<maxOccurs>1</maxOccurs>
</multiplicity>
</attribute>
</objectType>
</vo-dml:model>
1 change: 1 addition & 0 deletions models/sample/test/like_coords.vodsl
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,5 @@ otype CartesianCoordSpace -> PhysicalCoordSpace "Spatial domain, three-dimensio
//just here to make testing easier.
otype AnObject "example content" {
position:LonLatPoint "the position";
time:MJD "The time";
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public CoordsModel createModel() {

// note that this cannot be added directly as it is a dtype...
LonLatPoint llp = new LonLatPoint(new RealQuantity(45.0, deg), new RealQuantity(15.0, deg), new RealQuantity(1.5, new Unit("Mpc")), ICRS_SYS);
a = new AnObject(llp);
MJD mjd = new MJD(60310.0, TIMESYS_TT);
a = new AnObject(llp,mjd);
CoordsModel modelInstance = new CoordsModel();

modelInstance.addReference(TIMESYS_TT);
Expand All @@ -91,7 +92,17 @@ public CoordsModel createModel() {
return modelInstance;
}

@Override
/**
* {@inheritDoc}
* overrides @see org.ivoa.vodml.validation.AbstractBaseValidation#setDbDumpFile()
*/
@Override
protected String setDbDumpFile() {
return "notcoords_dump.sql";

}

@Override
public void testModel(CoordsModel coordsModel) {
List<AnObject> ts = coordsModel.getContent(AnObject.class);
assertNotNull(ts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public CoordsModel createModel() {

// note that this cannot be added directly as it is a dtype...
LonLatPoint llp = new LonLatPoint(new RealQuantity(45.0, deg), new RealQuantity(15.0, deg), new RealQuantity(1.5, new Unit("Mpc")), ICRS_SYS);
AnObject a = new AnObject(llp);
MJD mjd = new MJD(60000.0, TIMESYS_TT);
AnObject a = new AnObject(llp, mjd);
CoordsModel modelInstance = new CoordsModel();

modelInstance.addReference(TIMESYS_TT);
Expand Down
13 changes: 13 additions & 0 deletions tools/xslt/common-structure-functions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,19 @@ note - only define functions in here as it is included in the schematron rules
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="vf:isPrimitiveType" as="xsd:boolean">
<xsl:param name="el" as="element()"/>
<xsl:sequence select="vf:typeRole($el/datatype/vodml-ref) = 'primtiveType'"/>
</xsl:function>
<xsl:function name="vf:isDataType" as="xsd:boolean">
<xsl:param name="el" as="element()"/>
<xsl:sequence select="vf:typeRole($el/datatype/vodml-ref) = 'dataType'"/>
</xsl:function>
<xsl:function name="vf:isObjectType" as="xsd:boolean">
<xsl:param name="el" as="element()"/>
<xsl:sequence select="vf:typeRole($el/datatype/vodml-ref) = 'objectType'"/>
</xsl:function>

<!-- returns the vodml-refs of the members including inherited ones -->
<xsl:function name="vf:allInheritedMembers" as="xsd:string*">
<xsl:param name="vodml-ref" as="xsd:string"/>
Expand Down
29 changes: 25 additions & 4 deletions tools/xslt/jpa.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<!-- TODO need to think about subgraphs -->
)
</xsl:if>
<xsl:apply-templates select="current()[attribute[vf:isDataType(.)]]" mode="doEmbeddedRefs"/>

</xsl:template>

Expand Down Expand Up @@ -270,20 +271,20 @@

</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: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:for-each select="(reference, vf:baseTypes(vf:asvodmlref(current()))/reference)">
<xsl:sequence select="concat($prefix,'_',name)"/>
</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.
Expand Down Expand Up @@ -324,6 +325,26 @@
<xsl:value-of select="$prefix"/>
</xsl:template>

<!-- 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(.)]">
<xsl:apply-templates select="current()" mode="doEmbeddedRefs"/>
</xsl:for-each>
</xsl:variable>
<xsl:if test="not(empty($attovers))">
@jakarta.persistence.AssociationOverrides( {
<xsl:value-of select="string-join($attovers,concat(',',$cr))"/>
})
</xsl:if>
</xsl:template>

<xsl:template match="attribute" mode="doEmbeddedRefs" as="xsd:string*">
<xsl:variable name="thisname" select="name"/>
<xsl:for-each select="($models/key('ellookup',current()/datatype/vodml-ref)/reference,vf:baseTypes(current()/datatype/vodml-ref)/reference)">
<xsl:value-of select="concat('@jakarta.persistence.AssociationOverride(name=',$dq,$thisname,'.',name,$dq,',joinColumns = { @jakarta.persistence.JoinColumn(name=',$dq,$thisname,'_',name,$dq, ',nullable =',true(),')})')"/><!--IMPL have to allow null - too difficult to work out when not allowed - see proposalDM ObservingPlatform -->
</xsl:for-each>
</xsl:template>


<xsl:template match="attribute|reference|composition" mode="nullable">
Expand Down

0 comments on commit 2309548

Please sign in to comment.