Generatinga clean and believable-looking hibernate mapping, although not yet proven to work.
This commit is contained in:
parent
f64f137a67
commit
4c4a16631c
|
@ -16,8 +16,8 @@
|
||||||
are generated.
|
are generated.
|
||||||
|
|
||||||
$Author: sb $
|
$Author: sb $
|
||||||
$Revision: 1.4 $
|
$Revision: 1.5 $
|
||||||
$Date: 2008-02-07 16:35:00 $
|
$Date: 2008-02-07 17:45:32 $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<xsl:stylesheet version="1.0"
|
<xsl:stylesheet version="1.0"
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
* THIS FILE IS AUTOMATICALLY GENERATED AND SHOULD NOT
|
* THIS FILE IS AUTOMATICALLY GENERATED AND SHOULD NOT
|
||||||
* BE MANUALLY EDITED.
|
* BE MANUALLY EDITED.
|
||||||
*
|
*
|
||||||
* Generated using adl2canonical.xsl revision <xsl:value-of select="substring('$Revision: 1.4 $', 12)"/>
|
* Generated using adl2canonical.xsl revision <xsl:value-of select="substring('$Revision: 1.5 $', 12)"/>
|
||||||
*
|
*
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
</xsl:comment>
|
</xsl:comment>
|
||||||
|
@ -134,6 +134,9 @@
|
||||||
<xsl:value-of select="normalize-space( $key)"/>
|
<xsl:value-of select="normalize-space( $key)"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
<generator action="native"/>
|
<generator action="native"/>
|
||||||
|
<documentation>
|
||||||
|
Auto-generated abstract primary key
|
||||||
|
</documentation>
|
||||||
</property>
|
</property>
|
||||||
</key>
|
</key>
|
||||||
<xsl:apply-templates select="adl:property | adl:one-to-many | adl:many-to-many | adl:many-to-one"/>
|
<xsl:apply-templates select="adl:property | adl:one-to-many | adl:many-to-many | adl:many-to-one"/>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<xsl:stylesheet version="1.0"
|
<xsl:stylesheet version="1.0"
|
||||||
|
xmlns="urn:nhibernate-mapping-2.2"
|
||||||
xmlns:adl="http://cygnets.co.uk/schemas/adl-1.2"
|
xmlns:adl="http://cygnets.co.uk/schemas/adl-1.2"
|
||||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||||
xmlns:hbn="urn:nhibernate-mapping-2.2">
|
|
||||||
<!--
|
<!--
|
||||||
Application Description Framework
|
Application Description Framework
|
||||||
adl2hibernate.xsl
|
adl2hibernate.xsl
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
Transform ADL to Hibernate
|
Transform ADL to Hibernate
|
||||||
|
|
||||||
$Author: sb $
|
$Author: sb $
|
||||||
$Revision: 1.2 $
|
$Revision: 1.3 $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
-->
|
-->
|
||||||
<xsl:param name="abstract-key-name-convention" select="Id"/>
|
<xsl:param name="abstract-key-name-convention" select="Id"/>
|
||||||
|
|
||||||
<xsl:output indent="yes" method="xml" encoding="UTF-8"/>
|
<xsl:output indent="no" method="xml" encoding="UTF-8"/>
|
||||||
<!-- NOTE! indent="no" because hibernate falls over if there is whitespace inside
|
<!-- NOTE! indent="no" because hibernate falls over if there is whitespace inside
|
||||||
a 'key' or 'one-to-many' element, and the printer used by the NAnt 'style' task
|
a 'key' or 'one-to-many' element, and the printer used by the NAnt 'style' task
|
||||||
does not tag-minimize on output. If you change this the build will break, you
|
does not tag-minimize on output. If you change this the build will break, you
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
<xsl:variable name="assembly">SRU.Hospitality.DataModel</xsl:variable>
|
<xsl:variable name="assembly">SRU.Hospitality.DataModel</xsl:variable>
|
||||||
|
|
||||||
<xsl:template match="adl:application">
|
<xsl:template match="adl:application">
|
||||||
<hbn:hibernate-mapping>
|
<hibernate-mapping>
|
||||||
<xsl:attribute name="namespace">
|
<xsl:attribute name="namespace">
|
||||||
<xsl:value-of select="$namespace"/>
|
<xsl:value-of select="$namespace"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
|
@ -53,12 +53,12 @@
|
||||||
* THIS FILE IS AUTOMATICALLY GENERATED AND SHOULD NOT
|
* THIS FILE IS AUTOMATICALLY GENERATED AND SHOULD NOT
|
||||||
* BE MANUALLY EDITED.
|
* BE MANUALLY EDITED.
|
||||||
*
|
*
|
||||||
* Generated using adl2hibernate-mapping.xsl revision <xsl:value-of select="substring('$Revision: 1.2 $', 12)"/>
|
* Generated using adl2hibernate-mapping.xsl revision <xsl:value-of select="substring('$Revision: 1.3 $', 12)"/>
|
||||||
*
|
*
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
</xsl:comment>
|
</xsl:comment>
|
||||||
<xsl:apply-templates select="adl:entity"/>
|
<xsl:apply-templates select="adl:entity"/>
|
||||||
</hbn:hibernate-mapping>
|
</hibernate-mapping>
|
||||||
|
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
|
|
||||||
<xsl:template match="adl:entity">
|
<xsl:template match="adl:entity">
|
||||||
<xsl:apply-templates select="adl:documentation"/>
|
<xsl:apply-templates select="adl:documentation"/>
|
||||||
<hbn:class>
|
<class>
|
||||||
<xsl:attribute name="name">
|
<xsl:attribute name="name">
|
||||||
<xsl:value-of select="@name"/>
|
<xsl:value-of select="@name"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
|
@ -75,14 +75,15 @@
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
<xsl:apply-templates select="adl:key"/>
|
<xsl:apply-templates select="adl:key"/>
|
||||||
<xsl:apply-templates select="adl:property"/>
|
<xsl:apply-templates select="adl:property"/>
|
||||||
</hbn:class>
|
</class>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
<xsl:template match="adl:key">
|
<xsl:template match="adl:key">
|
||||||
<xsl:choose>
|
<xsl:choose>
|
||||||
<xsl:when test="count( property) = 0"/>
|
<xsl:when test="count( adl:property) = 0">
|
||||||
<xsl:when test="count( property) = 1">
|
</xsl:when>
|
||||||
<hbn:id>
|
<xsl:when test="count( adl:property) = 1">
|
||||||
|
<id>
|
||||||
<xsl:attribute name="name">
|
<xsl:attribute name="name">
|
||||||
<xsl:value-of select="adl:property[position()=1]/@name"/>
|
<xsl:value-of select="adl:property[position()=1]/@name"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
|
@ -101,17 +102,66 @@
|
||||||
<xsl:with-param name="property" select="adl:property[position()=1]"/>
|
<xsl:with-param name="property" select="adl:property[position()=1]"/>
|
||||||
</xsl:call-template>
|
</xsl:call-template>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
<xsl:apply-templates select="adl:generator"/>
|
<xsl:apply-templates select="adl:property[position()=1]/adl:generator"/>
|
||||||
</hbn:id>
|
</id>
|
||||||
</xsl:when>
|
</xsl:when>
|
||||||
<xsl:otherwise>
|
<xsl:otherwise>
|
||||||
<xsl:comment>Composite primary key - not yet implemented in adl2hibernate</xsl:comment>
|
<composite-id>
|
||||||
|
<xsl:attribute name="name">
|
||||||
|
<xsl:choose>
|
||||||
|
<xsl:when test="$abstract-key-name-convention='Name'">
|
||||||
|
<xsl:value-of select="ancestor::adl:entity/@name"/>
|
||||||
|
</xsl:when>
|
||||||
|
<xsl:when test="$abstract-key-name-convention = 'NameId'">
|
||||||
|
<xsl:value-of select="concat( ancestor::adl:entity/@name, 'Id')"/>
|
||||||
|
</xsl:when>
|
||||||
|
<xsl:when test="$abstract-key-name-convention = 'Name_Id'">
|
||||||
|
<xsl:value-of select="concat( ancestor::adl:entity/@name, '_Id')"/>
|
||||||
|
</xsl:when>
|
||||||
|
<xsl:otherwise>
|
||||||
|
<xsl:value-of select="'Id'"/>
|
||||||
|
</xsl:otherwise>
|
||||||
|
</xsl:choose>
|
||||||
|
</xsl:attribute>
|
||||||
|
<xsl:for-each select="adl:property[not(@type='entity')]">
|
||||||
|
<key-property>
|
||||||
|
<xsl:attribute name="name">
|
||||||
|
<xsl:value-of select="@name"/>
|
||||||
|
</xsl:attribute>
|
||||||
|
<xsl:attribute name="type">
|
||||||
|
<xsl:call-template name="csharp-type">
|
||||||
|
<xsl:with-param name="property" select="."/>
|
||||||
|
</xsl:call-template>
|
||||||
|
</xsl:attribute>
|
||||||
|
<xsl:apply-templates select="adl:documentation"/>
|
||||||
|
</key-property>
|
||||||
|
</xsl:for-each>
|
||||||
|
<xsl:for-each select="adl:property[@type='entity']">
|
||||||
|
<key-many-to-one>
|
||||||
|
<xsl:attribute name="name">
|
||||||
|
<xsl:value-of select="@name"/>
|
||||||
|
</xsl:attribute>
|
||||||
|
<xsl:attribute name="class">
|
||||||
|
<xsl:value-of select="@entity"/>
|
||||||
|
</xsl:attribute>
|
||||||
|
<xsl:choose>
|
||||||
|
<xsl:when test="@cascade='manual'"/>
|
||||||
|
<xsl:when test="@cascade">
|
||||||
|
<xsl:attribute name="cascade">
|
||||||
|
<xsl:value-of select="@cascade"/>
|
||||||
|
</xsl:attribute>
|
||||||
|
</xsl:when>
|
||||||
|
</xsl:choose>
|
||||||
|
<xsl:apply-templates select="adl:documentation"/>
|
||||||
|
</key-many-to-one>
|
||||||
|
</xsl:for-each>
|
||||||
|
</composite-id>
|
||||||
</xsl:otherwise>
|
</xsl:otherwise>
|
||||||
</xsl:choose>
|
</xsl:choose>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
<xsl:template match="adl:generator">
|
<xsl:template match="adl:generator">
|
||||||
<hbn:generator>
|
<generator>
|
||||||
<xsl:attribute name="class">
|
<xsl:attribute name="class">
|
||||||
<xsl:choose>
|
<xsl:choose>
|
||||||
<xsl:when test="@action='manual'">
|
<xsl:when test="@action='manual'">
|
||||||
|
@ -122,7 +172,7 @@
|
||||||
</xsl:otherwise>
|
</xsl:otherwise>
|
||||||
</xsl:choose>
|
</xsl:choose>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
</hbn:generator>
|
</generator>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
<xsl:template match="adl:property[@concrete='false']">
|
<xsl:template match="adl:property[@concrete='false']">
|
||||||
|
@ -132,8 +182,7 @@
|
||||||
|
|
||||||
<xsl:template match="adl:property[@type='entity']">
|
<xsl:template match="adl:property[@type='entity']">
|
||||||
<!-- a property of type entity translates to a Hibernate many-to-one -->
|
<!-- a property of type entity translates to a Hibernate many-to-one -->
|
||||||
<hbn:many-to-one>
|
<many-to-one>
|
||||||
<xsl:apply-templates select="adl:documentation"/>
|
|
||||||
<xsl:attribute name="name">
|
<xsl:attribute name="name">
|
||||||
<xsl:value-of select="@name"/>
|
<xsl:value-of select="@name"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
|
@ -148,7 +197,8 @@
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
</xsl:when>
|
</xsl:when>
|
||||||
</xsl:choose>
|
</xsl:choose>
|
||||||
</hbn:many-to-one>
|
<xsl:apply-templates select="adl:documentation"/>
|
||||||
|
</many-to-one>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
<xsl:template match="adl:property[@type='list']">
|
<xsl:template match="adl:property[@type='list']">
|
||||||
|
@ -164,8 +214,7 @@
|
||||||
</xsl:otherwise>
|
</xsl:otherwise>
|
||||||
</xsl:choose>
|
</xsl:choose>
|
||||||
</xsl:variable>
|
</xsl:variable>
|
||||||
<hbn:set>
|
<set>
|
||||||
<xsl:apply-templates select="adl:documentation"/>
|
|
||||||
<xsl:attribute name="name">
|
<xsl:attribute name="name">
|
||||||
<xsl:value-of select="@name"/>
|
<xsl:value-of select="@name"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
|
@ -176,18 +225,18 @@
|
||||||
<xsl:otherwise>false</xsl:otherwise>
|
<xsl:otherwise>false</xsl:otherwise>
|
||||||
</xsl:choose>
|
</xsl:choose>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
|
<xsl:apply-templates select="adl:documentation"/>
|
||||||
<!-- careful with reformatting here:
|
<!-- careful with reformatting here:
|
||||||
'The element cannot contain white space. Content model is empty.' -->
|
'The element cannot contain white space. Content model is empty.' -->
|
||||||
<hbn:key><xsl:attribute name="column">
|
<key><xsl:attribute name="column">
|
||||||
<!-- this is the name of the farside foreign key field which points to me -->
|
<!-- this is the name of the farside foreign key field which points to me -->
|
||||||
<xsl:value-of select="$farkey"/>
|
<xsl:value-of select="$farkey"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute></key>
|
||||||
</hbn:key>
|
<one-to-many>
|
||||||
<hbn:one-to-many>
|
|
||||||
<xsl:attribute name="class">
|
<xsl:attribute name="class">
|
||||||
<xsl:value-of select="@entity"/>
|
<xsl:value-of select="@entity"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
</hbn:one-to-many>
|
</one-to-many>
|
||||||
<xsl:choose>
|
<xsl:choose>
|
||||||
<xsl:when test="@cascade='manual'"/>
|
<xsl:when test="@cascade='manual'"/>
|
||||||
<xsl:when test="@cascade">
|
<xsl:when test="@cascade">
|
||||||
|
@ -196,7 +245,7 @@
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
</xsl:when>
|
</xsl:when>
|
||||||
</xsl:choose>
|
</xsl:choose>
|
||||||
</hbn:set>
|
</set>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
<xsl:template match="adl:property[@type='link']">
|
<xsl:template match="adl:property[@type='link']">
|
||||||
|
@ -218,7 +267,7 @@
|
||||||
</xsl:choose>
|
</xsl:choose>
|
||||||
</xsl:variable>
|
</xsl:variable>
|
||||||
|
|
||||||
<hbn:set>
|
<set>
|
||||||
<xsl:apply-templates select="adl:documentation"/>
|
<xsl:apply-templates select="adl:documentation"/>
|
||||||
<xsl:attribute name="name">
|
<xsl:attribute name="name">
|
||||||
<xsl:value-of select="@name"/>
|
<xsl:value-of select="@name"/>
|
||||||
|
@ -226,12 +275,12 @@
|
||||||
<xsl:attribute name="table">
|
<xsl:attribute name="table">
|
||||||
<xsl:value-of select="$tablename"/>
|
<xsl:value-of select="$tablename"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
<hbn:key>
|
<key>
|
||||||
<xsl:attribute name="column">
|
<xsl:attribute name="column">
|
||||||
<xsl:value-of select="concat( ../@name, 'Id')"/>
|
<xsl:value-of select="concat( ../@name, 'Id')"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
</hbn:key>
|
</key>
|
||||||
<hbn:many-to-many>
|
<many-to-many>
|
||||||
<xsl:attribute name="column">
|
<xsl:attribute name="column">
|
||||||
<xsl:choose>
|
<xsl:choose>
|
||||||
<xsl:when test="../@name = @entity">
|
<xsl:when test="../@name = @entity">
|
||||||
|
@ -245,16 +294,15 @@
|
||||||
<xsl:attribute name="class">
|
<xsl:attribute name="class">
|
||||||
<xsl:value-of select="@entity"/>
|
<xsl:value-of select="@entity"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
</hbn:many-to-many>
|
</many-to-many>
|
||||||
</hbn:set>
|
</set>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
<xsl:template match="adl:property">
|
<xsl:template match="adl:property">
|
||||||
<!-- tricky, this, because we're translating between ADL properties and
|
<!-- tricky, this, because we're translating between ADL properties and
|
||||||
Hibernate properties, which are (slightly) different. There's potential
|
Hibernate properties, which are (slightly) different. There's potential
|
||||||
for confusion -->
|
for confusion -->
|
||||||
<hbn:property>
|
<property>
|
||||||
<xsl:apply-templates select="adl:documentation"/>
|
|
||||||
<xsl:attribute name="name">
|
<xsl:attribute name="name">
|
||||||
<xsl:value-of select="@name"/>
|
<xsl:value-of select="@name"/>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
|
@ -263,10 +311,11 @@
|
||||||
<xsl:with-param name="property" select="."/>
|
<xsl:with-param name="property" select="."/>
|
||||||
</xsl:call-template>
|
</xsl:call-template>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
</hbn:property>
|
<xsl:apply-templates select="adl:documentation"/>
|
||||||
|
</property>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
<xsl:template name="adl:documentation">
|
<xsl:template match="adl:documentation">
|
||||||
<xsl:comment>
|
<xsl:comment>
|
||||||
<xsl:apply-templates/>
|
<xsl:apply-templates/>
|
||||||
</xsl:comment>
|
</xsl:comment>
|
||||||
|
|
Loading…
Reference in a new issue