Greatly improved Hibernate output; controller classes still broken
This commit is contained in:
parent
24078f8583
commit
0051f34ab8
|
@ -9,8 +9,8 @@
|
|||
Transform ADL into (partial) controller classes
|
||||
|
||||
$Author: sb $
|
||||
$Revision: 1.6 $
|
||||
$Date: 2008-02-11 16:21:32 $
|
||||
$Revision: 1.7 $
|
||||
$Date: 2008-02-13 09:52:42 $
|
||||
-->
|
||||
|
||||
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
|
||||
|
@ -62,7 +62,7 @@
|
|||
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.6 $', 11)"/>
|
||||
select="substring( '$Revision: 1.7 $', 11)"/>
|
||||
<xsl:variable name="transform-revision"
|
||||
select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/>
|
||||
|
||||
|
@ -174,7 +174,7 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
<!-- TODO: this does not correctly handle entities with composite primary keys -->
|
||||
record =
|
||||
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', @name)"/>))
|
||||
.Add(Expression.Eq("<xsl:value-of select="$key"/>", ((<xsl:value-of select="$keytype"/>)id)))
|
||||
.Add(Expression.Eq("<xsl:value-of select="$key"/>", id))
|
||||
.UniqueResult<<xsl:value-of select="concat( $entityns, '.', @name)"/>>();
|
||||
}
|
||||
|
||||
|
@ -190,9 +190,12 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
* special - BindObjectInstance /should/ do it all. Unfortunately it sometimes
|
||||
* doesn't, and I haven't yet characterised why not. */
|
||||
<!-- TODO: Fix this! -->
|
||||
<xsl:variable name="linkkeytype">
|
||||
<xsl:variable name="entityname" select="@entity"/>
|
||||
|
||||
// The broken bit: Entity name is <xsl:value-of select="$entityname"/>
|
||||
<!-- <xsl:variable name="linkkeytype">
|
||||
<xsl:call-template name="primary-key-csharp-type">
|
||||
<xsl:with-param name="entity" select="//entity[@name=@entity]"/>
|
||||
<xsl:with-param name="entity" select="//entity[@name=$entityname]"/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
record.<xsl:value-of select="@name"/> =
|
||||
|
@ -201,9 +204,10 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
<xsl:with-param name="entity" select="//entity[@name=@entity]"/>
|
||||
</xsl:call-template>", ((<xsl:value-of select="$linkkeytype"/>)Form["<xsl:value-of select="concat( $entityns, '.', @entity)"/>"])))
|
||||
.UniqueResult<<xsl:value-of select="concat( $entityns, '.', @entity)"/>>();
|
||||
-->
|
||||
</xsl:for-each>
|
||||
|
||||
<xsl:for-each select="property[@type='link']">
|
||||
<xsl:for-each select="property[@type='link']">
|
||||
/* to update a link table which has no other data than the near and far keys, it is
|
||||
* sufficient to smash the existing values and create new ones. It's also a lot easier! */
|
||||
|
||||
|
@ -266,9 +270,7 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
<xsl:variable name="entityname" select="@entity"/>
|
||||
<xsl:value-of select="@entity"/> item =
|
||||
hibernator.CreateCriteria(typeof(<xsl:value-of select="@entity"/>))
|
||||
.Add(Expression.Eq("<xsl:value-of select="@entity"/>Id", ((<xsl:call-template name="primary-key-csharp-type">
|
||||
<xsl:with-param name="entity" select="//adl:entity[@name=$entityname]"/>
|
||||
</xsl:call-template>)index)))
|
||||
.Add(Expression.Eq("<xsl:value-of select="@entity"/>Id", index))
|
||||
.UniqueResult<<xsl:value-of select="$entityns"/>.<xsl:value-of select="@entity"/>>();
|
||||
|
||||
if ( ! record.<xsl:value-of select="@name"/>.Contains( item))
|
||||
|
@ -337,9 +339,7 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
{
|
||||
<xsl:value-of select="concat($entityns, '.', @name)"/> record =
|
||||
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat($entityns, '.', @name)"/>))
|
||||
.Add(Expression.Eq("<xsl:value-of select="$key"/>", ((<xsl:call-template name="primary-key-csharp-type">
|
||||
<xsl:with-param name="entity" select="."/>
|
||||
</xsl:call-template>)))
|
||||
.Add(Expression.Eq("<xsl:value-of select="$key"/>", id))
|
||||
.UniqueResult<<xsl:value-of select="concat($entityns, '.', @name)"/>>();
|
||||
|
||||
if ( record != null)
|
||||
|
@ -348,7 +348,7 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
|
||||
hibernator.Delete(
|
||||
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat($entityns, '.', @name)"/>))
|
||||
.Add(Expression.Eq("<xsl:value-of select="$key"/>", ((<xsl:value-of select="$keytype"/>)id)))
|
||||
.Add(Expression.Eq("<xsl:value-of select="$key"/>", id))
|
||||
.UniqueResult<<xsl:value-of select="concat($entityns, '.', @name)"/>>());
|
||||
|
||||
hibernator.Flush();
|
||||
|
@ -392,7 +392,7 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
ISession hibernator =
|
||||
NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN],
|
||||
Session[NHibernateHelper.PASSTOKEN]</xsl:if>);
|
||||
IList<<xsl:value-of select="@name"/>> instances =
|
||||
IList<<xsl:value-of select="concat( $entityns, '.', @name)"/>> instances =
|
||||
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat($entityns, '.', @name)"/>))<xsl:for-each select="property[@distinct='user']">
|
||||
<xsl:value-of select="concat( '.AddOrder( new Order( "', @name, '", true))')"/>
|
||||
</xsl:for-each>.List<<xsl:value-of select="concat($entityns, '.', @name)"/>>();
|
||||
|
@ -515,7 +515,7 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
/// </summary>
|
||||
/// <param name="<xsl:value-of select="concat( ../@name, 'Id')"/>">the key value of the record to show</param>
|
||||
[AccessibleThrough(Verb.Get)]
|
||||
public void <xsl:value-of select="@name"/>( <xsl:value-of select="$keytype"/> <xsl:value-of select="concat( ../@name, 'Id')"/>)
|
||||
public void <xsl:value-of select="@name"/>( <xsl:value-of select="concat($keytype, ' ', ../@name, 'Id')"/>)
|
||||
{
|
||||
ISession hibernator =
|
||||
NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN],
|
||||
|
@ -601,9 +601,7 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
</xsl:message>
|
||||
</xsl:if>
|
||||
<xsl:call-template name="csharp-type">
|
||||
<xsl:with-param name="property">
|
||||
<xsl:value-of select="$entity/adl:key/adl:property[ position() = 1]"/>
|
||||
</xsl:with-param>
|
||||
<xsl:with-param name="property" select="$entity/adl:key/adl:property[ position() = 1]"/>
|
||||
</xsl:call-template>
|
||||
</xsl:template>
|
||||
|
||||
|
@ -645,4 +643,4 @@ namespace <xsl:value-of select="$controllerns"/> {
|
|||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
</xsl:stylesheet>
|
|
@ -12,7 +12,7 @@
|
|||
Transform ADL to Hibernate
|
||||
|
||||
$Author: sb $
|
||||
$Revision: 1.3 $
|
||||
$Revision: 1.4 $
|
||||
-->
|
||||
|
||||
<!--
|
||||
|
@ -23,6 +23,9 @@
|
|||
Name_Id - the name of the auto generated primary key is the name of the entity followed by '_Id'
|
||||
-->
|
||||
<xsl:param name="abstract-key-name-convention" select="Id"/>
|
||||
<xsl:param name="namespace"/>
|
||||
<xsl:param name="assembly"/>
|
||||
<xsl:param name="database"/>
|
||||
|
||||
<xsl:output indent="no" method="xml" encoding="UTF-8"/>
|
||||
<!-- NOTE! indent="no" because hibernate falls over if there is whitespace inside
|
||||
|
@ -32,9 +35,6 @@
|
|||
|
||||
<xsl:include href="csharp-type-include.xslt"/>
|
||||
|
||||
<xsl:variable name="namespace">SRU.Hospitality.Entities</xsl:variable>
|
||||
<xsl:variable name="assembly">SRU.Hospitality.DataModel</xsl:variable>
|
||||
|
||||
<xsl:template match="adl:application">
|
||||
<hibernate-mapping>
|
||||
<xsl:attribute name="namespace">
|
||||
|
@ -53,10 +53,11 @@
|
|||
* THIS FILE IS AUTOMATICALLY GENERATED AND SHOULD NOT
|
||||
* BE MANUALLY EDITED.
|
||||
*
|
||||
* Generated using adl2hibernate-mapping.xsl revision <xsl:value-of select="substring('$Revision: 1.3 $', 12)"/>
|
||||
* Generated using adl2hibernate-mapping.xsl revision <xsl:value-of select="substring('$Revision: 1.4 $', 12)"/>
|
||||
*
|
||||
***************************************************************************
|
||||
</xsl:comment>
|
||||
|
||||
<xsl:apply-templates select="adl:entity"/>
|
||||
</hibernate-mapping>
|
||||
|
||||
|
@ -66,12 +67,27 @@
|
|||
|
||||
<xsl:template match="adl:entity">
|
||||
<xsl:apply-templates select="adl:documentation"/>
|
||||
<xsl:variable name="prefix">
|
||||
<xsl:choose>
|
||||
<xsl:when test="string-length( $database) > 0">
|
||||
<xsl:value-of select="concat( $database, '.dbo.')"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise/>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
<class>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="@name"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="table">
|
||||
<xsl:value-of select="@name"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="@table">
|
||||
<xsl:value-of select="concat( $prefix, '[', @table, ']')"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="concat( $prefix, '[', @name, ']')"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:attribute>
|
||||
<xsl:apply-templates select="adl:key"/>
|
||||
<xsl:apply-templates select="adl:property"/>
|
||||
|
@ -98,16 +114,34 @@
|
|||
</xsl:choose>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="type">
|
||||
<xsl:call-template name="csharp-type">
|
||||
<xsl:call-template name="csharp-base-type">
|
||||
<xsl:with-param name="property" select="adl:property[position()=1]"/>
|
||||
</xsl:call-template>
|
||||
</xsl:attribute>
|
||||
<xsl:apply-templates select="adl:property[position()=1]/adl:generator"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="adl:property[position()=1]/adl:generator">
|
||||
<xsl:apply-templates select="adl:property[position()=1]/adl:generator"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="adl:property[position()=1 and @type='entity']">
|
||||
<generator class="foreign">
|
||||
<param name="property">
|
||||
<xsl:value-of select="adl:property[position()=1]/@name"/>
|
||||
</param>
|
||||
</generator>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:comment>TODO: remember you need to deal with this in manually maintained code</xsl:comment>
|
||||
<generator class="assigned"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</id>
|
||||
<xsl:if test="adl:property[position()=1 and @type='entity']">
|
||||
<xsl:apply-templates select="adl:property[position()=1]"/>
|
||||
</xsl:if>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<composite-id>
|
||||
<xsl:attribute name="name">
|
||||
<!-- xsl:attribute name="name">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$abstract-key-name-convention='Name'">
|
||||
<xsl:value-of select="ancestor::adl:entity/@name"/>
|
||||
|
@ -122,7 +156,7 @@
|
|||
<xsl:value-of select="'Id'"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:attribute>
|
||||
</xsl:attribute -->
|
||||
<xsl:for-each select="adl:property[not(@type='entity')]">
|
||||
<key-property>
|
||||
<xsl:attribute name="name">
|
||||
|
@ -180,25 +214,72 @@
|
|||
stored in the database -->
|
||||
</xsl:template>
|
||||
|
||||
|
||||
|
||||
<xsl:template match="adl:property[@type='entity']">
|
||||
<!-- a property of type entity translates to a Hibernate many-to-one -->
|
||||
<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"/>
|
||||
<!-- 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:when test="parent::adl:key">
|
||||
<one-to-one>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="@name"/>
|
||||
</xsl:attribute>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
<xsl:apply-templates select="adl:documentation"/>
|
||||
</many-to-one>
|
||||
<xsl:attribute name="class">
|
||||
<xsl:value-of select="@entity"/>
|
||||
</xsl:attribute>
|
||||
<!-- no column allowed on one-to-one? xsl:attribute name="column">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@column">
|
||||
<xsl:value-of select="@column"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="@name"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</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"/>
|
||||
</one-to-one>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<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:attribute name="column">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@column">
|
||||
<xsl:value-of select="@column"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="@name"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</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"/>
|
||||
</many-to-one>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="adl:property[@type='list']">
|
||||
|
@ -311,6 +392,16 @@
|
|||
<xsl:with-param name="property" select="."/>
|
||||
</xsl:call-template>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="column">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@column">
|
||||
<xsl:value-of select="@column"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="@name"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:attribute>
|
||||
<xsl:apply-templates select="adl:documentation"/>
|
||||
</property>
|
||||
</xsl:template>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
Convert ADL to MS-SQL
|
||||
|
||||
$Author: sb $
|
||||
$Revision: 1.7 $
|
||||
$Revision: 1.8 $
|
||||
-->
|
||||
|
||||
<xsl:output indent="no" encoding="UTF-8" method="text"/>
|
||||
|
@ -26,17 +26,22 @@
|
|||
Name_Id - the name of the auto generated primary key is the name of the entity followed by '_Id'
|
||||
-->
|
||||
<xsl:param name="abstract-key-name-convention" select="Id"/>
|
||||
<xsl:param name="database"/>
|
||||
|
||||
<xsl:template match="adl:application">
|
||||
-------------------------------------------------------------------------------------------------
|
||||
--
|
||||
-- Database for application <xsl:value-of select="@name"/> version <xsl:value-of select="@version"/>
|
||||
-- Generated for MS-SQL 2000+ using adl2mssql.xsl $Revision: 1.7 $
|
||||
-- Generated for MS-SQL 2000+ using adl2mssql.xsl $Revision: 1.8 $
|
||||
--
|
||||
-- Code generator (c) 2007 Cygnet Solutions Ltd
|
||||
--
|
||||
-------------------------------------------------------------------------------------------------
|
||||
|
||||
<xsl:if test="string-length( $database) > 0">
|
||||
use <xsl:value-of select="$database"/>;
|
||||
</xsl:if>
|
||||
|
||||
-------------------------------------------------------------------------------------------------
|
||||
-- authentication roles
|
||||
-------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
one place for ease of maintenance
|
||||
|
||||
$Author: sb $
|
||||
$Revision: 1.2 $
|
||||
$Date: 2008-02-07 16:35:00 $
|
||||
$Revision: 1.3 $
|
||||
$Date: 2008-02-13 09:52:42 $
|
||||
-->
|
||||
|
||||
<xsl:stylesheet version="1.0"
|
||||
|
@ -22,6 +22,37 @@
|
|||
|
||||
<xsl:include href="base-type-include.xslt"/>
|
||||
|
||||
<!-- return the primitive C# type of the property which is passed as
|
||||
a parameter - i.e. if csharp-type is an entity, then the csharp-type
|
||||
of the keyfield of that entity, and so on. -->
|
||||
<xsl:template name="csharp-base-type">
|
||||
<xsl:param name="property"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$property/@type = 'entity'">
|
||||
<xsl:variable name="entityname" select="$property/@entity"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="//adl:entity[@name=$entityname]/adl:key/adl:property">
|
||||
<!-- recurse... -->
|
||||
<xsl:call-template name="csharp-base-type">
|
||||
<xsl:with-param name="property"
|
||||
select="//adl:entity[@name=$entityname]/adl:key/adl:property[position()=1]"/>
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:message terminate="yes">
|
||||
ADL: ERROR: could not find C# base type of property <xsl:value-of select="$property/@name"/>
|
||||
</xsl:message>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:call-template name="csharp-type">
|
||||
<xsl:with-param name="property" select="$property"/>
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<!-- return the C# type of the property which is passed as a parameter -->
|
||||
<xsl:template name="csharp-type">
|
||||
<xsl:param name="property"/>
|
||||
|
@ -41,7 +72,7 @@
|
|||
<xsl:when test="$base-type = 'time'">DateTime</xsl:when>
|
||||
<xsl:when test="$base-type = 'string'">String</xsl:when>
|
||||
<xsl:when test="$base-type = 'text'">String</xsl:when>
|
||||
<xsl:when test="$base-type = 'boolean'">bool</xsl:when>
|
||||
<xsl:when test="$base-type = 'boolean'">Boolean</xsl:when>
|
||||
<xsl:when test="$base-type = 'timestamp'">DateTime</xsl:when>
|
||||
<xsl:when test="$base-type = 'integer'">int</xsl:when>
|
||||
<xsl:when test="$base-type = 'real'">double</xsl:when>
|
||||
|
|
Loading…
Reference in a new issue