bug 2840 : This one proved to have much more subtlety than one would have expected. Changes to adl2controllerclasses and new support class, LinkTableUpdater, in Cygnet.Utils

This commit is contained in:
sb 2009-04-29 13:58:51 +00:00
parent 97fd52777b
commit e32f089d27

View file

@ -9,8 +9,8 @@
Transform ADL into (partial) controller classes
$Author: sb $
$Revision: 1.37 $
$Date: 2009-04-28 18:27:59 $
$Revision: 1.38 $
$Date: 2009-04-29 13:58:51 $
-->
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -70,7 +70,7 @@
//
// Automatically generated abstract super class for controllers for the
// <xsl:value-of select="/adl:application/@name"/> application; generated using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.38 $', 10)"/>
//
// <xsl:value-of select="/adl:application/@revision"/>
//
@ -180,7 +180,7 @@
//
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
// Automatically generated from application description using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.37 $', 10)"/>
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.38 $', 10)"/>
//
// This file is automatically generated; DO NOT EDIT IT.
//
@ -202,6 +202,7 @@
using Cygnet.Web.Helpers;
using Cygnet.Web.Controllers;
using Cygnet.Web.SmartControls;
using Cygnet.Utility;
using NHibernate;
using NHibernate.Expression;
using Castle.MonoRail.Framework;
@ -470,6 +471,7 @@
</xsl:for-each>
<xsl:for-each select="descendant::adl:property[@type='link']">
<xsl:variable name="nearentityname" select="ancestor::adl:entity/@name"/>
<xsl:variable name="farentityname" select="@entity"/>
<xsl:variable name="entity" select="//adl:entity[@name=$farentityname]"/>
<xsl:variable name="farkey" select="$entity/adl:key/adl:property[position()=1]/@name"/>
@ -483,52 +485,43 @@
<xsl:with-param name="entity" select="$entity"/>
</xsl:call-template>
</xsl:variable>
/* 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! */
/* TODO: 20090427: rewrite so we don't do this - also add changes to 'modified' */
/* For a link, collect changes to link table and process them */
<xsl:if test="$authentication-layer = 'Database'">
if ( <xsl:for-each select="exsl:node-set( $deletegroups)/*">InGroup( "<xsl:value-of select="./@name"/>") ||</xsl:for-each> false) {
/* however, we cannot do anything unless we have delete permissions on the table, so
* should not try. */
</xsl:if>
string[] <xsl:value-of select="concat(@name, 'Values')"/> = Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>");
LinkChanges&lt;<xsl:value-of select="concat( $entityns, '.', @entity)"/>&gt; changes =
LinkTableUpdater&lt;<xsl:value-of select="concat( $entityns, '.', @entity)"/>&gt;.Changes( <xsl:value-of select="concat( 'record.', @name)"/>, Form.GetValues( "<xsl:value-of select="concat( 'instance.', @name)"/>"),
hibernator);
List&lt;Entity&gt; toAdd = new List&lt;Entity&gt;();
List&lt;Entity&gt; toRemove = new List&lt;Entity&gt;();
foreach (<xsl:value-of select="concat( $entityns, '.', @entity)"/> item in <xsl:value-of select="concat( 'record.', @name)"/>) {
foreach (string value in <xsl:value-of select="concat(@name, 'Values')"/>) {
if (item.KeyString.Equals(value)) {
toRemove.Add(item);
break;
}
}
}
foreach (string value in <xsl:value-of select="concat(@name, 'Values')"/>) {
Boolean add = true;
foreach (<xsl:value-of select="concat( $entityns, '.', @entity)"/> item in <xsl:value-of select="concat( 'record.', @name)"/>) {
if (item.KeyString.Equals(value)) {
add = false;
break;
}
}
if (add) {
toAdd.Add(hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', @entity)"/>))
<xsl:call-template name="add-hibernate-expression-eq">
<xsl:with-param name="property" select="//adl:entity[@name=$farentityname]/adl:key/adl:property[position()=1]"/>
<xsl:with-param name="value" select="'value'"/>
</xsl:call-template>
.UniqueResult&lt;<xsl:value-of select="concat( $entityns, '.', @entity)"/>&gt;());
}
}
foreach (<xsl:value-of select="concat( $entityns, '.', @entity)"/> item in toRemove) {
foreach ( var item in changes.ToRemove) {
modified.Add(item);
<xsl:value-of select="concat( 'record.', @name)"/>.Remove(item);
<xsl:for-each select="$entity//adl:property[@type='link' and @entity=$nearentityname]">
<xsl:value-of select="concat( 'item.', @name)"/>.Remove( record);
<xsl:if test="position() != 1">
/* WARNING WARNING WARNING! Could not uniquely determine the far side property;
* redesign your application or manually maintain this code! */
<xsl:message terminate="no">
WARNING: Could not uniquely determine far end of link represented by property <xsl:value-of select="@name"/> of <xsl:value-of select="$nearentityname"/>
</xsl:message>
</xsl:if>
</xsl:for-each>
}
foreach (<xsl:value-of select="concat( $entityns, '.', @entity)"/> item in toAdd) {
foreach ( var item in changes.ToAdd) {
modified.Add(item);
<xsl:value-of select="concat( 'record.', @name)"/>.Add(item);
<xsl:for-each select="$entity//adl:property[@type='link' and @entity=$nearentityname]">
<xsl:value-of select="concat( 'item.', @name)"/>.Add( record);
<xsl:if test="position() != 1">
/* WARNING WARNING WARNING! Could not uniquely determine the far side property;
* redesign your application or manually maintain this code! */
<xsl:message terminate="no">
WARNING: Could not uniquely determine far end of link represented by property <xsl:value-of select="@name"/> of <xsl:value-of select="$nearentityname"/>
</xsl:message>
</xsl:if>
</xsl:for-each>
}
<xsl:if test="$authentication-layer = 'Database'">