diff --git a/schemas/adl-0.dtd b/schemas/adl-0.dtd index 96efe12..b078d09 100755 --- a/schemas/adl-0.dtd +++ b/schemas/adl-0.dtd @@ -13,7 +13,7 @@ <!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --> <!-- - $Revision: 1.9 $ + $Revision: 1.10 $ --> <!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --> @@ -142,15 +142,11 @@ name: the name of this application version: the version number of this application - assembly: C# implementation detail, DEPRECATED: should not be here - namespace: C# implementation detail, DEPRECATED: should not be here xmlns: XML namespace, in case required --> <!ELEMENT application ( documentation?, content?, typedef*, group*, entity*)> <!ATTLIST application name CDATA #REQUIRED - assembly CDATA #IMPLIED - namespace CDATA #IMPLIED version CDATA #IMPLIED xmlns CDATA #IMPLIED> @@ -270,7 +266,9 @@ if type='list', the name of the entity that has a foreign key link to this entity farkey: if type='list', the name of farside key in the listed - entity + entity; if type='entity' and the farside field to join to + is not the farside primary key, then the name of that + farside field required: whether this propery is required (i.e. 'not null'). size: fieldwidth of the property if specified. concrete: if set to 'false', this property is not stored in the diff --git a/transforms01/adl2entityclass.xslt b/transforms01/adl2entityclass.xslt index 56e6cb9..4026c89 100755 --- a/transforms01/adl2entityclass.xslt +++ b/transforms01/adl2entityclass.xslt @@ -8,8 +8,8 @@ Transform ADL into entity classes $Author: sb $ - $Revision: 1.4 $ - $Date: 2008-02-06 17:24:53 $ + $Revision: 1.5 $ + $Date: 2008-02-13 15:56:31 $ --> <!-- WARNING WARNING WARNING: Do NOT reformat this file! @@ -45,15 +45,13 @@ <xsl:template match="adl:entity[@foreign='true']"/> <xsl:template match="adl:entity"> - <xsl:message terminate="no">Matched entity with name <xsl:value-of select="@name"/> - </xsl:message> <!-- what's all this about? the objective is to get the revision number of the transform into the output, /without/ getting that revision number overwritten with the revision number of the generated file if the generated file is stored to CVS --> <xsl:variable name="transform-rev1" - select="substring( '$Revision: 1.4 $', 11)"/> + select="substring( '$Revision: 1.5 $', 11)"/> <xsl:variable name="transform-revision" select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/> @@ -337,11 +335,11 @@ </xsl:choose> </xsl:when> <xsl:when test="normalize-space( $nullable-decoration) = '?'"> = null</xsl:when> - <xsl:when test="$base-type = 'boolean'"> = false</xsl:when> + <xsl:when test="$base-type = 'Boolean'"> = false</xsl:when> <xsl:when test="$base-type = 'int'"> = 0</xsl:when> <xsl:when test="$csharp-type = 'Decimal'"> = 0.0M</xsl:when> <xsl:when test="$base-type = 'real'"> = 0.0</xsl:when> - <xsl:when test="$base-type='string'"> = null</xsl:when> + <xsl:when test="$base-type='String'"> = null</xsl:when> </xsl:choose> </xsl:variable> @@ -427,6 +425,29 @@ } } + <xsl:if test="parent::adl:key and @type='entity'"> + /* generate primitive value getter/setter for key property of type entity (experimental) */ + <xsl:variable name="csharp-base-type"> + <xsl:call-template name="csharp-base-type"> + <xsl:with-param name="property" select="."/> + </xsl:call-template> + </xsl:variable> + private <xsl:value-of select="concat( $csharp-base-type, ' _', @name, '_Value')"/> <xsl:choose> + <xsl:when test="$csharp-base-type = 'Boolean'"> = false</xsl:when> + <xsl:when test="$csharp-base-type = 'int'"> = 0</xsl:when> + <xsl:when test="$csharp-base-type = 'Decimal'"> = 0.0M</xsl:when> + <xsl:when test="$csharp-base-type = 'real'"> = 0.0</xsl:when> + <xsl:when test="$csharp-base-type='String'"> = null</xsl:when> + <xsl:otherwise>[unknown? <xsl:value-of select="$csharp-base-type"/>] + </xsl:otherwise> + </xsl:choose>; + + public virtual <xsl:value-of select="concat( $csharp-base-type, ' ', @name, '_Value')"/> { + get { return <xsl:value-of select="concat( '_', @name, '_Value')"/>; } + set { <xsl:value-of select="concat( '_', @name, '_Value')"/> = value; } + } + </xsl:if> + </xsl:template> <xsl:template match="adl:help"> diff --git a/transforms01/adl2hibernate.xslt b/transforms01/adl2hibernate.xslt index 9af69d0..f786d96 100755 --- a/transforms01/adl2hibernate.xslt +++ b/transforms01/adl2hibernate.xslt @@ -12,7 +12,7 @@ Transform ADL to Hibernate $Author: sb $ - $Revision: 1.5 $ + $Revision: 1.6 $ --> <!-- @@ -35,6 +35,15 @@ <xsl:include href="csharp-type-include.xslt"/> + <xsl:variable name="dbprefix"> + <xsl:choose> + <xsl:when test="string-length( $database) > 0"> + <xsl:value-of select="concat( $database, '.dbo.')"/> + </xsl:when> + <xsl:otherwise/> + </xsl:choose> + </xsl:variable> + <xsl:template match="adl:application"> <hibernate-mapping> <xsl:attribute name="namespace"> @@ -53,7 +62,7 @@ * THIS FILE IS AUTOMATICALLY GENERATED AND SHOULD NOT * BE MANUALLY EDITED. * - * Generated using adl2hibernate-mapping.xsl revision <xsl:value-of select="substring('$Revision: 1.5 $', 12)"/> + * Generated using adl2hibernate-mapping.xsl revision <xsl:value-of select="substring('$Revision: 1.6 $', 12)"/> * *************************************************************************** </xsl:comment> @@ -100,9 +109,6 @@ </xsl:when> <xsl:when test="count( adl:property) = 1"> <id> - <xsl:attribute name="name"> - <xsl:value-of select="adl:property[position()=1]/@name"/> - </xsl:attribute> <xsl:attribute name="column"> <xsl:choose> <xsl:when test="adl:property[position()=1]/@column"> @@ -120,12 +126,32 @@ </xsl:attribute> <xsl:choose> <xsl:when test="adl:property[position()=1]/adl:generator"> + <xsl:attribute name="name"> + <xsl:value-of select="adl:property[position()=1]/@name"/> + </xsl:attribute> <xsl:apply-templates select="adl:property[position()=1]/adl:generator"/> </xsl:when> <xsl:when test="adl:property[position()=1 and @type='entity']"> + <xsl:attribute name="name"> + <xsl:value-of select="concat( adl:property[position()=1]/@name, '_Value')"/> + </xsl:attribute> + <xsl:variable name="entityname" select="adl:property[position()=1]/@entity"/> + <xsl:variable name="farkey"> + <xsl:choose> + <xsl:when test="adl:property[position()=1]/@farkey"> + <xsl:value-of select="adl:property[position()=1]/@farkey"/> + </xsl:when> + <xsl:when test="//adl:entity[@name=$entityname]/adl:key/adl:property"> + <xsl:value-of select="//adl:entity[@name=$entityname]/adl:key/adl:property[position()=1]/@name"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="'[unkown?]'"/> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> <generator class="foreign"> <param name="property"> - <xsl:value-of select="adl:property[position()=1]/@name"/> + <xsl:value-of select="$farkey"/> </param> </generator> </xsl:when> @@ -220,7 +246,7 @@ <!-- a property of type entity translates to a Hibernate many-to-one, unless it's part of the key, in which case it translates as one-to-one. TODO: Check this logic! --> - <xsl:choose> + <!-- xsl:choose> <xsl:when test="parent::adl:key"> <one-to-one> <xsl:attribute name="name"> @@ -229,6 +255,11 @@ <xsl:attribute name="class"> <xsl:value-of select="@entity"/> </xsl:attribute> + <xsl:if test="@farkey"> + <xsl:attribute name="property-ref"> + <xsl:value-of select="@farkey"/> + </xsl:attribute> + </xsl:if> <xsl:choose> <xsl:when test="@cascade='manual'"/> <xsl:when test="@cascade"> @@ -240,7 +271,7 @@ <xsl:apply-templates select="adl:documentation"/> </one-to-one> </xsl:when> - <xsl:otherwise> + <xsl:otherwise --> <many-to-one> <xsl:attribute name="name"> <xsl:value-of select="@name"/> @@ -258,6 +289,11 @@ </xsl:otherwise> </xsl:choose> </xsl:attribute> + <xsl:if test="@farkey"> + <xsl:attribute name="property-ref"> + <xsl:value-of select="@farkey"/> + </xsl:attribute> + </xsl:if> <xsl:choose> <xsl:when test="@cascade='manual'"/> <xsl:when test="@cascade"> @@ -268,8 +304,8 @@ </xsl:choose> <xsl:apply-templates select="adl:documentation"/> </many-to-one> - </xsl:otherwise> - </xsl:choose> + <!-- /xsl:otherwise> + </xsl:choose --> </xsl:template> <xsl:template match="adl:property[@type='list']"> @@ -330,10 +366,10 @@ <xsl:variable name="tablename"> <xsl:choose> <xsl:when test="$comparison =-1"> - <xsl:value-of select="concat( 'ln_', ../@name, '_', @entity)"/> + <xsl:value-of select="concat( $dbprefix, 'ln_', ../@name, '_', @entity)"/> </xsl:when> <xsl:otherwise> - <xsl:value-of select="concat( 'ln_', @entity, '_', ../@name)"/> + <xsl:value-of select="concat( $dbprefix, 'ln_', @entity, '_', ../@name)"/> </xsl:otherwise> </xsl:choose> </xsl:variable>